User: jules_gosnell
  Date: 02/01/15 16:36:51

  Modified:    jetty/src/main/org/jboss/jetty/session
                        AbstractDistributedStore.java ClusteredStore.java
                        CoarseDistributedStore.java
                        DistributedHttpSession.java
                        DistributedHttpSessionManager.java
  Log:
  prepare to hook ClusteredHTTPSession support to DistributedHttpSession.
  
  Revision  Changes    Path
  1.2       +4 -4      
contrib/jetty/src/main/org/jboss/jetty/session/AbstractDistributedStore.java
  
  Index: AbstractDistributedStore.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/session/AbstractDistributedStore.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractDistributedStore.java     2002/01/14 22:25:18     1.1
  +++ AbstractDistributedStore.java     2002/01/16 00:36:51     1.2
  @@ -5,7 +5,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: AbstractDistributedStore.java,v 1.1 2002/01/14 22:25:18 jules_gosnell Exp $
  +// $Id: AbstractDistributedStore.java,v 1.2 2002/01/16 00:36:51 jules_gosnell Exp $
   
   //----------------------------------------
   
  @@ -24,8 +24,8 @@
   {
     public String nextId();
     public AbstractHttpSessionData make();
  -  public AbstractHttpSessionData get(String id);
  -  public void set(String id, AbstractHttpSessionData data);
  -  //public void remove(String id);
  +  public AbstractHttpSessionData get(String id, boolean delete);
  +  public void put(String id, AbstractHttpSessionData data);
  +  public void remove(String id);
     public boolean isValid();
   }
  
  
  
  1.2       +143 -10   
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClusteredStore.java       2002/01/14 22:25:18     1.1
  +++ ClusteredStore.java       2002/01/16 00:36:51     1.2
  @@ -5,7 +5,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: ClusteredStore.java,v 1.1 2002/01/14 22:25:18 jules_gosnell Exp $
  +// $Id: ClusteredStore.java,v 1.2 2002/01/16 00:36:51 jules_gosnell Exp $
   
   //----------------------------------------
   
  @@ -13,6 +13,98 @@
   
   //----------------------------------------
   
  +import org.jboss.logging.Logger;
  +import java.util.Map;
  +
  +//----------------------------------------
  +
  +class
  +  ClusteredHttpSessionData
  +  implements AbstractHttpSessionData, java.io.Serializable
  +{
  +  String  _id;
  +  long    _creationTime;
  +  long    _lastAccessedTime;
  +  int     _maxInactiveInterval;
  +  Map     _attributes;
  +  boolean _attributesWerePassivated;
  +
  +  // from javax.servlet.http.HttpSession
  +  public long
  +    getCreationTime()
  +    {
  +      return _creationTime;
  +    }
  +
  +  public String
  +    getId()
  +    {
  +      return _id;
  +    }
  +
  +  public long
  +    getLastAccessedTime()
  +    {
  +      return _lastAccessedTime;
  +    }
  +
  +  public int
  +    getMaxInactiveInterval()
  +    {
  +      return _maxInactiveInterval;
  +    }
  +
  +  public void
  +    setMaxInactiveInterval(int maxInactiveInterval)
  +    {
  +      _maxInactiveInterval=_maxInactiveInterval;
  +    }
  +
  +  // extra accessors
  +  public Map
  +    getAttributes()
  +    {
  +      return _attributes;
  +    }
  +
  +  public void
  +    setAttributes(Map attributes)
  +    {
  +      _attributes=attributes;
  +    }
  +
  +  public void
  +    setId(String id)
  +    {
  +      _id=id;
  +    }
  +
  +  public void
  +    setCreationTime(long creationTime)
  +    {
  +      _creationTime=creationTime;
  +    }
  +
  +  public void
  +    setLastAccessedTime(long lastAccessedTime)
  +    {
  +      _lastAccessedTime=lastAccessedTime;
  +    }
  +
  +  // extra attributes
  +  public boolean
  +    getAttributesWerePassivated()
  +    {
  +      return _attributesWerePassivated;
  +    }
  +
  +  public void
  +    setAttributesWerePassivated(boolean attributesWerePassivated)
  +    {
  +      _attributesWerePassivated=attributesWerePassivated;
  +    }
  +}
  +
   /**
    * An abstraction of a manager for the distributed store of HttpSessions
    *
  @@ -20,34 +112,51 @@
    * @version 1.0
    * @since 1.0
    */
  -abstract class
  +public class
     ClusteredStore
  +  implements AbstractStore
   {
  -  // ClusteredHTTPSessionServiceMBean _mbean;
  +  final Logger _log=Logger.getLogger(getClass().getName());
  +  // final ClusteredHTTPSessionServiceMBean _mbean;
   
     public
       ClusteredStore()
       {
  +      _log.info("CTOR");
         // lookup JMX service
       }
   
  -  public String
  +//   public String
  +//     nextId()
  +//     {
  +//       _log.info("nextId");
  +//       //      return _mbean.getSessionId();
  +//       return null;
  +//     }
  +
  +  final Object _idLock=new Object();
  +  long         _nextId=0;
  +  public synchronized String
       nextId()
       {
  -      //      return _mbean.getSessionId();
  -      return null;
  +      long id;
  +      synchronized (_idLock) {
  +     id=_nextId++;
  +      }
  +      return ""+System.currentTimeMillis()+"-"+id;
       }
   
     public AbstractHttpSessionData
       make()
       {
  -      // return new WHAT ?
  -      return null;
  +      _log.info("make");
  +      return new ClusteredHttpSessionData();
       }
   
     public AbstractHttpSessionData
  -    get(String id)
  +    get(String id, boolean delete)
       {
  +      _log.info("get: "+id);
   //       try
   //       {
   //   return (AbstractHttpSessionData)_mbean.getHttpSession(id);
  @@ -56,12 +165,16 @@
   //       {
   //       }
   
  +      if (delete)
  +     remove(id);
  +
         return null;
       }
   
     public void
  -    set(String id, AbstractHttpSessionData data)
  +    put(String id, AbstractHttpSessionData data)
       {
  +      _log.info("put: "+id);
   //       try
   //       {
   //   _mbean.setHttpSession(id, data);
  @@ -69,5 +182,25 @@
   //       catch (Exception e)
   //       {
   //       }
  +    }
  +
  +  public void
  +    remove(String id)
  +    {
  +      _log.info("remove: "+id);
  +
  +//       try
  +//       {
  +//   _mbean.removeHttpSession(id, data);
  +//       }
  +//       catch (Exception e)
  +//       {
  +//       }
  +    }
  +
  +  public boolean
  +    isValid()
  +    {
  +      return false;
       }
   }
  
  
  
  1.4       +73 -54    
