Package jadex.noplatform.services
Class ExecutionService
- java.lang.Object
-
- jadex.noplatform.services.BaseService
-
- jadex.noplatform.services.ExecutionService
-
- All Implemented Interfaces:
IInternalService,IService,IExecutionService
public class ExecutionService extends BaseService implements IExecutionService
The asynchronous executor service that executes all tasks in separate executors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classExecutionService.StateThe possible states of the service.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<IExecutable,Executor>executorsThe currently waiting tasks (task->executor).protected Future<java.lang.Void>idlefutureThe idle future.protected java.util.Map<IExecutable,Executor>runningexesThe running (i.e. non-blocked) executors.protected ExecutionService.StatestateThe state.protected IThreadPoolthreadpoolThe threadpool.-
Fields inherited from class jadex.noplatform.services.BaseService
cid, sid
-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description ExecutionService(IComponentIdentifier cid, IThreadPool threadpool)Create a new asynchronous executor service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IFuture<java.lang.Void>cancel(IExecutable task)Cancel a task.booleancustomIsValid()Test if the service is valid.voidexecute(IExecutable task)Execute a task in its own thread.IFuture<java.lang.Void>getNextIdleFuture()Get the future indicating that executor is idle.IExecutable[]getRunningTasks()Get the currently running tasks.IFuture<java.lang.Void>shutdownService()Shutdown the executor service. // todo: make callable more than onceIFuture<java.lang.Void>startService()Start the execution service.-
Methods inherited from class jadex.noplatform.services.BaseService
getComponentId, getMethodInfos, getPropertyMap, getServiceId, invokeMethod, isValid, setComponentAccess, setServiceIdentifier
-
-
-
-
Field Detail
-
threadpool
protected IThreadPool threadpool
The threadpool.
-
executors
protected java.util.Map<IExecutable,Executor> executors
The currently waiting tasks (task->executor).
-
idlefuture
protected Future<java.lang.Void> idlefuture
The idle future.
-
state
protected ExecutionService.State state
The state.
-
runningexes
protected java.util.Map<IExecutable,Executor> runningexes
The running (i.e. non-blocked) executors.
-
-
Constructor Detail
-
ExecutionService
public ExecutionService(IComponentIdentifier cid, IThreadPool threadpool)
Create a new asynchronous executor service.
-
-
Method Detail
-
execute
public void execute(IExecutable task)
Execute a task in its own thread.- Specified by:
executein interfaceIExecutionService- Parameters:
task- The task to execute. (called from arbitrary threads)
-
cancel
public IFuture<java.lang.Void> cancel(IExecutable task)
Cancel a task. Triggers the task to be not executed in future.- Specified by:
cancelin interfaceIExecutionService- Parameters:
task- The task to execute.listener- The listener.- Returns:
- Future signaling cancellation.
-
getRunningTasks
public IExecutable[] getRunningTasks()
Get the currently running tasks.- Specified by:
getRunningTasksin interfaceIExecutionService
-
startService
public IFuture<java.lang.Void> startService()
Start the execution service. Resumes all scheduled tasks.- Specified by:
startServicein interfaceIInternalService- Returns:
- A future that is done when the service has completed starting.
-
shutdownService
public IFuture<java.lang.Void> shutdownService()
Shutdown the executor service. // todo: make callable more than once- Specified by:
shutdownServicein interfaceIInternalService- Returns:
- A future that is done when the service has completed its shutdown.
-
customIsValid
public boolean customIsValid()
Test if the service is valid.- Returns:
- True, if service can be used.
-
getNextIdleFuture
public IFuture<java.lang.Void> getNextIdleFuture()
Get the future indicating that executor is idle.- Specified by:
getNextIdleFuturein interfaceIExecutionService
-
-