asmuts      02/01/15 21:32:47

  Modified:    webapps/jcs/WEB-INF web.xml
               src/java/org/apache/stratum/jcs/utils/servlet/session
                        MetaHttpSession.java HttpServletRequestFacade.java
                        DistSessionTracker.java DistSessionGC.java
               src/java/org/apache/stratum/jcs/access GroupCacheAccess.java
               src/java/org/apache/stratum/jcs/engine/group GroupCache.java
  Log:
  working on distributed session and refining group handling
  this is a good test for group functionality
  
  i'm in the middle of some tweaking of the group funcitonality:
  update and removal of items -- remote update
  update of item list -- no remote update
  removal of list, invalidation of group -- remote update
  
  need to clean up the methods to cleanly secify if something should go remote or not
  
  group list iteration for item by item removal moved to array to avoid concurrent mod 
exception.  new items could get in gorup without locking, but the list should de dead. 
 this is the same as a new group being created.  no problem.  For sessions, the 
session id item will be removed so there is no real threat, unless it is being updated 
simultaneouly with an invalidation and come in last.  Need to consider this
  
  Revision  Changes    Path
  1.2       +9 -0      jakarta-turbine-stratum/webapps/jcs/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-stratum/webapps/jcs/WEB-INF/web.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- web.xml   15 Jan 2002 06:12:19 -0000      1.1
  +++ web.xml   16 Jan 2002 05:32:46 -0000      1.2
  @@ -21,6 +21,11 @@
       <servlet-name>ListTestCacheServlet</servlet-name>
       
<servlet-class>org.apache.stratum.jcs.test.servlet.ListTestCacheServlet</servlet-class>
     </servlet>
  +
  +  <servlet>
  +    <servlet-name>SessionExampleServlet</servlet-name>
  +    
