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 int
capacity
The number of free workers.protected int
deferdec
The defer factor to slow down thread deletion.protected int
deferdectarget
protected int
deferinc
The defer factor to slow down thread creation.protected int
deferinctarget
protected int
desfree
The desired number of free workers.protected boolean
dodeferdec
Defer the deletion of threads according to their distance from desfree.protected boolean
dodeferinc
Defer the creation of threads according to their distance from desfree.protected int
maxcnt
The maximum number of allowed workers.protected long
maxwait
The max wait time for workers.protected java.util.List<java.lang.Double>
waitings
The waiting times of the pool.protected int
workercnt
The 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 int
getCapacity()
Get the capacity.int
getDesiredFree()
Get the desfree.int
getMaxCount()
Get the max cnt.long
getMaxWait()
Get the maxwait.int
getWorkerCount()
Get the worker cnt.long
getWorkerTimeout()
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
taskAdded()
Called when a new task was added to the pool.boolean
taskFinished()
Called when a task is finished.void
taskServed(long waitdur)
Called when a new task was served from the pool.java.lang.String
toString()
Get the string representation.void
workersAdded(int cnt)
Called when a new worker was added proactively to the pool.boolean
workerTimeoutOccurred()
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:
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
public java.lang.String toString()
Get the string representation.- Overrides:
toString
in classjava.lang.Object
-
-