Package jisa.experiment.queue
Class ActionQueue
- java.lang.Object
-
- jisa.experiment.queue.ActionQueue
-
- All Implemented Interfaces:
java.io.Serializable
public class ActionQueue extends java.lang.Object implements java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ActionQueue.ListListener<T>
static class
ActionQueue.Result
-
Constructor Summary
Constructors Modifier Constructor Description ActionQueue()
protected
ActionQueue(boolean subQueues)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends Action>
TaddAction(T action)
Adds an action to the queue.void
addActions(java.util.Collection<Action<?>> actions)
Adds all the given actions to the queue.void
addActions(Action... actions)
Adds all the given actions to the queue.ActionQueue.ListListener<Action<?>>
addListener(ActionQueue.ListListener<Action<?>> listener)
Adds a listener to be triggered every time the queue is changed (actions added, removed or changed order).protected void
checkRunning()
Internal method for checking whether the queue is running before making queue alterations.void
clear()
Removes all actions from the queue.java.util.List<Action<?>>
getActions()
Action<?>
getInterruptedAction()
ActionQueue
getStartActions()
ActionQueue
getStopActions()
int
indexOf(Action<?> action)
Returns the index of a given action in the queueboolean
isInterrupted()
Returns whether the last run of the queue was interrupted or not.boolean
isRunning()
void
loadActions(java.lang.String path)
void
removeAction(Action action)
Removes the supplied action from the queue.void
removeActions(java.util.Collection<Action<?>> actions)
Removes all the supplied actions from the queue.void
removeActions(Action... actions)
Removes all the supplied actions from the queue.void
removeListener(ActionQueue.ListListener<Action> listener)
Removes a listener from the queue.ActionQueue.Result
resume()
Starts the queue from the last interrupted action.void
saveActions(java.lang.String path)
int
size()
Returns the number of actions in the queue.ActionQueue.Result
start()
Starts the queue from the beginning.protected ActionQueue.Result
start(boolean resume)
void
stop()
void
swapActions(int indexA, int indexB)
Swaps the positions of two actions in the queue.void
swapActions(Action a, Action b)
Swaps the positions of two actions in the queue.
-
-
-
Method Detail
-
addAction
public <T extends Action> T addAction(T action)
Adds an action to the queue.- Type Parameters:
T
- Action type- Parameters:
action
- Action to add- Returns:
- The action that was added
-
saveActions
public void saveActions(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
loadActions
public void loadActions(java.lang.String path) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
addActions
public void addActions(Action... actions)
Adds all the given actions to the queue.- Parameters:
actions
- Actions to add
-
addActions
public void addActions(java.util.Collection<Action<?>> actions)
Adds all the given actions to the queue.- Parameters:
actions
- Actions to add
-
removeAction
public void removeAction(Action action)
Removes the supplied action from the queue.- Parameters:
action
- Action to remove
-
removeActions
public void removeActions(Action... actions)
Removes all the supplied actions from the queue.- Parameters:
actions
- Actions to remove
-
removeActions
public void removeActions(java.util.Collection<Action<?>> actions)
Removes all the supplied actions from the queue.- Parameters:
actions
- Actions to remove
-
size
public int size()
Returns the number of actions in the queue.- Returns:
- Number of actions in queue
-
indexOf
public int indexOf(Action<?> action)
Returns the index of a given action in the queue- Parameters:
action
- Action to find index of- Returns:
- Index of action
-
swapActions
public void swapActions(int indexA, int indexB)
Swaps the positions of two actions in the queue.- Parameters:
indexA
- Index of action to swapindexB
- Index of action to swap
-
swapActions
public void swapActions(Action a, Action b)
Swaps the positions of two actions in the queue.- Parameters:
a
- Action to swapb
- Action to swap
-
getActions
public java.util.List<Action<?>> getActions()
-
clear
public void clear()
Removes all actions from the queue.
-
addListener
public ActionQueue.ListListener<Action<?>> addListener(ActionQueue.ListListener<Action<?>> listener)
Adds a listener to be triggered every time the queue is changed (actions added, removed or changed order).- Parameters:
listener
- Listener to add- Returns:
- The listener that was added
-
removeListener
public void removeListener(ActionQueue.ListListener<Action> listener)
Removes a listener from the queue.- Parameters:
listener
- The listener to be removed
-
checkRunning
protected void checkRunning() throws java.lang.IllegalStateException
Internal method for checking whether the queue is running before making queue alterations. Throws an IllegalStateException if it is running.- Throws:
java.lang.IllegalStateException
- If the queue is running
-
isRunning
public boolean isRunning()
-
isInterrupted
public boolean isInterrupted()
Returns whether the last run of the queue was interrupted or not.- Returns:
- Was it interrupted?
-
getInterruptedAction
public Action<?> getInterruptedAction()
-
start
public ActionQueue.Result start()
Starts the queue from the beginning. Returns the overall result of the queue once completed.- Returns:
- Result of queue execution (SUCCESS, INTERRUPTED or ERROR)
-
resume
public ActionQueue.Result resume()
Starts the queue from the last interrupted action.- Returns:
- Result of queue execution (SUCCESS, INTERRUPTED or ERROR)
-
getStartActions
public ActionQueue getStartActions()
-
getStopActions
public ActionQueue getStopActions()
-
start
protected ActionQueue.Result start(boolean resume)
-
stop
public void stop()
-
-