1 6 7 package org.jfox.pool; 8 9 import java.lang.reflect.InvocationHandler ; 10 import java.lang.reflect.Method ; 11 12 17 18 public class PoolableObjectInvocationHandler implements InvocationHandler { 19 20 private PoolableObject poolableObject = null; 21 private boolean passivated = false; 22 23 public PoolableObjectInvocationHandler() { 24 25 } 26 27 public PoolableObjectInvocationHandler(PoolableObject poolableObject) { 28 this.poolableObject = poolableObject; 29 } 30 31 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable { 32 if(passivated) throw new NullPointerException ("pooled object had passviated."); 33 34 if(method.getName().equals("passivate") && method.getParameterTypes().length == 0) { 36 passivated = true; 37 } 38 return method.invoke(poolableObject, args); 39 } 40 41 public PoolableObject getPoolableObject() { 42 return poolableObject; 43 } 44 45 } 46 | Popular Tags |