User: slaboure Date: 01/12/31 07:18:43 Added: src/main/org/jboss/ha/httpsession/ejb ClusteredHTTPSessionBeanAbstract.java ClusteredHTTPSessionBeanCmp11.java ClusteredHTTPSessionBeanImpl.java Log: ClusteredHTTPSession EB implementation Revision Changes Path 1.1 jbossmx/src/main/org/jboss/ha/httpsession/ejb/ClusteredHTTPSessionBeanAbstract.java Index: ClusteredHTTPSessionBeanAbstract.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.httpsession.ejb; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.RemoveException; import java.rmi.RemoteException; import java.io.Serializable; import org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionBusiness; import org.jboss.ha.httpsession.interfaces.ClusteredHTTPSession; import org.jboss.ha.httpsession.interfaces.SerializableHttpSession; /** * Abstract default implementation of the Clustered HTTP session for servlets. * * @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSession * @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionBusiness * @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSessionHome * * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>. * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> * * <p><b>31. décembre 2001 Sacha Labourey:</b> * <ul> * <li> First implementation </li> * </ul> */ public abstract class ClusteredHTTPSessionBeanAbstract implements javax.ejb.EntityBean, ClusteredHTTPSessionBusiness { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- protected javax.ejb.EntityContext ejbContext; // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- public ClusteredHTTPSession ejbCreate (String sessionId) throws CreateException { this.setSessionId (sessionId); return null; } public void ejbPostCreate (String sessionId) throws CreateException {} public ClusteredHTTPSession ejbCreate (String sessionId, SerializableHttpSession session) throws CreateException { this.setSessionId (sessionId); this.setSession (session); return null; } public void ejbPostCreate (String sessionId, SerializableHttpSession session) throws CreateException {} // Optimisation: called by the CMP engine // public abstract boolean isModified (); // EntityBean implementation ---------------------------------------------- public void ejbStore () throws EJBException, RemoteException {} public void ejbActivate () throws EJBException, RemoteException {} public void ejbPassivate () throws EJBException, RemoteException {} public void ejbLoad () throws EJBException, RemoteException {} public void setEntityContext (javax.ejb.EntityContext ctx) { ejbContext = ctx; } public void ejbRemove () throws RemoveException, EJBException, RemoteException {} public void unsetEntityContext () { ejbContext = null; } // ClusteredHTTPSessionBusiness implementation ---------------------------------------------- public abstract String getSessionId (); public abstract void setSessionId (String sessionId); public abstract Serializable getSerializedSession (); public abstract void setSerializedSession (Serializable session); public abstract long getLastAccessedTime (); public abstract void setLastAccessedTime (long value); public abstract long getCreationTime (); public abstract void setCreationTime (long value); // This field is not directly stored by the CMP engine // public abstract SerializableHttpSession getSession () throws EJBException; public abstract void setSession (SerializableHttpSession session); // Y overrides --------------------------------------------------- // Package protected --------------------------------------------- // Protected ----------------------------------------------------- protected javax.ejb.EntityContext getEntityContext () { return ejbContext; } // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- } 1.1 jbossmx/src/main/org/jboss/ha/httpsession/ejb/ClusteredHTTPSessionBeanCmp11.java Index: ClusteredHTTPSessionBeanCmp11.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.httpsession.ejb; import java.io.Serializable; /** * CMP 1.1 concrete implementation for the HTTPSession bean. * * @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSession * @see org.jboss.ha.httpsession.ejb.ClusteredHTTPSessionBeanImpl * * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>. * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> * * <p><b>31. décembre 2001 Sacha Labourey:</b> * <ul> * <li> First implementation </li> * </ul> */ public class ClusteredHTTPSessionBeanCmp11 extends ClusteredHTTPSessionBeanImpl { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- public String id; public Serializable serializedSession; public long lastAccessTime; public long creationTime; // Static -------------------------------------------------------- // Constructors -------------------------------------------------- public ClusteredHTTPSessionBeanCmp11 () { } // Public -------------------------------------------------------- // Z implementation ---------------------------------------------- // ClusteredHTTPSessionBeanCmp11 overrides --------------------------------------------------- public String getSessionId () { return this.id; } public void setSessionId (String sessionId) { this.id = sessionId; } public Serializable getSerializedSession () { return this.serializedSession; } public void setSerializedSession (Serializable session) { this.serializedSession = session; } public long getLastAccessedTime () { return this.lastAccessTime; } public void setLastAccessedTime (long value) { this.lastAccessTime = value; } public long getCreationTime () { return this.creationTime; } public void setCreationTime (long value) { this.creationTime = value; } // Package protected --------------------------------------------- // Protected ----------------------------------------------------- // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- } 1.1 jbossmx/src/main/org/jboss/ha/httpsession/ejb/ClusteredHTTPSessionBeanImpl.java Index: ClusteredHTTPSessionBeanImpl.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.ha.httpsession.ejb; import java.rmi.RemoteException; import java.rmi.MarshalledObject; import javax.ejb.EJBException; import org.jboss.ha.httpsession.interfaces.SerializableHttpSession; /** * Core implementation of methods for the bean. * * @see org.jboss.ha.httpsession.interfaces.ClusteredHTTPSession * @see org.jboss.ha.httpsession.ejb.ClusteredHTTPSessionBeanAbstract * * @author <a href="mailto:[EMAIL PROTECTED]">Sacha Labourey</a>. * @version $Revision: 1.1 $ * * <p><b>Revisions:</b> * * <p><b>31. décembre 2001 Sacha Labourey:</b> * <ul> * <li> First implementation </li> * </ul> */ public abstract class ClusteredHTTPSessionBeanImpl extends ClusteredHTTPSessionBeanAbstract { // Constants ----------------------------------------------------- // Attributes ---------------------------------------------------- protected SerializableHttpSession tmpSession = null; protected boolean isModified = false; // Static -------------------------------------------------------- // Constructors -------------------------------------------------- // Public -------------------------------------------------------- // Z implementation ---------------------------------------------- // ClusteredHTTPSessionBeanAbstract overrides --------------------------------------------------- public void ejbStore () throws EJBException, RemoteException { if (tmpSession != null) // the tmpSession has been assigned. Furthermore, if ejbStore is called // it means that isModified==true => we need to rebuild a serialized representation // serializeSession(); } public void ejbLoad () throws EJBException, RemoteException { // the tmp value is no more valid: a new serialized representation is just loaded. // it will be transformed only if explicitly asked. // tmpSession = null; isModified = false; } public SerializableHttpSession getSession () throws EJBException { if (tmpSession == null) { // this is the first access to the object representation. // we use a lazy scheme => we unserialize now unserializeSession (); } return this.tmpSession; } public void setSession (SerializableHttpSession session) { if (tmpSession == null) isModified = true; else isModified = session.areAttributesModified (tmpSession); // in any case, we update the "time" attributes // this.setCreationTime (session.getCreationTime ()); this.setLastAccessedTime (session.getLastAccessedTime ()); // in any cases, we assign the new session: this is because the session // may have internal data that is not used for the isModified comparison // (such as last access time). Consequently, if we use a load-balancer with // sticky sessions, the values will be kept in cache correctly whereas if we // don't have sticky session, these values will only be clustered-saved if // an attributed is modified! // this.tmpSession = session; } // Optimisation: called by the CMP engine // public boolean isModified () { return this.isModified; } // Package protected --------------------------------------------- // Protected ----------------------------------------------------- protected void serializeSession() throws EJBException { // In the current release, we use MarshalledObject. It is probably not a // solution at all but it is very easy to change // try { this.setSerializedSession (new MarshalledObject (this.tmpSession)); } catch (Exception e) { throw new EJBException (e.toString ()); } } protected void unserializeSession() throws EJBException { try { this.tmpSession = (SerializableHttpSession)((MarshalledObject)(this.getSerializedSession ())).get (); } catch (Exception e) { throw new EJBException (e.toString ()); } } // Private ------------------------------------------------------- // Inner classes ------------------------------------------------- }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development