public class CurrentTaskFuture extends java.lang.Object implements ChangeableRunLevelFuture
Modifier and Type | Class and Description |
---|---|
private static interface |
CurrentTaskFuture.AllTheWay |
private static class |
CurrentTaskFuture.CancelTimer |
private class |
CurrentTaskFuture.DownAllTheWay
Goes down all the way to the proposed level
|
private static class |
CurrentTaskFuture.DownQueueRunner |
private static class |
CurrentTaskFuture.HardCancelDownTimer |
private static class |
CurrentTaskFuture.QueueRunner |
private class |
CurrentTaskFuture.UpAllTheWay |
private class |
CurrentTaskFuture.UpOneLevel |
Modifier and Type | Field and Description |
---|---|
private java.util.List<ServiceHandle<RunLevelListener>> |
allListenerHandles |
private java.util.List<ServiceHandle<ProgressStartedListener>> |
allProgressStartedHandles |
private java.util.List<ServiceHandle<Sorter>> |
allSorterHandles |
private AsyncRunLevelContext |
asyncContext |
private boolean |
cancelled |
private long |
cancelTimeout |
private boolean |
done |
private CurrentTaskFuture.DownAllTheWay |
downAllTheWay |
private java.util.concurrent.Executor |
executor |
private boolean |
inCallback |
private ServiceLocator |
locator |
private int |
maxThreads |
private int |
proposedLevel |
private java.util.Timer |
timer |
private CurrentTaskFuture.UpAllTheWay |
upAllTheWay |
private boolean |
useThreads |
Constructor and Description |
---|
CurrentTaskFuture(AsyncRunLevelContext asyncContext,
java.util.concurrent.Executor executor,
ServiceLocator locator,
int proposedLevel,
int maxThreads,
boolean useThreads,
long cancelTimeout,
java.util.Timer timer) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
The cancel method attempts to cancel the current running
job (if the job is not already completed or already cancelled).
|
int |
changeProposedLevel(int proposedLevel)
Changes the proposedLevel of this future.
|
java.lang.Object |
get() |
java.lang.Object |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
int |
getProposedLevel()
This gets the level that this future job is attempting
to get to
|
(package private) void |
go() |
private void |
go(CurrentTaskFuture.UpAllTheWay localUpAllTheWay,
CurrentTaskFuture.DownAllTheWay localDownAllTheWay) |
private static void |
invokeOnCancelled(CurrentTaskFuture job,
int levelAchieved,
java.util.List<ServiceHandle<RunLevelListener>> listeners) |
private static ErrorInformation |
invokeOnError(CurrentTaskFuture job,
java.lang.Throwable th,
ErrorInformation.ErrorAction action,
java.util.List<ServiceHandle<RunLevelListener>> listeners,
Descriptor descriptor) |
private void |
invokeOnProgress(ChangeableRunLevelFuture job,
int level,
java.util.List<ServiceHandle<RunLevelListener>> listeners) |
private void |
invokeOnProgressStarted(ChangeableRunLevelFuture job,
int level,
java.util.List<ServiceHandle<ProgressStartedListener>> listeners) |
private static boolean |
isACertainException(java.lang.Throwable th,
java.lang.Class<? extends java.lang.Throwable> type) |
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isDown()
Returns true if this job represents the system going from
a higher level to a lower level.
|
boolean |
isUp()
Returns true if this job represents the system going from
a lower level to a higher level.
|
private static boolean |
isWasCancelled(java.lang.Throwable th) |
(package private) static boolean |
isWouldBlock(java.lang.Throwable th) |
private void |
setInCallback(boolean inCallback) |
java.lang.String |
toString() |
private final AsyncRunLevelContext asyncContext
private final java.util.concurrent.Executor executor
private final ServiceLocator locator
private int proposedLevel
private final boolean useThreads
private final java.util.List<ServiceHandle<RunLevelListener>> allListenerHandles
private final java.util.List<ServiceHandle<ProgressStartedListener>> allProgressStartedHandles
private final java.util.List<ServiceHandle<Sorter>> allSorterHandles
private final int maxThreads
private final java.util.Timer timer
private final long cancelTimeout
private CurrentTaskFuture.UpAllTheWay upAllTheWay
private CurrentTaskFuture.DownAllTheWay downAllTheWay
private boolean done
private boolean cancelled
private boolean inCallback
CurrentTaskFuture(AsyncRunLevelContext asyncContext, java.util.concurrent.Executor executor, ServiceLocator locator, int proposedLevel, int maxThreads, boolean useThreads, long cancelTimeout, java.util.Timer timer)
void go()
private void go(CurrentTaskFuture.UpAllTheWay localUpAllTheWay, CurrentTaskFuture.DownAllTheWay localDownAllTheWay)
public boolean isUp()
RunLevelFuture
isUp
in interface RunLevelFuture
public boolean isDown()
RunLevelFuture
isDown
in interface RunLevelFuture
public boolean cancel(boolean mayInterruptIfRunning)
RunLevelFuture
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.
cancel
in interface java.util.concurrent.Future<java.lang.Object>
cancel
in interface RunLevelFuture
mayInterruptIfRunning
- is currently ignoredpublic boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<java.lang.Object>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<java.lang.Object>
public int getProposedLevel()
RunLevelFuture
getProposedLevel
in interface RunLevelFuture
public int changeProposedLevel(int proposedLevel)
ChangeableRunLevelFuture
This method may be called from the RunLevelListener.onProgress(ChangeableRunLevelFuture, int)
callback
changeProposedLevel
in interface ChangeableRunLevelFuture
proposedLevel
- The new proposed levelprivate void setInCallback(boolean inCallback)
public java.lang.Object get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<java.lang.Object>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public java.lang.Object get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
get
in interface java.util.concurrent.Future<java.lang.Object>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
private void invokeOnProgress(ChangeableRunLevelFuture job, int level, java.util.List<ServiceHandle<RunLevelListener>> listeners)
private void invokeOnProgressStarted(ChangeableRunLevelFuture job, int level, java.util.List<ServiceHandle<ProgressStartedListener>> listeners)
private static void invokeOnCancelled(CurrentTaskFuture job, int levelAchieved, java.util.List<ServiceHandle<RunLevelListener>> listeners)
private static ErrorInformation invokeOnError(CurrentTaskFuture job, java.lang.Throwable th, ErrorInformation.ErrorAction action, java.util.List<ServiceHandle<RunLevelListener>> listeners, Descriptor descriptor)
static final boolean isWouldBlock(java.lang.Throwable th)
private static final boolean isWasCancelled(java.lang.Throwable th)
private static final boolean isACertainException(java.lang.Throwable th, java.lang.Class<? extends java.lang.Throwable> type)
public java.lang.String toString()
toString
in class java.lang.Object