KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ejb > handler > A5_InstancePoolHandler


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6
7 package org.jfox.ejb.handler;
8
9 import java.util.Iterator JavaDoc;
10 import javax.ejb.EnterpriseBean JavaDoc;
11
12 import org.jfox.ejb.Bucket;
13 import org.jfox.ejb.EJBObjectMethod;
14 import org.jfox.ejb.EJBPoolableObject;
15 import org.jfox.ejb.connector.EJBInvocation;
16
17 /**
18  * 从实例池取得 Bean 实例,执行后返回
19  * <p/>
20  * A5 用于排序
21  *
22  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
23  */

24
25 public class A5_InstancePoolHandler extends AbstractHandler {
26
27     public Object JavaDoc invokeBean(Bucket bucket, EJBInvocation invocation, Iterator JavaDoc iter) throws Exception JavaDoc {
28         EJBPoolableObject pobj = bucket.retrieveBean(invocation.getObjectId());
29         EnterpriseBean JavaDoc bean = pobj.getBeanInstance();
30         invocation.setBean(bean);
31
32         /**
33          * 拦截 remove 方法调用,因为这个调用将不再把 Bean 返回给 ObjectPool
34          */

35         if(invocation.getMethod().equals(EJBObjectMethod.Remove)) {
36             bucket.remove(bean);
37             pobj = null;
38             return null;
39         }
40
41         try {
42             return super.invokeBean(bucket, invocation, iter);
43         }
44         finally {
45             bucket.restoreBean(invocation.getObjectId(), pobj);
46         }
47
48     }
49
50     public static void main(String JavaDoc[] args) {
51
52     }
53 }
Popular Tags