1 6 7 package org.jfox.ejb; 8 9 import org.jfox.ioc.common.AbstractComponent; 10 import org.jfox.pool.AbstractObjectPool; 11 import org.jfox.pool.ObjectFactory; 12 import org.jfox.pool.ObjectPool; 13 import org.jfox.pool.PoolableObject; 14 import org.jfox.pool.SimpleObjectPool; 15 16 21 22 public class StatelessObjectPool extends AbstractComponent implements ObjectPool, EJBObjectPool { 23 private AbstractObjectPool pool = null; 24 private EJBObjectFactory factory = null; 25 26 27 public StatelessObjectPool() { 28 29 } 30 31 public void setEJBObjectFactory(EJBObjectFactory factory) { 32 if(factory == null) throw new NullPointerException ("factory is null."); 33 this.factory = factory; 34 } 35 36 public synchronized PoolableObject createObject() throws Exception { 37 return retrieveObject(); 38 } 39 40 public synchronized PoolableObject retrieveObject() throws Exception { 41 return pool.retrieveObject(); 43 } 44 45 51 public boolean restoreObject(PoolableObject obj) { 52 try { 53 return pool.restoreObject(obj); 54 } 55 catch(Exception e) { 56 logger.warn("restoreObject " + obj + " failed, exception is: " + e); 57 return false; 58 } 59 } 60 61 67 public boolean removeObject(PoolableObject obj) { 68 try { 69 return pool.restoreObject(obj); 70 } 71 catch(Exception e) { 72 logger.warn("removeObject " + obj + " failed, exception is: " + e); 73 return false; 74 } 75 } 76 77 public void clear() { 78 pool.clear(); 79 } 80 81 public ObjectFactory getObjectFactory() { 82 return factory; 83 } 84 85 public String getObjectClass() { 86 return factory.getObjectClass().getName(); 87 } 88 89 public int getWorking() { 90 return pool.getWorking(); 91 } 92 93 public int getRest() { 94 return pool.getRest(); 95 } 96 97 protected void doInit() throws Exception { 98 if(factory == null) throw new NullPointerException ("factory is null."); 99 pool = new SimpleObjectPool(factory, 0, 10); 100 pool.init(); 101 } 102 103 protected void doDestroy() throws Exception { 104 pool.destroy(); 105 } 106 107 public int getInitNum() { 108 return pool.getInitNum(); 109 } 110 111 public int getMaxRest() { 112 return pool.getMaxRest(); 113 } 114 115 public static void main(String [] args) { 116 117 } 118 } | Popular Tags |