Class StorageQueueHandler

  • All Implemented Interfaces:
    LoggingSupporter, SizeOfHandler, Serializable

    public class StorageQueueHandler
    extends LoggingObject
    Wrapper class around a LinkedBlockingDeque object stored in internal storage. Allows to limit the queue size and the specification of a logging actor. It is possible to define retrieval timestamps for queue items, i.e., only after the timestamp passes is the retrieval possible ("delayed retrieval"). The underlying assumption with delayed retrieveal is that items added to the queue at a later stage will have increasing retrieval timestamps (they queue items don't get reordered based on that timestamp).
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    LogEntry, Serialized Form
    • Field Detail

      • m_Name

        protected String m_Name
        the name of the queue.
      • m_Limit

        protected int m_Limit
        the limit for the queue (-1 is unlimited).
      • m_Logging

        protected Actor m_Logging
        the (optional) logging actor.
      • m_Monitoring

        protected Actor m_Monitoring
        the (optional) monitoring actor.
    • Constructor Detail

      • StorageQueueHandler

        public StorageQueueHandler​(String name)
        Initializes the limitless queue with no logging.
        Parameters:
        name - the name of the queue
      • StorageQueueHandler

        public StorageQueueHandler​(String name,
                                   int limit,
                                   Actor logging,
                                   Actor monitoring)
        Initializes the queue with the specified limit and logging.
        Parameters:
        name - the name of the queue
        limit - the size limit, use <= 0 for unlimited
        logging - the logging actor for sending the LogEntry objects to
        monitoring - the monitoring actor for sending the LogEntry objects to
    • Method Detail

      • setLoggingLevel

        public void setLoggingLevel​(LoggingLevel value)
        Sets the logging level.
        Parameters:
        value - the level
      • getname

        public String getname()
        Returns the name of the queue.
        Returns:
        the name
      • getLimit

        public int getLimit()
        Returns the limit of the queue.
        Returns:
        the limit
      • hasLogging

        public boolean hasLogging()
        Checks whether a logging actor is available.
        Returns:
        true if available
      • getLogging

        public Actor getLogging()
        Returns the logging actor.
        Returns:
        the actor, null if not available
      • hasMonitoring

        public boolean hasMonitoring()
        Checks whether a monitoring actor is available.
        Returns:
        true if available
      • getMonitoring

        public Actor getMonitoring()
        Returns the monitoring actor.
        Returns:
        the actor, null if not available
      • log

        protected void log​(LogEntry log,
                           Actor actor)
        Logs the log entry with the specified actor.
        Parameters:
        log - the log entry to send
        actor - the logging actor to send the LogEntry to
      • logError

        protected void logError​(String msg,
                                Object obj)
        Creates a log entry and sends it to the logging actor.
        Parameters:
        msg - the msg
        obj - the object
      • logMonitor

        protected void logMonitor​(String type,
                                  Object obj)
        Creates a log entry and sends it to the monitoring actor.
        Parameters:
        type - the monitoring event type (Add or Remove)
        obj - the object to add, null in case of remove
      • add

        public boolean add​(Object obj)
        Adds the object to the queue.
        Parameters:
        obj - the object to add
        Returns:
        true if successfully added
      • addDelayedBy

        public boolean addDelayedBy​(Object obj,
                                    long delay)
        Adds the object to the queue with the specified retrieval delay.
        Parameters:
        obj - the object to add
        delay - the retrieval delay to use for the object
        Returns:
        true if successfully added
      • addDelayedAt

        public boolean addDelayedAt​(Object obj,
                                    long retrievalAt)
        Adds the object to the queue with the specified timestamp from which to allow retrieval.
        Parameters:
        obj - the object to add
        retrievalAt - the retrieval timestamp to associate with the object, 0 for immediate retrieval
        Returns:
        true if successfully added
      • canRemove

        public boolean canRemove()
        Checks whether it is possible to dequeue an item.
        Returns:
        true if object can be dequeued
      • remove

        public Object remove()
        Removes the first element from the queue and returns it.
        Returns:
        the first element from the queue
      • size

        public int size()
        Returns the size of the queue.
        Returns:
        the size
      • poll

        public Object poll​(long timeout,
                           TimeUnit unit)
                    throws InterruptedException
        Polls the queue in a blocking fashion.
        Parameters:
        timeout - the timeout for the poll
        unit - the time unit
        Returns:
        the value from the queue, null if timeout or not allowed to retrieve yet
        Throws:
        InterruptedException - if interrupted
      • toString

        public String toString()
        Returns a short description of the queue.
        Overrides:
        toString in class Object
        Returns:
        the description