Package org.jboss.msc.service
Class StabilityMonitor
- java.lang.Object
-
- org.jboss.msc.service.StabilityMonitor
-
public final class StabilityMonitor extends java.lang.ObjectA stability detection utility. It can be used to detect if all the registered controllers withStabilityMonitorare 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 stateSample 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- See Also:
StabilityStatistics
-
-
Field Summary
Fields Modifier and Type Field Description private booleanaddInProgressprivate booleancleanupInProgressprivate IdentityHashSet<ServiceControllerImpl<?>>controllersprivate java.lang.ObjectcontrollersLockprivate java.util.Set<ServiceController<?>>failedprivate java.util.Set<ServiceController<?>>problemsprivate booleanremoveInProgressprivate java.lang.ObjectstabilityLockprivate intunstableServices
-
Constructor Summary
Constructors Constructor Description StabilityMonitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddController(ServiceController<?> controller)Register controller with this monitor.(package private) voidaddControllerNoCallback(ServiceControllerImpl<?> controller)Register controller with this monitor but don't call serviceController.addMonitor() at all.(package private) voidaddFailed(ServiceController<?> controller)(package private) voidaddProblem(ServiceController<?> controller)private voidawaitAddCompletion()private voidawaitCleanupCompletion()private voidawaitRemoveCompletion()voidawaitStability()Causes the current thread to wait until the monitor is stable.booleanawaitStability(long timeout, java.util.concurrent.TimeUnit unit)Causes the current thread to wait until the monitor is stable.booleanawaitStability(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.booleanawaitStability(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.booleanawaitStability(long timeout, java.util.concurrent.TimeUnit unit, StabilityStatistics statistics)Causes the current thread to wait until the monitor is stable.voidawaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems)Causes the current thread to wait until the monitor is stable.voidawaitStability(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.voidawaitStability(StabilityStatistics statistics)Causes the current thread to wait until the monitor is stable.voidclear()Removes all the registered controllers in this monitor.(package private) voiddecrementUnstableServices()(package private) voidincrementUnstableServices()private voidprovideStatistics(int failedCount, int problemsCount, StabilityStatistics statistics)voidremoveController(ServiceController<?> controller)Unregister controller with this monitor.(package private) voidremoveControllerNoCallback(ServiceControllerImpl<?> controller)Unregister controller with this monitor but don't call serviceController.removeMonitor() at all.(package private) voidremoveFailed(ServiceController<?> controller)(package private) voidremoveProblem(ServiceController<?> controller)
-
-
-
Field Detail
-
stabilityLock
private final java.lang.Object stabilityLock
-
controllersLock
private final java.lang.Object controllersLock
-
problems
private final java.util.Set<ServiceController<?>> problems
-
failed
private final java.util.Set<ServiceController<?>> failed
-
addInProgress
private boolean addInProgress
-
cleanupInProgress
private boolean cleanupInProgress
-
removeInProgress
private boolean removeInProgress
-
controllers
private IdentityHashSet<ServiceControllerImpl<?>> controllers
-
unstableServices
private int unstableServices
-
-
Method Detail
-
addController
public void addController(ServiceController<?> controller) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
Register controller with this monitor.- Parameters:
controller- to be registered for stability detection.- Throws:
java.lang.IllegalArgumentException- ifcontrolleris nulljava.lang.IllegalStateException- ifcontrollers lock is held by current thread
-
addControllerNoCallback
void addControllerNoCallback(ServiceControllerImpl<?> controller)
Register controller with this monitor but don't call serviceController.addMonitor() at all.- Parameters:
controller- to be registered for stability detection.
-
removeController
public void removeController(ServiceController<?> controller) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
Unregister controller with this monitor.- Parameters:
controller- to be unregistered from stability detection.- Throws:
java.lang.IllegalArgumentException- ifcontrolleris nulljava.lang.IllegalStateException- ifcontrollers lock is held by current thread
-
removeControllerNoCallback
void removeControllerNoCallback(ServiceControllerImpl<?> controller)
Unregister controller with this monitor but don't call serviceController.removeMonitor() at all.- Parameters:
controller- to be unregistered from stability detection.
-
clear
public void clear()
Removes all the registered controllers in this monitor. The monitor can be later reused for stability detection again.
-
awaitStability
public void awaitStability() throws java.lang.InterruptedExceptionCauses the current thread to wait until the monitor is stable.- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability(StabilityStatistics statistics) throws java.lang.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
statistics- stability statistics report to fill in- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionCauses the current thread to wait until the monitor is stable.- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargument- Returns:
- true if this monitor achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, java.util.concurrent.TimeUnit unit, StabilityStatistics statistics) throws java.lang.InterruptedExceptionCauses the current thread to wait until the monitor is stable.- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargumentstatistics- stability statistics report to fill in- Returns:
- true if this monitor achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems) throws java.lang.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
failed- a set into which failed services should be copiedproblems- a set into which problem services should be copied- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public boolean awaitStability(long timeout, java.util.concurrent.TimeUnit unit, java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems) throws java.lang.InterruptedExceptionCauses the current thread to wait until the monitor is stable.- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargumentfailed- a set into which failed services should be copiedproblems- a set into which problem services should be copied- Returns:
- true if this monitor achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public void awaitStability(java.util.Set<? super ServiceController<?>> failed, java.util.Set<? super ServiceController<?>> problems, StabilityStatistics statistics) throws java.lang.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
failed- a set into which failed services should be copiedproblems- a set into which problem services should be copiedstatistics- stability statistics report to fill in- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
awaitStability
public 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.InterruptedExceptionCauses the current thread to wait until the monitor is stable.- Parameters:
timeout- the maximum time to waitunit- the time unit of thetimeoutargumentfailed- a set into which failed services should be copiedproblems- a set into which problem services should be copiedstatistics- stability statistics report to fill in- Returns:
- true if this monitor achieved stability, false if the timeout elapsed before stability
- Throws:
java.lang.InterruptedException- if the current thread is interrupted while waiting
-
addProblem
void addProblem(ServiceController<?> controller)
-
removeProblem
void removeProblem(ServiceController<?> controller)
-
addFailed
void addFailed(ServiceController<?> controller)
-
removeFailed
void removeFailed(ServiceController<?> controller)
-
incrementUnstableServices
void incrementUnstableServices()
-
decrementUnstableServices
void decrementUnstableServices()
-
provideStatistics
private void provideStatistics(int failedCount, int problemsCount, StabilityStatistics statistics)
-
awaitAddCompletion
private void awaitAddCompletion()
-
awaitCleanupCompletion
private void awaitCleanupCompletion()
-
awaitRemoveCompletion
private void awaitRemoveCompletion()
-
-