felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1662686 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: ./ whiteboard/
Date Fri, 27 Feb 2015 14:33:09 GMT
Author: cziegeler
Date: Fri Feb 27 14:33:09 2015
New Revision: 1662686

URL: http://svn.apache.org/r1662686
Log:
FELIX-4060 : Minor refactoring; code cleanup

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java?rev=1662686&r1=1662685&r2=1662686&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
Fri Feb 27 14:33:09 2015
@@ -21,6 +21,7 @@ package org.apache.felix.http.base.inter
 import javax.servlet.http.HttpSessionAttributeListener;
 import javax.servlet.http.HttpSessionBindingEvent;
 import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
 
 /**
@@ -28,8 +29,12 @@ import javax.servlet.http.HttpSessionLis
  * container (embedded Jetty or container in which the framework is running
  * in bridged mode) to any {@link HttpSessionAttributeListener} or
  * {@link HttpSessionListener} services.
+ *
+ * TODO - only HttpSessionIdListener and HttpSessionListener should be
+ *        required; HttpSessionListener only for getting notified of
+ *        terminated session.
  */
-public class EventDispatcher implements HttpSessionAttributeListener, HttpSessionListener
+public class EventDispatcher implements HttpSessionAttributeListener, HttpSessionListener,
HttpSessionIdListener
 {
 
     private final HttpServiceController controller;
@@ -39,28 +44,38 @@ public class EventDispatcher implements
         this.controller = controller;
     }
 
-    public void sessionCreated(HttpSessionEvent se)
+    @Override
+    public void sessionCreated(final HttpSessionEvent se)
     {
         controller.getSessionListener().sessionCreated(se);
     }
 
-    public void sessionDestroyed(HttpSessionEvent se)
+    @Override
+    public void sessionDestroyed(final HttpSessionEvent se)
     {
         controller.getSessionListener().sessionDestroyed(se);
     }
 
-    public void attributeAdded(HttpSessionBindingEvent se)
+    @Override
+    public void attributeAdded(final HttpSessionBindingEvent se)
     {
         controller.getSessionAttributeListener().attributeAdded(se);
     }
 
-    public void attributeRemoved(HttpSessionBindingEvent se)
+    @Override
+    public void attributeRemoved(final HttpSessionBindingEvent se)
     {
         controller.getSessionAttributeListener().attributeRemoved(se);
     }
 
-    public void attributeReplaced(HttpSessionBindingEvent se)
+    @Override
+    public void attributeReplaced(final HttpSessionBindingEvent se)
     {
         controller.getSessionAttributeListener().attributeReplaced(se);
     }
+
+    @Override
+    public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId)
{
+        controller.getSessionIdListener().sessionIdChanged(event, oldSessionId);
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java?rev=1662686&r1=1662685&r2=1662686&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
Fri Feb 27 14:33:09 2015
@@ -21,6 +21,7 @@ import java.util.Hashtable;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSessionAttributeListener;
 import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionIdListener;
 import javax.servlet.http.HttpSessionListener;
 
 import org.apache.felix.http.base.internal.console.HttpServicePlugin;
@@ -41,6 +42,8 @@ public final class HttpServiceController
     private final HttpServiceFactory httpServiceFactory;
     private final WhiteboardManager whiteboardManager;
 
+    private volatile HttpSessionListener httpSessionListener;
+
     public HttpServiceController(final BundleContext bundleContext)
     {
         this.bundleContext = bundleContext;
@@ -63,19 +66,25 @@ public final class HttpServiceController
 
     HttpSessionListener getSessionListener()
     {
-        return new HttpSessionListener() {
-
-            @Override
-            public void sessionDestroyed(final HttpSessionEvent se) {
-                httpServiceFactory.getSessionListener().sessionDestroyed(se);
-                whiteboardManager.sessionDestroyed(se.getSession(), HttpSessionWrapper.getSessionContextIds(se.getSession()));
-            }
+        // we don't need to sync here, if the object gets created several times
+        // its not a problem
+        if ( httpSessionListener == null )
+        {
+            httpSessionListener = new HttpSessionListener() {
 
-            @Override
-            public void sessionCreated(final HttpSessionEvent se) {
-                httpServiceFactory.getSessionListener().sessionCreated(se);
-            }
-        };
+                @Override
+                public void sessionDestroyed(final HttpSessionEvent se) {
+                    httpServiceFactory.getSessionListener().sessionDestroyed(se);
+                    whiteboardManager.sessionDestroyed(se.getSession(), HttpSessionWrapper.getSessionContextIds(se.getSession()));
+                }
+
+                @Override
+                public void sessionCreated(final HttpSessionEvent se) {
+                    httpServiceFactory.getSessionListener().sessionCreated(se);
+                }
+            };
+        }
+        return httpSessionListener;
     }
 
     HttpSessionAttributeListener getSessionAttributeListener()
@@ -83,6 +92,17 @@ public final class HttpServiceController
         return httpServiceFactory.getSessionAttributeListener();
     }
 
+    HttpSessionIdListener getSessionIdListener()
+    {
+        return new HttpSessionIdListener() {
+
+            @Override
+            public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) {
+                // TODO Auto-generated method stub
+
+            }
+        };
+    }
     public void setProperties(final Hashtable<String, Object> props)
     {
         this.httpServiceFactory.setProperties(props);
@@ -118,5 +138,6 @@ public final class HttpServiceController
         }
 
         this.registry.shutdown();
