Class Service<Conf>

  • Type Parameters:
    Conf - The type of the configuration class for this service.

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

      • Service

        public Service()
    • Method Detail

      • main

        public static void main​(String... args)
      • 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
      • 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)