Package emissary.pool
Class AgentPool
- java.lang.Object
-
- org.apache.commons.pool2.BaseObject
-
- org.apache.commons.pool2.impl.BaseGenericObjectPool<T>
-
- org.apache.commons.pool2.impl.GenericObjectPool<IMobileAgent>
-
- emissary.pool.AgentPool
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.apache.commons.pool2.impl.GenericObjectPoolMXBean
,org.apache.commons.pool2.ObjectPool<IMobileAgent>
,org.apache.commons.pool2.UsageTracking<IMobileAgent>
public class AgentPool extends org.apache.commons.pool2.impl.GenericObjectPool<IMobileAgent>
Extends the GenericObjectPool to hold MobileAgents, each on it's own thread.
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
DEFAULT_NAMESPACE_NAME
The default name by which we register into the namespaceprotected MobileAgentFactory
factory
Super class has private access on factory, so save hereprotected static org.slf4j.Logger
logger
Our loggerprotected String
namespaceName
The name used by this pool
-
Constructor Summary
Constructors Constructor Description AgentPool(MobileAgentFactory factory)
Create and configure the pool using the default name and sizeAgentPool(MobileAgentFactory factory, int maxActive)
Create and configure the pool using the default nameAgentPool(MobileAgentFactory factory, int maxActive, String name)
Create and configure the pool using the specified name
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
bindPool()
Bind the pool into the namespaceIMobileAgent
borrowAgent()
Get an agent from the poolvoid
close()
Gracefully close down all agents and unbind the poolstatic int
computePoolSize()
Compute the default size for the poolprotected static int
computePoolSize(long maxMemoryInBytes, Integer poolSizeOverride)
Compute the default size for the poolprotected void
configurePool(String name)
Configure the commons pool stuff based on our requirementsprotected void
emptyPool()
protected void
fillPool()
Ensure the pool is fullString
getClassName()
Get the name of the class being used from the factoryint
getCurrentPoolSize()
String
getPoolName()
Get the name used to register this poolboolean
isAgentAvailable()
Try to predict whether a borrow will block/grow the poolvoid
kill()
Forcibly stop all agents and unbind the poolstatic AgentPool
lookup()
Return the default named agent pool instance from the namespacestatic AgentPool
lookup(String name)
Return the specified agent pool instance from the Namespacevoid
resetFactory(MobileAgentFactory factory)
Reset the factory.void
returnAgent(IMobileAgent agent)
Return an agent to the poolString
toString()
To string for lightweight reporting-
Methods inherited from class org.apache.commons.pool2.impl.GenericObjectPool
addObject, borrowObject, borrowObject, borrowObject, clear, evict, getFactory, getFactoryType, getMaxIdle, getMinIdle, getNumActive, getNumIdle, getNumWaiters, invalidateObject, invalidateObject, listAllObjects, preparePool, returnObject, setConfig, setMaxIdle, setMinIdle, toStringAppendFields, use
-
Methods inherited from class org.apache.commons.pool2.impl.BaseGenericObjectPool
getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getDurationBetweenEvictionRuns, getEvictionPolicy, getEvictionPolicyClassName, getEvictorShutdownTimeout, getEvictorShutdownTimeoutDuration, getEvictorShutdownTimeoutMillis, getFairness, getJmxName, getLifo, getLogAbandoned, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitDuration, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMessageStatistics, getMinEvictableIdleDuration, getMinEvictableIdleTime, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutDuration, getReturnedCount, getSoftMinEvictableIdleDuration, getSoftMinEvictableIdleTime, getSoftMinEvictableIdleTimeMillis, getSwallowedExceptionListener, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRuns, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosed, markReturningState, setAbandonedConfig, setBlockWhenExhausted, setConfig, setEvictionPolicy, setEvictionPolicyClassName, setEvictionPolicyClassName, setEvictorShutdownTimeout, setEvictorShutdownTimeoutMillis, setLifo, setMaxTotal, setMaxWait, setMaxWaitMillis, setMessagesStatistics, setMinEvictableIdle, setMinEvictableIdleTime, setMinEvictableIdleTimeMillis, setNumTestsPerEvictionRun, setSoftMinEvictableIdle, setSoftMinEvictableIdleTime, setSoftMinEvictableIdleTimeMillis, setSwallowedExceptionListener, setTestOnBorrow, setTestOnCreate, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRuns, setTimeBetweenEvictionRunsMillis
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.pool2.impl.GenericObjectPoolMXBean
getBlockWhenExhausted, getBorrowedCount, getCreatedCount, getCreationStackTrace, getDestroyedByBorrowValidationCount, getDestroyedByEvictorCount, getDestroyedCount, getFairness, getLifo, getLogAbandoned, getMaxBorrowWaitTimeMillis, getMaxTotal, getMaxWaitMillis, getMeanActiveTimeMillis, getMeanBorrowWaitTimeMillis, getMeanIdleTimeMillis, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getRemoveAbandonedOnBorrow, getRemoveAbandonedOnMaintenance, getRemoveAbandonedTimeout, getReturnedCount, getTestOnBorrow, getTestOnCreate, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, isAbandonedConfig, isClosed
-
-
-
-
Field Detail
-
DEFAULT_NAMESPACE_NAME
protected static final String DEFAULT_NAMESPACE_NAME
The default name by which we register into the namespace- See Also:
- Constant Field Values
-
factory
protected MobileAgentFactory factory
Super class has private access on factory, so save here
-
logger
protected static final org.slf4j.Logger logger
Our logger
-
namespaceName
protected String namespaceName
The name used by this pool
-
-
Constructor Detail
-
AgentPool
public AgentPool(MobileAgentFactory factory)
Create and configure the pool using the default name and size- Parameters:
factory
- pool object producer
-
AgentPool
public AgentPool(MobileAgentFactory factory, int maxActive)
Create and configure the pool using the default name- Parameters:
maxActive
- max pool sizefactory
- pool object producer
-
AgentPool
public AgentPool(MobileAgentFactory factory, int maxActive, String name)
Create and configure the pool using the specified name- Parameters:
factory
- pool object producermaxActive
- max pool sizename
- name of the pool in the namespace
-
-
Method Detail
-
computePoolSize
protected static int computePoolSize(long maxMemoryInBytes, @Nullable Integer poolSizeOverride)
Compute the default size for the pool- Parameters:
maxMemoryInBytes
- System max memory used in calculating pool sizepoolSizeOverride
- User set property for pool size
-
computePoolSize
public static int computePoolSize()
Compute the default size for the pool
-
configurePool
protected void configurePool(String name)
Configure the commons pool stuff based on our requirements- Parameters:
name
- name of the pool in the namespace
-
fillPool
protected void fillPool()
Ensure the pool is full
-
resetFactory
public void resetFactory(MobileAgentFactory factory)
Reset the factory. Pool will be emptied and refilled- Parameters:
factory
- the new factory
-
bindPool
protected void bindPool()
Bind the pool into the namespace
-
getPoolName
public String getPoolName()
Get the name used to register this pool
-
borrowAgent
public IMobileAgent borrowAgent() throws Exception
Get an agent from the pool- Throws:
Exception
-
getCurrentPoolSize
public int getCurrentPoolSize()
-
emptyPool
protected void emptyPool()
-
close
public void close()
Gracefully close down all agents and unbind the pool- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.apache.commons.pool2.ObjectPool<IMobileAgent>
- Overrides:
close
in classorg.apache.commons.pool2.impl.GenericObjectPool<IMobileAgent>
-
kill
public void kill()
Forcibly stop all agents and unbind the pool
-
returnAgent
public void returnAgent(IMobileAgent agent)
Return an agent to the pool
-
lookup
public static AgentPool lookup() throws NamespaceException
Return the default named agent pool instance from the namespace- Throws:
NamespaceException
-
lookup
public static AgentPool lookup(String name) throws NamespaceException
Return the specified agent pool instance from the Namespace- Throws:
NamespaceException
-
toString
public String toString()
To string for lightweight reporting- Overrides:
toString
in classorg.apache.commons.pool2.BaseObject
-
getClassName
public String getClassName()
Get the name of the class being used from the factory- Returns:
- class name for the agents
-
isAgentAvailable
public boolean isAgentAvailable()
Try to predict whether a borrow will block/grow the pool
-
-