+        this.httpSessionListener = null;
     }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java?rev=1662686&r1=1662685&r2=1662686&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ContextHandler.java
Fri Feb 27 14:33:09 2015
@@ -21,11 +21,6 @@ import java.util.Map;
 
 import javax.annotation.Nonnull;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletRequestAttributeListener;
-import javax.servlet.ServletRequestListener;
-import javax.servlet.http.HttpSessionAttributeListener;
-import javax.servlet.http.HttpSessionListener;
 
 import org.apache.felix.http.base.internal.context.ExtServletContext;
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
@@ -47,39 +42,21 @@ public final class ContextHandler implem
     /** A map of all created servlet contexts. Each bundle gets it's own instance. */
     private final Map<Long, ContextHolder> perBundleContextMap = new HashMap<Long,
ContextHolder>();
 
-    private final HttpSessionListener sessionListener;
-    private final HttpSessionAttributeListener sessionAttributeListener;
-    private final ServletRequestListener requestListener;
-    private final ServletRequestAttributeListener requestAttributeListener;
-
-    public ContextHandler(ServletContextHelperInfo info,
-            ServletContext webContext,
-            PerContextEventListener eventListener,
-            Bundle bundle)
-    {
-        this(info, webContext, eventListener, eventListener, eventListener, eventListener,
eventListener, bundle);
-    }
-
-    public ContextHandler(ServletContextHelperInfo info,
-            ServletContext webContext,
-            ServletContextAttributeListener servletContextAttributeListener,
-            HttpSessionListener sessionListener,
-            HttpSessionAttributeListener sessionAttributeListener,
-            ServletRequestListener requestListener,
-            ServletRequestAttributeListener requestAttributeListener,
-            Bundle bundle)
+    private final PerContextEventListener eventListener;
+
+    public ContextHandler(final ServletContextHelperInfo info,
+            final ServletContext webContext,
+            final PerContextEventListener eventListener,
+            final Bundle bundle)
     {
         this.info = info;
-        this.sessionListener = sessionListener;
-        this.sessionAttributeListener = sessionAttributeListener;
-        this.requestListener = requestListener;
-        this.requestAttributeListener = requestAttributeListener;
+        this.eventListener = eventListener;
         this.bundle = bundle;
         this.sharedContext = new SharedServletContextImpl(webContext,
                 info.getName(),
                 info.getPath(),
                 info.getInitParameters(),
-                servletContextAttributeListener);
+                eventListener);
     }
 
     public ServletContextHelperInfo getContextInfo()
