Package jadex.micro.examples.mandelbrot
Class ServicePoolManager
- java.lang.Object
-
- jadex.micro.examples.mandelbrot.ServicePoolManager
-
public class ServicePoolManager extends java.lang.ObjectGeneric class that allows dispatching tasks to a dynamic pool of services.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classServicePoolManager.AllocationDataHandler for a single task allocation.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.MapbusyThe collection of busy services (id->service).protected IInternalAccesscomponentThe component, which manages the pool.protected booleancreatingFlag to indicate an ongoing creation.protected java.util.MapfreeThe collection of free services (id->service).protected IServicePoolHandlerhandlerThe handler for service creation, selection and invocation.protected intmaxThe maximum number of services (-1 for unlimited).protected java.lang.StringnameThe services name.protected booleansearchingFlag to indicate an ongoing search.protected java.util.MaptasksThe open tasks with their corresponding allocation data.protected ITimertimerThe search timeout timer.
-
Constructor Summary
Constructors Constructor Description ServicePoolManager(IInternalAccess component, java.lang.String name, IServicePoolHandler handler, int max)Create a new service pool manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddService(IService service)Add a service to the pool and start working on tasks.protected voidcreateServices()Create services until there are no more todo items.IIntermediateFutureperformTasks(java.util.Set tasks, boolean retry, java.lang.Object user)Perform the given tasks using available or newly created services.protected booleanretryTask(java.lang.Object task, ServicePoolManager.AllocationData ad)(Re-)start working on a task.protected voidsearchServices()Search for services or create new services as needed.voidsetMax(int max)Set the maximum number of services.
-
-
-
Field Detail
-
component
protected IInternalAccess component
The component, which manages the pool.
-
name
protected java.lang.String name
The services name.
-
handler
protected IServicePoolHandler handler
The handler for service creation, selection and invocation.
-
max
protected int max
The maximum number of services (-1 for unlimited).
-
free
protected java.util.Map free
The collection of free services (id->service).
-
busy
protected java.util.Map busy
The collection of busy services (id->service).
-
tasks
protected java.util.Map tasks
The open tasks with their corresponding allocation data.
-
searching
protected boolean searching
Flag to indicate an ongoing search.
-
creating
protected boolean creating
Flag to indicate an ongoing creation.
-
timer
protected ITimer timer
The search timeout timer.
-
-
Constructor Detail
-
ServicePoolManager
public ServicePoolManager(IInternalAccess component, java.lang.String name, IServicePoolHandler handler, int max)
Create a new service pool manager.- Parameters:
name- The services name.handler- The code for service invocation.
-
-
Method Detail
-
performTasks
public IIntermediateFuture performTasks(java.util.Set tasks, boolean retry, java.lang.Object user)
Perform the given tasks using available or newly created services.- Parameters:
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).- Returns:
- A future with intermediate and final results.
-
setMax
public void setMax(int max)
Set the maximum number of services. Only affects the creation of new services.
-
retryTask
protected boolean retryTask(java.lang.Object task, ServicePoolManager.AllocationData ad)(Re-)start working on a task.- Parameters:
task- The task.ad- The allocation data.- Returns:
- True, when the task was assigned to an available service.
-
searchServices
protected void searchServices()
Search for services or create new services as needed.
-
addService
protected void addService(IService service)
Add a service to the pool and start working on tasks.- Parameters:
service- The service to add.
-
createServices
protected void createServices()
Create services until there are no more todo items.- Parameters:
todo- The collection of remaining tasks.
-
-