ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r799227 - in /incubator/ace/trunk: server/src/org/apache/ace/client/repository/impl/ webui/src/org/apache/ace/server/ webui/war/WEB-INF/
Date Thu, 30 Jul 2009 10:24:22 GMT
Author: marrs
Date: Thu Jul 30 10:24:22 2009
New Revision: 799227

URL: http://svn.apache.org/viewvc?rev=799227&view=rev
Log:
Added the session listener to web.xml again, fixed some outstanding issues with cleaning up
sessions. This should now work fine.

Removed:
    incubator/ace/trunk/webui/src/org/apache/ace/server/SessionConstants.java
Modified:
    incubator/ace/trunk/server/src/org/apache/ace/client/repository/impl/Activator.java
    incubator/ace/trunk/webui/src/org/apache/ace/server/Activator.java
    incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java
    incubator/ace/trunk/webui/war/WEB-INF/web.xml

Modified: incubator/ace/trunk/server/src/org/apache/ace/client/repository/impl/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/server/src/org/apache/ace/client/repository/impl/Activator.java?rev=799227&r1=799226&r2=799227&view=diff
==============================================================================
--- incubator/ace/trunk/server/src/org/apache/ace/client/repository/impl/Activator.java (original)
+++ incubator/ace/trunk/server/src/org/apache/ace/client/repository/impl/Activator.java Thu
Jul 30 10:24:22 2009
@@ -19,9 +19,9 @@
 package org.apache.ace.client.repository.impl;
 
 import java.util.Dictionary;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Set;
+import java.util.Map;
 
 import org.apache.ace.client.repository.RepositoryAdmin;
 import org.apache.ace.client.repository.SessionFactory;
@@ -71,44 +71,52 @@
     public synchronized void destroy(BundleContext context, DependencyManager manager) throws
Exception {
     }
 
