Class SailPointWorker
- java.lang.Object
 - 
- com.identityworksllc.iiq.common.threads.SailPointWorker
 
 
- 
- All Implemented Interfaces:
 Serializable,Runnable
- Direct Known Subclasses:
 ExportPartition,RuleWorker,TerminatorWorker,ThreadExecutorWorker
public abstract class SailPointWorker extends Object implements Runnable, Serializable
A worker thread for multi-threaded actions.This class can be used with AbstractThreadedObjectIteratorTask to implement a multi-threaded task or with SailPointWorkerExecutor to distribute the workers across the cluster.
If intended for use with a Request, all parts of the subclass, including objects stored in lists, maps, and other structures, must be either Serializable or Externalizable.
- See Also:
 - Serialized Form
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSailPointWorker.ExceptionHandlerAn interface used as an error callback, specifically for use via the SailPointWorkerExecutor but potentially usable by testing code as well. 
- 
Field Summary
Fields Modifier and Type Field Description protected sailpoint.task.TaskMonitormonitorAn instance of the TaskMonitor interfacestatic StringMULTI_SERIALIZED_WORKERS_ATTRThe attribute used to pass this object in serialized form toSailPointWorkerExecutor.protected OutcomeoutcomeAn Outcome object allowing subclasses to provide output 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedSailPointWorker()Constructs a new Worker with the default name (the class + UUID)protectedSailPointWorker(String name)A worker constructor that takes a nameprotectedSailPointWorker(String name, int phase)A worker constructor that takes a nameprotectedSailPointWorker(String name, int phase, int dependentPhase)A worker constructor that takes a name 
- 
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddChild(SailPointWorker childWorker)Adds a child of this task.voidaddDependency(SailPointWorker dependency, Future<?> workerFuture)Adds a dependency Future which will be invoked prior to any child tasks and also this task.voidaddTaskCallback(TaskCallback<SailPointWorker,Object> taskCallback)Adds a task callback, which can be used to receive eventsprotected voidcheckCancel()Checks for any of the abnormal termination states, throwing anCancellationExceptionif one is encountered.abstract Objectexecute(sailpoint.api.SailPointContext context, org.apache.commons.logging.Log logger)Executes this task in a SailPoint context that will be dynamically constructed for it.protected ObjectgetDependencyOutput(String key)Retrieve the output of a dependency (listened-to) or child task of this task.intgetDependentPhase()Returns the dependent phase of this workerSailPointWorker.ExceptionHandlergetExceptionHandler()Gets the exception handler for this workersailpoint.task.TaskMonitorgetMonitor()Gets the monitor associated with this worker (if any)SailPointWorkergetParent()Retrieves the parent task of this oneintgetPhase()Returns the phase of this workerStringgetWorkerName()Returns the name of this worker, which can be used in log messages or as the name of a partitioned request object.booleanisTerminated()Returns true if this worker has been terminated or if it has timed out.booleanisTimedOut()Returns true if this task has timed out.voidrun()Invokes this SailPointWorker by constructing a new private SailPointContext, then invoking the subclass’sexecute(SailPointContext, Log)method, then handling success or failure according to the optional objects.Runnablerunnable()Gets this object as a Runnable, mainly for use with an ExecutorServicevoidsetCompletedCounter(AtomicInteger completedCounter)Set the completed counter on this task and any of its childrenvoidsetDependentPhase(int dependentPhase)Set the dependent phase for this worker.voidsetExceptionHandler(SailPointWorker.ExceptionHandler exceptionHandler)Sets the exception handler for this class.voidsetFailedCounter(AtomicInteger failedCounter)Sets the failure counter that will be incremented on any worker failure.voidsetMonitor(sailpoint.task.TaskMonitor monitor)Sets the TaskMonitor for this worker and its children.protected voidsetParent(SailPointWorker parent)Sets the parent task of this one to the given value.voidsetPhase(int phase)Sets the phase for this worker.voidsetTimeout(int duration, TimeUnit unit)Sets the timeout duration in the specified unit.static Future<?>submitWithListeners(ExecutorService executor, SailPointWorker self, SailPointWorker... listeners)Submits the task to the given executor and returns its future.booleanterminate()Attempts to terminate the workerCallable<Object>toCallable()Returns a Callable object that will implement the logic of this SailPointWorker, properly returning a value or an exception forFuturepurposes.RecursiveTask<List<Object>>toForkJoinTask()Creates a new recursive task from this worker, for use with a ForkJoinPool and a tree of child worker tasks.FutureTask<Object>toFutureTask()Creates a FutureTask wrapping this object as a Callablesailpoint.object.RequesttoRequest(sailpoint.object.RequestDefinition requestDefinition)Serializes this SailPointWorker object into a Request suitable for use withSailPointWorkerExecutor.static sailpoint.object.RequesttoRequest(sailpoint.object.RequestDefinition requestDefinition, List<SailPointWorker> workers)Serializes a list of SailPointWorker object into a Request suitable for use withSailPointWorkerExecutor.StringtoString() 
 - 
 
