User: jules_gosnell Date: 02/01/18 16:49:50 Modified: jetty/src/main/org/jboss/jetty/session ClusteredStore.java DistributedHttpSessionManager.java Log: a first attempt at a full hook-up to Sacha's Clustered HttpSession support Revision Changes Path 1.3 +175 -51 contrib/jetty/src/main/org/jboss/jetty/session/ClusteredStore.java Index: ClusteredStore.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/session/ClusteredStore.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClusteredStore.java 2002/01/16 00:36:51 1.2 +++ ClusteredStore.java 2002/01/19 00:49:50 1.3 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: ClusteredStore.java,v 1.2 2002/01/16 00:36:51 jules_gosnell Exp $ +// $Id: ClusteredStore.java,v 1.3 2002/01/19 00:49:50 jules_gosnell Exp $ //---------------------------------------- @@ -15,12 +15,24 @@ import org.jboss.logging.Logger; import java.util.Map; +import javax.naming.InitialContext; +import java.net.InetAddress; +import javax.management.*; +import java.util.List; + +import org.jboss.ha.httpsession.interfaces.SerializableHttpSession; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSessionContext; +import java.util.Enumeration; //---------------------------------------- + + class ClusteredHttpSessionData - implements AbstractHttpSessionData, java.io.Serializable + implements AbstractHttpSessionData, SerializableHttpSession { String _id; long _creationTime; @@ -103,6 +115,86 @@ { _attributesWerePassivated=attributesWerePassivated; } + + // extras that I don't want/need... + + public ServletContext + getServletContext() + { + return null; + } + + public HttpSessionContext + getSessionContext() + { + return null; + } + + public Object + getAttribute(String name) + throws IllegalStateException + { + return null; + } + + public Enumeration + getAttributeNames() + throws IllegalStateException + { + return null; + } + + public void + setAttribute(String name, Object value) + throws IllegalStateException + {} + + public void + removeAttribute(String name) + throws IllegalStateException + {} + public Object + getValue(String name) + throws IllegalStateException + { + return getAttribute(name); + } + + public String[] + getValueNames() + throws IllegalStateException + { + return null; + } + + public void + putValue(String name, Object value) + throws IllegalStateException + {} + + public void + removeValue(String name) + throws IllegalStateException + {} + + public void + invalidate() + throws IllegalStateException + {} + + public boolean + isNew() + throws IllegalStateException + { + return false; + } + + // Sacha's API + public boolean + areAttributesModified(SerializableHttpSession s) + { + return true; + } } /** @@ -116,34 +208,45 @@ ClusteredStore implements AbstractStore { - final Logger _log=Logger.getLogger(getClass().getName()); - // final ClusteredHTTPSessionServiceMBean _mbean; + final Logger _log =Logger.getLogger(getClass().getName()); + MBeanServer _server=null; + ObjectName _name =null; public ClusteredStore() { - _log.info("CTOR"); - // lookup JMX service + // we are only expecting one server... + try + { + _server=(MBeanServer)MBeanServerFactory.findMBeanServer(null).iterator().next(); + _name =new ObjectName("jboss", "service", "ClusteredHttpSession"); + } + catch (Exception e) + { + _log.warn("Clustered HttpSession support is not loaded - disabled"); + } } -// public String -// nextId() -// { -// _log.info("nextId"); -// // return _mbean.getSessionId(); -// return null; -// } - - final Object _idLock=new Object(); - long _nextId=0; - public synchronized String + public String nextId() { - long id; - synchronized (_idLock) { - id=_nextId++; + String id=null; + try + { + Object tmp=_server.invoke(_name, // name + "getSessionId", // operation + new Object[] {}, // params + new String[] {} // signature + ); + id=(String)tmp; + _log.info("next session id "+id); + } + catch (Exception e) + { + _log.error("could not get next session id ", e); } - return ""+System.currentTimeMillis()+"-"+id; + + return id; } public AbstractHttpSessionData @@ -156,51 +259,72 @@ public AbstractHttpSessionData get(String id, boolean delete) { - _log.info("get: "+id); -// try -// { -// return (AbstractHttpSessionData)_mbean.getHttpSession(id); -// } -// catch (Exception e) -// { -// } - - if (delete) - remove(id); + AbstractHttpSessionData data=null; + try + { + Object tmp=_server.invoke(_name, // name + "getHttpSession", // operation + new Object[] { id }, // params + new String[] { id.getClass().getName() } // signature + ); + data=(AbstractHttpSessionData)tmp; + _log.info("retrieve ClusteredHttpSession "+id); + } + catch (Exception e) + { + _log.error("could not retrieve ClusteredHttpSession "+id, e); + } - return null; + return data; } public void put(String id, AbstractHttpSessionData data) { - _log.info("put: "+id); -// try -// { -// _mbean.setHttpSession(id, data); -// } -// catch (Exception e) -// { -// } + try + { + Object tmp=_server.invoke(_name, // name + "setHttpSession", // operation + new Object[] { id, data }, // params + new String[] { id.getClass().getName(), "org.jboss.ha.httpsession.interfaces.SerializableHttpSession" } // signature + ); + _log.info("saved ClusteredHttpSession "+id); + } + catch (Exception e) + { + _log.error("could not save ClusteredHttpSession "+id, e); + } } public void remove(String id) { - _log.info("remove: "+id); - -// try -// { -// _mbean.removeHttpSession(id, data); -// } -// catch (Exception e) -// { -// } + try + { + Object tmp=_server.invoke(_name, // name + "removeHttpSession", // operation + new Object[] { id }, // params + new String[] { id.getClass().getName() } // signature + ); + _log.info("removed ClusteredHttpSession "+id); + } + catch (Exception e) + { + _log.error("could not remove ClusteredHttpSession "+id, e); + } } public boolean isValid() { - return false; + boolean valid=false; + try + { + valid=(_server.getObjectInstance(_name)!=null); + } + catch (Exception e) + { + } + return valid; } } 1.5 +6 -3 contrib/jetty/src/main/org/jboss/jetty/session/DistributedHttpSessionManager.java Index: DistributedHttpSessionManager.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/session/DistributedHttpSessionManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DistributedHttpSessionManager.java 2002/01/16 00:36:51 1.4 +++ DistributedHttpSessionManager.java 2002/01/19 00:49:50 1.5 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: DistributedHttpSessionManager.java,v 1.4 2002/01/16 00:36:51 jules_gosnell Exp $ +// $Id: DistributedHttpSessionManager.java,v 1.5 2002/01/19 00:49:50 jules_gosnell Exp $ // TODO @@ -67,7 +67,7 @@ //------------------------------------------------------------------------------ /** * - * @version $Id: DistributedHttpSessionManager.java,v 1.4 2002/01/16 00:36:51 jules_gosnell Exp $ + * @version $Id: DistributedHttpSessionManager.java,v 1.5 2002/01/19 00:49:50 jules_gosnell Exp $ * @author [EMAIL PROTECTED] */ //---------------------------------------- @@ -116,7 +116,10 @@ public HttpSession newHttpSession() { - String id=getStore().nextId(); + String id=""+System.currentTimeMillis(); // TODO + if (_store!=null && _store.isValid()) + id=_store.nextId(); + DistributedHttpSession session = new DistributedHttpSession(this, id, _dftMaxIdleSecs); // _log.info("creating DistributedHttpSession: "+session.getId()+" : "+_dftMaxIdleSecs);
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development