fhanik      2004/02/05 14:57:52

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/io
                        XByteBuffer.java
               modules/cluster/src/share/org/apache/catalina/cluster/mcast
                        McastService.java
               modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java DeltaSession.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        ReplicationListener.java SimpleTcpCluster.java
               modules/cluster/src/share/org/apache/catalina/cluster/util
                        SmartQueue.java
  Log:
  Fixed bug with the fact that the manager base has a static variable called name, 
caused session messages to be sent to the wrong managers
  
  Revision  Changes    Path
  1.6       +19 -14    
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/io/XByteBuffer.java
  
  Index: XByteBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/io/XByteBuffer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XByteBuffer.java  9 Jan 2004 23:24:08 -0000       1.5
  +++ XByteBuffer.java  5 Feb 2004 22:57:52 -0000       1.6
  @@ -76,6 +76,10 @@
   
   public class XByteBuffer
   {
  +    
  +    public static org.apache.commons.logging.Log log =
  +        org.apache.commons.logging.LogFactory.getLog( XByteBuffer.class );
  +    
       /**
        * This is a package header, 7 bytes
        */
  @@ -168,7 +172,7 @@
   
           if (bufSize > START_DATA.length && (firstIndexOf(buf,0,START_DATA)==-1)){
               bufSize = 0;
  -            System.out.println("Discarded the package, invalid header");
  +            log.error("Discarded the package, invalid header");
               return false;
           }
           return true;
  @@ -395,18 +399,18 @@
       }//createDataPackage
   
       public static void main(String[] args) throws Exception {
  -       System.out.println("Before="+Integer.MAX_VALUE);
  +       log.info("Before="+Integer.MAX_VALUE);
          byte[] d = toBytes(Integer.MAX_VALUE);
  -       System.out.println("After="+toInt(d,0));
  +       log.info("After="+toInt(d,0));
   
   
  -       System.out.println("Before="+Long.MAX_VALUE);
  +       log.info("Before="+Long.MAX_VALUE);
          d = toBytes(Long.MAX_VALUE);
  -       System.out.println("After="+toLong(d,0));
  +       log.info("After="+toLong(d,0));
   
  -       System.out.println("Before=" + 4564564);
  +       log.info("Before=" + 4564564);
          d = toBytes((long)4564564);
  -       System.out.println("After=" + toLong(d, 0));
  +       log.info("After=" + toLong(d, 0));
   
          byte[] d1 = createDataPackage(new byte[] {1});
          byte[] d2 = createDataPackage(new byte[] {2});
  @@ -422,7 +426,7 @@
          XByteBuffer b = new XByteBuffer();
          b.append(test,0,test.length);
          int s = b.countPackages();
  -       System.out.println("Nr of packages="+s);
  +       log.info("Nr of packages="+s);
          while ( s > 0 ) {
              d = b.extractPackage(true);
              System.out.print("Package d1=");
  @@ -433,10 +437,11 @@
       }
   
       public static void printBuf(byte[] b) {
  +        StringBuffer buf = new StringBuffer();
           for ( int i=0; i<b.length; i++ ) {
  -            System.out.print(b[i] + " ");
  +            buf.append(b[i] + " ");
           }
  -        System.out.println();
  +        log.info(buf);
       }
   
   }//class
  
  
  
  1.7       +5 -5      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java
  
  Index: McastService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- McastService.java 5 Feb 2004 05:27:31 -0000       1.6
  +++ McastService.java 5 Feb 2004 22:57:52 -0000       1.7
  @@ -275,7 +275,7 @@
        * @throws Exception
        */
       public static void main(String args[]) throws Exception {
  -        System.out.println("Usage McastService hostname tcpport");
  +        log.info("Usage McastService hostname tcpport");
           McastService service = new McastService();
           java.util.Properties p = new java.util.Properties();
           p.setProperty("mcastPort","5555");
  
  
  
  1.12      +8 -7      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
  
  Index: DeltaManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DeltaManager.java 5 Feb 2004 21:08:02 -0000       1.11
  +++ DeltaManager.java 5 Feb 2004 22:57:52 -0000       1.12
  @@ -149,7 +149,9 @@
       /**
        * The descriptive name of this Manager implementation (for logging).
        */
  -    protected static String name = "DeltaManager";
  +    protected static String managerName = "DeltaManager";
  +    
  +    protected String name = null;
   
   
       /**
  @@ -634,7 +636,6 @@
        *  that prevents this component from being used
        */
       public void start() throws LifecycleException {
  -
           if( ! initialized )
               init();
   
  @@ -868,7 +869,7 @@
           */
          protected void messageReceived(SessionMessage msg, Member sender) {
              try {
  -               log.debug("Received SessionMessage of type=" + 
msg.getEventTypeString()+" from "+sender);
  +               log.info("Manager ("+name+") Received SessionMessage of type=" + 
msg.getEventTypeString()+" from "+sender);
                  switch (msg.getEventType()) {
                      case SessionMessage.EVT_GET_ALL_SESSIONS: {
                          //get a list of all the session from this manager
  
  
  
  1.13      +16 -6     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java
  
  Index: DeltaSession.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaSession.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DeltaSession.java 5 Feb 2004 21:08:02 -0000       1.12
  +++ DeltaSession.java 5 Feb 2004 22:57:52 -0000       1.13
  @@ -102,7 +102,7 @@
   import org.apache.catalina.session.ManagerBase;
   import org.apache.catalina.session.Constants;
   import org.apache.catalina.cluster.ClusterSession;
  -
  +import org.apache.catalina.realm.GenericPrincipal;
   /**
    *
    * Similar to the StandardSession, this code is identical, but for update
  @@ -1416,7 +1416,13 @@
           isNew = ((Boolean) stream.readObject()).booleanValue();
           isValid = ((Boolean) stream.readObject()).booleanValue();
           thisAccessedTime = ((Long) stream.readObject()).longValue();
  -        principal = null;        // Transient only
  +        boolean hasPrincipal = stream.readBoolean();
  +        principal = null;   
  +        if ( hasPrincipal ) {
  +            SerializablePrincipal p = (SerializablePrincipal)stream.readObject();
  +            principal = p.getPrincipal(getManager().getContainer().getRealm());
  +        }
  +            
           //        setId((String) stream.readObject());
           id = (String) stream.readObject();
           if (log.isDebugEnabled())
  @@ -1472,6 +1478,10 @@
           stream.writeObject(new Boolean(isNew));
           stream.writeObject(new Boolean(isValid));
           stream.writeObject(new Long(thisAccessedTime));
  +        stream.writeBoolean(getPrincipal()!=null);
  +        if (getPrincipal() != null) stream.writeObject(SerializablePrincipal.
  +            createPrincipal( (GenericPrincipal) getPrincipal()));
  +        
           stream.writeObject(id);
           if (log.isDebugEnabled())
               log.debug("writeObject() storing session " + id);
  
  
  
  1.12      +3 -8      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationListener.java
  
  Index: ReplicationListener.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ReplicationListener.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- ReplicationListener.java  5 Feb 2004 05:27:31 -0000       1.11
  +++ ReplicationListener.java  5 Feb 2004 22:57:52 -0000       1.12
  @@ -155,9 +155,7 @@
               // selected set contains keys of the ready channels
               try {
   
  -                //System.out.println("Selecting with timeout="+timeout);
                   int n = selector.select(tcpSelectorTimeout);
  -                //System.out.println("select returned="+n);
                   if (n == 0) {
                       continue; // nothing to do
                   }
  @@ -178,18 +176,15 @@
                               callback));
                       }
                       // is there data to read on this channel?
  -                    //System.out.println("key readable="+key.isReadable());
                       if (key.isReadable()) {
                           readDataFromSocket(key);
                       } else {
  -                        //System.out.println("This shouldn't get called");
                           key.interestOps(key.interestOps() & (~key.OP_WRITE));
                       }
   
                       // remove key from selected set, it's been handled
                       it.remove();
                   }
  -                //System.out.println("Done with loop");
               }
               catch (java.nio.channels.CancelledKeyException nx) {
                   log.warn(
  
  
  
  1.33      +11 -12    
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java
  
  Index: SimpleTcpCluster.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- SimpleTcpCluster.java     5 Feb 2004 21:08:02 -0000       1.32
  +++ SimpleTcpCluster.java     5 Feb 2004 22:57:52 -0000       1.33
  @@ -338,7 +338,7 @@
   
   
       public synchronized Manager createManager(String name) {
  -        log.debug("Creating ClusterManager for context "+name + " using class 
"+getManagerClassName());
  +        log.info("Creating ClusterManager for context "+name + " using class 
"+getManagerClassName());
           ClusterManager manager = null;
           try {
               manager = 
(ClusterManager)getClass().getClassLoader().loadClass(getManagerClassName()).newInstance();
  @@ -538,13 +538,12 @@
                                         getClass().getClassLoader());
               Object myobj = stream.readObject();
               if ( myobj != null && myobj instanceof SessionMessage ) {
  +                
                   SessionMessage msg = (SessionMessage)myobj;
  -                //remove when checking in
  -                perfMessageRecvd(msg.getTimestamp());
  -                String name = msg.getContextName();
  +                String ctxname = msg.getContextName();
                   //check if the message is a EVT_GET_ALL_SESSIONS,
                   //if so, wait until we are fully started up
  -                if ( name == null ) {
  +                if ( ctxname == null ) {
                       java.util.Iterator i = managers.keySet().iterator();
                       while ( i.hasNext() ) {
                           String key = (String)i.next();
  @@ -557,11 +556,11 @@
                           }
                       }//while
                   } else {
  -                    ClusterManager mgr = (ClusterManager) managers.get(name);
  +                    ClusterManager mgr = (ClusterManager) managers.get(ctxname);
                       if (mgr != null)
                           mgr.messageDataReceived(msg);
                       else
  -                        log.warn("Context manager doesn't exist:" + name);
  +                        log.warn("Context manager doesn't exist:" + ctxname);
                   }//end if
               }  else
                   log.warn("Received invalid message myobj="+myobj);
  @@ -621,7 +620,7 @@
        *  during installation
        */
       public void installContext(String contextPath, URL war) {
  -        System.out.println("\n\n\n\nCluster Install called for 
context:"+contextPath+"\n\n\n\n");
  +        log.debug("\n\n\n\nCluster Install called for 
context:"+contextPath+"\n\n\n\n");
       }
   
   
  
  
  
  1.2       +13 -9     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/util/SmartQueue.java
  
  Index: SmartQueue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/util/SmartQueue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SmartQueue.java   18 Apr 2003 02:51:24 -0000      1.1
  +++ SmartQueue.java   5 Feb 2004 22:57:52 -0000       1.2
  @@ -79,6 +79,10 @@
   import java.util.HashMap;
   
   public class SmartQueue {
  +    
  +    public static org.apache.commons.logging.Log log =
  +        org.apache.commons.logging.LogFactory.getLog( SmartQueue.class );
  +    
       /**
        * This is the actual queue
        */
  @@ -106,14 +110,14 @@
               SmartEntry current = (SmartEntry)queueMap.get(entry.getKey());
               if ( current == null ) {
                   /*the object has not been queued, at it to the end of the queue*/
  -                if ( debug != 0 ) 
System.out.println("["+Thread.currentThread().getName()+"][SmartQueue] Adding new 
object="+entry);
  +                if ( debug != 0 ) 
log.debug("["+Thread.currentThread().getName()+"][SmartQueue] Adding new 
object="+entry);
                   queue.addLast(entry);
                   queueMap.put(entry.getKey(),entry);
               }else {
                   /*the object has been queued, replace the value*/
                   if ( debug != 0 ) 
System.out.print("["+Thread.currentThread().getName()+"][SmartQueue] Replacing old 
object="+current);
                   current.setValue(entry.getValue());
  -                if ( debug != 0 ) System.out.println("with new object="+current);
  +                if ( debug != 0 ) log.debug("with new object="+current);
               }
               /*wake up all the threads that are waiting for the lock to be released*/
               mutex.notifyAll();
  @@ -135,9 +139,9 @@
           synchronized (mutex) {
               while ( size() == 0 ) {
                   try {
  -                    if ( debug != 0 ) 
System.out.println("["+Thread.currentThread().getName()+"][SmartQueue] Queue sleeping 
until object added size="+size()+".");
  +                    if ( debug != 0 ) 
log.debug("["+Thread.currentThread().getName()+"][SmartQueue] Queue sleeping until 
object added size="+size()+".");
                       mutex.wait();
  -                    if ( debug != 0 ) 
System.out.println("["+Thread.currentThread().getName()+"][SmartQueue] Queue woke up 
or interrupted size="+size()+".");
  +                    if ( debug != 0 ) 
log.debug("["+Thread.currentThread().getName()+"][SmartQueue] Queue woke up or 
interrupted size="+size()+".");
                   }
                   catch(IllegalMonitorStateException ex) {
                       throw ex;
  @@ -148,7 +152,7 @@
               /*guaranteed that we are not empty by now*/
               result = (SmartEntry)queue.removeFirst();
               queueMap.remove(result.getKey());
  -            if ( debug != 0 ) 
System.out.println("["+Thread.currentThread().getName()+"][SmartQueue] 
Returning="+result);
  +            if ( debug != 0 ) 
log.debug("["+Thread.currentThread().getName()+"][SmartQueue] Returning="+result);
           }
           return result;
       }
  @@ -195,4 +199,4 @@
       }
       
   
  -}
  \ No newline at end of file
  +}
  
  
  

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

Reply via email to