Class CurrentTaskFuture

  • All Implemented Interfaces:
    java.util.concurrent.Future<java.lang.Object>, ChangeableRunLevelFuture, RunLevelFuture

    public class CurrentTaskFuture
    extends java.lang.Object
    implements ChangeableRunLevelFuture
    This is the implementation of RunLevelFuture. There should only be one of these active in the system at any time. Of course users are given a handle to this object, so they can hold onto references to it for as long as they'd like.
    • Constructor Detail

      • CurrentTaskFuture

        CurrentTaskFuture​(AsyncRunLevelContext asyncContext,
                          java.util.concurrent.Executor executor,
                          ServiceLocator locator,
                          int proposedLevel,
                          int maxThreads,
                          boolean useThreads,
                          long cancelTimeout,
                          java.util.Timer timer)
    • Method Detail

      • go

        void go()
      • isUp

        public boolean isUp()
        Description copied from interface: RunLevelFuture
        Returns true if this job represents the system going from a lower level to a higher level. This method and isDown can both be false (for the case that proceedTo asked to go to the level it is already at) but they cannot both be true
        Specified by:
        isUp in interface RunLevelFuture
        Returns:
        true if this job was proceeding from a lower level to a higher level
      • isDown

        public boolean isDown()
        Description copied from interface: RunLevelFuture
        Returns true if this job represents the system going from a higher level to a lower level. This method and isUp can both be false (for the case that proceedTo asked to go to the level it is already at) but they cannot both be true
        Specified by:
        isDown in interface RunLevelFuture
        Returns:
        true if this job was proceeding from a higher level to a lower level
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Description copied from interface: RunLevelFuture
        The cancel method attempts to cancel the current running job (if the job is not already completed or already cancelled). The meaning of cancel is different depending on whether or not the system was going up to a level or coming down to a level.

        If the system was going up to a level then calling cancel will cause the system to stop going up, and instead proceed back down to the last completed level. For example, suppose there were three services at level ten and the system was going up to level ten. As the system was proceeding up to level ten the first of the three services had already been started and the second service was in progress and the third service had not been started. The system will wait for the second service to complete coming up and then will shut it down along with the first service. Since the last completed level was nine, the system will remain at level nine and this job will be complete.

        If the system was going down to a level then calling cancel will cause the system to continue going down, but it will stop going down at the next level. For example, suppose there were three services at level ten and the current proposed level is five. Suppose one of those three services had already been shutdown and one was in the process of being shutdown and the other had not yet been shutdown when the cancel arrives. The system will continue to shutdown the one in progress and then will shutdown the remaining service at level ten to reach level nine. However, the job will no longer attempt to go down to level five, but will instead be finished at level nine.

        There is a cancel timeout value that is set. This is the amount of time the system will wait for services to complete after cancel has been called. Any services still running after this timeout will be orphaned (they will not be shutdown if they do eventually complete). Further, if an attempt is made to start the same service that is still running on another thread that request will fail.

        Specified by:
        cancel in interface java.util.concurrent.Future<java.lang.Object>
        Specified by:
        cancel in interface RunLevelFuture
        Parameters:
        mayInterruptIfRunning - is currently ignored
      • isCancelled

        public boolean isCancelled()
        Specified by:
        isCancelled in interface java.util.concurrent.Future<java.lang.Object>
      • isDone

        public boolean isDone()
        Specified by:
        isDone in interface java.util.concurrent.Future<java.lang.Object>
      • getProposedLevel

        public int getProposedLevel()
        Description copied from interface: RunLevelFuture
        This gets the level that this future job is attempting to get to
        Specified by:
        getProposedLevel in interface RunLevelFuture
        Returns:
        The level that this future job is attempting to go to
      • setInCallback

        private void setInCallback​(boolean inCallback)
      • get

        public java.lang.Object get()
                             throws java.lang.InterruptedException,
                                    java.util.concurrent.ExecutionException
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Object>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public java.lang.Object get​(long timeout,
                                    java.util.concurrent.TimeUnit unit)
                             throws java.lang.InterruptedException,
                                    java.util.concurrent.ExecutionException,
                                    java.util.concurrent.TimeoutException
        Specified by:
        get in interface java.util.concurrent.Future<java.lang.Object>
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • isWouldBlock

        static final boolean isWouldBlock​(java.lang.Throwable th)
      • isWasCancelled

        private static final boolean isWasCancelled​(java.lang.Throwable th)
      • isACertainException

        private static final boolean isACertainException​(java.lang.Throwable th,
                                                         java.lang.Class<? extends java.lang.Throwable> type)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object