Package emissary.pool

Class 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 namespace
      protected MobileAgentFactory factory
      Super class has private access on factory, so save here
      protected static org.slf4j.Logger logger
      Our logger
      protected String namespaceName
      The name used by this pool
      • Fields inherited from class org.apache.commons.pool2.impl.BaseGenericObjectPool

        abandonedConfig, MEAN_TIMING_STATS_CACHE_SIZE
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void bindPool()
      Bind the pool into the namespace
      IMobileAgent borrowAgent()
      Get an agent from the pool
      void close()
      Gracefully close down all agents and unbind the pool
      static int computePoolSize()
      Compute the default size for the pool
      protected static int computePoolSize​(long maxMemoryInBytes, Integer poolSizeOverride)
      Compute the default size for the pool
      protected void configurePool​(String name)
      Configure the commons pool stuff based on our requirements
      protected void emptyPool()  
      protected void fillPool()
      Ensure the pool is full
      String getClassName()
      Get the name of the class being used from the factory
      int getCurrentPoolSize()  
      String getPoolName()
      Get the name used to register this pool
      boolean isAgentAvailable()
      Try to predict whether a borrow will block/grow the pool
      void kill()
      Forcibly stop all agents and unbind the pool
      static AgentPool lookup()
      Return the default named agent pool instance from the namespace
      static AgentPool lookup​(String name)
      Return the specified agent pool instance from the Namespace
      void resetFactory​(MobileAgentFactory factory)
      Reset the factory.
      void returnAgent​(IMobileAgent agent)
      Return an agent to the pool
      String 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 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
      • Methods inherited from interface org.apache.commons.pool2.ObjectPool

        addObjects
    • 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 size
        factory - 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 producer
        maxActive - max pool size
        name - 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 size
        poolSizeOverride - 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
      • 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 interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface org.apache.commons.pool2.ObjectPool<IMobileAgent>
        Overrides:
        close in class org.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
      • toString

        public String toString()
        To string for lightweight reporting
        Overrides:
        toString in class org.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