@Contract public interface RunLevelController
RunLevel
scope. All
services annotated with a RunLevel
equal to
or less than the current level of the system will be
started. All services annotated with a RunLevel
higher than the current level of the system will not
be started. This service can be used to change the
current level of the system.
Whether or not separate threads are used by the RunLevelController is a policy set by the caller. By default the RunLevelController will use as many threads as there are services to be started at a particular level. So if your system has possibly hundreds of services at some level, you will probably want to set your maximum number of threads to some reasonable number. You can also change your threading policy to USE_NO_THREADS, in which case the RunLevelController will not spawn any threads at all, but will instead use the thread of the caller to perform all work. In this mode the Async API will throw an exception.
The RunLevelController starts at level -2. The reasoning behind this is to allow two "immediate" levels. The first thing a system might do is proceed to level 0 (running all services at level -1 and 0). Thereafter the system may go up and down in levels, never going below zero. Note this is only a convention, and individual systems can choose other meanings for the levels -1 and 0.
Modifier and Type | Interface and Description |
---|---|
static class |
RunLevelController.ThreadingPolicy
These are the policies for how the RunLevelController
will use threads
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
If there is a current procedure in process this method will get it
and cancel it
|
long |
getCancelTimeoutMilliseconds()
Returns the amount of time in milliseconds
the run level service will
wait after a cancel call before orphaning
services that have not yet completed execution
|
RunLevelFuture |
getCurrentProceeding()
This method will return the current proceedTo that the RunLevelController
is working on, or it will return null if the controller is not currently
moving up or down
|
int |
getCurrentRunLevel()
The current run level state.
|
Executor |
getExecutor()
Gets the executor that will be used by the system
when executing tasks.
|
int |
getMaximumUseableThreads()
Returns the current number of maximum useable threads
|
RunLevelController.ThreadingPolicy |
getThreadingPolicy()
Returns the threading policy currently being used by
this controller
|
Integer |
getValidationOverride()
Returns the override value for the
RunLevel.mode() field
in RunLevel services. |
void |
proceedTo(int runLevel)
This method will move to the given run level synchronously as per
proceedToAsync(int) . |
RunLevelFuture |
proceedToAsync(int runLevel)
Causes this RunLevelController to move to the specified run level for
all
RunLevel instances, orchestrating the appropriate
lifecycle events. |
void |
setCancelTimeoutMilliseconds(long cancelTimeout)
Sets the amount of time in milliseconds
the run level service will
wait after a cancel call before orphaning
services that have not yet completed execution
|
void |
setExecutor(Executor executor)
Sets the executor to use for the next job.
|
void |
setMaximumUseableThreads(int maximumThreads)
This sets the maximum number of threads that the system
can create for creation and/or destruction of threads.
|
void |
setThreadingPolicy(RunLevelController.ThreadingPolicy policy)
Sets the threading policy that will be used by
this controller.
|
void |
setValidationOverride(Integer validationMode)
Sets the override value for the
RunLevel.mode() field
in RunLevel services. |
RunLevelFuture proceedToAsync(int runLevel) throws CurrentlyRunningException, IllegalStateException
RunLevel
instances, orchestrating the appropriate
lifecycle events.
If the run level specified is the same as the current run level then the RunLevelController may return immediately
runLevel
- the run level to move toCurrentlyRunningException
- if there is currently a job running
this exception will be thrown with the currently running jobIllegalStateException
- if this method is called when the
USE_NO_THREADS policy is in effectvoid proceedTo(int runLevel) throws CurrentlyRunningException
proceedToAsync(int)
.runLevel
- The level that should be proceeded toCurrentlyRunningException
- if there is an already running
job in progressRunLevelFuture getCurrentProceeding()
void cancel()
int getCurrentRunLevel()
void setMaximumUseableThreads(int maximumThreads)
maximumThreads
- The maximum number of threads that
can be used by the system for creation or destruction of
servicesint getMaximumUseableThreads()
void setThreadingPolicy(RunLevelController.ThreadingPolicy policy)
policy
- The policy that should be used by this controllerRunLevelController.ThreadingPolicy getThreadingPolicy()
void setExecutor(Executor executor)
executor
- The executor to use for the
next job. If null a default executor will
be usedExecutor getExecutor()
long getCancelTimeoutMilliseconds()
void setCancelTimeoutMilliseconds(long cancelTimeout)
The default value is 5000 (5 seconds). In general this value should be set to be longer than than the running time of the longest service that may be cancelled
cancelTimeout
- The amount of time in milliseconds that cancel
will wait for running services. Must be greater than 0Integer getValidationOverride()
RunLevel.mode()
field
in RunLevel services. If this value is non-null then the mode will
be forced to this value. This is useful in testing scenarios where
the test would like to instantiate a run-level service without having
to instantiate all the others at a certain levelRunLevel.mode()
value should bevoid setValidationOverride(Integer validationMode)
RunLevel.mode()
field
in RunLevel services. If this value is non-null then the mode will
be forced to this value. This is useful in testing scenarios where
the test would like to instantiate a run-level service without having
to instantiate all the others at a certain levelvalidationMode
- null if there is no override or the value that the
RunLevel.mode()
value should beCopyright © 2009-2017, Oracle and/or its affiliates. All Rights Reserved.