public interface CommandQueue
Definition of an interface that describes a command queue.
A command queue can be used by an application to execute longer-running tasks in the background without blocking the main event dispatching thread. This way the application will stay responsive. The command pattern also provides a suitable way of structuring the logic implemented in an application.
The most important method in this interface is of course the
execute()
method, which allows scheduling new commands to be
executed. With shutdown()
the queue can be gracefully closed
(commands that are contained in the queue or are currently executed will be
finished before the queue actually shuts down). Further methods are available
for checking the current status of the queue.
Modifier and Type | Method and Description |
---|---|
void |
addQueueListener(CommandQueueListener l)
Adds a new listener to this queue.
|
void |
execute(Command cmd)
Adds a new
Command object to this queue. |
GUISynchronizer |
getGUISynchronizer()
Returns the
GUISynchronizer that is used by this command
queue. |
boolean |
isPending()
Checks if there are commands to be executed or in execution.
|
boolean |
isShutdown()
Returns a flag if
shutdown() was called. |
void |
removeQueueListener(CommandQueueListener l)
Removes the specified event listener from this command queue.
|
void |
setGUISynchronizer(GUISynchronizer sync)
Sets the
GUISynchronizer to be used by this command queue. |
void |
shutdown(boolean immediate)
Initiates the shutdown sequence.
|
void addQueueListener(CommandQueueListener l)
l
- the event listener to add (must not be null)IllegalArgumentException
- if the listener is undefinedvoid removeQueueListener(CommandQueueListener l)
l
- the listener to removeGUISynchronizer getGUISynchronizer()
GUISynchronizer
that is used by this command
queue.void setGUISynchronizer(GUISynchronizer sync)
GUISynchronizer
to be used by this command queue.
This object will be used to ensure that GUI updates performed by commands
are done on the event dispatch thread.sync
- the GUI synchronizervoid execute(Command cmd)
Command
object to this queue. It will be
executed as soon as the next worker thread is available.cmd
- the command to be executed (must not be null)IllegalArgumentException
- if the command is nullIllegalStateException
- if shutdown()
has already
been calledboolean isPending()
boolean isShutdown()
shutdown()
was called. After that no
commands can be executed any more.void shutdown(boolean immediate)
immediate
- a flag how the shutdown should be performedCopyright © 2016 The JGUIraffe Team. All rights reserved.