Package jadex.commons
Class DefaultPoolStrategy
- java.lang.Object
-
- jadex.commons.DefaultPoolStrategy
-
- All Implemented Interfaces:
IPoolStrategy
public class DefaultPoolStrategy extends java.lang.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 intcapacityThe number of free workers.protected intdeferdecThe defer factor to slow down thread deletion.protected intdeferdectargetprotected intdeferincThe defer factor to slow down thread creation.protected intdeferinctargetprotected intdesfreeThe desired number of free workers.protected booleandodeferdecDefer the deletion of threads according to their distance from desfree.protected booleandodeferincDefer the creation of threads according to their distance from desfree.protected intmaxcntThe maximum number of allowed workers.protected longmaxwaitThe max wait time for workers.protected java.util.List<java.lang.Double>waitingsThe waiting times of the pool.protected intworkercntThe number of workers in the pool.
-
Constructor Summary
Constructors Constructor Description DefaultPoolStrategy()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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetCapacity()Get the capacity.intgetDesiredFree()Get the desfree.intgetMaxCount()Get the max cnt.longgetMaxWait()Get the maxwait.intgetWorkerCount()Get the worker cnt.longgetWorkerTimeout()Get the worker timeout.voidsetCapacity(int capacity)Set the capacity.voidsetDesiredFree(int desfree)Set the desfree.voidsetMaxCount(int maxcnt)Set the max cnt.voidsetMaxWait(long maxwait)Set the maxwait.voidsetWorkerCount(int workercnt)Set the worker cnt.booleantaskAdded()Called when a new task was added to the pool.booleantaskFinished()Called when a task is finished.voidtaskServed(long waitdur)Called when a new task was served from the pool.java.lang.StringtoString()Get the string representation.voidworkersAdded(int cnt)Called when a new worker was added proactively to the pool.booleanworkerTimeoutOccurred()Notify the strategy that a timeout for a worker has occurred, i.e.
-
-
-
Field Detail
-
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 java.util.List<java.lang.Double> waitings
The waiting times of the pool.
-
-
Constructor Detail
-
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 Detail
-
taskAdded
public boolean taskAdded()
Called when a new task was added to the pool.- Specified by:
taskAddedin 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:
workersAddedin 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:
taskServedin interfaceIPoolStrategy- Parameters:
waitdur- The waiting time of the task.
-
taskFinished
public boolean taskFinished()
Called when a task is finished.- Specified by:
taskFinishedin interfaceIPoolStrategy- Returns:
- True, if executing worker be excluded from the pool.
-
getWorkerTimeout
public long getWorkerTimeout()
Get the worker timeout.- Specified by:
getWorkerTimeoutin 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:
workerTimeoutOccurredin interfaceIPoolStrategy- Returns:
- True, if the worker be excluded from the pool.
-
getWorkerCount
public int getWorkerCount()
Get the worker cnt.- Specified by:
getWorkerCountin 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:
getCapacityin 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
public java.lang.String toString()
Get the string representation.- Overrides:
toStringin classjava.lang.Object
-
-