Class CurrentTaskFuture
- All Implemented Interfaces:
Future<Object>
,ChangeableRunLevelFuture
,RunLevelFuture
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interface
private static class
private class
Goes down all the way to the proposed levelprivate static class
private static class
private static class
private class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<ServiceHandle<RunLevelListener>> private final List
<ServiceHandle<ProgressStartedListener>> private final List
<ServiceHandle<Sorter>> private final AsyncRunLevelContext
private boolean
private final long
private boolean
private CurrentTaskFuture.DownAllTheWay
private final Executor
private boolean
private final ServiceLocator
private final int
private int
private final Timer
private CurrentTaskFuture.UpAllTheWay
private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionCurrentTaskFuture
(AsyncRunLevelContext asyncContext, Executor executor, ServiceLocator locator, int proposedLevel, int maxThreads, boolean useThreads, long cancelTimeout, Timer timer) -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.get()
int
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, List<ServiceHandle<RunLevelListener>> listeners) private static ErrorInformation
invokeOnError
(CurrentTaskFuture job, Throwable th, ErrorInformation.ErrorAction action, List<ServiceHandle<RunLevelListener>> listeners, Descriptor descriptor) private void
invokeOnProgress
(ChangeableRunLevelFuture job, int level, List<ServiceHandle<RunLevelListener>> listeners) private void
invokeOnProgressStarted
(ChangeableRunLevelFuture job, int level, List<ServiceHandle<ProgressStartedListener>> listeners) private static final boolean
isACertainException
(Throwable th, Class<? extends Throwable> type) boolean
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 final boolean
(package private) static final boolean
private void
setInCallback
(boolean inCallback) toString()
-
Field Details
-
asyncContext
-
executor
-
locator
-
proposedLevel
private int proposedLevel -
useThreads
private final boolean useThreads -
allListenerHandles
-
allProgressStartedHandles
-
allSorterHandles
-
maxThreads
private final int maxThreads -
timer
-
cancelTimeout
private final long cancelTimeout -
upAllTheWay
-
downAllTheWay
-
done
private boolean done -
cancelled
private boolean cancelled -
inCallback
private boolean inCallback
-
-
Constructor Details
-
CurrentTaskFuture
CurrentTaskFuture(AsyncRunLevelContext asyncContext, Executor executor, ServiceLocator locator, int proposedLevel, int maxThreads, boolean useThreads, long cancelTimeout, Timer timer)
-
-
Method Details
-
go
void go() -
go
private void go(CurrentTaskFuture.UpAllTheWay localUpAllTheWay, CurrentTaskFuture.DownAllTheWay localDownAllTheWay) -
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 interfaceRunLevelFuture
- 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 interfaceRunLevelFuture
- 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 interfaceFuture<Object>
- Specified by:
cancel
in interfaceRunLevelFuture
- Parameters:
mayInterruptIfRunning
- is currently ignored
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<Object>
-
isDone
public boolean isDone() -
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 interfaceRunLevelFuture
- Returns:
- The level that this future job is attempting to go to
-
changeProposedLevel
public int changeProposedLevel(int proposedLevel) Description copied from interface:ChangeableRunLevelFuture
Changes the proposedLevel of this future. A future cannot have its level changed if it is doneThis method may be called from the
RunLevelListener.onProgress(ChangeableRunLevelFuture, int)
callback- Specified by:
changeProposedLevel
in interfaceChangeableRunLevelFuture
- Parameters:
proposedLevel
- The new proposed level- Returns:
- The old proposed level
-
setInCallback
private void setInCallback(boolean inCallback) -
get
- Specified by:
get
in interfaceFuture<Object>
- Throws:
InterruptedException
ExecutionException
-
get
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<Object>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
invokeOnProgress
private void invokeOnProgress(ChangeableRunLevelFuture job, int level, List<ServiceHandle<RunLevelListener>> listeners) -
invokeOnProgressStarted
private void invokeOnProgressStarted(ChangeableRunLevelFuture job, int level, List<ServiceHandle<ProgressStartedListener>> listeners) -
invokeOnCancelled
private static void invokeOnCancelled(CurrentTaskFuture job, int levelAchieved, List<ServiceHandle<RunLevelListener>> listeners) -
invokeOnError
private static ErrorInformation invokeOnError(CurrentTaskFuture job, Throwable th, ErrorInformation.ErrorAction action, List<ServiceHandle<RunLevelListener>> listeners, Descriptor descriptor) -
isWouldBlock
-
isWasCancelled
-
isACertainException
-
toString
-