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 interfaceActionQueue.ListListener<T>static classActionQueue.Result
-
Constructor Summary
Constructors Modifier Constructor Description ActionQueue()protectedActionQueue(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.voidaddActions(java.util.Collection<Action<?>> actions)Adds all the given actions to the queue.voidaddActions(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 voidcheckRunning()Internal method for checking whether the queue is running before making queue alterations.voidclear()Removes all actions from the queue.java.util.List<Action<?>>getActions()Action<?>getInterruptedAction()ActionQueuegetStartActions()ActionQueuegetStopActions()intindexOf(Action<?> action)Returns the index of a given action in the queuebooleanisInterrupted()Returns whether the last run of the queue was interrupted or not.booleanisRunning()voidloadActions(java.lang.String path)voidremoveAction(Action action)Removes the supplied action from the queue.voidremoveActions(java.util.Collection<Action<?>> actions)Removes all the supplied actions from the queue.voidremoveActions(Action... actions)Removes all the supplied actions from the queue.voidremoveListener(ActionQueue.ListListener<Action> listener)Removes a listener from the queue.ActionQueue.Resultresume()Starts the queue from the last interrupted action.voidsaveActions(java.lang.String path)intsize()Returns the number of actions in the queue.ActionQueue.Resultstart()Starts the queue from the beginning.protected ActionQueue.Resultstart(boolean resume)voidstop()voidswapActions(int indexA, int indexB)Swaps the positions of two actions in the queue.voidswapActions(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.IOExceptionjava.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.IllegalStateExceptionInternal 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()
-
-