public class ActionQueue extends Object implements Runnable
Constructor and Description |
---|
ActionQueue()
Creates a new ActionQueue.
|
Modifier and Type | Method and Description |
---|---|
void |
addAction(Action action)
Adds an Action to the end of this ActionQueue.
|
void |
addActionQueueListener(ActionQueueListener listener)
Adds an ActionQueueListener to the list of objects that are
interested in observing events from this ActionQueue.
|
protected void |
fireActionFinished(Action action)
Reports that an Action has completed successfully.
|
protected void |
fireActionQueueFailed(Throwable error)
Reports that the ActionQueue failed.
|
protected void |
fireActionQueueFinished()
Reports that the ActionQueue has finished successfully.
|
protected void |
fireActionStarting(Action action)
Reports that an Action is about to be performed.
|
int |
getActionCount()
Returns the number of Actions in this ActionQueue.
|
Enumeration |
getActions()
Returns the Actions in this ActionQueue.
|
void |
insertActionAt(Action action,
int index)
Inserts an Action into this ActionQueue at a specified index.
|
boolean |
isRunning()
Returns true if this ActionQueue is currently executing.
|
void |
removeActionAt(int index)
Removes an Action occuring at a specified index from this ActionQueue.
|
void |
removeActionQueueListener(ActionQueueListener listener)
Removes an ActionQueueListener such that it no longer receives
ActionQueue event notifications.
|
void |
run()
Executes this ActionQueue.
|
void |
start()
Performs all the Actions in this ActionQueue.
|
void |
stop()
Attempts to stop this ActionQueue.
|
void |
waitUntilDone()
Blocks the invoking Thread until the ActionQueue has completed.
|
public void addAction(Action action)
action
- the Action to add.public Enumeration getActions()
public void addActionQueueListener(ActionQueueListener listener)
listener
- the ActionQueueListener to add.public void removeActionQueueListener(ActionQueueListener listener)
listener
- the ActionQueueListener to remove.public void insertActionAt(Action action, int index)
action
- the Action to add.index
- the index that specifies the order when the
action should occur.ArrayIndexOutOfBoundsException
- if the index is invalid.public void removeActionAt(int index)
index
- the index that specifies the Action to be removed.ArrayIndexOutOfBoundsException
- if the index is invalid.public int getActionCount()
public void start()
Note: This method starts a separate Thread. It can be invoked only when the ActionQueue is idle. That is, while actions are being performed (the background Thread is still alive), this method will do nothing.
public void stop()
Invoking this method should stop this ActionQueue in a reasonable amount of
time, as long as the currently executing Action implements the stop method
correctly, according to the contract defined by the Action interface.
Clients can use the isRunning
to find out if the ActionQueue
has stopped.
Note: Once this method has been invoked, the ActionQueue will no longer
report that it has completed or failed. The ActionQueue will also no longer
report that the currently executing Action has finished. It is up to the
client to wait for the ActionQueue to finish because there can be no
guarantee that the currently executing Action will stop.
Clients can use the waitUntilDone
method immediately
after invoking this method to block until the ActionQueue has stopped.
public boolean isRunning()
public void waitUntilDone() throws InterruptedException
InterruptedException
- if the Thread is interrupted.public void run()
perform
method for
every Action. Also notifies registered listeners of Action events.protected void fireActionQueueFinished()
protected void fireActionQueueFailed(Throwable error)
error
- the Exception or Error that caused the failure.protected void fireActionStarting(Action action)
action
- the Action that is about to begin.protected void fireActionFinished(Action action)
action
- the Action that has finished.Copyright © 2023. All rights reserved.