Class AbstractRESTProvider

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.SizeOfHandler, adams.flow.core.FlowContextHandler, RESTProvider, Serializable
    Direct Known Subclasses:
    EchoServer, GenericServer

    public abstract class AbstractRESTProvider
    extends adams.core.option.AbstractOptionHandler
    implements RESTProvider
    Ancestor for servers providing webservices.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected io.dropwizard.core.Application m_Application
      the application.
      protected adams.core.io.PlaceholderFile m_ConfigFile
      the YAML config file to use.
      protected io.dropwizard.core.setup.Environment m_Environment
      the environment in use.
      protected adams.flow.core.Actor m_Owner
      the owning actor.
      protected boolean m_Running
      whether the webservice is running.
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void check()
      Performs some initial checks before starting the service.
      void cleanUp()
      Cleans up data structures, frees up memory.
      String configFileTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      protected abstract com.github.fracpete.javautils.struct.Struct2<io.dropwizard.core.Application,​io.dropwizard.core.setup.Environment> doStart()
      Performs the actual start of the service.
      protected void doStop()
      Performs the actual stop of the service.
      adams.core.io.PlaceholderFile getConfigFile()
      Returns the YAML config file in use.
      adams.flow.core.Actor getFlowContext()
      Returns the owning actor.
      boolean isRunning()
      Returns whether the service is running.
      void log​(String msg, String id)
      Logs an error message if a valid global log actor has been set up.
      void setConfigFile​(adams.core.io.PlaceholderFile value)
      Sets the YAML config file to use.
      void setFlowContext​(adams.flow.core.Actor value)
      Sets the actor that executes this webservice.
      String start()
      Starts the service.
      String stop()
      Stops the service.
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_ConfigFile

        protected adams.core.io.PlaceholderFile m_ConfigFile
        the YAML config file to use.
      • m_Owner

        protected adams.flow.core.Actor m_Owner
        the owning actor.
      • m_Running

        protected boolean m_Running
        whether the webservice is running.
      • m_Application

        protected io.dropwizard.core.Application m_Application
        the application.
      • m_Environment

        protected io.dropwizard.core.setup.Environment m_Environment
        the environment in use.
    • Constructor Detail

      • AbstractRESTProvider

        public AbstractRESTProvider()
    • Method Detail

      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • setConfigFile

        public void setConfigFile​(adams.core.io.PlaceholderFile value)
        Sets the YAML config file to use.
        Specified by:
        setConfigFile in interface RESTProvider
        Parameters:
        value - the file
      • getConfigFile

        public adams.core.io.PlaceholderFile getConfigFile()
        Returns the YAML config file in use.
        Specified by:
        getConfigFile in interface RESTProvider
        Returns:
        the file
      • configFileTipText

        public String configFileTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setFlowContext

        public void setFlowContext​(adams.flow.core.Actor value)
        Sets the actor that executes this webservice.
        Specified by:
        setFlowContext in interface adams.flow.core.FlowContextHandler
        Specified by:
        setFlowContext in interface RESTProvider
        Parameters:
        value - the owner
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the owning actor.
        Specified by:
        getFlowContext in interface adams.flow.core.FlowContextHandler
        Specified by:
        getFlowContext in interface RESTProvider
        Returns:
        the owner
      • check

        protected void check()
        Performs some initial checks before starting the service.

        Default implementation does nothing.
      • log

        public void log​(String msg,
                        String id)
        Logs an error message if a valid global log actor has been set up.
        Parameters:
        msg - the message to log
        id - an optional ID of the data token that failed in the web service
      • doStart

        protected abstract com.github.fracpete.javautils.struct.Struct2<io.dropwizard.core.Application,​io.dropwizard.core.setup.Environment> doStart()
                                                                                                                                                    throws Exception
        Performs the actual start of the service.
        Returns:
        the tuple of application and environment
        Throws:
        Exception - if start fails
      • start

        public String start()
        Starts the service.
        Specified by:
        start in interface RESTProvider
        Returns:
        null if successful, otherwise error message
      • isRunning

        public boolean isRunning()
        Returns whether the service is running.
        Specified by:
        isRunning in interface RESTProvider
        Returns:
        true if running
      • doStop

        protected void doStop()
                       throws Exception
        Performs the actual stop of the service.
        Throws:
        Exception - if stopping fails
      • stop

        public String stop()
        Stops the service.
        Specified by:
        stop in interface RESTProvider
        Returns:
        null if successful, otherwise error message
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory.
        Specified by:
        cleanUp in interface adams.core.CleanUpHandler
        Specified by:
        cleanUp in interface RESTProvider