public final class StabilityMonitor
extends java.lang.Object
StabilityMonitor are in REST state.
The following controller substates are considered to be in REST state:
ServiceController.Substate.NEWServiceController.Substate.CANCELLEDServiceController.Substate.WAITINGServiceController.Substate.WONT_STARTServiceController.Substate.PROBLEMServiceController.Substate.START_FAILEDServiceController.Substate.UPServiceController.Substate.REMOVED
Set<ServiceController<?>> controllers = ...
StabilityMonitor monitor = new StabilityMonitor();
for (ServiceController<?> controller : controllers) {
monitor.addController(controller);
}
try {
monitor.awaitStability();
} finally {
monitor.clear();
// since now on the monitor can be reused for another stability detection
}
// do something after all the controllers are in REST state
Sample simple usage:
ServiceController<?> controller = ...
StabilityMonitor monitor = new StabilityMonitor();
monitor.addController(controller);
controller.setMode(REMOVE);
try {
monitor.awaitStability();
} finally {
monitor.removeController(controller);
}
// do something after controller have been removed from container
StabilityStatistics| Modifier and Type | Field and Description |
|---|---|
private boolean |
addInProgress |
private boolean |
cleanupInProgress |
private IdentityHashSet<ServiceControllerImpl<?>> |
controllers |
private java.lang.Object |
controllersLock |
private java.util.Set<ServiceController<?>> |
failed |
private java.util.Set<ServiceController<?>> |
problems |
private boolean |
removeInProgress |
private java.lang.Object |
stabilityLock |
private int |
unstableServices |
| Constructor and Description |
|---|
StabilityMonitor() |
| Modifier and Type | Method and Description |
|---|---|
void |
addController(ServiceController<?> controller)
Register controller with this monitor.
|
(package private) void |
addControllerNoCallback(ServiceControllerImpl<?> controller)
Register controller with this monitor but don't call serviceController.addMonitor() at all.
|
(package private) void |
addFailed(ServiceController<?> controller) |
(package private) void |
addProblem(ServiceController<?> controller) |
private void |
awaitAddCompletion() |
private void |
awaitCleanupCompletion() |
private void |
awaitRemoveCompletion() |
void |
awaitStability()
Causes the current thread to wait until the monitor is stable.
|
boolean |
awaitStability(long timeout,
java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the monitor is stable.
|
boolean |
awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems)
Causes the current thread to wait until the monitor is stable.
|
boolean |
awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems,
StabilityStatistics statistics)
Causes the current thread to wait until the monitor is stable.
|
boolean |
awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
StabilityStatistics statistics)
Causes the current thread to wait until the monitor is stable.
|
void |
awaitStability(java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems)
Causes the current thread to wait until the monitor is stable.
|
void |
awaitStability(java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems,
StabilityStatistics statistics)
Causes the current thread to wait until the monitor is stable.
|
void |
awaitStability(StabilityStatistics statistics)
Causes the current thread to wait until the monitor is stable.
|
void |
clear()
Removes all the registered controllers in this monitor.
|
(package private) void |
decrementUnstableServices() |
(package private) void |
incrementUnstableServices() |
private void |
provideStatistics(int failedCount,
int problemsCount,
StabilityStatistics statistics) |
void |
removeController(ServiceController<?> controller)
Unregister controller with this monitor.
|
(package private) void |
removeControllerNoCallback(ServiceControllerImpl<?> controller)
Unregister controller with this monitor but don't call serviceController.removeMonitor() at all.
|
(package private) void |
removeFailed(ServiceController<?> controller) |
(package private) void |
removeProblem(ServiceController<?> controller) |
private final java.lang.Object stabilityLock
private final java.lang.Object controllersLock
private final java.util.Set<ServiceController<?>> problems
private final java.util.Set<ServiceController<?>> failed
private boolean addInProgress
private boolean cleanupInProgress
private boolean removeInProgress
private IdentityHashSet<ServiceControllerImpl<?>> controllers
private int unstableServices
public void addController(ServiceController<?> controller) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
controller - to be registered for stability detection.java.lang.IllegalArgumentException - if controller is nulljava.lang.IllegalStateException - if controllers lock is held by current threadvoid addControllerNoCallback(ServiceControllerImpl<?> controller)
controller - to be registered for stability detection.public void removeController(ServiceController<?> controller) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
controller - to be unregistered from stability detection.java.lang.IllegalArgumentException - if controller is nulljava.lang.IllegalStateException - if controllers lock is held by current threadvoid removeControllerNoCallback(ServiceControllerImpl<?> controller)
controller - to be unregistered from stability detection.public void clear()
public void awaitStability()
throws java.lang.InterruptedException
java.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitStability(StabilityStatistics statistics) throws java.lang.InterruptedException
statistics - stability statistics report to fill injava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic boolean awaitStability(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout - the maximum time to waitunit - the time unit of the timeout argumentjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic boolean awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
StabilityStatistics statistics)
throws java.lang.InterruptedException
timeout - the maximum time to waitunit - the time unit of the timeout argumentstatistics - stability statistics report to fill injava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems) throws java.lang.InterruptedException
failed - a set into which failed services should be copiedproblems - a set into which problem services should be copiedjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic boolean awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems)
throws java.lang.InterruptedException
timeout - the maximum time to waitunit - the time unit of the timeout argumentfailed - a set into which failed services should be copiedproblems - a set into which problem services should be copiedjava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems, StabilityStatistics statistics) throws java.lang.InterruptedException
failed - a set into which failed services should be copiedproblems - a set into which problem services should be copiedstatistics - stability statistics report to fill injava.lang.InterruptedException - if the current thread is interrupted
while waitingpublic boolean awaitStability(long timeout,
java.util.concurrent.TimeUnit unit,
java.util.Set<? super ServiceController<?>> failed,
java.util.Set<? super ServiceController<?>> problems,
StabilityStatistics statistics)
throws java.lang.InterruptedException
timeout - the maximum time to waitunit - the time unit of the timeout argumentfailed - a set into which failed services should be copiedproblems - a set into which problem services should be copiedstatistics - stability statistics report to fill injava.lang.InterruptedException - if the current thread is interrupted
while waitingvoid addProblem(ServiceController<?> controller)
void removeProblem(ServiceController<?> controller)
void addFailed(ServiceController<?> controller)
void removeFailed(ServiceController<?> controller)
void incrementUnstableServices()
void decrementUnstableServices()
private void provideStatistics(int failedCount,
int problemsCount,
StabilityStatistics statistics)
private void awaitAddCompletion()
private void awaitCleanupCompletion()
private void awaitRemoveCompletion()