Class ServicePoolManager


  • public class ServicePoolManager
    extends java.lang.Object
    Generic class that allows dispatching tasks to a dynamic pool of services.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map busy
      The collection of busy services (id->service).
      protected 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 ITimer timer
      The search timeout timer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addService​(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.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.