Class DBCommandQueue

java.lang.Object
marauroa.server.db.command.DBCommandQueue

public final class DBCommandQueue extends Object
An asynchronous command queue.
Author:
hendrik, madmetzger
  • Method Details

    • get

      public static DBCommandQueue get()
      gets the singleton instance
      Returns:
      DBCommandQueue
    • enqueue

      public void enqueue(DBCommand command)
      enqueues a "fire and forget" command.
      Parameters:
      command - DBCommand to add to the queue
    • enqueue

      public void enqueue(DBCommand command, DBCommandPriority priority)
      enqueues a "fire and forget" command.
      Parameters:
      command - DBCommand to add to the queue
      priority - DBCommandPriority
    • enqueueAndAwaitResult

      public void enqueueAndAwaitResult(DBCommand command, ResultHandle handle)
      enqueues a command and remembers the result.
      Parameters:
      command - DBCommand to add to the queue
      handle - ResultHandle
    • enqueueAndAwaitResult

      public void enqueueAndAwaitResult(DBCommand command, DBCommandPriority priority, ResultHandle handle)
      enqueues a command and remembers the result.
      Parameters:
      command - DBCommand to add to the queue
      priority - DBCommandPriority
      handle - ResultHandle
    • getNextCommand

      protected marauroa.server.db.command.DBCommandMetaData getNextCommand() throws InterruptedException
      gets the next command in the queue.
      Returns:
      next command or null
      Throws:
      InterruptedException - in case the waiting was interrupted
    • addResult

      protected void addResult(marauroa.server.db.command.DBCommandMetaData metaData)
      adds a result to be fetched later
      Parameters:
      metaData - a processed DBCommandMetaData
    • getResults

      public <T extends DBCommand> List<T> getResults(Class<T> clazz, ResultHandle handle)
      gets the processed results of the specified DBCommand class that have been requested in the current thread.
      Type Parameters:
      T - the type of the DBCommand
      Parameters:
      clazz - the type of the DBCommand
      handle - a handle to the expected results
      Returns:
      a list of processed DBCommands; it may be empty
    • getOneResult

      public <T extends DBCommand> T getOneResult(Class<T> clazz, ResultHandle handle)
      gets one processed result of the specified DBCommand class that have been requested in the current thread.
      Type Parameters:
      T - the type of the DBCommand
      Parameters:
      clazz - the type of the DBCommand
      handle - a handle to the expected results
      Returns:
      a list of processed DBCommands; it may be empty
    • finish

      public void finish()
      shuts the background thread down.
    • isFinished

      protected boolean isFinished()
      should the background set be terminated?
      Returns:
      true, if the background thread should be terminated, false if it should continue.
    • size

      public int size()
      returns the size of the queue
      Returns:
      size of queue
    • getOldestEnqueueTimestamp

      protected Timestamp getOldestEnqueueTimestamp()
      gets the timestamp of the oldest pending command
      Returns:
      Timestamp or null
    • dumpQueue

      protected marauroa.server.db.command.DBCommandMetaData[] dumpQueue()
      returns a frozen array of the complete queue content
      Returns:
      array of the queue content