Class AutoRestartingService<S extends com.google.common.util.concurrent.Service>

  • All Implemented Interfaces:
    com.google.common.util.concurrent.Service, RestartableService

    public class AutoRestartingService<S extends com.google.common.util.concurrent.Service>
    extends java.lang.Object
    implements RestartableService
    A Restartable Service that will automatically restart itself if
    See Also:
    Original version
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

        com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoRestartingService​(java.util.function.Supplier<S> factory)
      This will create an AutoRestartingService that will always restart whenever the existing service enters the Service.State.FAILED state.
      AutoRestartingService​(java.util.function.Supplier<S> factory, ServiceRestartPolicy policy)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addListener​(com.google.common.util.concurrent.Service.Listener listener, java.util.concurrent.Executor executor)
      This is only guaranteed to add the listeners to future services.
      void awaitRunning()  
      void awaitRunning​(long timeout, java.util.concurrent.TimeUnit unit)  
      void awaitTerminated()  
      void awaitTerminated​(long timeout, java.util.concurrent.TimeUnit unit)  
      java.lang.Throwable failureCause()  
      protected S getDelegate()
      Used for testing only.
      boolean isRunning()  
      AutoRestartingService startAsync()
      If the service state is Service.State.NEW, Service.State.FAILED, Service.State.TERMINATED this initiates service startup and returns immediately.
      com.google.common.util.concurrent.Service.State state()  
      void stopAndAwait()  
      void stopAndAwait​(long timeout, java.util.concurrent.TimeUnit unit)  
      AutoRestartingService stopAsync()
      Stops the service.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AutoRestartingService

        public AutoRestartingService​(java.util.function.Supplier<S> factory,
                                     ServiceRestartPolicy policy)
        Parameters:
        factory - This should always supply a new instance of the service that can be restarted.
        policy - A policy that allows for custom logic to determine if a service that has entered the Service.State.FAILED state should restart.
      • AutoRestartingService

        public AutoRestartingService​(java.util.function.Supplier<S> factory)
        This will create an AutoRestartingService that will always restart whenever the existing service enters the Service.State.FAILED state.
        Parameters:
        factory - This should always supply a new instance of the service that can be restarted.
    • Method Detail

      • getDelegate

        protected S getDelegate()
        Used for testing only.
        Returns:
        delegate
      • startAsync

        public AutoRestartingService startAsync()
        Description copied from interface: RestartableService
        If the service state is Service.State.NEW, Service.State.FAILED, Service.State.TERMINATED this initiates service startup and returns immediately.
        Specified by:
        startAsync in interface RestartableService
        Specified by:
        startAsync in interface com.google.common.util.concurrent.Service
        Returns:
        this
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface com.google.common.util.concurrent.Service
      • state

        public com.google.common.util.concurrent.Service.State state()
        Specified by:
        state in interface com.google.common.util.concurrent.Service
      • stopAndAwait

        public void stopAndAwait​(long timeout,
                                 java.util.concurrent.TimeUnit unit)
                          throws java.util.concurrent.TimeoutException
        Specified by:
        stopAndAwait in interface RestartableService
        Throws:
        java.util.concurrent.TimeoutException
      • awaitRunning

        public void awaitRunning()
        Specified by:
        awaitRunning in interface com.google.common.util.concurrent.Service
      • awaitRunning

        public void awaitRunning​(long timeout,
                                 java.util.concurrent.TimeUnit unit)
                          throws java.util.concurrent.TimeoutException
        Specified by:
        awaitRunning in interface com.google.common.util.concurrent.Service
        Throws:
        java.util.concurrent.TimeoutException
      • awaitTerminated

        public void awaitTerminated()
        Specified by:
        awaitTerminated in interface com.google.common.util.concurrent.Service
      • awaitTerminated

        public void awaitTerminated​(long timeout,
                                    java.util.concurrent.TimeUnit unit)
                             throws java.util.concurrent.TimeoutException
        Specified by:
        awaitTerminated in interface com.google.common.util.concurrent.Service
        Throws:
        java.util.concurrent.TimeoutException
      • failureCause

        public java.lang.Throwable failureCause()
        Specified by:
        failureCause in interface com.google.common.util.concurrent.Service
      • addListener

        public void addListener​(com.google.common.util.concurrent.Service.Listener listener,
                                java.util.concurrent.Executor executor)
        This is only guaranteed to add the listeners to future services. It will make a best effort attempt to add the listener to the existing service.
        Specified by:
        addListener in interface com.google.common.util.concurrent.Service