Class AbstractBackend

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.SizeOfHandler, Serializable
    Direct Known Subclasses:
    FileBased, InMemory

    public abstract class AbstractBackend
    extends adams.core.option.AbstractOptionHandler
    Ancestor for backend schemes.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean m_Initialized
      whether the backed has been initialized.
      protected boolean m_SequentialTokens
      whether to use sequential tokens (for testing only).
      protected int m_TimeToLive
      the time to live for items.
      • Fields inherited from class adams.core.option.AbstractOptionHandler

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

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractBackend()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      String add​(byte[] data)
      Adds the item, returns the generated token.
      protected abstract String addItem​(byte[] data)
      Adds the item, returns the generated token.
      void clear()
      Removes all items.
      void defineOptions()
      Adds options to the internal list of options.
      protected abstract void doClear()
      Removes all items.
      protected abstract String doInitBackend()
      Initializes the backend.
      protected abstract void doPurge()
      Purges any expired items.
      byte[] get​(String token)
      Gets the item, if present.
      protected abstract byte[] getItem​(String token)
      Gets the item, if present.
      boolean getSequentialTokens()
      Returns whether to generate sequential tokens (for testing only).
      int getTimeToLive()
      Returns the time to live for uploaded items.
      boolean has​(String token)
      Checks whether the item is present.
      protected abstract boolean hasItem​(String token)
      Checks whether the item is present.
      String initBackend()
      Initializes the backend, if necessary.
      protected String nextToken()
      Generates the next token.
      void purge()
      Purges any expired items.
      boolean remove​(String token)
      Removes the data associated with the token.
      protected abstract boolean removeItem​(String token)
      Removes the data associated with the token.
      protected void reset()
      Resets the scheme.
      String sequentialTokensTipText()
      Returns the tip text for this property.
      void setSequentialTokens​(boolean value)
      Sets whether to generate sequential tokens (for testing only).
      void setTimeToLive​(int value)
      Sets the time to live for uploaded items.
      String timeToLiveTipText()
      Returns the tip text for this property.
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, loggingLevelTipText, newOptionManager, 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_TimeToLive

        protected int m_TimeToLive
        the time to live for items.
      • m_SequentialTokens

        protected boolean m_SequentialTokens
        whether to use sequential tokens (for testing only).
      • m_Initialized

        protected boolean m_Initialized
        whether the backed has been initialized.
    • Constructor Detail

      • AbstractBackend

        public AbstractBackend()
    • 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
      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class adams.core.option.AbstractOptionHandler
      • setTimeToLive

        public void setTimeToLive​(int value)
        Sets the time to live for uploaded items.
        Parameters:
        value - the time to live (seconds)
      • getTimeToLive

        public int getTimeToLive()
        Returns the time to live for uploaded items.
        Returns:
        the time to live (seconds)
      • timeToLiveTipText

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

        public void setSequentialTokens​(boolean value)
        Sets whether to generate sequential tokens (for testing only).
        Parameters:
        value - true if sequential
      • getSequentialTokens

        public boolean getSequentialTokens()
        Returns whether to generate sequential tokens (for testing only).
        Returns:
        true if sequential
      • sequentialTokensTipText

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

        protected String nextToken()
        Generates the next token.
        Returns:
        the token
      • doInitBackend

        protected abstract String doInitBackend()
        Initializes the backend.
        Returns:
        null if sucessfully initialized, otherwise error message
      • initBackend

        public String initBackend()
        Initializes the backend, if necessary.
        Returns:
        null if sucessfully initialized, otherwise error message
      • doClear

        protected abstract void doClear()
        Removes all items.
      • clear

        public void clear()
        Removes all items.
      • doPurge

        protected abstract void doPurge()
        Purges any expired items.
      • purge

        public void purge()
        Purges any expired items.
      • hasItem

        protected abstract boolean hasItem​(String token)
        Checks whether the item is present.
        Parameters:
        token - the token to check
        Returns:
        true if available
      • has

        public boolean has​(String token)
        Checks whether the item is present.
        Parameters:
        token - the token to check
        Returns:
        true if available
      • getItem

        protected abstract byte[] getItem​(String token)
        Gets the item, if present.
        Parameters:
        token - the token to get
        Returns:
        the item, null if not available
      • get

        public byte[] get​(String token)
        Gets the item, if present.
        Parameters:
        token - the token to get
        Returns:
        the item, null if not available
      • addItem

        protected abstract String addItem​(byte[] data)
        Adds the item, returns the generated token.
        Parameters:
        data - the data to add
        Returns:
        the token, null if failed to add
      • add

        public String add​(byte[] data)
        Adds the item, returns the generated token.
        Parameters:
        data - the data to add
        Returns:
        the token, null if failed to add
      • removeItem

        protected abstract boolean removeItem​(String token)
        Removes the data associated with the token.
        Parameters:
        token - the token to remove the data for
        Returns:
        true if removed
      • remove

        public boolean remove​(String token)
        Removes the data associated with the token.
        Parameters:
        token - the token to remove the data for
        Returns:
        true if removed