Class SailPointWorker

    • 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 name
        phase - The worker phase
      • SailPointWorker

        protected SailPointWorker​(String name,
                                  int phase,
                                  int dependentPhase)
        A worker constructor that takes a name
        Parameters:
        name - The worker name
        phase - 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 to
        self - The task to submit
        listeners - 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 with SailPointWorkerExecutor.

        That executor must be associated with the provided RequestDefinition.

        Parameters:
        requestDefinition - The request definition associated with SailPointWorkerExecutor
        workers - 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 object
        IOException - if any failures occur serializing this SailPointWorker
      • 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
      • checkCancel

        protected void checkCancel()
                            throws CancellationException
        Checks for any of the abnormal termination states, throwing an CancellationException if 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 Log will be passed to this method.

        Parameters:
        context - The private context to use for this thread worker
        logger - 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
      • getMonitor

        public sailpoint.task.TaskMonitor getMonitor()
        Gets the monitor associated with this worker (if any)
        Returns:
        The monitor, which may be null
      • 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’s execute(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.

        Specified by:
        run in interface Runnable
      • 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
      • 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<ObjecttoCallable()
        Returns a Callable object that will implement the logic of this SailPointWorker, properly returning a value or an exception for Future purposes.

        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 using Future and 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
      • 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 with SailPointWorkerExecutor.

        That executor must be associated with the provided RequestDefinition.

        Parameters:
        requestDefinition - The request definition associated with SailPointWorkerExecutor
        Returns:
        The Request containing a serialized object
        Throws:
        sailpoint.tools.GeneralException - if any failures occur compressing the object
        IOException - if any failures occur serializing this SailPointWorker