Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50230
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Nov 2010 22:10:25 +0000 (22:10 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 11 Nov 2010 22:10:25 +0000 (22:10 +0000)
Add new DistributedManager interface that is implemented by the Backup Manager to remove circular dependency between tomcat-catalina-ha and tomcat-catalina modules. Also allows third-party distributed Manager implementations to report full session information through the HTML Manager.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1034174 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/DistributedManager.java [new file with mode: 0644]
java/org/apache/catalina/ha/session/BackupManager.java
java/org/apache/catalina/manager/HTMLManagerServlet.java
webapps/docs/changelog.xml

diff --git a/java/org/apache/catalina/DistributedManager.java b/java/org/apache/catalina/DistributedManager.java
new file mode 100644 (file)
index 0000000..2d042c6
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina;
+
+import java.util.Set;
+
+/**
+ * Interface implemented by session managers that do not keep a complete copy
+ * of all sessions on the local node but do know where every session is. The
+ * BackupManager is an example of such a Manager. Sessions can be primary
+ * (master copy on this node), backup (backup copy on this node) or proxy (only
+ * the session ID on this node). The identity of the primary and backup nodes
+ * are known for all sessions, including proxy sessions.
+ */
+public interface DistributedManager {
+
+    /**
+     * Returns the total session count for primary, backup and proxy.
+     * 
+     * @return  The total session count across the cluster.
+     */
+    public int getActiveSessionsFull();
+
+    /**
+     * Returns the list of all sessions IDS (primary, backup and proxy).
+     * 
+     * @return  The complete set of sessions IDs across the cluster.
+     */
+    public Set<String> getSessionIdsFull();
+}
index aca0342..5d844cb 100644 (file)
@@ -20,6 +20,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.catalina.DistributedManager;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Session;
@@ -36,7 +37,8 @@ import org.apache.juli.logging.LogFactory;
  *@author Filip Hanik
  *@version 1.0
  */
-public class BackupManager extends ClusterManagerBase implements MapOwner {
+public class BackupManager extends ClusterManagerBase
+        implements MapOwner, DistributedManager {
 
     private static final Log log = LogFactory.getLog(BackupManager.class);
 
@@ -254,22 +256,13 @@ public class BackupManager extends ClusterManagerBase implements MapOwner {
         return result;
     }
 
+    @Override
     public int getActiveSessionsFull() {
         LazyReplicatedMap map = (LazyReplicatedMap)sessions;
         return map.sizeFull();
     }
 
-    public String listSessionIdsFull() {
-        StringBuilder sb=new StringBuilder();
-        LazyReplicatedMap map = (LazyReplicatedMap)sessions;
-        @SuppressWarnings("unchecked") // sessions is of type Map<String, Session>
-        Iterator<String> keys = map.keySetFull().iterator();
-        while (keys.hasNext()) {
-            sb.append(keys.next()).append(" ");
-        }
-        return sb.toString();
-    }
-    
+    @Override
     public Set<String> getSessionIdsFull() {
         Set<String> sessionIds = new HashSet<String>();
         LazyReplicatedMap map = (LazyReplicatedMap)sessions;
index b05ba4c..dda96b2 100644 (file)
@@ -45,9 +45,9 @@ import javax.servlet.http.Part;
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
+import org.apache.catalina.DistributedManager;
 import org.apache.catalina.Manager;
 import org.apache.catalina.Session;
-import org.apache.catalina.ha.session.BackupManager;
 import org.apache.catalina.manager.util.BaseSessionComparator;
 import org.apache.catalina.manager.util.ReverseComparator;
 import org.apache.catalina.manager.util.SessionUtils;
@@ -517,9 +517,9 @@ public final class HTMLManagerServlet extends ManagerServlet {
                     (request.getContextPath() +
                      "/html/sessions?path=" + URL_ENCODER.encode(displayPath));
                 Manager manager = ctxt.getManager(); 
-                if (manager instanceof BackupManager && showProxySessions) {
+                if (manager instanceof DistributedManager && showProxySessions) {
                     args[5] = new Integer(
-                            ((BackupManager)manager).getActiveSessionsFull());
+                            ((DistributedManager)manager).getActiveSessionsFull());
                 } else if (ctxt.getManager() != null){
                     args[5] = new Integer(manager.getActiveSessions());
                 } else {
@@ -871,10 +871,10 @@ public final class HTMLManagerServlet extends ManagerServlet {
         Manager manager = ctxt.getManager();
         List<Session> sessions = new ArrayList<Session>();
         sessions.addAll(Arrays.asList(manager.findSessions()));
-        if (manager instanceof BackupManager && showProxySessions) {
+        if (manager instanceof DistributedManager && showProxySessions) {
             // Add dummy proxy sessions
             Set<String> sessionIds =
-                ((BackupManager) manager).getSessionIdsFull();
+                ((DistributedManager) manager).getSessionIdsFull();
             // Remove active (primary and backup) session IDs from full list
             for (Session session : sessions) {
                 sessionIds.remove(session.getId());
index ee472d9..bc31f6b 100644 (file)
       <fix>
         Correct broken links for on-line JavaDocs. (markt)
       </fix>
+      <fix>
+        <bug>50230</bug>: Add new DistributedManager interface that is
+        implemented by the Backup Manager to remove circular dependency between
+        tomcat-catalina-ha and tomcat-catalina modules. Also allows third-party
+        distributed Manager implementations to report full session information
+        through the HTML Manager. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Other">