Class ThreadTaskPtr


  • public class ThreadTaskPtr
    extends java.lang.Object
    Ptr stores a pointer and optionally takes ownership of the value.
    • Constructor Summary

      Constructors 
      Constructor Description
      ThreadTaskPtr()
      Default constructor yielding a NULL-pointer.
      ThreadTaskPtr​(long cPtr, boolean cMemoryOwn)  
      ThreadTaskPtr​(ThreadTask ptr)
      Do not take ownership of ptr.

      ptr can be null.

      The constructor is implicit on purpose.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ThreadTask __ref__()
      Dereferencing operator.
      boolean addSubTask​(ThreadTaskPtr subtask)
      Add a child task to this task.

      This task will not end before all child tasks has ended.
      Never call execute on the child tasks - they will be executed by the parent task.

      ThreadTaskCPtr cptr()  
      void delete()  
      ThreadTask deref()
      The pointer stored in the object.
      void done()
      Function is executed when work is finished (at this point new subtasks can NOT be
      added).
      boolean equals​(ThreadTask p)  
      boolean execute()
      Start executing the work in this task and all subtasks already added, by using the
      assigned ThreadPool.
      Note: There is no guarantee that the parent run() function starts executing before the
      childrens run() functions.
      static long getCPtr​(ThreadTaskPtr obj)  
      ThreadTask getDeref()
      Member access operator.
      SWIGTYPE_p_std__vectorT_rw__core__Exception_t getException()
      Get a list of exceptions registered in task and subtasks.
      ThreadTask.TaskState getState()
      Get the current state of the task (non-blocking).
      SWIGTYPE_p_std__vectorT_rw__core__PtrT_rw__common__ThreadTask_t_t getSubTasks()
      Get the subtasks currently added to the ThreadTask.
      ThreadPoolPtr getThreadPool()
      Get the ThreadPool that is used by this task currently.

      void idle()
      Function is executed when the task becomes idle (new subtasks can be added in
      this function).
      boolean isNull()
      checks if the pointer is null
      boolean isShared()
      check if this Ptr has shared ownership or none
      ownership
      boolean keepAlive()
      Check is the task has keep alive option enabled.
      void registerFailure​(RWException e)
      Mark the task as a failure by registering an exception.

      The user should override the #subTaskDone function in the parent task to
      either handle the exceptions appropriately or propagate them further on.

      void run()
      Function is the first function executed to do the actual work (new subtasks can
      be added in this function).
      void setKeepAlive​(boolean enable)
      Choose if the thread should exit automatically when all work and children has
      finished (this is the default).

      Remember to set this to false when there is no more work to be done by the task, to allow
      the task to stop.

      boolean setThreadPool​(ThreadPoolPtr pool)
      Set which ThreadPool to use to do the actual execution of work.
      When execution is started the pool can not be changed anymore.
      void subTaskDone​(ThreadTask subtask)
      Function is executed each time a subtask has finished (new subtasks can be added
      in this function).
      ThreadTask.TaskState wait​(ThreadTask.TaskState previous)
      Wait until state of task changes (blocking).

      Remember to check if the new State is the desired (for instance DONE).

      void waitUntilDone()
      Wait until state of task changes to DONE (blocking).
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThreadTaskPtr

        public ThreadTaskPtr​(long cPtr,
                             boolean cMemoryOwn)
      • ThreadTaskPtr

        public ThreadTaskPtr()
        Default constructor yielding a NULL-pointer.
      • ThreadTaskPtr

        public ThreadTaskPtr​(ThreadTask ptr)
        Do not take ownership of ptr.

        ptr can be null.

        The constructor is implicit on purpose.
    • Method Detail

      • delete

        public void delete()
      • deref

        public ThreadTask deref()
        The pointer stored in the object.
      • __ref__

        public ThreadTask __ref__()
        Dereferencing operator.
      • getDeref

        public ThreadTask getDeref()
        Member access operator.
      • equals

        public boolean equals​(ThreadTask p)
      • isShared

        public boolean isShared()
        check if this Ptr has shared ownership or none
        ownership
        Returns:
        true if Ptr has shared ownership, false if it has no ownership.
      • isNull

        public boolean isNull()
        checks if the pointer is null
        Returns:
        Returns true if the pointer is null
      • setThreadPool

        public boolean setThreadPool​(ThreadPoolPtr pool)
        Set which ThreadPool to use to do the actual execution of work.
        When execution is started the pool can not be changed anymore.
        Parameters:
        pool - [in] pointer to the pool
        Returns:
        true if change was successful, false otherwise.
      • getThreadPool

        public ThreadPoolPtr getThreadPool()
        Get the ThreadPool that is used by this task currently.

        Returns:
        pointer to the ThreadPool.
      • run

        public void run()
        Function is the first function executed to do the actual work (new subtasks can
        be added in this function).
      • subTaskDone

        public void subTaskDone​(ThreadTask subtask)
        Function is executed each time a subtask has finished (new subtasks can be added
        in this function). If #registerFailure is used to register failures in subtasks, this
        function should handle or propagate the failures. The default implementation of this
        function is as follows:
        for(const Exception& e : subtask->getExceptions()) { registerFailure(e); }

        Parameters:
        subtask - [in] the subtask that just finished.
      • idle

        public void idle()
        Function is executed when the task becomes idle (new subtasks can be added in
        this function).
      • done

        public void done()
        Function is executed when work is finished (at this point new subtasks can NOT be
        added).
      • execute

        public boolean execute()
        Start executing the work in this task and all subtasks already added, by using the
        assigned ThreadPool.
        Note: There is no guarantee that the parent run() function starts executing before the
        childrens run() functions.
        Returns:
        true if execution started successfully, false if already running or thread has
        finished.
      • wait

        public ThreadTask.TaskState wait​(ThreadTask.TaskState previous)
        Wait until state of task changes (blocking).

        Remember to check if the new State is the desired (for instance DONE).

        Parameters:
        previous - [in] the previous state (wait for changes from this)
        Returns:
        the new TaskState
      • waitUntilDone

        public void waitUntilDone()
        Wait until state of task changes to DONE (blocking).
      • getState

        public ThreadTask.TaskState getState()
        Get the current state of the task (non-blocking).
        Returns:
        the current TaskState.
      • addSubTask

        public boolean addSubTask​(ThreadTaskPtr subtask)
        Add a child task to this task.

        This task will not end before all child tasks has ended.
        Never call execute on the child tasks - they will be executed by the parent task.

        Parameters:
        subtask - the ThreadTask to add as child.
        Returns:
        true if child was added successfully (only if task has not already ended)
      • setKeepAlive

        public void setKeepAlive​(boolean enable)
        Choose if the thread should exit automatically when all work and children has
        finished (this is the default).

        Remember to set this to false when there is no more work to be done by the task, to allow
        the task to stop.

        Parameters:
        enable - [in] true if the thread should NOT finish automatically.
      • keepAlive

        public boolean keepAlive()
        Check is the task has keep alive option enabled.
        Returns:
        true if task should be kept alive, false otherwise.
      • registerFailure

        public void registerFailure​(RWException e)
        Mark the task as a failure by registering an exception.

        The user should override the #subTaskDone function in the parent task to
        either handle the exceptions appropriately or propagate them further on.

        Parameters:
        e - [in] an exception describing the problem.