-    private Set<String> m_sessions = new HashSet<String>();
-    private Service m_service;
-    private Service m_service2;
+    private Map<String, SessionData> m_sessions = new HashMap<String, SessionData>();
+    private static class SessionData {
+        public static SessionData EMPTY_SESSION = new SessionData();
+
+        private Service m_service;
+        private Service m_service2;
+    }
 
     public void createSession(String sessionID) {
         boolean create = false;
         synchronized (m_sessions) {
-            if (!m_sessions.contains(sessionID)) {
-                m_sessions.add(sessionID);
+            if (!m_sessions.containsKey(sessionID)) {
+                m_sessions.put(sessionID, SessionData.EMPTY_SESSION);
                 create = true;
             }
         }
         if (create) {
-            createSessionServices(sessionID);
+            SessionData sd = createSessionServices(sessionID);
+            m_sessions.put(sessionID, sd);
         }
     }
 
     public void destroySession(String sessionID) {
         boolean destroy = false;
+        SessionData sd = SessionData.EMPTY_SESSION;
         synchronized (m_sessions) {
-            destroy = m_sessions.remove(sessionID);
+            destroy = m_sessions.containsKey(sessionID);
+            sd = m_sessions.remove(sessionID);
         }
-        if (destroy) {
-            destroySessionServices(sessionID);
+        if (destroy && !sd.equals(SessionData.EMPTY_SESSION)) {
+            destroySessionServices(sessionID, sd);
         }
     }
 
     @SuppressWarnings("unchecked")
-    private void createSessionServices(String sessionID) {
+    private SessionData createSessionServices(String sessionID) {
+        SessionData sd = new SessionData();
         RepositoryAdminImpl rai = new RepositoryAdminImpl(sessionID);
-        m_service = createService()
+        sd.m_service = createService()
             .setInterface(RepositoryAdmin.class.getName(), rai.getSessionProps())
             .setImplementation(rai)
             .setComposition("getInstances")
             .add(createServiceDependency().setService(PreferencesService.class).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(true))
             .add(createServiceDependency().setService(LogService.class).setRequired(false));
-        m_dependencyManager.add(m_service);
+        m_dependencyManager.add(sd.m_service);
 
         Dictionary topic = new Hashtable();
         topic.put(EventConstants.EVENT_TOPIC, new String[] {
@@ -125,7 +133,7 @@
         topic.put(EventConstants.EVENT_FILTER, filter);
         topic.put(SessionFactory.SERVICE_SID, sessionID);
         StatefulGatewayRepositoryImpl statefulGatewayRepositoryImpl = new StatefulGatewayRepositoryImpl();
-        m_service2 = createService()
+        sd.m_service2 = createService()
             .setInterface(new String[] { StatefulGatewayRepository.class.getName(), EventHandler.class.getName()
}, topic)
             .setImplementation(statefulGatewayRepositoryImpl)
             .add(createServiceDependency().setService(ArtifactRepository.class, filter).setRequired(true))
@@ -135,13 +143,12 @@
             .add(createServiceDependency().setService(BundleHelper.class).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(true))
             .add(createServiceDependency().setService(LogService.class).setRequired(false));
-        m_dependencyManager.add(m_service2);
+        m_dependencyManager.add(sd.m_service2);
+        return sd;
     }
 
-    private void destroySessionServices(String sessionID) {
-        m_dependencyManager.remove(m_service2);
-        m_dependencyManager.remove(m_service);
-        m_service2 = null;
-        m_service = null;
+    private void destroySessionServices(String sessionID, SessionData sd) {
+        m_dependencyManager.remove(sd.m_service2);
+        m_dependencyManager.remove(sd.m_service);
     }
 }

Modified: incubator/ace/trunk/webui/src/org/apache/ace/server/Activator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/src/org/apache/ace/server/Activator.java?rev=799227&r1=799226&r2=799227&view=diff
==============================================================================
--- incubator/ace/trunk/webui/src/org/apache/ace/server/Activator.java (original)
+++ incubator/ace/trunk/webui/src/org/apache/ace/server/Activator.java Thu Jul 30 10:24:22
2009
@@ -47,6 +47,10 @@
         return m_context;
     }
     
+    static void destroySession(String sessionID) {
+        m_instance.m_sessionFactory.destroySession(sessionID);
+    }
+    
     /**
      * Gets a base directory for this bundle's data; you can use this directory 
      * to pass to {@link SessionFramework#getFramework(javax.servlet.http.HttpSession, File)}.

Modified: incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java?rev=799227&r1=799226&r2=799227&view=diff
==============================================================================
--- incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java (original)
+++ incubator/ace/trunk/webui/src/org/apache/ace/server/SessionListener.java Thu Jul 30 10:24:22
2009
@@ -18,33 +18,22 @@
  */
 package org.apache.ace.server;
 
-import javax.servlet.http.HttpSession;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-
 /**
- * Listener that examines sessions that are destroyed and stops an embedded
- * framework stored in <code>SessionConstants.FRAMEWORK</code> if present.
+ * Listener that destroys all session specific services that were published for that session.
  */
 public class SessionListener implements HttpSessionListener {
     public void sessionCreated(HttpSessionEvent se) {
+        // nothing to do when the session was created, the SessionFactory already 
+        // created the appropriate services when we arrive at this point
     }
 
     public void sessionDestroyed(HttpSessionEvent se) {
-        HttpSession session = se.getSession();
-        if (session != null) {
-            Bundle framework = (Bundle) session.getAttribute(SessionConstants.FRAMEWORK);
-            if (framework != null) {
-                try {
-                    framework.stop();
-                }
-                catch (BundleException e) {
-                    // not much we can do if this fails
-                }
-            }
-        }
+        // get the session ID from the session
+        String sessionID = se.getSession().getId();
+        // destroy the session related services
+        Activator.destroySession(sessionID);
     }
 }

Modified: incubator/ace/trunk/webui/war/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/webui/war/WEB-INF/web.xml?rev=799227&r1=799226&r2=799227&view=diff
==============================================================================
--- incubator/ace/trunk/webui/war/WEB-INF/web.xml (original)
+++ incubator/ace/trunk/webui/war/WEB-INF/web.xml Thu Jul 30 10:24:22 2009
@@ -9,6 +9,11 @@
   <welcome-file-list>
     <welcome-file>webui.html</welcome-file>
   </welcome-file-list>
+
+  <!-- Session listener -->
+  <listener>
+    <listener-class>org.apache.ace.server.SessionListener</listener-class>
+  </listener>
   
   <!-- Servlets -->
   <servlet>



Mime
View raw message