Class StabilityMonitor

    • Field Detail

      • stabilityLock

        private final java.lang.Object stabilityLock
      • controllersLock

        private final java.lang.Object controllersLock
      • addInProgress

        private boolean addInProgress
      • cleanupInProgress

        private boolean cleanupInProgress
      • removeInProgress

        private boolean removeInProgress
      • unstableServices

        private int unstableServices
    • Constructor Detail

      • StabilityMonitor

        public StabilityMonitor()
    • 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 - if controller is null
        java.lang.IllegalStateException - if controllers 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 - if controller is null
        java.lang.IllegalStateException - if controllers 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 wait
        unit - the time unit of the timeout 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 wait
        unit - the time unit of the timeout argument
        statistics - 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 copied
        problems - 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 wait
        unit - the time unit of the timeout argument
        failed - a set into which failed services should be copied
        problems - 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 copied
        problems - a set into which problem services should be copied
        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,
                                      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 wait
        unit - the time unit of the timeout argument
        failed - a set into which failed services should be copied
        problems - a set into which problem services should be copied
        statistics - 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
      • 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()