tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfuj...@apache.org
Subject svn commit: r1446072 - in /tomcat/trunk/java/org/apache/catalina: Manager.java Session.java ha/session/DeltaManager.java session/ManagerBase.java session/StandardSession.java
Date Thu, 14 Feb 2013 08:57:43 GMT
Author: kfujino
Date: Thu Feb 14 08:57:43 2013
New Revision: 1446072

URL: http://svn.apache.org/r1446072
Log:
Remove duplicate code on ManagerBase and DeltaManager.
Introduce following interfaces.
  Manager#changeSessionId(Session, String)
  Session#tellChangedSessionId(String, String, boolean, boolean)

Modified:
    tomcat/trunk/java/org/apache/catalina/Manager.java
    tomcat/trunk/java/org/apache/catalina/Session.java
    tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
    tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java
    tomcat/trunk/java/org/apache/catalina/session/StandardSession.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=1446072&r1=1446071&r2=1446072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Manager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Manager.java Thu Feb 14 08:57:43 2013
@@ -280,6 +280,15 @@ public interface Manager {
 
 
     /**
+     * Change the session ID of the current session to a specified session ID.
+     *
+     * @param session   The session to change the session ID for
+     * @param newId   new session ID
+     */
+    public void changeSessionId(Session session, String newId);
+
+
+    /**
      * Get a session from the recycled ones or create a new empty one.
      * The PersistentManager manager does not need to create session data
      * because it reads it from the Store.

Modified: tomcat/trunk/java/org/apache/catalina/Session.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Session.java?rev=1446072&r1=1446071&r2=1446072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Session.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Session.java Thu Feb 14 08:57:43 2013
@@ -327,4 +327,18 @@ public interface Session {
     public void setNote(String name, Object value);
 
 
+    /**
+     * Inform the listeners about the change session ID.
+     *
+     * @param newId  new session ID
+     * @param oldId  old session ID
+     * @param notifySessionListeners  Should any associated sessionListeners be
+     *        notified that session ID has been changed?     
+     * @param notifyContainerListeners  Should any associated ContainerListeners
+     *        be notified that session ID has been changed?
+     */
+    public void tellChangedSessionId(String newId, String oldId,
+            boolean notifySessionListeners, boolean notifyContainerListeners);
+
+
 }

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=1446072&r1=1446071&r2=1446072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java Thu Feb 14 08:57:43
2013
@@ -526,13 +526,31 @@ public class DeltaManager extends Cluste
         changeSessionId(session, true);
     }
 