contrib/jetty/src/main/org/jboss/jetty/session/CoarseDistributedStore.java
  
  Index: CoarseDistributedStore.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/session/CoarseDistributedStore.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CoarseDistributedStore.java       2002/01/14 22:25:18     1.3
  +++ CoarseDistributedStore.java       2002/01/16 00:36:51     1.4
  @@ -5,7 +5,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: CoarseDistributedStore.java,v 1.3 2002/01/14 22:25:18 jules_gosnell Exp $
  +// $Id: CoarseDistributedStore.java,v 1.4 2002/01/16 00:36:51 jules_gosnell Exp $
   
   //----------------------------------------
   
  @@ -46,19 +46,19 @@
   
     public
       CoarseDistributedStore()
  -  {
  -    try
       {
  -      _jndiContext=new InitialContext();
  -      Object o=_jndiContext.lookup(_name);
  -      _home=(CoarseHttpSessionHome)PortableRemoteObject.narrow(o, 
CoarseHttpSessionHome.class);
  -      _log.info("Support for EJB-based Distributed HttpSessions loaded: "+_home);
  -    }
  -    catch (NamingException e)
  -    {
  -      _log.warn("WARNING: Support for EJB-based Distributed HttpSessions does not 
appear to be loaded");
  +      try
  +      {
  +     _jndiContext=new InitialContext();
  +     Object o=_jndiContext.lookup(_name);
  +     _home=(CoarseHttpSessionHome)PortableRemoteObject.narrow(o, 
CoarseHttpSessionHome.class);
  +     _log.info("Support for EJB-based Distributed HttpSessions loaded: "+_home);
  +      }
  +      catch (NamingException e)
  +      {
  +     _log.warn("WARNING: Support for EJB-based Distributed HttpSessions does not 
appear to be loaded");
  +      }
       }
  -  }
   
     /**
      * create a new HttpSessionData instance, of the correct type for
  @@ -67,9 +67,9 @@
      */
     public AbstractHttpSessionData
       make()
  -  {
  -    return new CoarseHttpSessionData();
  -  }
  +    {
  +      return new CoarseHttpSessionData();
  +    }
   
     /**
      * retrieve HttpSessionData from a distributed store
  @@ -77,29 +77,32 @@
      * @param id a <code>String</code> value
      */
     public AbstractHttpSessionData
  -    get(String id)
  -  {
  -    if (_home==null)
  -      return null;
  -
  -    AbstractHttpSessionData data=null;
  -
  -    try
  +    get(String id, boolean delete)
       {
  -      CoarseHttpSession ejb=_home.findByPrimaryKey(id);
  +      if (_home==null)
  +     return null;
   
  -      if (ejb!=null)
  +      AbstractHttpSessionData data=null;
  +
  +      try
         {
  -     data= ejb.getData();
  -     ejb.remove();
  -     ejb=null;
  +     CoarseHttpSession ejb=_home.findByPrimaryKey(id);
  +
  +     if (ejb!=null)
  +     {
  +       data= ejb.getData();
  +
  +       if (delete)
  +         ejb.remove();
  +
  +       ejb=null;
  +     }
         }
  -    }
  -    catch (Throwable e)
  -    {}
  +      catch (Throwable e)
  +      {}
   
  -    return data;
  -  }
  +      return data;
  +    }
   
     /**
      * submit HttpSessionData to a distributed store
  @@ -108,33 +111,49 @@
      * @param data an <code>AbstractHttpSessionData</code> value
      */
     public void
  -    set(String id, AbstractHttpSessionData data)
  -  {
  -    if (_home==null)
  -      return;
  -
  -    try
  -    {
  -      CoarseHttpSession ejb=_home.create((CoarseHttpSessionData)data);
  -      ejb=null;
  -    }
  -    catch (RemoteException e)
  -    {}
  -    catch (CreateException e)
  -    {}
  -  }
  +    put(String id, AbstractHttpSessionData data)
  +    {
  +      if (_home==null)
  +     return;
  +
  +      try
  +      {
  +     CoarseHttpSession ejb=_home.create((CoarseHttpSessionData)data);
  +     ejb=null;
  +      }
  +      catch (RemoteException e)
  +      {}
  +      catch (CreateException e)
  +      {}
  +    }
   
  +  public void
  +    remove(String id)
  +    {
  +      if (_home==null)
  +     return;
  +
  +//       try
  +//       {
  +//   //      CoarseHttpSession ejb=_home.remove(id);
  +//       }
  +//       catch (RemoteException e)
  +//       {}
  +//       catch (RemoveException e)
  +//       {}
  +    }
  +
     final Object _idLock=new Object();
     long         _nextId=0;
     public synchronized String
       nextId()
  -  {
  -    long id;
  -    synchronized (_idLock) {
  -      id=_nextId++;
  +    {
  +      long id;
  +      synchronized (_idLock) {
  +     id=_nextId++;
  +      }
  +      return ""+System.currentTimeMillis()+"-"+id;
       }
  -    return ""+System.currentTimeMillis()+"-"+id;
  -  }
   
     public boolean
       isValid()
  
  
  
  1.4       +9 -4      
contrib/jetty/src/main/org/jboss/jetty/session/DistributedHttpSession.java
  
  Index: DistributedHttpSession.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/session/DistributedHttpSession.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DistributedHttpSession.java       2002/01/14 22:25:18     1.3
  +++ DistributedHttpSession.java       2002/01/16 00:36:51     1.4
  @@ -96,8 +96,10 @@
   
       _attributes.putAll(data.getAttributes());
   
  +    boolean notify=data.getAttributesWerePassivated() || _snapshotNeedsActivation;
  +
       // send activate events to listening attributes
  -    if (_snapshotNeedsActivation && _attributes.size()>0)
  +    if (notify && _attributes.size()>0)
       {
         boolean warn=!data.getAttributesWerePassivated();
         HttpSessionEvent event=new HttpSessionEvent(this);
  @@ -462,7 +464,8 @@
       if (!_isDirty && !shutdown)
         return;
   
  -    if (_manager.getStore()!=null)
  +    AbstractStore store=_manager.getStore();
  +    if (store!=null && store.isValid())
       {
         // whilst this method is synchronized, _attributes may still be
         // modified via their public access which only synchronise on
  @@ -510,9 +513,11 @@
         data.setAttributes(copy);
         data.setCreationTime(getCreationTime());
         data.setLastAccessedTime(getLastAccessedTime());
  -      data.setMaxInactiveInterval(getMaxInactiveInterval());
  +      // provided I slow down the collection of the stored state, it
  +      // will never be collected before me....
  +      data.setMaxInactiveInterval(getMaxInactiveInterval()+5);
         data.setAttributesWerePassivated(notifyAttributes);
  -      _manager.getStore().set(getId(), data);
  +      store.put(getId(), data);
       }
     }
   
  
  
  
  1.4       +7 -6      
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DistributedHttpSessionManager.java        2002/01/14 22:25:18     1.3
  +++ DistributedHttpSessionManager.java        2002/01/16 00:36:51     1.4
  @@ -5,7 +5,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: DistributedHttpSessionManager.java,v 1.3 2002/01/14 22:25:18 jules_gosnell 
Exp $
  +// $Id: DistributedHttpSessionManager.java,v 1.4 2002/01/16 00:36:51 jules_gosnell 
Exp $
   
   // TODO
   
  @@ -67,7 +67,7 @@
   //------------------------------------------------------------------------------
   /**
    *
  - * @version $Id: DistributedHttpSessionManager.java,v 1.3 2002/01/14 22:25:18 
jules_gosnell Exp $
  + * @version $Id: DistributedHttpSessionManager.java,v 1.4 2002/01/16 00:36:51 
jules_gosnell Exp $
    * @author [EMAIL PROTECTED]
    */
   //----------------------------------------
  @@ -78,7 +78,8 @@
     static AbstractTimeOutManager    _scavenger                 =new 
NaiveTimeOutManager(5*1000, new MyTimeOutNotifier(), new MyTimeOutTester());
     static { _scavenger.start(); }
   
  -  final AbstractStore              _store                     =new 
CoarseDistributedStore();
  +  //  final AbstractStore              _store                     =new 
CoarseDistributedStore();
  +  final AbstractStore              _store                     =new ClusteredStore();
     final Logger                     _log;
     final JBossWebApplicationContext _context;
     final ServletHandler             _handler;
  @@ -86,8 +87,9 @@
     final List                       _sessionAttributeListeners =new ArrayList();
     final Map                        _sessions                  =new HashMap();
     volatile boolean                 _isDistributed             =false;
  +  volatile boolean                 _maintainDistributedState  =false;
     volatile boolean                 _isStarted                 =false; // TODO
  -  volatile int                     _dftMaxIdleSecs            =30; // negative 
means never timeout...
  +  volatile int                     _dftMaxIdleSecs            =0; // <=0 means 
never timeout...
   
     //----------------------------------------
   
  @@ -155,8 +157,7 @@
       // 2. check distributed store
       if (session==null && _isDistributed && _store.isValid())
       {
  -      AbstractHttpSessionData data=_store.get(id);
  -      _log.info("activated HttpSession data: "+id);
  +      AbstractHttpSessionData data=_store.get(id, !_maintainDistributedState);
        if (data!=null)
         {
        session=new DistributedHttpSession(this, id, data);
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to