Class BasicTaskWrapper

  • All Implemented Interfaces:
    java.lang.Runnable, TaskWrapper

    public class BasicTaskWrapper
    extends java.lang.Object
    implements TaskWrapper
    A wrapper for the task.
    Version:
    $Revision$
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BasicTaskWrapper()
      Create a task wrapper without a task
        BasicTaskWrapper​(Task task)
      Create a new task wrapper
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acceptTask()
      The task has been accepted
      protected long getElapsedTime()
      Calculate the elapsed time since the task was started
      protected java.lang.String getStateString()
      Get the state as a string
      long getTaskCompletionTimeout()
      The time before the task must be completed
      int getTaskPriority()
      The priority of the task
      long getTaskStartTimeout()
      The time before the task must be accepted
      int getTaskWaitType()
      Get the type of wait
      boolean isComplete()
      Is the task complete.
      void rejectTask​(java.lang.RuntimeException e)
      The task has been rejected
      void run()
      Called by the thread pool executor
      protected void setTask​(Task task)
      Set thetask for this wrapper
      void stopTask()
      Invoked by the threadpool when it wants to stop the task
      protected boolean taskAccepted()
      Notify the task it has been accepted
      protected boolean taskCompleted​(java.lang.Throwable throwable)
      Notify the task it has completed
      protected boolean taskRejected​(java.lang.RuntimeException e)
      Notify the task it has been rejected
      protected boolean taskStarted()
      Notify the task it has started
      protected boolean taskStop()
      Stop the task
      void waitForTask()
      Wait according the wait type
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static final org.jboss.logging.Logger log
        The log
      • TASK_NOT_ACCEPTED

        public static final int TASK_NOT_ACCEPTED
        The task has not been accepted
        See Also:
        Constant Field Values
      • TASK_ACCEPTED

        public static final int TASK_ACCEPTED
        The task has been accepted
        See Also:
        Constant Field Values
      • TASK_STARTED

        public static final int TASK_STARTED
        The task has been started
        See Also:
        Constant Field Values
      • TASK_COMPLETED

        public static final int TASK_COMPLETED
        The task has completed
        See Also:
        Constant Field Values
      • TASK_REJECTED

        public static final int TASK_REJECTED
        The task was rejected
        See Also:
        Constant Field Values
      • TASK_STOPPED

        public static final int TASK_STOPPED
        The task has been stopped
        See Also:
        Constant Field Values
      • state

        private int state
        The state of the task
      • stateLock

        private java.lang.Object stateLock
        The state lock
      • task

        private Task task
        The task
      • taskString

        private java.lang.String taskString
        The task as a string
      • startTime

        private long startTime
        The start time
      • startTimeout

        private long startTimeout
        The start timeout
      • completionTimeout

        private long completionTimeout
        The completion timeout
      • priority

        private int priority
        The priority
      • waitType

        private int waitType
        The wait type
      • runThread

        private java.lang.Thread runThread
        The thread
    • Constructor Detail

      • BasicTaskWrapper

        protected BasicTaskWrapper()
        Create a task wrapper without a task
      • BasicTaskWrapper

        public BasicTaskWrapper​(Task task)
        Create a new task wrapper
        Parameters:
        task - the task
        Throws:
        java.lang.IllegalArgumentException - for a null task
    • Method Detail

      • getTaskWaitType

        public int getTaskWaitType()
        Description copied from interface: TaskWrapper
        Get the type of wait
        Specified by:
        getTaskWaitType in interface TaskWrapper
        Returns:
        the wait type
      • getTaskPriority

        public int getTaskPriority()
        Description copied from interface: TaskWrapper
        The priority of the task
        Specified by:
        getTaskPriority in interface TaskWrapper
        Returns:
        the task priority
      • getTaskStartTimeout

        public long getTaskStartTimeout()
        Description copied from interface: TaskWrapper
        The time before the task must be accepted
        Specified by:
        getTaskStartTimeout in interface TaskWrapper
        Returns:
        the start timeout
      • getTaskCompletionTimeout

        public long getTaskCompletionTimeout()
        Description copied from interface: TaskWrapper
        The time before the task must be completed
        Specified by:
        getTaskCompletionTimeout in interface TaskWrapper
        Returns:
        the completion timeout
      • acceptTask

        public void acceptTask()
        Description copied from interface: TaskWrapper
        The task has been accepted
        Specified by:
        acceptTask in interface TaskWrapper
      • rejectTask

        public void rejectTask​(java.lang.RuntimeException e)
        Description copied from interface: TaskWrapper
        The task has been rejected
        Specified by:
        rejectTask in interface TaskWrapper
        Parameters:
        e - any error associated with the rejection
      • isComplete

        public boolean isComplete()
        Description copied from interface: TaskWrapper
        Is the task complete.
        Specified by:
        isComplete in interface TaskWrapper
        Returns:
        true if compelet, false otherwise
      • stopTask

        public void stopTask()
        Description copied from interface: TaskWrapper
        Invoked by the threadpool when it wants to stop the task
        Specified by:
        stopTask in interface TaskWrapper
      • waitForTask

        public void waitForTask()
        Description copied from interface: TaskWrapper
        Wait according the wait type
        Specified by:
        waitForTask in interface TaskWrapper
      • run

        public void run()
        Called by the thread pool executor
        Specified by:
        run in interface java.lang.Runnable
      • setTask

        protected void setTask​(Task task)
        Set thetask for this wrapper
        Parameters:
        task - the task
      • taskAccepted

        protected boolean taskAccepted()
        Notify the task it has been accepted
        Returns:
        true when the notification succeeds, false otherwise
      • taskRejected

        protected boolean taskRejected​(java.lang.RuntimeException e)
        Notify the task it has been rejected
        Parameters:
        e - any error associated with the rejection
        Returns:
        true when the notification succeeds, false otherwise
      • taskStarted

        protected boolean taskStarted()
        Notify the task it has started
        Returns:
        true when the notification succeeds, false otherwise
      • taskCompleted

        protected boolean taskCompleted​(java.lang.Throwable throwable)
        Notify the task it has completed
        Parameters:
        throwable - any throwable associated with the completion
        Returns:
        true when the notification succeeds, false otherwise
      • taskStop

        protected boolean taskStop()
        Stop the task
        Returns:
        true when the notification succeeds, false otherwise
      • getElapsedTime

        protected long getElapsedTime()
        Calculate the elapsed time since the task was started
        Returns:
        the elapsed time in millis
      • getStateString

        protected java.lang.String getStateString()
        Get the state as a string
        Returns:
        the state string