Class Service<Conf>

java.lang.Object
me.legrange.service.Service<Conf>
Type Parameters:
Conf - The type of the configuration class for this service.

public abstract class Service<Conf> extends Object
Author:
gideon
  • Constructor Details

    • Service

      public Service()
  • Method Details

    • main

      public static void main(String... args)
    • start

      public final void start(Conf config) throws ServiceException
      Throws:
      ServiceException
    • stop

      public final void stop() throws ServiceException
      Throws:
      ServiceException
    • getComponent

      public final <C extends Component> C getComponent(Class<C> clazz) throws ComponentNotFoundException
      Get the running component for the given component class.
      Type Parameters:
      C - The type of the component
      Parameters:
      clazz - The class representing the component
      Returns:
      The component
      Throws:
      ComponentNotFoundException - Thrown if the component requested cannot be found
    • requireComponent

      public final <C extends Component> C requireComponent(Class<C> clazz) throws ServiceException
      Throws:
      ServiceException
    • isRunning

      public final boolean isRunning()
    • start

      protected abstract void start() throws ServiceException
      Start the service. This needs to be implemented by the implementation subclass to get work done.
      Throws:
      ServiceException - Thrown if the service cannot be started
    • onStop

      protected void onStop() throws ServiceException
      Stop the service. This can be implemented by the implementation subclass to release resources, do cleanup or accomplish other shut down tasks.
      Throws:
      ServiceException - Thrown if there is a problem stopping the service
    • getConfig

      protected Conf getConfig()
      Return the service configuration.
      Returns:
      The configuration object
    • submit

      public void submit(Runnable task)
      Submit a task for running to the thread pool.
      Parameters:
      task - The task to run.
    • sleep

      public final void sleep(int seconds)