- 
- 
Field Detail
- 
MULTI_SERIALIZED_WORKERS_ATTR
public static final String MULTI_SERIALIZED_WORKERS_ATTR
The attribute used to pass this object in serialized form toSailPointWorkerExecutor.- See Also:
 - Constant Field Values
 
 
- 
monitor
protected transient sailpoint.task.TaskMonitor monitor
An instance of the TaskMonitor interface 
 - 
 
- 
Constructor Detail
- 
SailPointWorker
protected SailPointWorker()
Constructs a new Worker with the default name (the class + UUID) 
- 
SailPointWorker
protected SailPointWorker(String name)
A worker constructor that takes a name- Parameters:
 name- The worker name
 
- 
SailPointWorker
protected SailPointWorker(String name, int phase)
A worker constructor that takes a name- Parameters:
 name- The worker namephase- The worker phase
 
- 
SailPointWorker
protected SailPointWorker(String name, int phase, int dependentPhase)
A worker constructor that takes a name- Parameters:
 name- The worker namephase- The worker phase
 
 - 
 
- 
Method Detail
- 
submitWithListeners
public static Future<?> submitWithListeners(ExecutorService executor, SailPointWorker self, SailPointWorker... listeners)
Submits the task to the given executor and returns its future.If any listeners are passed, the given task’s Future will be registered with the listeners as a dependency. The listeners will not be able to run until the Future resolves.
- Parameters:
 executor- The executor to submit the task toself- The task to submitlisteners- Any other workers that care about the output of this one- Returns:
 - The Future for this task
 
 
- 
toRequest
public static sailpoint.object.Request toRequest(sailpoint.object.RequestDefinition requestDefinition, List<SailPointWorker> workers) throws sailpoint.tools.GeneralException, IOException
Serializes a list of SailPointWorker object into a Request suitable for use withSailPointWorkerExecutor.That executor must be associated with the provided RequestDefinition.
- Parameters:
 requestDefinition- The request definition associated withSailPointWorkerExecutorworkers- A list of SailPointWorkers to pass to the request handler- Returns:
 - The Request containing a serialized object
 - Throws:
 sailpoint.tools.GeneralException- if any failures occur compressing the objectIOException- if any failures occur serializing thisSailPointWorker
 
- 
addChild
public void addChild(SailPointWorker childWorker)
Adds a child of this task.All child tasks will be resolved before this task runs and their output will be available to this one. This could be used to implement phased execution, for example.
This is NOT the same as a dependency, which is an asynchronous Future that will block until completion.
- Parameters:
 childWorker- The worker to add as a child
 
- 
addDependency
public void addDependency(SailPointWorker dependency, Future<?> workerFuture)
Adds a dependency Future which will be invoked prior to any child tasks and also this task.- Parameters:
 dependency- The dependency task (used to extract the name)workerFuture- The future for that dependency
 
- 
addTaskCallback
public void addTaskCallback(TaskCallback<SailPointWorker,Object> taskCallback)
Adds a task callback, which can be used to receive events- Parameters:
 taskCallback- The task callback
 
- 
checkCancel
protected void checkCancel() throws CancellationException
Checks for any of the abnormal termination states, throwing anCancellationExceptionif one is encountered.Subclasses that are working in a loop should invoke this method routinely and allow the exception to abort whatever loop is being run.
- Throws:
 CancellationException- if this thread should abnormally terminate
 
- 
execute
public abstract Object execute(sailpoint.api.SailPointContext context, org.apache.commons.logging.Log logger) throws Exception
Executes this task in a SailPoint context that will be dynamically constructed for it.A private context and
Logwill be passed to this method.- Parameters:
 context- The private context to use for this thread workerlogger- The log attached to this Worker- Returns:
 - any object, which will be ignored
 - Throws:
 Exception- any exception, which will be logged
 
- 
getDependencyOutput
protected Object getDependencyOutput(String key)
Retrieve the output of a dependency (listened-to) or child task of this task.- Parameters:
 key- The name of the child worker- Returns:
 - The output
 
 
- 
getDependentPhase
public int getDependentPhase()
Returns the dependent phase of this worker- Returns:
 - The dependent phase
 
 
