Package org.jboss.msc.service
Class StabilityMonitor
- java.lang.Object
-
- org.jboss.msc.service.StabilityMonitor
-
public final class StabilityMonitor extends java.lang.Object
A stability detection utility. It can be used to detect if all the registered controllers withStabilityMonitor
are in REST state. The following controller substates are considered to be in REST state:ServiceController.Substate.NEW
ServiceController.Substate.CANCELLED
ServiceController.Substate.WAITING
ServiceController.Substate.WONT_START
ServiceController.Substate.PROBLEM
ServiceController.Substate.START_FAILED
ServiceController.Substate.UP
ServiceController.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
- See Also:
StabilityStatistics
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description StabilityMonitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
-
-
-
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
- ifcontroller
is nulljava.lang.IllegalStateException
- ifcontroller
s 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
- ifcontroller
is nulljava.lang.IllegalStateException
- ifcontroller
s 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.InterruptedException
Causes 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.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argument- 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.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argumentstatistics
- 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.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argumentfailed
- 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.InterruptedException
Causes the current thread to wait until the monitor is stable.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of thetimeout
argumentfailed
- 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()
-
-