From: Scott M S. <st...@us...> - 2002-09-25 15:43:08
|
User: starksm Date: 02/09/25 08:43:07 Modified: src/main/org/jboss/test/cts/ejb StatefulSessionBean.java Log: Add a test of serializing a stateful session handle to/from an in memory object stream. Revision Changes Path 1.18 +55 -6 jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java Index: StatefulSessionBean.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- StatefulSessionBean.java 15 Jun 2002 02:06:26 -0000 1.17 +++ StatefulSessionBean.java 25 Sep 2002 15:43:07 -0000 1.18 @@ -1,13 +1,18 @@ package org.jboss.test.cts.ejb; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.rmi.RemoteException; -import javax.naming.*; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.EJBObject; import javax.ejb.Handle; import javax.ejb.RemoveException; import javax.ejb.SessionSynchronization; +import javax.naming.Context; +import javax.naming.InitialContext; import org.apache.log4j.Category; import org.jboss.test.cts.interfaces.BeanContextInfo; @@ -24,7 +29,7 @@ /** The stateful session ejb implementation * * @author Sco...@jb... - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ */ public class StatefulSessionBean extends SessionSupport @@ -37,6 +42,7 @@ private Context enc; private Handle sessionHandle; private SessionRef sessionRef; + private byte[] statefulHandle; private boolean wasActivated; private boolean wasPassivated; @@ -44,7 +50,7 @@ { this.testName = testName; log = Category.getInstance(StatefulSessionBean.class.getName()+"#"+testName); - log.debug("ejbCreate( )"); + log.debug("ejbCreate( ), ctx="+sessionCtx); } public void ejbActivate() @@ -125,8 +131,7 @@ try { Context ctx = new InitialContext(); - StatefulSessionHome home = - ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean"); + StatefulSessionHome home = (StatefulSessionHome) ctx.lookup("ejbcts/StatefulSessionBean"); StatefulSession sessionBean; try { @@ -195,6 +200,7 @@ public void createSessionHandle() { + log.info("createSessionHandle"); try { InitialContext ctx = new InitialContext(); @@ -212,6 +218,7 @@ public String useSessionHandle(String arg) { + log.info("useSessionHandle"); try { StatelessSession bean = (StatelessSession) sessionHandle.getEJBObject(); @@ -225,17 +232,59 @@ return arg; } + public void createStatefulSessionHandle(String testName) + { + log.info("createStatefulSessionHandle"); + try + { + StatefulSessionHome home = (StatefulSessionHome) sessionCtx.getEJBHome(); + StatefulSession bean = home.create(testName); + bean.incCounter(); + Handle handle = bean.getHandle(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(handle); + this.statefulHandle = baos.toByteArray(); + } + catch(Exception e) + { + log.error("Failed to serialize session handle", e); + throw new EJBException("Failed to serialize session handle", e); + } + } + + public void useStatefulSessionHandle() + { + log.info("useStatefulSessionHandle"); + try + { + ByteArrayInputStream bais = new ByteArrayInputStream(statefulHandle); + ObjectInputStream ois = new ObjectInputStream(bais); + Handle handle = (Handle) ois.readObject(); + StatefulSession bean = (StatefulSession) handle.getEJBObject(); + bean.incCounter(); + int count = bean.getCounter(); + log.info("useStatefulSessionHandle, count="+count); + } + catch(Exception e) + { + log.error("Failed to read session from handle", e); + throw new EJBException("SFailed to read session from handle", e); + } + } + public void createSessionRef() throws RemoteException { + log.info("createSessionRef"); Handle handle = super.sessionCtx.getEJBObject().getHandle(); this.sessionRef = new SessionRef(handle); } public String useSessionRef() throws RemoteException { + log.info("useSessionRef"); Handle handle = sessionRef.getHandle(); return handle.toString(); } } - |