-    public void changeSessionId(Session session, boolean notify) {
-        // original sessionID
+    /**
+     * Change the session ID of the current session to a specified session ID.
+     *
+     * @param session   The session to change the session ID for
+     * @param newId   new session ID
+     */
+    @Override
+    public void changeSessionId(Session session, String newId) {
+        changeSessionId(session, newId, true);
+    }
+
+    protected void changeSessionId(Session session, boolean notify) {
         String orgSessionID = session.getId();
         super.changeSessionId(session);
-        if (notify && cluster.getMembers().length > 0) {
-            // changed sessionID
-            String newSessionID = session.getId();
+        if (notify) sendChangeSessionId(session.getId(), orgSessionID);
+    }
+
+    protected void changeSessionId(Session session, String newId, boolean notify) {
+        String orgSessionID = session.getId();
+        super.changeSessionId(session, newId);
+        if (notify) sendChangeSessionId(session.getId(), orgSessionID);
+    }
+
+    protected void sendChangeSessionId(String newSessionID, String orgSessionID) {
+        if (cluster.getMembers().length > 0) {
             try {
                 // serialize sessionID
                 byte[] data = serializeSessionId(newSessionID);
@@ -1469,35 +1487,8 @@ public class DeltaManager extends Cluste
         if (session != null) {
             String newSessionID = deserializeSessionId(msg.getSession());
             session.setPrimarySession(false);
-            session.setId(newSessionID, false);
-            if (notifyContainerListenersOnReplication) {
-                getContext().fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
-                        new String[] {msg.getSessionID(), newSessionID});
-            }
-
-            if (notifySessionListenersOnReplication) {
-                Object listeners[] = getContext().
-                    getApplicationEventListeners();
-                if (listeners != null && listeners.length > 0) {
-                    HttpSessionEvent event =
-                        new HttpSessionEvent(session.getSession());
-
-                    for(Object listener : listeners) {
-                        if (!(listener instanceof HttpSessionIdListener))
-                            continue;
-
-                        HttpSessionIdListener idListener =
-                            (HttpSessionIdListener)listener;
-                        try {
-                            idListener.
-                                sessionIdChanged(event, msg.getSessionID());
-                        } catch (Throwable t) {
-                            log.error(sm.getString(
-                                "standardSession.sessionEvent"), t);
-                        }
-                    }
-                }
-            }
+            // change session id
+            changeSessionId(session, newSessionID, notifySessionListenersOnReplication, notifyContainerListenersOnReplication);
         }
     }
 

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=1446072&r1=1446071&r2=1446072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java Thu Feb 14 08:57:43 2013
@@ -760,30 +760,27 @@ public abstract class ManagerBase extend
      */
     @Override
     public void changeSessionId(Session session) {
+        String newId = generateSessionId();
+        changeSessionId(session, newId, true, true);
+    }
+
+    /**
+     * Change the session ID of the current session to a specified session ID.
+     *
+     * @param session   The session to change the session ID for
+     * @param newId   new session ID
+     */
+    @Override
+    public void changeSessionId(Session session, String newId) {
+        changeSessionId(session, newId, true, true);
+    }
+
+    protected void changeSessionId(Session session, String newId,
+            boolean notifySessionListeners, boolean notifyContainerListeners) {
         String oldId = session.getIdInternal();
-        session.setId(generateSessionId(), false);
-        String newId = session.getIdInternal();
-        context.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
-                new String[] {oldId, newId});
-
-        Object listeners[] = context.getApplicationEventListeners();
-        if (listeners != null && listeners.length > 0) {
-            HttpSessionEvent event =
-                new HttpSessionEvent(session.getSession());
-
-            for(Object listener : listeners) {
-                if (!(listener instanceof HttpSessionIdListener))
-                    continue;
-
-                HttpSessionIdListener idListener =
-                    (HttpSessionIdListener)listener;
-                try {
-                    idListener.sessionIdChanged(event, oldId);
-                } catch (Throwable t) {
-                    log.error(sm.getString("standardSession.sessionEvent"), t);
-                }
-            }
-        }
+        session.setId(newId, false);
+        session.tellChangedSessionId(newId, oldId,
+                notifySessionListeners, notifyContainerListeners);
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/session/StandardSession.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardSession.java?rev=1446072&r1=1446071&r2=1446072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StandardSession.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/StandardSession.java Thu Feb 14 08:57:43
2013
@@ -44,6 +44,7 @@ import javax.servlet.http.HttpSessionAtt
 import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionBindingListener;
 import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
 
 import org.apache.catalina.Context;
@@ -430,6 +431,50 @@ public class StandardSession implements 
 
     }
 
+    /**
+     * Inform the listeners about the change session ID.
+     *
+     * @param newId  new session ID
+     * @param oldId  old session ID
+     * @param notifySessionListeners  Should any associated sessionListeners be
+     *        notified that session ID has been changed?     
+     * @param notifyContainerListeners  Should any associated ContainerListeners
+     *        be notified that session ID has been changed?
+     */
+    @Override
+    public void tellChangedSessionId(String newId, String oldId,
+            boolean notifySessionListeners, boolean notifyContainerListeners) {
+        Context context = manager.getContext();
+         // notify ContainerListeners
+        if (notifyContainerListeners) {
+            context.fireContainerEvent(Context.CHANGE_SESSION_ID_EVENT,
+                    new String[] {oldId, newId});
+        }
+
+        // notify HttpSessionIdListener
+        if (notifySessionListeners) {
+            Object listeners[] = context.getApplicationEventListeners();
+            if (listeners != null && listeners.length > 0) {
+                HttpSessionEvent event =
+                    new HttpSessionEvent(getSession());
+
+                for(Object listener : listeners) {
+                    if (!(listener instanceof HttpSessionIdListener))
+                        continue;
+
+                    HttpSessionIdListener idListener =
+                        (HttpSessionIdListener)listener;
+                    try {
+                        idListener.sessionIdChanged(event, oldId);
+                    } catch (Throwable t) {
+                        manager.getContext().getLogger().error
+                            (sm.getString("standardSession.sessionEvent"), t);
+                    }
+                }
+            }   
+        }
+    }
+
 
     /**
      * Return the last time the client sent a request associated with this



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


Mime
View raw message