Package marauroa.server.db.command
Class DBCommandQueue
java.lang.Object
marauroa.server.db.command.DBCommandQueue
An asynchronous command queue.
- Author:
- hendrik, madmetzger
-
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddResult(marauroa.server.db.command.DBCommandMetaData metaData)adds a result to be fetched laterprotected marauroa.server.db.command.DBCommandMetaData[]returns a frozen array of the complete queue contentvoidenqueues a "fire and forget" command.voidenqueue(DBCommand command, DBCommandPriority priority)enqueues a "fire and forget" command.voidenqueueAndAwaitResult(DBCommand command, DBCommandPriority priority, ResultHandle handle)enqueues a command and remembers the result.voidenqueueAndAwaitResult(DBCommand command, ResultHandle handle)enqueues a command and remembers the result.voidfinish()shuts the background thread down.static DBCommandQueueget()gets the singleton instanceprotected marauroa.server.db.command.DBCommandMetaDatagets the next command in the queue.protected Timestampgets the timestamp of the oldest pending command<T extends DBCommand>
TgetOneResult(Class<T> clazz, ResultHandle handle)gets one processed result of the specified DBCommand class that have been requested in the current thread.getResults(Class<T> clazz, ResultHandle handle)gets the processed results of the specified DBCommand class that have been requested in the current thread.protected booleanshould the background set be terminated?intsize()returns the size of the queue
-
Method Details
-
get
gets the singleton instance- Returns:
- DBCommandQueue
-
enqueue
enqueues a "fire and forget" command.- Parameters:
command- DBCommand to add to the queue
-
enqueue
enqueues a "fire and forget" command.- Parameters:
command- DBCommand to add to the queuepriority- DBCommandPriority
-
enqueueAndAwaitResult
enqueues a command and remembers the result.- Parameters:
command- DBCommand to add to the queuehandle- 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 queuepriority- DBCommandPriorityhandle- ResultHandle
-
getNextCommand
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
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 DBCommandhandle- a handle to the expected results- Returns:
- a list of processed DBCommands; it may be empty
-
getOneResult
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 DBCommandhandle- 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
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
-