public class CommandQueueImpl extends Object implements CommandQueue
A command queue implementation for GUI applications.
This class maintains a queue, in which Command objects can be
inserted by an application. At least one worker thread monitors the queue and
executes the commands.
In an application usually the execute() method is of most
importance. Here new Command objects are passed. Then the
application need not bother about execution of these commands in a background
thread. The other methods will be used by worker threads to obtain commands
and send notifications about executed commands.
| Constructor and Description |
|---|
CommandQueueImpl(GUISynchronizer sync)
Creates a new instance of
CommandQueue and initializes it
with the GUISynchronizer. |
CommandQueueImpl(GUISynchronizer sync,
ExecutorService execSrvc)
Creates a new instance of
CommandQueueImpl and initializes
it with the GUISynchronizer and the
ExecutorService to be used. |
| Modifier and Type | Method and Description |
|---|---|
void |
addQueueListener(CommandQueueListener l)
Adds an event listener to this queue.
|
protected Runnable |
createTask(Command cmd)
Creates a task object for executing the passed in command.
|
void |
execute(Command cmd)
Executes the specified command object.
|
protected void |
fireQueueEvent(Command cmd,
CommandQueueEvent.Type eventType)
Notifies all registered listeners about a change in the state of this
queue.
|
ExecutorService |
getExecutorService()
Returns the
ExecutorService used by this command queue. |
GUISynchronizer |
getGUISynchronizer()
Returns the
GUISynchronizer. |
boolean |
isPending()
Tests whether there are commands that have not been executed.
|
boolean |
isShutdown()
Tests whether this command queue was shutdown.
|
void |
processingFinished(Command cmd)
This method is called by a worker thread if a command has been executed.
|
void |
removeQueueListener(CommandQueueListener l)
Removes the specified event listener from this queue.
|
void |
setGUISynchronizer(GUISynchronizer sync)
Sets the
GUISynchronizer. |
void |
shutdown(boolean immediate)
Shuts down this command queue.
|
public CommandQueueImpl(GUISynchronizer sync)
CommandQueue and initializes it
with the GUISynchronizer. A default
ExecutorService will be created.sync - the GUI synchronizer object (must not be null)IllegalArgumentException - if a required parameter is missingpublic CommandQueueImpl(GUISynchronizer sync, ExecutorService execSrvc)
CommandQueueImpl and initializes
it with the GUISynchronizer and the
ExecutorService to be used.sync - the GUISynchronizer (must not be null)execSrvc - the ExecutorService (must not be null)IllegalArgumentException - if a required parameter is missingpublic GUISynchronizer getGUISynchronizer()
GUISynchronizer.getGUISynchronizer in interface CommandQueuepublic void setGUISynchronizer(GUISynchronizer sync)
GUISynchronizer.setGUISynchronizer in interface CommandQueuesync - the GUI synchronizer (must not be null)IllegalArgumentException - if the synchronizer is nullpublic ExecutorService getExecutorService()
ExecutorService used by this command queue.public void addQueueListener(CommandQueueListener l)
addQueueListener in interface CommandQueuel - the listener to add (must not be null)IllegalArgumentException - if the listener is undefinedpublic void removeQueueListener(CommandQueueListener l)
removeQueueListener in interface CommandQueuel - the listener to removepublic void execute(Command cmd)
createTask() to create a task object for actually
executing the command. This task is then passed to the
ExecutorService, so it will be processed by a background
thread.execute in interface CommandQueuecmd - the command to be executed (must not be null)IllegalArgumentException - if the command is nullIllegalStateException - if shutdown() has already
been calledpublic void processingFinished(Command cmd)
cmd - the command that has been processedpublic boolean isPending()
execute() method) that have not yet been completed.isPending in interface CommandQueuepublic boolean isShutdown()
isShutdown in interface CommandQueueshutdown() was calledpublic void shutdown(boolean immediate)
shutdown in interface CommandQueueimmediate - a flag whether an immediate shutdown should be performedprotected void fireQueueEvent(Command cmd, CommandQueueEvent.Type eventType)
cmd - the affected commandeventType - the type of the event to fireCopyright © 2016 The JGUIraffe Team. All rights reserved.