1 6 7 package org.jfox.pool; 8 9 import org.jfox.ioc.common.AbstractComponent; 10 11 14 15 public abstract class AbstractIndexableObjectPool extends AbstractComponent implements IndexableObjectPool { 16 19 protected AbstractObjectPool pool = null; 20 21 protected ObjectFactory factory = null; 22 23 public AbstractIndexableObjectPool(ObjectFactory factory) { 24 if(factory == null) throw new NullPointerException ("factory is null."); 25 this.factory = factory; 26 } 27 28 public AbstractIndexableObjectPool(String objectFactoryClassName, String poolableClassName) { 29 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 31 try { 32 Class factoryClass = loader.loadClass(objectFactoryClassName); 33 factory = (ObjectFactory) factoryClass.getConstructor(new Class []{java.lang.String .class}).newInstance(new Object []{poolableClassName}); 34 } 35 catch(ClassNotFoundException e) { 36 logger.fatal("Class " + objectFactoryClassName + " not found!" + e); 37 } 38 catch(NoSuchMethodException e) { 39 logger.fatal("No such constructor" + e); 40 } 41 catch(Exception e) { 42 logger.fatal("ObjectFactory " + objectFactoryClassName + " instantiator error" + e); 43 } 44 } 45 46 public void clear() { 47 pool.clear(); 48 } 49 50 public ObjectFactory getObjectFactory() { 51 return factory; 52 } 53 54 public int getRest() { 55 return pool.getRest(); 56 } 57 58 public int getWorking() { 59 return pool.getWorking(); 60 } 61 62 protected void doInit() throws Exception { 63 pool = new SimpleObjectPool(factory); 64 } 65 66 protected void doDestroy() throws Exception { 67 pool.destroy(); 68 } 69 } | Popular Tags |