- 
getExceptionHandler
public SailPointWorker.ExceptionHandler getExceptionHandler()
Gets the exception handler for this worker- Returns:
 - The exception handler for this worker
 
 
- 
getMonitor
public sailpoint.task.TaskMonitor getMonitor()
Gets the monitor associated with this worker (if any)- Returns:
 - The monitor, which may be null
 
 
- 
getParent
public SailPointWorker getParent()
Retrieves the parent task of this one- Returns:
 - The parent task
 
 
- 
getPhase
public int getPhase()
Returns the phase of this worker- Returns:
 - The phase of this worker
 
 
- 
getWorkerName
public String getWorkerName()
Returns the name of this worker, which can be used in log messages or as the name of a partitioned request object.By default, this is generated from the name of this concrete class (your subclass) and a random UUID.
Override this method to provide your own more sensible naming scheme.
- Returns:
 - The worker name
 
 
- 
isTerminated
public boolean isTerminated()
Returns true if this worker has been terminated or if it has timed out. 
- 
isTimedOut
public boolean isTimedOut()
Returns true if this task has timed out.- Returns:
 - True if this task has timed out.
 
 
- 
run
public void run()
Invokes this SailPointWorker by constructing a new private SailPointContext, then invoking the subclass’sexecute(SailPointContext, Log)method, then handling success or failure according to the optional objects.The subclass is responsible for logging and rethrowing any exceptions if a failure is to be counted.
 
- 
runnable
public final Runnable runnable()
Gets this object as a Runnable, mainly for use with an ExecutorService- Returns:
 - This object as a Runnable
 
 
- 
setCompletedCounter
public void setCompletedCounter(AtomicInteger completedCounter)
Set the completed counter on this task and any of its children- Parameters:
 completedCounter- The completed counter
 
- 
setDependentPhase
public void setDependentPhase(int dependentPhase)
Set the dependent phase for this worker.This is only useful if running the worker as a partitioned Request.
- Parameters:
 dependentPhase- The completed counter
 
- 
setExceptionHandler
public void setExceptionHandler(SailPointWorker.ExceptionHandler exceptionHandler)
Sets the exception handler for this class.- Parameters:
 exceptionHandler- The exception handler
 
- 
setFailedCounter
public void setFailedCounter(AtomicInteger failedCounter)
Sets the failure counter that will be incremented on any worker failure.- Parameters:
 failedCounter- The failed counter
 
- 
setMonitor
public void setMonitor(sailpoint.task.TaskMonitor monitor)
Sets the TaskMonitor for this worker and its children.This will be set by the SPW request executor, among other places.
- Parameters:
 monitor- The task monitor
 
- 
setParent
protected void setParent(SailPointWorker parent)
Sets the parent task of this one to the given value.This can be null
- Parameters:
 parent- The parent task
 
- 
setTimeout
public void setTimeout(int duration, TimeUnit unit)
Sets the timeout duration in the specified unit. 
- 
setPhase
public void setPhase(int phase)
Sets the phase for this worker.This is only useful if running as a
Request.- Parameters:
 phase- The phase number for this worker
 
- 
terminate
public boolean terminate()
Attempts to terminate the worker- Returns:
 - True, only to satisfy the Terminable interface
 
 
- 
toCallable
public Callable<Object> toCallable()
Returns a Callable object that will implement the logic of this SailPointWorker, properly returning a value or an exception forFuturepurposes.This is used mainly because
ExecutorService.submit(Runnable)gets messy if the same object implements both Runnable and Callable. This must also be used if you want to chain workers usingFutureand the dependency function. 
- 
toForkJoinTask
public RecursiveTask<List<Object>> toForkJoinTask()
Creates a new recursive task from this worker, for use with a ForkJoinPool and a tree of child worker tasks.- Returns:
 - The recursive task
 
 
- 
toFutureTask
public FutureTask<Object> toFutureTask()
Creates a FutureTask wrapping this object as a Callable- Returns:
 - The FutureTask
 
 
- 
toRequest
public sailpoint.object.Request toRequest(sailpoint.object.RequestDefinition requestDefinition) throws sailpoint.tools.GeneralException, IOException
Serializes this SailPointWorker object into a Request suitable for use withSailPointWorkerExecutor.That executor must be associated with the provided RequestDefinition.
- Parameters:
 requestDefinition- The request definition associated withSailPointWorkerExecutor- Returns:
 - The Request containing a serialized object
 - Throws:
 sailpoint.tools.GeneralException- if any failures occur compressing the objectIOException- if any failures occur serializing thisSailPointWorker
 
- 
toString
public String toString()
- Overrides:
 toStringin classObject- See Also:
 Object.toString()
 
 - 
 
 -