1 14 15 package org.quickserver.util.pool; 16 17 import java.util.*; 18 import org.apache.commons.pool.*; 19 20 24 public class MakeQSObjectPool implements QSObjectPool, QSObjectPoolMaker { 25 protected ObjectPool objectPool = null; 26 protected List list = null; 27 28 public QSObjectPool getQSObjectPool(ObjectPool objectPool) { 29 return new MakeQSObjectPool(objectPool); 30 } 31 32 public MakeQSObjectPool() { 33 } 34 35 public MakeQSObjectPool(ObjectPool objectPool) { 36 setObjectPool(objectPool); 37 } 38 39 protected void setObjectPool(ObjectPool objectPool) { 40 this.objectPool = objectPool; 41 list = Collections.synchronizedList(new LinkedList()); 42 } 43 44 public void returnObject(Object obj) throws Exception { 45 list.remove(obj); 46 objectPool.returnObject(obj); 47 } 48 49 public Object borrowObject() throws Exception { 50 Object obj = objectPool.borrowObject(); 51 list.add(obj); 52 return obj; 53 } 54 55 public synchronized void close() throws Exception { 56 list.clear(); 57 objectPool.close(); 58 } 59 60 63 public Iterator getAllActiveObjects() { 64 return list.iterator(); 65 } 66 67 public Object getObjectToSynchronize() { 68 return list; 69 } 70 71 public void addObject() throws Exception { 72 objectPool.addObject(); 73 } 74 75 public void clear() throws Exception { 76 objectPool.clear(); 77 } 78 79 public int getNumActive() { 80 return objectPool.getNumActive(); 81 } 82 83 public int getNumIdle() { 84 return objectPool.getNumIdle(); 85 } 86 87 public void invalidateObject(Object obj) throws Exception { 88 objectPool.invalidateObject(obj); 89 } 90 91 public void setFactory(PoolableObjectFactory factory) { 92 objectPool.setFactory(factory); 93 } 94 } 95 | Popular Tags |