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 void
addResult(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 contentvoid
enqueues a "fire and forget" command.void
enqueue(DBCommand command, DBCommandPriority priority)
enqueues a "fire and forget" command.void
enqueueAndAwaitResult(DBCommand command, DBCommandPriority priority, ResultHandle handle)
enqueues a command and remembers the result.void
enqueueAndAwaitResult(DBCommand command, ResultHandle handle)
enqueues a command and remembers the result.void
finish()
shuts the background thread down.static DBCommandQueue
get()
gets the singleton instanceprotected marauroa.server.db.command.DBCommandMetaData
gets the next command in the queue.protected Timestamp
gets 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 boolean
should the background set be terminated?int
size()
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
-