tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1357414 - in /tomcat/trunk/java/org/apache/catalina: Manager.java ha/session/ClusterManagerBase.java ha/session/DeltaManager.java session/LocalStrings.properties session/ManagerBase.java session/StandardManager.java
Date Wed, 04 Jul 2012 21:23:00 GMT
Author: markt
Date: Wed Jul  4 21:23:00 2012
New Revision: 1357414

URL: http://svn.apache.org/viewvc?rev=1357414&view=rev
Log:
Refactor Manager to retain reference to Context rather than Container

Modified:
    tomcat/trunk/java/org/apache/catalina/Manager.java
    tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
    tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
    tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java
    tomcat/trunk/java/org/apache/catalina/session/StandardManager.java

Modified: tomcat/trunk/java/org/apache/catalina/Manager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Manager.java?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Manager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Manager.java Wed Jul  4 21:23:00 2012
@@ -51,7 +51,11 @@ public interface Manager {
 
     /**
      * Return the Container with which this Manager is associated.
+     *
+     * @deprecated Use {@link #getContext()}. This method will be removed in
+     *             Tomcat 9 onwards.
      */
+    @Deprecated
     public Container getContainer();
 
 
@@ -59,11 +63,29 @@ public interface Manager {
      * Set the Container with which this Manager is associated.
      *
      * @param container The newly associated Container
+     *
+     * @deprecated Use {@link #setContext()}. This method will be removed in
+     *             Tomcat 9 onwards.
      */
+    @Deprecated
     public void setContainer(Container container);
 
 
     /**
+     * Return the Context with which this Manager is associated.
+     */
+    public Context getContext();
+
+
+    /**
+     * Set the Container with which this Manager is associated.
+     *
+     * @param container The newly associated Context
+     */
+    public void setContext(Context context);
+
+
+    /**
      * Return the distributable flag for the sessions supported by
      * this Manager.
      */

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/ClusterManagerBase.java Wed Jul  4 21:23:00
2012
@@ -144,7 +144,7 @@ public abstract class ClusterManagerBase
 
 
     public ClassLoader[] getClassLoaders() {
-        return getClassLoaders(container);
+        return getClassLoaders(getContext());
     }
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java Wed Jul  4 21:23:00
2012
@@ -849,7 +849,9 @@ public class DeltaManager extends Cluste
      */
     protected void registerSessionAtReplicationValve(DeltaSession session) {
         if(replicationValve == null) {
-            if(container instanceof StandardContext && ((StandardContext)container).getCrossContext())
{
+            Context context = getContext();
+            if(context instanceof StandardContext &&
+                    ((StandardContext)context).getCrossContext()) {
                 CatalinaCluster cluster = getCluster() ;
                 if(cluster != null) {
                     Valve[] valves = cluster.getValves();

Modified: tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/session/LocalStrings.properties Wed Jul  4 21:23:00
2012
@@ -30,6 +30,7 @@ JDBCStore.checkConnectionClassNotFoundEx
 JDBCStore.wrongDataSource=Cannot open JNDI DataSource [{0}]
 JDBCStore.missingDataSourceName=No valid JNDI name was given.
 JDBCStore.commitSQLException=SQLException committing connection before closing
+managerBase.container.noop=Managers added to containers other than Contexts will never be
used
 managerBase.createSession.ise=createSession: Too many active sessions
 managerBase.sessionTimeout=Invalid session timeout setting {0}
 standardManager.loading=Loading persisted sessions from {0}

Modified: tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java Wed Jul  4 21:23:00 2012
@@ -63,9 +63,9 @@ public abstract class ManagerBase extend
     // ----------------------------------------------------- Instance Variables
 
     /**
-     * The Container with which this Manager is associated.
+     * The Context with which this Manager is associated.
      */
-    protected Container container;
+    private Context context;
 
 
     /**
@@ -208,40 +208,49 @@ public abstract class ManagerBase extend
 
     // ------------------------------------------------------------- Properties
 
-    /**
-     * Return the Container with which this Manager is associated.
-     */
     @Override
+    @Deprecated
     public Container getContainer() {
+        return getContext();
+    }
 
-        return (this.container);
 
+    @Override
+    @Deprecated
+    public void setContainer(Container container) {
+
+        if (container instanceof Context || container == null) {
+            setContext((Context) container);
+        } else {
+            log.warn(sm.getString("managerBase.container.noop"));
+        }
     }
 
 
-    /**
-     * Set the Container with which this Manager is associated.
-     *
-     * @param container The newly associated Container
-     */
     @Override
-    public void setContainer(Container container) {
+    public Context getContext() {
+        return context;
+    }
+
 
-        // De-register from the old Container (if any)
-        if ((this.container != null) && (this.container instanceof Context))
-            ((Context) this.container).removePropertyChangeListener(this);
-
-        Container oldContainer = this.container;
-        this.container = container;
-        support.firePropertyChange("container", oldContainer, this.container);
-
-        // Register with the new Container (if any)
-        if ((this.container != null) && (this.container instanceof Context)) {
-            setMaxInactiveInterval
-                ( ((Context) this.container).getSessionTimeout()*60 );
-            ((Context) this.container).addPropertyChangeListener(this);
+    @Override
+    public void setContext(Context context) {
+        // De-register from the old Context (if any)
+        if (this.context != null) {
+            this.context.removePropertyChangeListener(this);
         }
 
+        Context oldContext = this.context;
+        this.context = context;
+        support.firePropertyChange("context", oldContext, this.context);
+        // TODO - delete the line below in Tomcat 9 onwards
+        support.firePropertyChange("container", oldContext, this.context);
+
+        // Register with the new Context (if any)
+        if (this.context != null) {
+            setMaxInactiveInterval(this.context.getSessionTimeout() * 60);
+            this.context.addPropertyChangeListener(this);
+        }
     }
 
 
@@ -751,7 +760,7 @@ public abstract class ManagerBase extend
         String oldId = session.getIdInternal();
         session.setId(generateSessionId(), false);
         String newId = session.getIdInternal();
-        container.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
+        context.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
                 new String[] {oldId, newId});
     }
 
@@ -1220,10 +1229,10 @@ public abstract class ManagerBase extend
     public String toString() {
         StringBuilder sb = new StringBuilder(this.getClass().getName());
         sb.append('[');
-        if (container == null) {
-            sb.append("Container is null");
+        if (context == null) {
+            sb.append("Context is null");
         } else {
-            sb.append(container.getName());
+            sb.append(context.getName());
         }
         sb.append(']');
         return sb.toString();
@@ -1236,29 +1245,22 @@ public abstract class ManagerBase extend
 
         StringBuilder name = new StringBuilder("type=Manager");
 
-        if (container instanceof Context) {
-            name.append(",context=");
-            String contextName = container.getName();
-            if (!contextName.startsWith("/")) {
-                name.append('/');
-            }
-            name.append(contextName);
-
-            Context context = (Context) container;
-            name.append(",host=");
-            name.append(context.getParent().getName());
-        } else {
-            // Unlikely / impossible? Handle it to be safe
-            name.append(",container=");
-            name.append(container.getName());
+        name.append(",context=");
+        String contextName = context.getName();
+        if (!contextName.startsWith("/")) {
+            name.append('/');
         }
+        name.append(contextName);
+
+        name.append(",host=");
+        name.append(context.getParent().getName());
 
         return name.toString();
     }
 
     @Override
     public String getDomainInternal() {
-        return container.getDomain();
+        return context.getDomain();
     }
 
     // ----------------------------------------- PropertyChangeListener Methods

Modified: tomcat/trunk/java/org/apache/catalina/session/StandardManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardManager.java?rev=1357414&r1=1357413&r2=1357414&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StandardManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/StandardManager.java Wed Jul  4 21:23:00
2012
@@ -215,8 +215,9 @@ public class StandardManager extends Man
         try {
             fis = new FileInputStream(file.getAbsolutePath());
             bis = new BufferedInputStream(fis);
-            if (container instanceof Context)
-                loader = ((Context) container).getLoader();
+            Context c = getContext();
+            if (c != null)
+                loader = c.getLoader();
             if (loader != null)
                 classLoader = loader.getClassLoader();
             if (classLoader != null) {
@@ -535,9 +536,9 @@ public class StandardManager extends Man
             return (null);
         File file = new File(pathname);
         if (!file.isAbsolute()) {
-            if (container instanceof Context) {
-                ServletContext servletContext =
-                    ((Context) container).getServletContext();
+            Context context = getContext();
+            if (context != null) {
+                ServletContext servletContext = context.getServletContext();
                 File tempdir = (File)
                     servletContext.getAttribute(ServletContext.TEMPDIR);
                 if (tempdir != null)



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


Mime
View raw message