Interface ServiceController<S>

Type Parameters:
S - the service type
All Superinterfaces:
Value<S>
All Known Subinterfaces:
SingletonServiceController<T>
All Known Implementing Classes:
DelegatingServiceController

public interface ServiceController<S> extends Value<S>
A controller for a single service instance.
Author:
David M. Lloyd, Richard Opalka
  • Method Details

    • getParent

      ServiceController<?> getParent()
      Get this service's parent service, or null if there is none.
      Returns:
      the parent service or null if this service has no parent
    • getServiceContainer

      ServiceContainer getServiceContainer()
      Get the service container associated with this controller.
      Returns:
      the container
    • getMode

      Get the service controller's current mode.
      Returns:
      the controller mode
    • compareAndSetMode

      boolean compareAndSetMode(ServiceController.Mode expected, ServiceController.Mode newMode)
      Compare the current mode against expected; if it matches, change it to newMode. The return value is true when the mode was matched and changed.
      Parameters:
      expected - the expected mode
      newMode - the new mode
      Returns:
      true if the mode was changed
    • setMode

      void setMode(ServiceController.Mode mode)
      Change the service controller's current mode. Might result in the service starting or stopping. The mode may only be changed if it was not already set to ServiceController.Mode.REMOVE. Calling this method with the controller's current mode has no effect and is always allowed.
      Parameters:
      mode - the new controller mode
      Throws:
      IllegalStateException - if the mode given is null, or the caller attempted to change the service's mode from ServiceController.Mode.REMOVE to a different mode
    • getState

      Get the current service controller state.
      Returns:
      the current state
    • getValue

      Deprecated.
      this method will be removed in a future release
      Get the service value.
      Specified by:
      getValue in interface Value<S>
      Returns:
      the service value
      Throws:
      IllegalStateException - if the service is not available (i.e. it is not up)
    • awaitValue

      Deprecated.
      this method will be removed in a future release
      Wait for a service to come up, and then return its value.
      Returns:
      the service value
      Throws:
      IllegalStateException - if the service is not available (i.e. it was removed or failed)
      InterruptedException - if the wait operation was interrupted
    • awaitValue

      Deprecated.
      this method will be removed in a future release
      Wait for a service to come up for a certain amount of time, and then return its value.
      Parameters:
      time - the amount of time to wait
      unit - the unit of time to wait
      Returns:
      the service value
      Throws:
      IllegalStateException - if the service is not available (i.e. it was removed or failed)
      InterruptedException - if the wait operation was interrupted
      TimeoutException
    • getService

      Deprecated.
      this method will be removed in a future release
      Get the service.
      Returns:
      the service
      Throws:
      IllegalStateException - if the service is not available (i.e. it is not up)
    • getName

      Deprecated.
      Use ServiceController#provides() instead. This method will be removed in a future release.
      Get the name of this service, if any.
      Returns:
      the name, or null if none was specified.
      See Also:
    • getAliases

      @Deprecated ServiceName[] getAliases()
      Deprecated.
      Use ServiceController#provides() instead. This method will be removed in a future release.
      Get other names this service is known as.
      Returns:
      the aliases
      See Also:
    • requires

      Set<ServiceName> requires()
      Get the names of all values this service require.
      Returns:
      names of required values
    • provides

      Set<ServiceName> provides()
      Get the names of all values this service provide.
      Returns:
      names of provided values
    • missing

      Set<ServiceName> missing()
      Get the names of all missing values this service require.
      Returns:
      names of missing values
    • addListener

      void addListener(LifecycleListener listener)
      Add a service lifecycle listener.
      Parameters:
      listener - the lifecycle listener
    • removeListener

      void removeListener(LifecycleListener listener)
      Remove a lifecycle listener.
      Parameters:
      listener - the lifecycle listener to remove
    • getStartException

      StartException getStartException()
      Get the reason why the last start failed.
      Returns:
      the last start exception, or null if the last start succeeded or the service has not yet started
    • retry

      void retry()
      Retry a failed service. Does nothing if the state is not ServiceController.State.START_FAILED.
    • getUnavailableDependencies

      @Deprecated Collection<ServiceName> getUnavailableDependencies()
      Deprecated.
      Use ServiceController#missing() instead. This method will be removed in a future release.
      Get the complete list of dependencies that are unavailable.
      Returns:
      a set containing the names of all unavailable dependencies