Class ActionExecutor
- java.lang.Object
-
- org.nuiton.jaxx.runtime.swing.application.ActionExecutor
-
public class ActionExecutor extends Object
Executor ofActionWorker.- Since:
- 2.1
- Author:
- Tony Chemit - dev@tchemit.fr
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<ActionWorker<?,?>>tasksCuurrent tasks.protected PropertyChangeListenerworkerListenerThe listener of running action.
-
Constructor Summary
Constructors Constructor Description ActionExecutor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActionWorker<?,?>addAction(String actionLabel, Runnable action)Add an new action to perform.voidaddAction(ActionWorker<?,?> worker)Add an new worker to perform.voidaddActionExecutorListener(ActionExecutorListener listener)RunnablecreateRunnable(Object methodContainer, String methodName, Object... arguments)Creates a runnable instance (via a Proxy) to a method given by his name (methodName) to invoke onmethodcontainerwith givenarguments.protected voidexecuteWorker(String actionLabel, ActionWorker<?,?> worker)Execute worker once it was added to tasks.protected voidfireAction(ActionWorker<?,?> worker, BiConsumer<ActionExecutorListener,ActionExecutorEvent> function)protected voidfireActionCancel(ActionWorker<?,?> source)protected voidfireActionDone(ActionWorker<?,?> worker)protected voidfireActionEnd(ActionWorker<?,?> source)protected voidfireActionFail(ActionWorker<?,?> source)protected voidfireActionStart(ActionWorker<?,?> source)protected ActionExecutorListener[]getActionExecutorListener()intgetNbActions()Set<ActionWorker<?,?>>getTasks()voidonActionCancel(ActionWorker<?,?> source)Hook when a action has been canceled.voidonActionEnd(ActionWorker<?,?> source)Hook when a action has end with no failure or cancel.voidonActionFail(ActionWorker<?,?> source)Hook when a action has failed.voidonActionStart(ActionWorker<?,?> source)Hook when a action is about to start.voidonAfterAction(ActionWorker<?,?> source)Hook after action is consumed.voidremoveActionExecutorListener(ActionExecutorListener listener)voidterminatesAndWaits()Ask the thread to stop.
-
-
-
Field Detail
-
tasks
protected final Set<ActionWorker<?,?>> tasks
Cuurrent tasks.
-
workerListener
protected final PropertyChangeListener workerListener
The listener of running action.
-
-
Method Detail
-
addAction
public ActionWorker<?,?> addAction(String actionLabel, Runnable action)
Add an new action to perform.- Parameters:
actionLabel- the name of the action to performaction- the action to perform- Returns:
- the worker that will launch the action
-
addAction
public void addAction(ActionWorker<?,?> worker)
Add an new worker to perform.- Parameters:
worker- the worker to run
-
onActionStart
public void onActionStart(ActionWorker<?,?> source)
Hook when a action is about to start.- Parameters:
source- the action worker containing the action to perform
-
onActionFail
public void onActionFail(ActionWorker<?,?> source)
Hook when a action has failed.- Parameters:
source- the action worker containing the action to perform
-
onActionCancel
public void onActionCancel(ActionWorker<?,?> source)
Hook when a action has been canceled.- Parameters:
source- the action worker containing the action to perform
-
onActionEnd
public void onActionEnd(ActionWorker<?,?> source)
Hook when a action has end with no failure or cancel.- Parameters:
source- the action worker containing the action to perform
-
onAfterAction
public void onAfterAction(ActionWorker<?,?> source)
Hook after action is consumed.- Parameters:
source- the action worker containing the action to perform
-
terminatesAndWaits
public void terminatesAndWaits()
Ask the thread to stop.It will finish all incoming files (but will not accept more tasks). Note: The method does not return until all tasks are not consumed.
-
addActionExecutorListener
public void addActionExecutorListener(ActionExecutorListener listener)
-
removeActionExecutorListener
public void removeActionExecutorListener(ActionExecutorListener listener)
-
getActionExecutorListener
protected ActionExecutorListener[] getActionExecutorListener()
-
fireActionStart
protected void fireActionStart(ActionWorker<?,?> source)
-
fireActionFail
protected void fireActionFail(ActionWorker<?,?> source)
-
fireActionCancel
protected void fireActionCancel(ActionWorker<?,?> source)
-
fireActionEnd
protected void fireActionEnd(ActionWorker<?,?> source)
-
fireActionDone
protected void fireActionDone(ActionWorker<?,?> worker)
-
fireAction
protected void fireAction(ActionWorker<?,?> worker, BiConsumer<ActionExecutorListener,ActionExecutorEvent> function)
-
getNbActions
public int getNbActions()
-
getTasks
public Set<ActionWorker<?,?>> getTasks()
-
createRunnable
public Runnable createRunnable(Object methodContainer, String methodName, Object... arguments)
Creates a runnable instance (via a Proxy) to a method given by his name (methodName) to invoke onmethodcontainerwith givenarguments.This is a great feature to create runnable code with a real context.
- Parameters:
methodContainer- the container of the method to invokemethodName- the name of the method to invokearguments- parameters to pass to method to invke.- Returns:
- the proxy instance
-
executeWorker
protected void executeWorker(String actionLabel, ActionWorker<?,?> worker)
Execute worker once it was added to tasks.This method permits to override how to execute it.
- Parameters:
actionLabel- action labelworker- worker to execute
-
-