Class Services


  • public final class Services
    extends java.lang.Object
    Helper methods that allow controlling Services.
    • Constructor Summary

      Constructors 
      Constructor Description
      Services()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isTerminating​(com.google.common.util.concurrent.Service.State state)
      Determines whether the given Service.State indicates the Service is either in the process of Stopping or already Terminated or Failed.
      static void onStop​(com.google.common.util.concurrent.Service service, java.lang.Runnable terminatedCallback, java.util.function.Consumer<java.lang.Throwable> failureCallback, java.util.concurrent.Executor executor)
      Attaches the given callbacks which will be invoked when the given Service enters a TERMINATED or FAILED state.
      static java.util.concurrent.CompletableFuture<java.lang.Void> startAsync​(com.google.common.util.concurrent.Service service, java.util.concurrent.Executor executor)
      Asynchronously starts a Service and returns a CompletableFuture that will indicate when it is running.
      static java.util.concurrent.CompletableFuture<java.lang.Void> stopAsync​(com.google.common.util.concurrent.Service service, java.util.concurrent.Executor executor)
      Asynchronously stops a Service and returns a CompletableFuture that will indicate when it is stopped.
      • Methods inherited from class java.lang.Object

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

      • Services

        public Services()
    • Method Detail

      • startAsync

        public static java.util.concurrent.CompletableFuture<java.lang.Void> startAsync​(com.google.common.util.concurrent.Service service,
                                                                                        java.util.concurrent.Executor executor)
        Asynchronously starts a Service and returns a CompletableFuture that will indicate when it is running.
        Parameters:
        service - The Service to start.
        executor - An Executor to use for callback invocations.
        Returns:
        A CompletableFuture that will be completed when the service enters a RUNNING state, or completed exceptionally if the service failed to start.
      • stopAsync

        public static java.util.concurrent.CompletableFuture<java.lang.Void> stopAsync​(com.google.common.util.concurrent.Service service,
                                                                                       java.util.concurrent.Executor executor)
        Asynchronously stops a Service and returns a CompletableFuture that will indicate when it is stopped.
        Parameters:
        service - The Service to stop.
        executor - An Executor to use for callback invocations.
        Returns:
        A CompletableFuture that will be completed when the service enters a TERMINATED state, or completed exceptionally if the service enters a FAILED state.
      • onStop

        public static void onStop​(com.google.common.util.concurrent.Service service,
                                  java.lang.Runnable terminatedCallback,
                                  java.util.function.Consumer<java.lang.Throwable> failureCallback,
                                  java.util.concurrent.Executor executor)
        Attaches the given callbacks which will be invoked when the given Service enters a TERMINATED or FAILED state. The callbacks are optional and may be invoked synchronously if the Service is already in one of these states.
        Parameters:
        service - The Service to attach to.
        terminatedCallback - (Optional) A Runnable that will be invoked if the Service enters a TERMINATED state.
        failureCallback - (Optional) A Runnable that will be invoked if the Service enters a FAILED state.
        executor - An Executor to use for callback invocations.
      • isTerminating

        public static boolean isTerminating​(com.google.common.util.concurrent.Service.State state)
        Determines whether the given Service.State indicates the Service is either in the process of Stopping or already Terminated or Failed.
        Parameters:
        state - The Service.State to test.
        Returns:
        Whether this is a terminating state.