@@ -125,10 +102,7 @@ public final class ContextHandler implem
                     holder.servletContext = new PerBundleServletContextImpl(bundle,
                             this.sharedContext,
                             holder.servletContextHelper,
-                            this.sessionListener,
-                            this.sessionAttributeListener,
-                            this.requestListener,
-                            this.requestAttributeListener);
+                            this.eventListener);
                     this.perBundleContextMap.put(key, holder);
                 }
                 // TODO - check null for so
@@ -156,14 +130,7 @@ public final class ContextHandler implem
                         final ServiceObjects<ServletContextHelper> so = bundle.getBundleContext().getServiceObjects(this.info.getServiceReference());
                         if ( so != null )
                         {
-                            try
-                            {
-                                so.ungetService(holder.servletContextHelper);
-                            }
-                            catch ( final IllegalArgumentException iae)
-                            {
-                                // this seems to be thrown sometimes on shutdown; we have
to evaluate
-                            }
+                            so.ungetService(holder.servletContextHelper);
                         }
                     }
                 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java?rev=1662686&r1=1662685&r2=1662686&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerBundleServletContextImpl.java
Fri Feb 27 14:33:09 2015
@@ -58,26 +58,17 @@ public class PerBundleServletContextImpl
     private final Bundle bundle;
     private final ServletContext delegatee;
     private final ServletContextHelper contextHelper;
-    private final HttpSessionListener sessionListener;
-    private final HttpSessionAttributeListener sessionAttributeListener;
-    private final ServletRequestListener requestListener;
-    private final ServletRequestAttributeListener requestAttributeListener;
+    private final PerContextEventListener eventListener;
 
     public PerBundleServletContextImpl(final Bundle bundle,
             final ServletContext sharedContext,
             final ServletContextHelper delegatee,
-            final HttpSessionListener sessionListener,
-            final HttpSessionAttributeListener sessionAttributeListener,
-            final ServletRequestListener requestListener,
-            final ServletRequestAttributeListener requestAttributeListener)
+            final PerContextEventListener eventListener)
     {
         this.bundle = bundle;
         this.delegatee = sharedContext;
         this.contextHelper = delegatee;
-        this.sessionListener = sessionListener;
-        this.sessionAttributeListener = sessionAttributeListener;
-        this.requestListener = requestListener;
-        this.requestAttributeListener = requestAttributeListener;
+        this.eventListener = eventListener;
     }
 
     @Override
@@ -91,25 +82,25 @@ public class PerBundleServletContextImpl
     @Override
     public HttpSessionListener getHttpSessionListener()
     {
-        return this.sessionListener;
+        return this.eventListener;
     }
 
     @Override
     public HttpSessionAttributeListener getHttpSessionAttributeListener()
     {
-        return this.sessionAttributeListener;
+        return this.eventListener;
     }
 
     @Override
     public ServletRequestListener getServletRequestListener()
     {
-        return this.requestListener;
+        return this.eventListener;
     }
 
     @Override
     public ServletRequestAttributeListener getServletRequestAttributeListener()
     {
-        return this.requestAttributeListener;
+        return this.eventListener;
     }
 
     @Override

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java?rev=1662686&r1=1662685&r2=1662686&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/PerContextEventListener.java
Fri Feb 27 14:33:09 2015
@@ -17,7 +17,6 @@
 package org.apache.felix.http.base.internal.whiteboard;
 
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ConcurrentSkipListMap;
 
