1 17 18 package org.apache.avalon.fortress.impl.handler; 19 20 import org.apache.avalon.framework.configuration.Configurable; 21 import org.apache.avalon.framework.configuration.Configuration; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.excalibur.mpool.Pool; 26 import org.apache.excalibur.mpool.PoolManager; 27 28 36 public final class PoolableComponentHandler 37 extends AbstractComponentHandler 38 implements Configurable 39 { 40 41 private PoolManager m_poolManager; 42 43 44 private Pool m_pool; 45 46 47 private int m_poolMin; 48 49 55 public void service( final ServiceManager serviceManager ) 56 throws ServiceException 57 { 58 super.service( serviceManager ); 59 m_poolManager = 60 (PoolManager) serviceManager.lookup( PoolManager.ROLE ); 61 } 62 63 70 public void configure( final Configuration configuration ) 71 throws ConfigurationException 72 { 73 m_poolMin = configuration.getAttributeAsInteger( "pool-min", 10 ); 74 } 75 76 80 protected void doPrepare() 81 throws Exception 82 { 83 m_pool = m_poolManager.getManagedPool( m_factory, m_poolMin ); 84 } 85 86 90 protected Object doGet() 91 throws Exception 92 { 93 return m_pool.acquire(); 94 } 95 96 100 protected void doPut( final Object component ) 101 { 102 m_pool.release( component ); 103 } 104 } 105 | Popular Tags |