tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r408460 - in /tomcat/container/tc5.5.x/modules: cluster/src/share/org/apache/catalina/cluster/session/ ha/src/share/org/apache/catalina/ha/session/
Date Sun, 21 May 2006 18:26:02 GMT
Author: fhanik
Date: Sun May 21 11:26:01 2006
New Revision: 408460

URL: http://svn.apache.org/viewvc?rev=408460&view=rev
Log:
When applying a new attribute, make sure to set the threads context class loader correctly.

Modified:
    tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
    tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java
    tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java
    tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaManager.java
    tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java

Modified: tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java?rev=408460&r1=408459&r2=408460&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
(original)
+++ tomcat/container/tc5.5.x/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
Sun May 21 11:26:01 2006
@@ -198,6 +198,20 @@
 
     // ------------------------------------------------------------- Properties
     
+    public static ClassLoader[] getClassLoaders(Container container) {
+        Loader loader = null;
+        ClassLoader classLoader = null;
+        if (container != null) loader = container.getLoader();
+        if (loader != null) classLoader = loader.getClassLoader();
+        else classLoader = Thread.currentThread().getContextClassLoader();
+        if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
+            return new ClassLoader[] {classLoader};
+        } else {
+            return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
+        }
+    }
+
+    
     /**
      * Return descriptive information about this Manager implementation and the
      * corresponding version number, in the format
@@ -678,19 +692,8 @@
         ByteArrayInputStream fis = null;
         ReplicationStream ois = null;
         Loader loader = null;
-        ClassLoader classLoader = null;
-        //fix to be able to run the DeltaManager
-        //stand alone without a container.
-        //use the Threads context class loader
-        if (container != null)
-            loader = container.getLoader();
-        if (loader != null)
-            classLoader = loader.getClassLoader();
-        else
-            classLoader = Thread.currentThread().getContextClassLoader();
-        //end fix
         fis = new ByteArrayInputStream(data);
-        ois = new ReplicationStream(fis, classLoader);
+        ois = new ReplicationStream(fis, getClassLoaders(this.container)[0]);
         session.getDeltaRequest().readExternal(ois);
         ois.close();
         return session.getDeltaRequest();
@@ -1482,7 +1485,10 @@
         if(isSendClusterDomainOnly() && !checkSenderDomain(msg,sender)) {
             return;
         }
+        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
         try {
+            ClassLoader[] loaders = getClassLoaders(container);
+            if ( loaders != null && loaders.length > 0 ) Thread.currentThread().setContextClassLoader(loaders[0]);
             if (log.isDebugEnabled())
                 log.debug(sm.getString("deltaManager.receiveMessage.eventType",
                         getName(), msg.getEventTypeString(), sender));
@@ -1524,6 +1530,8 @@
         } catch (Exception x) {
             log.error(sm.getString("deltaManager.receiveMessage.error",
                     getName()), x);
+        } finally {
+            Thread.currentThread().setContextClassLoader(contextLoader);
         }
     }
 

Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java?rev=408460&r1=408459&r2=408460&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java
(original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/BackupManager.java
Sun May 21 11:26:01 2006
@@ -140,16 +140,7 @@
     }
     
     public ClassLoader[] getClassLoaders() {
-        Loader loader = null;
-        ClassLoader classLoader = null;
-        if (container != null) loader = container.getLoader();
-        if (loader != null) classLoader = loader.getClassLoader();
-        if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader();
-        if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
-            return new ClassLoader[] {classLoader};
-        } else {
-            return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
-        }
+        return ClusterManagerBase.getClassLoaders(this.container);
     }
 
     /**

Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java?rev=408460&r1=408459&r2=408460&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java
(original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/ClusterManagerBase.java
Sun May 21 11:26:01 2006
@@ -24,6 +24,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import org.apache.catalina.tribes.io.ReplicationStream;
+import org.apache.catalina.Container;
 
 /**
  * 
@@ -33,7 +34,8 @@
 
 public abstract class ClusterManagerBase extends ManagerBase implements Lifecycle, PropertyChangeListener,
ClusterManager{
     
-    public ClassLoader[] getClassLoaders() {
+
+    public static ClassLoader[] getClassLoaders(Container container) {
         Loader loader = null;
         ClassLoader classLoader = null;
         if (container != null) loader = container.getLoader();
@@ -44,6 +46,11 @@
         } else {
             return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
         }
+    }
+
+
+    public ClassLoader[] getClassLoaders() {
+        return getClassLoaders(container);
     }
 
     /**

Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaManager.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaManager.java?rev=408460&r1=408459&r2=408460&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaManager.java
(original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaManager.java
Sun May 21 11:26:01 2006
@@ -1282,7 +1282,11 @@
         if(isSendClusterDomainOnly() && !checkSenderDomain(msg,sender)) {
             return;
         }
+        ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
         try {
+            
+            ClassLoader[] loaders = getClassLoaders();
+            if ( loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]);
             if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.eventType",getName(),
msg.getEventTypeString(), sender));
  
             switch (msg.getEventType()) {
@@ -1321,6 +1325,8 @@
             } //switch
         } catch (Exception x) {
             log.error(sm.getString("deltaManager.receiveMessage.error",getName()), x);
+        } finally {
+            Thread.currentThread().setContextClassLoader(contextLoader);
         }
     }
 

Modified: tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java
URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java?rev=408460&r1=408459&r2=408460&view=diff
==============================================================================
--- tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java
(original)
+++ tomcat/container/tc5.5.x/modules/ha/src/share/org/apache/catalina/ha/session/DeltaSession.java
Sun May 21 11:26:01 2006
@@ -41,6 +41,8 @@
 import org.apache.catalina.tribes.tipis.ReplicatedMapEntry;
 import org.apache.catalina.util.Enumerator;
 import org.apache.catalina.util.StringManager;
+import org.apache.catalina.session.StandardManager;
+import org.apache.catalina.session.ManagerBase;
 
 /**
  *
@@ -133,6 +135,18 @@
             return getDeltaRequest().serialize();
         }
 
+        public ClassLoader[] getClassLoaders() {
+            if ( manager instanceof BackupManager ) return ((BackupManager)manager).getClassLoaders();
+            else if ( manager instanceof ClusterManagerBase ) return ((ClusterManagerBase)manager).getClassLoaders();
+            else if ( manager instanceof StandardManager ) {
+                StandardManager sm = (StandardManager)manager;
+                return ClusterManagerBase.getClassLoaders(sm.getContainer());
+            } else if ( manager instanceof ManagerBase ) {
+                ManagerBase mb = (ManagerBase)manager;
+                return ClusterManagerBase.getClassLoaders(mb.getContainer());
+            }//end if
+            return null;
+        }
 
         /**
          * Applies a diff to an existing object.
@@ -144,7 +158,14 @@
         public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException
{
             ReplicationStream stream = ((ClusterManager)getManager()).getReplicationStream(diff,offset,length);
             getDeltaRequest().readExternal(stream);
-            getDeltaRequest().execute(this);
+            ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
+            try {
+                ClassLoader[] loaders = getClassLoaders();
+                if ( loaders != null && loaders.length >0 ) Thread.currentThread().setContextClassLoader(loaders[0]);
+                getDeltaRequest().execute(this);
+            }finally {
+                Thread.currentThread().setContextClassLoader(contextLoader);
+            }
         }
 
         /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message