Package jadex.platform.service.execution
Class AsyncExecutionService
- java.lang.Object
-
- jadex.bridge.service.BasicService
-
- jadex.platform.service.execution.AsyncExecutionService
-
- All Implemented Interfaces:
IInternalService
,IService
,IExecutionService
public class AsyncExecutionService extends BasicService implements IExecutionService
The asynchronous executor service that executes all tasks in separate executors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AsyncExecutionService.State
The possible states of the service.
-
Field Summary
Fields Modifier and Type Field Description protected IInternalAccess
component
The component.protected java.util.Map<IExecutable,Executor>
executors
The currently waiting tasks (task->executor).protected Future<java.lang.Void>
idlefuture
The idle future.protected java.util.Map<IExecutable,Executor>
runningexes
The running (i.e.protected AsyncExecutionService.State
state
The state.protected IThreadPoolService
threadpool
The threadpool.-
Fields inherited from class jadex.bridge.service.BasicService
idcnt, impltype, internalaccess, providerid, shutdowned, sid, started, type
-
Fields inherited from interface jadex.bridge.service.IService
EMPTY_SERVICES
-
-
Constructor Summary
Constructors Constructor Description AsyncExecutionService(IInternalAccess component)
Create a new asynchronous executor service.AsyncExecutionService(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> properties)
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.boolean
customIsValid()
Test if the service is valid.void
execute(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.IFuture<java.lang.Void>
startService()
Start the execution service.-
Methods inherited from class jadex.bridge.service.BasicService
createServiceIdentifier, createServiceIdentifier, equals, generateServiceName, getInterfaceType, getInternalAccess, getInvokeMethod, getMethodInfos, getMethodTimeout, getPropertyMap, getProviderId, getServiceId, hashCode, initNFProperties, invokeMethod, isValid, setComponentAccess, setPropertyMap, setServiceIdentifier, toString
-
-
-
-
Field Detail
-
threadpool
protected IThreadPoolService 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 AsyncExecutionService.State state
The state.
-
component
protected IInternalAccess component
The component.
-
runningexes
protected java.util.Map<IExecutable,Executor> runningexes
The running (i.e. non-blocked) executors.
-
-
Constructor Detail
-
AsyncExecutionService
public AsyncExecutionService(IInternalAccess component)
Create a new asynchronous executor service.
-
AsyncExecutionService
public AsyncExecutionService(IInternalAccess component, java.util.Map<java.lang.String,java.lang.Object> properties)
Create a new asynchronous executor service.
-
-
Method Detail
-
execute
public void execute(IExecutable task)
Execute a task in its own thread.- Specified by:
execute
in 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:
cancel
in 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:
getRunningTasks
in interfaceIExecutionService
-
startService
public IFuture<java.lang.Void> startService()
Start the execution service. Resumes all scheduled tasks.- Specified by:
startService
in interfaceIInternalService
- Overrides:
startService
in classBasicService
- 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:
shutdownService
in interfaceIInternalService
- Overrides:
shutdownService
in classBasicService
- 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:
getNextIdleFuture
in interfaceIExecutionService
-
-