Package jadex.common

Class DefaultPoolStrategy

java.lang.Object
jadex.common.DefaultPoolStrategy
All Implemented Interfaces:
IPoolStrategy

public class DefaultPoolStrategy extends Object implements IPoolStrategy
This strategy has two parameters: - The desired number of free workers in the pool. - The maximum timeout for workers to wait for new tasks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The number of free workers.
    protected int
    The defer factor to slow down thread deletion.
    protected int
     
    protected int
    The defer factor to slow down thread creation.
    protected int
     
    protected int
    The desired number of free workers.
    protected boolean
    Defer the deletion of threads according to their distance from desfree.
    protected boolean
    Defer the creation of threads according to their distance from desfree.
    protected int
    The maximum number of allowed workers.
    protected long
    The max wait time for workers.
    protected List<Double>
    The waiting times of the pool.
    protected int
    The number of workers in the pool.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new default pool strategy.
    DefaultPoolStrategy(int desfree, int maxcnt)
    Create a new default pool strategy.
    DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt)
    Create a new default pool strategy.
    DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt, boolean defer)
    Create a new default pool strategy.
    DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt, boolean deferinc, boolean deferdec)
    Create a new default pool strategy.
    DefaultPoolStrategy(int desfree, long maxwait, int maxcnt)
    Create a new default pool strategy.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Get the capacity.
    int
    Get the desfree.
    int
    Get the max cnt.
    long
    Get the maxwait.
    int
    Get the worker cnt.
    long
    Get the worker timeout.
    void
    setCapacity(int capacity)
    Set the capacity.
    void
    setDesiredFree(int desfree)
    Set the desfree.
    void
    setMaxCount(int maxcnt)
    Set the max cnt.
    void
    setMaxWait(long maxwait)
    Set the maxwait.
    void
    setWorkerCount(int workercnt)
    Set the worker cnt.
    boolean
    Called when a new task was added to the pool.
    boolean
    Called when a task is finished.
    void
    taskServed(long waitdur)
    Called when a new task was served from the pool.
    Get the string representation.
    void
    workersAdded(int cnt)
    Called when a new worker was added proactively to the pool.
    boolean
    Notify the strategy that a timeout for a worker has occurred, i.e.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • workercnt

      protected int workercnt
      The number of workers in the pool.
    • capacity

      protected int capacity
      The number of free workers.
    • desfree

      protected int desfree
      The desired number of free workers.
    • maxwait

      protected long maxwait
      The max wait time for workers.
    • maxcnt

      protected int maxcnt
      The maximum number of allowed workers.
    • dodeferinc

      protected boolean dodeferinc
      Defer the creation of threads according to their distance from desfree.
    • dodeferdec

      protected boolean dodeferdec
      Defer the deletion of threads according to their distance from desfree.
    • deferinc

      protected int deferinc
      The defer factor to slow down thread creation.
    • deferinctarget

      protected int deferinctarget
    • deferdec

      protected int deferdec
      The defer factor to slow down thread deletion.
    • deferdectarget

      protected int deferdectarget
    • waitings

      protected List<Double> waitings
      The waiting times of the pool.
  • Constructor Details

    • DefaultPoolStrategy

      public DefaultPoolStrategy()
      Create a new default pool strategy.
    • DefaultPoolStrategy

      public DefaultPoolStrategy(int desfree, int maxcnt)
      Create a new default pool strategy.
    • DefaultPoolStrategy

      public DefaultPoolStrategy(int desfree, long maxwait, int maxcnt)
      Create a new default pool strategy.
    • DefaultPoolStrategy

      public DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt)
      Create a new default pool strategy.
    • DefaultPoolStrategy

      public DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt, boolean defer)
      Create a new default pool strategy.
    • DefaultPoolStrategy

      public DefaultPoolStrategy(int workercnt, int desfree, long maxwait, int maxcnt, boolean deferinc, boolean deferdec)
      Create a new default pool strategy.
  • Method Details

    • taskAdded

      public boolean taskAdded()
      Called when a new task was added to the pool.
      Specified by:
      taskAdded in interface IPoolStrategy
      Returns:
      True, if a new worker should be added to the pool.
    • workersAdded

      public void workersAdded(int cnt)
      Called when a new worker was added proactively to the pool.
      Specified by:
      workersAdded in interface IPoolStrategy
      Parameters:
      cnt - The number of new workers.
    • taskServed

      public void taskServed(long waitdur)
      Called when a new task was served from the pool.
      Specified by:
      taskServed in interface IPoolStrategy
      Parameters:
      waitdur - The waiting time of the task.
    • taskFinished

      public boolean taskFinished()
      Called when a task is finished.
      Specified by:
      taskFinished in interface IPoolStrategy
      Returns:
      True, if executing worker be excluded from the pool.
    • getWorkerTimeout

      public long getWorkerTimeout()
      Get the worker timeout.
      Specified by:
      getWorkerTimeout in interface IPoolStrategy
      Returns:
      The timeout for the worker to wait for new tasks in the pool.
    • workerTimeoutOccurred

      public boolean workerTimeoutOccurred()
      Notify the strategy that a timeout for a worker has occurred, i.e. it was not needed for serving some task.
      Specified by:
      workerTimeoutOccurred in interface IPoolStrategy
      Returns:
      True, if the worker be excluded from the pool.
    • getWorkerCount

      public int getWorkerCount()
      Get the worker cnt.
      Specified by:
      getWorkerCount in interface IPoolStrategy
    • setWorkerCount

      public void setWorkerCount(int workercnt)
      Set the worker cnt.
      Parameters:
      workercnt - The workercnt to set.
    • getCapacity

      public int getCapacity()
      Get the capacity.
      Specified by:
      getCapacity in interface IPoolStrategy
      Returns:
      The capacity.
    • setCapacity

      public void setCapacity(int capacity)
      Set the capacity.
      Parameters:
      capacity - The capacity to set.
    • getDesiredFree

      public int getDesiredFree()
      Get the desfree.
      Returns:
      The desfree.
    • setDesiredFree

      public void setDesiredFree(int desfree)
      Set the desfree.
      Parameters:
      desfree - The desfree to set.
    • getMaxWait

      public long getMaxWait()
      Get the maxwait.
      Returns:
      The maxwait.
    • setMaxWait

      public void setMaxWait(long maxwait)
      Set the maxwait.
      Parameters:
      maxwait - The maxwait to set.
    • getMaxCount

      public int getMaxCount()
      Get the max cnt.
      Returns:
      The max cnt.
    • setMaxCount

      public void setMaxCount(int maxcnt)
      Set the max cnt.
      Parameters:
      maxservicecnt - The max cnt to set.
    • toString

      public String toString()
      Get the string representation.
      Overrides:
      toString in class Object