Class InstallTask
- java.lang.Object
-
- org.apache.sling.installer.api.tasks.InstallTask
-
- All Implemented Interfaces:
java.lang.Comparable<InstallTask>
- Direct Known Subclasses:
ChangeStateTask
public abstract class InstallTask extends java.lang.Object implements java.lang.Comparable<InstallTask>
Base class for tasks that can be executed by theOsgiInstaller. The task is invoked by the installer through theexecute(InstallationContext)method. During execution the task should use thesetFinishedState(ResourceState)orsetFinishedState(ResourceState, String)method once the task is performed or the task decided that the task can never be performed. If the task needs to be retried, the implementation should just not alter the state at all. The installer will invoke the tasks at a later time again for retrying.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringASYNC_ATTR_NAMEAttribute which is set by the OSGi installer for asynchronous execution.
-
Constructor Summary
Constructors Constructor Description InstallTask(TaskResourceGroup erl)Constructor for the task
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intcompareTo(InstallTask o)All comparisons are based on getSortKey().booleanequals(java.lang.Object o)abstract voidexecute(InstallationContext ctx)This is the heart of the task - it performs the actual task.TaskResourcegetResource()Return the corresponding resource - depending on the task this might be null.TaskResourceGroupgetResourceGroup()Return the corresponding resource - depending on the task this might be null.abstract java.lang.StringgetSortKey()Tasks are sorted according to this key.inthashCode()booleanisAsynchronousTask()If this an asynchronous task it should returntrueThe OSGi installer will set the attributeASYNC_ATTR_NAMEwith an integer value.voidsetFinishedState(ResourceState state)Set the finished state for the resource.voidsetFinishedState(ResourceState state, java.lang.String alias)Set the finished state for the resource and the aliasvoidsetFinishedState(ResourceState state, java.lang.String alias, java.lang.String error)Set the finish state for the active resource and alias (may be null).java.lang.StringtoString()
-
-
-
Field Detail
-
ASYNC_ATTR_NAME
public static final java.lang.String ASYNC_ATTR_NAME
Attribute which is set by the OSGi installer for asynchronous execution. The value of the attribute is an Integer which is increased on each async call, it starts with the value1.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
InstallTask
public InstallTask(TaskResourceGroup erl)
Constructor for the task- Parameters:
erl- The resource group ornull.
-
-
Method Detail
-
getResource
public TaskResource getResource()
Return the corresponding resource - depending on the task this might be null.- Returns:
- The task resource or
null.
-
getResourceGroup
public TaskResourceGroup getResourceGroup()
Return the corresponding resource - depending on the task this might be null.- Returns:
- The task resource group or
null.
-
execute
public abstract void execute(InstallationContext ctx)
This is the heart of the task - it performs the actual task.- Parameters:
ctx- The installation context.
-
getSortKey
public abstract java.lang.String getSortKey()
Tasks are sorted according to this key. Therefore this key must uniquely identify this task. A typical sort key contains the entity id of the resource in execution.- Returns:
- The sorting key.
-
setFinishedState
public void setFinishedState(ResourceState state)
Set the finished state for the resource.- Parameters:
state- The new state.
-
setFinishedState
public void setFinishedState(ResourceState state, java.lang.String alias)
Set the finished state for the resource and the alias- Parameters:
state- The new state.alias- The new alias- Since:
- 1.1
-
setFinishedState
public void setFinishedState(ResourceState state, java.lang.String alias, java.lang.String error)
Set the finish state for the active resource and alias (may be null). In addition set an error text (may benull).- Parameters:
state- The new state.alias- The new alias (may benull).error- An error text (may benull).- Since:
- 1.4
- See Also:
setFinishedState(ResourceState)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public final int compareTo(InstallTask o)
All comparisons are based on getSortKey().- Specified by:
compareToin interfacejava.lang.Comparable<InstallTask>
-
isAsynchronousTask
public boolean isAsynchronousTask()
If this an asynchronous task it should returntrueThe OSGi installer will set the attributeASYNC_ATTR_NAMEwith an integer value. The next time, after the asynchronous task has been run and the OSGi installer has restarted, this attribute will be set on the resource. Asynchronous tasks should only be used for tasks which require the OSGi installer to stop and force it to restart, like a bundle update of the installer itself or a system update. The OSGi installer stops itself for an asynchronous task and is not able to restart itself!- Returns:
- If this is a async request,
trueotherwisefalse - Since:
- 1.3
-
-