@@ -55,7 +54,7 @@ public final class PerContextEventListen
         ServletRequestAttributeListener
 {
     /** Servlet context listeners. */
-    private final Map<ServiceReference<ServletContextListener>, ServletContextListener>
listeners = new HashMap<ServiceReference<ServletContextListener>, ServletContextListener>();
+    private final Map<ServiceReference<ServletContextListener>, ServletContextListener>
contextListeners = new ConcurrentSkipListMap<ServiceReference<ServletContextListener>,
ServletContextListener>();
 
     /** Servlet context attribute listeners. */
     private final Map<ServiceReference<ServletContextAttributeListener>, ServletContextAttributeListener>
contextAttributeListeners = new ConcurrentSkipListMap<ServiceReference<ServletContextAttributeListener>,
ServletContextAttributeListener>();
@@ -80,13 +79,12 @@ public final class PerContextEventListen
     }
 
     void initialized(@Nonnull final ServletContextListenerInfo listenerInfo,
-            ContextHandler contextHandler)
+            @Nonnull ContextHandler contextHandler)
     {
         final ServletContextListener listener = listenerInfo.getService(bundle);
         if (listener != null)
         {
-            // no need to sync map - initialized is called in sync
-            this.listeners.put(listenerInfo.getServiceReference(), listener);
+            this.contextListeners.put(listenerInfo.getServiceReference(), listener);
 
             final ServletContext context = contextHandler
                     .getServletContext(listenerInfo.getServiceReference()
@@ -97,11 +95,11 @@ public final class PerContextEventListen
     }
 
     void destroyed(@Nonnull final ServletContextListenerInfo listenerInfo,
-            ContextHandler contextHandler)
+            @Nonnull ContextHandler contextHandler)
     {
         final ServiceReference<ServletContextListener> listenerRef = listenerInfo
                 .getServiceReference();
-        final ServletContextListener listener = this.listeners
+        final ServletContextListener listener = this.contextListeners
                 .remove(listenerRef);
         if (listener != null)
         {
@@ -118,7 +116,7 @@ public final class PerContextEventListen
 
     /**
      * Add servlet context attribute listener
-     * 
+     *
      * @param info
      */
     void addListener(@Nonnull final ServletContextAttributeListenerInfo info)
@@ -133,7 +131,7 @@ public final class PerContextEventListen
 
     /**
      * Remove servlet context attribute listener
-     * 
+     *
      * @param info
      */
     void removeListener(@Nonnull final ServletContextAttributeListenerInfo info)
@@ -148,7 +146,7 @@ public final class PerContextEventListen
 
     /**
      * Add session attribute listener
-     * 
+     *
      * @param info
      */
     void addListener(@Nonnull final HttpSessionAttributeListenerInfo info)
@@ -163,7 +161,7 @@ public final class PerContextEventListen
 
     /**
      * Remove session attribute listener
-     * 
+     *
      * @param info
      */
     void removeListener(@Nonnull final HttpSessionAttributeListenerInfo info)
@@ -178,7 +176,7 @@ public final class PerContextEventListen
 
     /**
      * Add session listener
-     * 
+     *
      * @param info
      */
     void addListener(@Nonnull final HttpSessionListenerInfo info)
@@ -192,7 +190,7 @@ public final class PerContextEventListen
 
     /**
      * Remove session listener
-     * 
+     *
      * @param info
      */
     void removeListener(@Nonnull final HttpSessionListenerInfo info)
@@ -207,7 +205,7 @@ public final class PerContextEventListen
 
     /**
      * Add request listener
-     * 
+     *
      * @param info
      */
     void addListener(@Nonnull final ServletRequestListenerInfo info)
@@ -221,7 +219,7 @@ public final class PerContextEventListen
 
     /**
      * Remove request listener
-     * 
+     *
      * @param info
      */
     void removeListener(@Nonnull final ServletRequestListenerInfo info)
@@ -236,7 +234,7 @@ public final class PerContextEventListen
 
     /**
      * Add request attribute listener
-     * 
+     *
      * @param info
      */
     void addListener(@Nonnull final ServletRequestAttributeListenerInfo info)
@@ -251,7 +249,7 @@ public final class PerContextEventListen
 
     /**
      * Remove request attribute listener
-     * 
+     *
      * @param info
      */
     void removeListener(@Nonnull final ServletRequestAttributeListenerInfo info)
@@ -407,6 +405,7 @@ public final class PerContextEventListen
     Collection<ServiceReference<?>> getRuntime()
     {
         return CollectionUtils.<ServiceReference<?>> union(
+                contextListeners.keySet(),
                 contextAttributeListeners.keySet(),
                 sessionAttributeListeners.keySet(),
                 sessionListeners.keySet(),



Mime
View raw message