Class AbstractService

  • All Implemented Interfaces:
    Service
    Direct Known Subclasses:
    BlockingQueueConsumer

    public abstract class AbstractService
    extends java.lang.Object
    implements Service
    An abstract implementation of the Service interface.

    This implementation is flexible, weather the internal service is scheduled on a thread pool runs on a unique thread, or has other means of running.

    Since:
    2.6.0
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractService()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean hasStopped()
      Call to check if the service has been stopped (and thus can no longer be used).
      boolean isRunning()
      Call to check if the service has been started, and not shutdown yet.
      void start()
      Starts the service, blocking until the service is running.
      boolean startIfNotStarted()
      Starts the service if it has not already been started.
      void stop()
      Stops the service, blocking until the service is shutdown.
      boolean stopIfRunning()
      Stops the service if it currently running.
      • Methods inherited from class java.lang.Object

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

      • AbstractService

        public AbstractService()
    • Method Detail

      • start

        public void start()
                   throws java.lang.IllegalStateException
        Description copied from interface: Service
        Starts the service, blocking until the service is running.
        Specified by:
        start in interface Service
        Throws:
        java.lang.IllegalStateException - thrown if the service has already been started
      • startIfNotStarted

        public boolean startIfNotStarted()
        Description copied from interface: Service
        Starts the service if it has not already been started. If the service has been started this invocation will do nothing (except return false). If this call starts the service the thread will block until the service is running.
        Specified by:
        startIfNotStarted in interface Service
        Returns:
        true if the service has been started from this call
      • stop

        public void stop()
        Description copied from interface: Service
        Stops the service, blocking until the service is shutdown.
        Specified by:
        stop in interface Service
      • stopIfRunning

        public boolean stopIfRunning()
        Description copied from interface: Service
        Stops the service if it currently running. If the service has been stopped already, or never started this invocation will do nothing (except return false). If this call stops the service the thread will block until the service is shutdown.
        Specified by:
        stopIfRunning in interface Service
        Returns:
        true if the service has been stopped from this call
      • isRunning

        public boolean isRunning()
        Description copied from interface: Service
        Call to check if the service has been started, and not shutdown yet. If you need a check that will be consistent while both new and while running please see Service.hasStopped().
        Specified by:
        isRunning in interface Service
        Returns:
        true if the service is currently running
      • hasStopped

        public boolean hasStopped()
        Description copied from interface: Service
        Call to check if the service has been stopped (and thus can no longer be used). This is different from Service.isRunning() in that it will return false until Service.stop() or Service.stopIfRunning() has been invoked. Thus allowing you to make a check that's state will be consistent when it is new and while it is running.
        Specified by:
        hasStopped in interface Service
        Returns:
        true if the server has been stopped