<servlet-class>org.apache.stratum.jcs.test.servlet.SessionExampleServlet</servlet-class>
  +  </servlet>
    
   
     <servlet-mapping>
  @@ -49,6 +54,10 @@
       <url-pattern>/ListTest/*</url-pattern>
     </servlet-mapping>
   
  +  <servlet-mapping>
  +    <servlet-name>SessionExampleServlet</servlet-name>
  +    <url-pattern>/SessionExample/*</url-pattern>
  +  </servlet-mapping>
   
     <mime-mapping>
       <extension>html</extension>
  
  
  
  1.4       +0 -2      
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/MetaHttpSession.java
  
  Index: MetaHttpSession.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/MetaHttpSession.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MetaHttpSession.java      15 Jan 2002 21:33:37 -0000      1.3
  +++ MetaHttpSession.java      16 Jan 2002 05:32:46 -0000      1.4
  @@ -1,9 +1,7 @@
  -
   package org.apache.stratum.jcs.utils.servlet.session;
   
   import javax.servlet.http.HttpSession;
   
  -import org.apache.stratum.jcs.utils.servlet.session.MetaHttpSession;
   
   /**
    *  Used to contain an http session and/or the associated information.
  
  
  
  1.4       +3 -4      
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/HttpServletRequestFacade.java
  
  Index: HttpServletRequestFacade.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/HttpServletRequestFacade.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HttpServletRequestFacade.java     15 Jan 2002 21:33:37 -0000      1.3
  +++ HttpServletRequestFacade.java     16 Jan 2002 05:32:46 -0000      1.4
  @@ -19,11 +19,10 @@
   import javax.servlet.http.HttpSession;
   
   import org.apache.stratum.jcs.utils.servlet.session.DistSessionTracker;
  -import org.apache.stratum.jcs.utils.servlet.session.HttpServletRequestFacade;
   import org.apache.stratum.jcs.utils.servlet.session.MetaHttpSession;
   
   /**
  - *  Description of the Class
  + *  Session wrapper, to overide some methods.  Servlet 2.3 has an easier way to do 
this.
    *
    *@author     asmuts
    *@created    January 15, 2002
  @@ -537,7 +536,7 @@
        */
       public String getRequestedSessionId()
       {
  -        return req.getRequestedSessionId();
  +        return dst.getRequestedSessionId( this );
       }
   
   
  @@ -571,7 +570,7 @@
        */
       public boolean isRequestedSessionIdValid()
       {
  -        return req.isRequestedSessionIdValid();
  +        return dst.isRequestedSessionIdValid(this);
       }
   
   
  
  
  
  1.4       +34 -15    
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/DistSessionTracker.java
  
  Index: DistSessionTracker.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/DistSessionTracker.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DistSessionTracker.java   15 Jan 2002 21:33:37 -0000      1.3
  +++ DistSessionTracker.java   16 Jan 2002 05:32:46 -0000      1.4
  @@ -15,7 +15,6 @@
   import org.apache.stratum.jcs.utils.servlet.session.DistSession;
   import org.apache.stratum.jcs.utils.servlet.session.DistSessionGC;
   import org.apache.stratum.jcs.utils.servlet.session.DistSessionPoolManager;
  -import org.apache.stratum.jcs.utils.servlet.session.DistSessionTracker;
   import org.apache.stratum.jcs.utils.servlet.session.ISessionConstants;
   import org.apache.stratum.jcs.utils.servlet.session.MetaHttpSession;
   
  @@ -25,7 +24,7 @@
    *
    *@author     Aaron Smuts
    *@created    January 15, 2002
  - *@version    $Revision: 1.3 $ $Date: 2002/01/15 21:33:37 $
  + *@version    $Revision: 1.4 $ $Date: 2002/01/16 05:32:46 $
    */
   
   public class DistSessionTracker implements ISessionConstants
  @@ -173,25 +172,15 @@
       {
           log.info( "in getSession" );
           DistSession sess = null;
  -        String session_id = null;
  -        Cookie[] cookies = req.getCookies();
  -        if ( cookies != null )
  -        {
  -            for ( int i = 0; i < cookies.length; i++ )
  -            {
  -                String tempName = cookies[i].getName();
  -                if ( tempName.equals( SESSION_COOKIE_NAME ) )
  -                {
  -                    session_id = cookies[i].getValue();
  -                }
  -            }
  -        }
  +        String session_id = getRequestedSessionId(req);
  +
           if ( session_id == null )
           {
               log.info( "no cookie found" );
               return new MetaHttpSession( null, null );
           }
           sess = new DistSession();
  +
           if ( !sess.init( session_id ) )
           {
               return new MetaHttpSession( session_id, null );
  @@ -214,6 +203,36 @@
           return new MetaHttpSession( session_id, sess );
       }
       // end  getSession
  +
  +
  +    /**
  +     * Gets the requested session id from the cookie.
  +     * Todo, implement URL session tracking.
  +     */
  +    public String getRequestedSessionId( HttpServletRequest req )
  +    {
  +        String session_id = null;
  +        Cookie[] cookies = req.getCookies();
  +        if ( cookies != null )
  +        {
  +            for ( int i = 0; i < cookies.length; i++ )
  +            {
  +                String tempName = cookies[i].getName();
  +                if ( tempName.equals( SESSION_COOKIE_NAME ) )
  +                {
  +                    session_id = cookies[i].getValue();
  +                }
  +            }
  +        }
  +        return session_id;
  +    }
  +
  +
  +    public boolean isRequestedSessionIdValid(HttpServletRequest req)
  +    {
  +      DistSession sess = new DistSession();
  +      return sess.init( getRequestedSessionId(req) );
  +    }
   
       ///////////////////////////
       /**
  
  
  
  1.4       +0 -1      
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/DistSessionGC.java
  
  Index: DistSessionGC.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/utils/servlet/session/DistSessionGC.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DistSessionGC.java        15 Jan 2002 21:33:37 -0000      1.3
  +++ DistSessionGC.java        16 Jan 2002 05:32:46 -0000      1.4
  @@ -7,7 +7,6 @@
   import org.apache.stratum.jcs.utils.log.LoggerManager;
   
   import org.apache.stratum.jcs.utils.servlet.session.DistSession;
  -import org.apache.stratum.jcs.utils.servlet.session.DistSessionGC;
   import org.apache.stratum.jcs.utils.servlet.session.ISessionConstants;
   
   /**
  
  
  
  1.5       +24 -84    
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/access/GroupCacheAccess.java
  
  Index: GroupCacheAccess.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/access/GroupCacheAccess.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GroupCacheAccess.java     15 Jan 2002 22:25:49 -0000      1.4
  +++ GroupCacheAccess.java     16 Jan 2002 05:32:47 -0000      1.5
  @@ -57,6 +57,7 @@
   import java.io.Serializable;
   
   import java.util.Collection;
  +import java.util.ConcurrentModificationException;
   import java.util.Collections;
   import java.util.Enumeration;
   import java.util.HashSet;
  @@ -85,7 +86,7 @@
   
   ///////////////////////////////////////////
   /**
  - *  Description of the Class
  + *  Access for groups.
    *
    *@author     asmuts
    *@created    January 15, 2002
  @@ -478,7 +479,7 @@
   
       /////////////////////////////////////
       /**
  -     *  Description of the Method
  +     *  Invalidates a group
        *
        *@param  group  Description of the Parameter
        */
  @@ -486,10 +487,27 @@
       {
           // Removes all the attributes and attribute names from the Cache.
           // In doing so, need to unbind any object associated with the session.
  -        for ( Enumeration en = getAttributeNames( group ); en.hasMoreElements();  )
  -        {
  -            removeAttribute( ( String ) en.nextElement(), group );
  -        }
  +        // need a static list not dependent on the current state of the source
  +        // remove each item, may want to try using partial delete here
  +        // move to gorupcache?
  +        Set set = getAttributeNameSet( group );
  +        Object[] ar = set.toArray();
  +        int arS = ar.length;
  +        for ( int i = 0; i < arS; i++ ) {
  +           removeAttribute( ( String )ar[i], group );
  +           //System.out.println( ( String )ar[i] );
  +        }
  +
  +        //        for ( Enumeration en = getAttributeNames( group ); 
en.hasMoreElements();  )
  +//        {
  +//            //try {
  +//              removeAttribute( ( String ) en.nextElement(), group );
  +//            //} catch ( ConcurrentModificationException cme ) {
  +//              //log.warn( cme );
  +//            //}
  +//        }
  +        // get into concurrent modificaiton problems here.
  +        // could make the removal of the ID invalidate the list?
           cache_control.remove( new GroupId( cache_control.getCacheName(), group ), 
false );
           return;
       }
  @@ -507,83 +525,5 @@
           return ( String[] ) getAttributeNameSet( group ).toArray( new String[0] );
       }
   
  -
  -    // old tester
  -    /////////////////////////////////////////////////////
  -    /**
  -     *  The main program for the GroupCacheAccess class
  -     *
  -     *@param  args  The command line arguments
  -     */
  -    public static void main( String[] args )
  -    {
  -
  -        try
  -        {
  -
  -            Logger log = LoggerManager.getLogger( "cacheaccess" );
  -            //log.setLogLevel( log.DEBUG );
  -
  -
  -            //CacheManager   cacheMgr = CacheManagerFactory.getInstance();
  -            CacheAttributes cattr = new CacheAttributes();
  -            cattr.setMaxObjects( 10 );
  -            cattr.setUseDisk( true );
  -
  -            GroupCacheAccess cache_control = GroupCacheAccess.getGroupAccess( 
"testCache" );
  -            p( "cache_control = " + cache_control );
  -
  -            cache_control.defineGroup( "testgroup" );
  -
  -            int size = 5;
  -            if ( args.length > 0 )
  -            {
  -                size = Integer.parseInt( args[0] );
  -            }
  -
  -//      p("\n------------------------------------" );
  -//      cache_control.dumpMap();
  -//
  -//      p("\n------------------------------------" );
  -//      cache_control.dumpCacheEntries();
  -
  -            p( "\n------------------------------------" );
  -            p( "---about to put " + size + "---" );
  -            Attributes attr = new Attributes();
  -            //attr.setFlags( attr.LATERAL );
  -            attr.setFlags( attr.REMOTE );
  -            attr.setFlags( attr.SPOOL );
  -
  -            p( "IS_LATERAL= " + String.valueOf( attr.isSet( attr.LATERAL ) ) );
  -            long p_start = System.currentTimeMillis();
  -            for ( int i = 0; i < size; i++ )
  -            {
  -                attr.setTimeToLive( i );
  -                cache_control.putG( "key" + i, "testgroup", "data" + i + " 
asdfghjklzxcvbnmqwertyuiop", attr.copy() );
  -            }
  -            long p_end = System.currentTimeMillis();
  -            p( "---put " + size + " in " + String.valueOf( p_end - p_start ) + " 
millis ---" );
  -
  -            p( "\n------------------------------------" );
  -            p( "stats = " + cache_control.getStats() );
  -
  -            cache_control.dispose();
  -
  -            p( "* \n" );
  -            p( "* \n" );
  -            p( "* \n" );
  -            p( "* \n" );
  -            p( "* \n" );
  -
  -            p( "-- attribute names " + cache_control.getAttributeNames( "testgroup" 
) );
  -            p( "-- attributes " + cache_control.getAttributeNameSet( "testgroup" ) 
);
  -
  -        }
  -        catch ( Exception e )
  -        {
  -            e.printStackTrace( System.out );
  -        }
  -
  -    }
   
   }
  
  
  
  1.4       +17 -4     
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/group/GroupCache.java
  
  Index: GroupCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/group/GroupCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GroupCache.java   15 Jan 2002 21:33:35 -0000      1.3
  +++ GroupCache.java   16 Jan 2002 05:32:47 -0000      1.4
  @@ -40,9 +40,9 @@
   {
       //////////////// debug MUST BE SET TO false in production! ///////////////////
   
  -    private final static boolean debug = false;
  +    private final static boolean debug = false;//true;
       //true;
  -    private final static boolean debuggan = false;
  +    private final static boolean debuggan = false;//true;
       private ReadWriteLockManager locker = GroupRWLockManager.getInstance();
   
       private String source_id = "org.apache.stratum.jcs.engine.group.GroupCache";
  @@ -778,6 +778,7 @@
                   {
                       attrNameSet.add( key.attrName );
                   }
  +
                   if ( attrNameSet.size() > 0 )
                   {
                       // update the changed name set.
  @@ -818,7 +819,9 @@
                           {
                               p( "calling systemGroupIdCache.remove( groupId.key, 
EXCLUDE_REMOTE_CACHE )" );
                           }
  -                        systemGroupIdCache.remove( groupId.key, 
EXCLUDE_REMOTE_CACHE );
  +                        // removal should go remote
  +                        //systemGroupIdCache.remove( groupId.key, 
EXCLUDE_REMOTE_CACHE );
  +                        systemGroupIdCache.remove( groupId.key, 
this.INCLUDE_REMOTE_CACHE );
                       }
                       catch ( IOException ioe )
                       {}
  @@ -893,8 +896,18 @@
           }
           try
           {
  +
  +            // remove the items
  +            // groupid cache should be remote, but the lsit should not
  +            // be propagated
  +
               //ok = super.remove(groupId.key, nonLocal);
  -            ok = systemGroupIdCache.remove( groupId.key, nonLocal );
  +            //ok = systemGroupIdCache.remove( groupId.key, nonLocal );
  +            // TODO: make sure that an update tot he list does not propagate
  +            // the list to the remote cache.  Orders to delete the item should
  +            // propagate.
  +            // A removal of the list should propagate.
  +            ok = systemGroupIdCache.remove( groupId.key, this.INCLUDE_REMOTE_CACHE 
);
           }
           catch ( IOException ioeg )
           {
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to