1 14 15 package org.quickserver.net.server.impl; 16 17 import org.apache.commons.pool.*; 18 import org.apache.commons.pool.impl.*; 19 import org.quickserver.util.pool.thread.ClientPool; 20 import org.quickserver.util.pool.ByteBufferObjectFactory; 21 import org.quickserver.util.xmlreader.PoolConfig; 22 import org.quickserver.net.server.PoolManager; 23 import java.util.logging.*; 24 25 30 public class BasicPoolManager implements PoolManager { 31 private static final Logger logger = Logger.getLogger( 32 BasicPoolManager.class.getName()); 33 34 public ObjectPool makeByteBufferPool(PoolableObjectFactory factory, 35 PoolConfig opConfig) { 36 GenericObjectPool.Config bconfig = new GenericObjectPool.Config(); 37 bconfig.maxActive = opConfig.getMaxActive(); 38 bconfig.maxIdle = opConfig.getMaxIdle(); 39 bconfig.testOnReturn = true; 40 bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK; 41 return new GenericObjectPool(factory, bconfig); 42 } 43 44 public ObjectPool makeClientPool(PoolableObjectFactory factory, 45 PoolConfig opConfig) { 46 GenericObjectPool.Config bconfig = new GenericObjectPool.Config(); 47 bconfig.maxActive = opConfig.getMaxActive(); 48 bconfig.maxIdle = opConfig.getMaxIdle(); 49 bconfig.testOnReturn = true; 50 bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; 51 return new GenericObjectPool(factory, bconfig); 52 } 53 54 public ObjectPool makeClientHandlerPool(PoolableObjectFactory factory, 55 PoolConfig opConfig) { 56 GenericObjectPool.Config bconfig = new GenericObjectPool.Config(); 57 bconfig.maxActive = opConfig.getMaxActive(); 58 bconfig.maxIdle = opConfig.getMaxIdle(); 59 bconfig.testOnReturn = true; 60 bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; 61 return new GenericObjectPool(factory, bconfig); 62 } 63 64 public ObjectPool makeClientDataPool(PoolableObjectFactory factory, 65 PoolConfig opConfig) { 66 GenericObjectPool.Config bconfig = new GenericObjectPool.Config(); 67 bconfig.maxActive = opConfig.getMaxActive(); 68 bconfig.maxIdle = opConfig.getMaxIdle(); 69 bconfig.testOnReturn = true; 70 bconfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_FAIL; 71 return new GenericObjectPool(factory, bconfig); 72 } 73 74 public void initPool(ObjectPool objectPool, PoolConfig opConfig) { 75 int initSize = opConfig.getInitSize(); 76 try { 77 while(objectPool.getNumIdle()<initSize) 78 objectPool.addObject(); 79 } catch(Exception e) { 80 logger.fine("Error: "+e); 81 } 82 } 83 } 84 | Popular Tags |