public class ServicePoolManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ServicePoolManager.AllocationData
Handler for a single task allocation.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map |
busy
The collection of busy services (id->service).
|
protected jadex.bridge.IInternalAccess |
component
The component, which manages the pool.
|
protected boolean |
creating
Flag to indicate an ongoing creation.
|
protected java.util.Map |
free
The collection of free services (id->service).
|
protected IServicePoolHandler |
handler
The handler for service creation, selection and invocation.
|
protected int |
max
The maximum number of services (-1 for unlimited).
|
protected java.lang.String |
name
The services name.
|
protected boolean |
searching
Flag to indicate an ongoing search.
|
protected java.util.Map |
tasks
The open tasks with their corresponding allocation data.
|
protected jadex.bridge.service.types.clock.ITimer |
timer
The search timeout timer.
|
Constructor and Description |
---|
ServicePoolManager(jadex.bridge.IInternalAccess component,
java.lang.String name,
IServicePoolHandler handler,
int max)
Create a new service pool manager.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addService(jadex.bridge.service.IService service)
Add a service to the pool and start working on tasks.
|
protected void |
createServices()
Create services until there are no more todo items.
|
jadex.commons.future.IIntermediateFuture |
performTasks(java.util.Set tasks,
boolean retry,
java.lang.Object user)
Perform the given tasks using available or newly created services.
|
protected boolean |
retryTask(java.lang.Object task,
ServicePoolManager.AllocationData ad)
(Re-)start working on a task.
|
protected void |
searchServices()
Search for services or create new services as needed.
|
void |
setMax(int max)
Set the maximum number of services.
|
protected jadex.bridge.IInternalAccess component
protected java.lang.String name
protected IServicePoolHandler handler
protected int max
protected java.util.Map free
protected java.util.Map busy
protected java.util.Map tasks
protected boolean searching
protected boolean creating
protected jadex.bridge.service.types.clock.ITimer timer
public ServicePoolManager(jadex.bridge.IInternalAccess component, java.lang.String name, IServicePoolHandler handler, int max)
name
- The services name.handler
- The code for service invocation.public jadex.commons.future.IIntermediateFuture performTasks(java.util.Set tasks, boolean retry, java.lang.Object user)
tasks
- The set of tasks to be performed.retry
- True, when failed tasks should be retried.user
- User data that is provided for service selection, creation, invocation (if any).public void setMax(int max)
protected boolean retryTask(java.lang.Object task, ServicePoolManager.AllocationData ad)
task
- The task.ad
- The allocation data.protected void searchServices()
protected void addService(jadex.bridge.service.IService service)
service
- The service to add.protected void createServices()
todo
- The collection of remaining tasks.