1 15 16 package com.jdon.controller.pool; 17 import org.apache.commons.pool.PoolableObjectFactory; 18 import org.apache.commons.pool.impl.GenericObjectPool; 19 20 import com.jdon.bussinessproxy.TargetMetaDef; 21 import com.jdon.bussinessproxy.target.TargetServiceFactory; 22 import com.jdon.util.Debug; 23 24 public class CommonsPoolFactory implements PoolableObjectFactory { 25 private final static String module = CommonsPoolFactory.class.getName(); 26 27 private TargetServiceFactory targetServiceFactory; 28 private TargetMetaDef targetMetaDef; 29 private CommonsPoolAdapter pool; 30 31 34 public CommonsPoolFactory(TargetServiceFactory targetServiceFactory, 35 TargetMetaDef targetMetaDef, 36 String maxSize) { 37 super(); 38 this.targetServiceFactory = targetServiceFactory; 39 this.targetMetaDef = targetMetaDef; 40 41 GenericObjectPool apachePool = new GenericObjectPool(this); 42 pool = new CommonsPoolAdapter(apachePool); 43 if (maxSize == null){ 44 Debug.logError("[JdonFramework] not set pool's max size", module); 45 }else{ 46 int maxInt = Integer.parseInt(maxSize); 47 pool.setMaxPoolSize(maxInt); 48 } 49 } 50 51 52 55 public CommonsPoolAdapter getPool() { 56 return pool; 57 } 58 59 60 public Object makeObject() { 61 Object o = null; 62 try { 63 o = targetServiceFactory.create(targetMetaDef); 64 } catch (Exception ex) { 65 Debug.logError("[JdonFramework] Pool can not make object, error: " + ex , module); 66 } 67 return o; 68 } 69 70 public void destroyObject(Object o) throws Exception { 71 targetServiceFactory.destroy(targetMetaDef); 72 } 73 74 public void activateObject(Object o) throws Exception { 75 } 76 77 public void passivateObject(Object o) throws Exception { 78 } 79 80 public boolean validateObject(Object o) { 81 return true; 82 } 83 84 } 85 | Popular Tags |