Package jadex.common
Class DefaultPoolStrategy
java.lang.Object
jadex.common.DefaultPoolStrategy
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprotected 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.The waiting times of the pool.protected int
The number of workers in the pool. -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 TypeMethodDescriptionint
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.toString()
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.
-
Field Details
-
workercnt
protected int workercntThe number of workers in the pool. -
capacity
protected int capacityThe number of free workers. -
desfree
protected int desfreeThe desired number of free workers. -
maxwait
protected long maxwaitThe max wait time for workers. -
maxcnt
protected int maxcntThe maximum number of allowed workers. -
dodeferinc
protected boolean dodeferincDefer the creation of threads according to their distance from desfree. -
dodeferdec
protected boolean dodeferdecDefer the deletion of threads according to their distance from desfree. -
deferinc
protected int deferincThe defer factor to slow down thread creation. -
deferinctarget
protected int deferinctarget -
deferdec
protected int deferdecThe defer factor to slow down thread deletion. -
deferdectarget
protected int deferdectarget -
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 interfaceIPoolStrategy
- 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 interfaceIPoolStrategy
- 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 interfaceIPoolStrategy
- Parameters:
waitdur
- The waiting time of the task.
-
taskFinished
public boolean taskFinished()Called when a task is finished.- Specified by:
taskFinished
in interfaceIPoolStrategy
- Returns:
- True, if executing worker be excluded from the pool.
-
getWorkerTimeout
public long getWorkerTimeout()Get the worker timeout.- Specified by:
getWorkerTimeout
in interfaceIPoolStrategy
- 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 interfaceIPoolStrategy
- Returns:
- True, if the worker be excluded from the pool.
-
getWorkerCount
public int getWorkerCount()Get the worker cnt.- Specified by:
getWorkerCount
in interfaceIPoolStrategy
-
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 interfaceIPoolStrategy
- 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
Get the string representation.
-