felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1656701 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: HttpServiceController.java handler/HandlerRegistry.java whiteboard/ServletContextHelperManager.java whiteboard/WhiteboardHttpService.java
Date Tue, 03 Feb 2015 11:55:16 GMT
Author: cziegeler
Date: Tue Feb  3 11:55:16 2015
New Revision: 1656701

URL: http://svn.apache.org/r1656701
Log:
FELIX-4060 : Implement HTTP Service Update (RFC-189)

Modified:
    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/handler/HandlerRegistry.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java

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=1656701&r1=1656700&r2=1656701&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
Tue Feb  3 11:55:16 2015
@@ -24,7 +24,6 @@ import org.apache.felix.http.api.ExtHttp
 import org.apache.felix.http.base.internal.dispatch.Dispatcher;
 import org.apache.felix.http.base.internal.handler.HandlerRegistry;
 import org.apache.felix.http.base.internal.handler.HttpServicePlugin;
-import org.apache.felix.http.base.internal.handler.PerContextHandlerRegistry;
 import org.apache.felix.http.base.internal.listener.HttpSessionAttributeListenerManager;
 import org.apache.felix.http.base.internal.listener.HttpSessionListenerManager;
 import org.apache.felix.http.base.internal.listener.ServletContextAttributeListenerManager;
@@ -79,7 +78,6 @@ public final class HttpServiceController
     {
         this.bundleContext = bundleContext;
         this.registry = new HandlerRegistry();
-        this.registry.add(new PerContextHandlerRegistry());
         this.dispatcher = new Dispatcher(this.registry);
         this.serviceProps = new Hashtable<String, Object>();
         this.contextAttributeListener = new ServletContextAttributeListenerManager(bundleContext);
@@ -177,7 +175,7 @@ public final class HttpServiceController
             try
             {
                 this.serviceReg.unregister();
-                this.registry.removeAll();
+                this.registry.shutdown();
             }
             finally
             {

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java?rev=1656701&r1=1656700&r2=1656701&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HandlerRegistry.java
Tue Feb  3 11:55:16 2015
@@ -18,6 +18,7 @@ package org.apache.felix.http.base.inter
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.annotation.Nonnull;
@@ -25,33 +26,95 @@ import javax.servlet.DispatcherType;
 
 import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
 
+/**
+ * Registry for all services.
+ *
+ * The registry is organized per servlet context and is dispatching to one
+ * of the {@link PerContextHandlerRegistry} registries.
+ */
 public final class HandlerRegistry
 {
+    /** Current list of context registrations. */
     private volatile List<PerContextHandlerRegistry> registrations = Collections.emptyList();
 
-    public void add(@Nonnull PerContextHandlerRegistry registry)
+    public HandlerRegistry()
     {
+        this.add(new PerContextHandlerRegistry());
+    }
+
+    /**
+     * Shutdown
+     */
+    public void shutdown()
+    {
+        final List<PerContextHandlerRegistry> list;
+
         synchronized ( this )
         {
-            final List<PerContextHandlerRegistry> updatedList = new ArrayList<PerContextHandlerRegistry>(this.registrations);
-            updatedList.add(registry);
-            Collections.sort(updatedList);
+            list = new ArrayList<PerContextHandlerRegistry>(this.registrations);
+            this.registrations = Collections.emptyList();
 
-            this.registrations = updatedList;
+        }
+
+        for(final PerContextHandlerRegistry r : list)
+        {
+            r.removeAll();
         }
     }
 
-    public void remove(@Nonnull PerContextHandlerRegistry registry)
+    /**
+     * Add a context registration.
+     * @param info The servlet context helper info
+     */
+    public void add(@Nonnull ServletContextHelperInfo info)
+    {
+        this.add(new PerContextHandlerRegistry(info));
+    }
+
+    /**
+     * Remove a context registration.
+     * @param info The servlet context helper info
+     */
+    public void remove(@Nonnull ServletContextHelperInfo info)
     {
         synchronized ( this )
         {
             final List<PerContextHandlerRegistry> updatedList = new ArrayList<PerContextHandlerRegistry>(this.registrations);
-            updatedList.remove(registry);
+            final Iterator<PerContextHandlerRegistry> i = updatedList.iterator();
+            while ( i.hasNext() )
+            {
+                final PerContextHandlerRegistry reg = i.next();
+                if ( reg.getContextServiceId() == info.getServiceId() )
+                {
+                    i.remove();
+                    this.registrations = updatedList;
+                    break;
+                }
+            }
+        }
+    }
+
+
+    /**
+     * Add a new context registration.
+     */
+    private void add(@Nonnull PerContextHandlerRegistry registry)
+    {
+        synchronized ( this )
+        {
+            final List<PerContextHandlerRegistry> updatedList = new ArrayList<PerContextHandlerRegistry>(this.registrations);
+            updatedList.add(registry);
+            Collections.sort(updatedList);
 
             this.registrations = updatedList;
         }
     }
 
+    /**
+     * Get the per context registry.
+     * @param info The servlet context helper info or {@code null} for the Http Service context.
+     * @return A per context registry or {@code null}
+     */
     public PerContextHandlerRegistry getRegistry(final ServletContextHelperInfo info)
     {
         final long key = (info == null ? 0 : info.getServiceId());
@@ -65,11 +128,9 @@ public final class HandlerRegistry
                     return r;
                 }
             }
-            final PerContextHandlerRegistry reg = new PerContextHandlerRegistry(info);
-            this.add(reg);
-
-            return reg;
         }
+
+        return null;
     }
 
     public ErrorsMapping getErrorsMapping(final String requestURI, final Long serviceId)
@@ -140,21 +201,4 @@ public final class HandlerRegistry
         }
         return null;
     }
-
-    public synchronized void removeAll()
-    {
-        final List<PerContextHandlerRegistry> list;
-
-        synchronized ( this )
-        {
-            list = new ArrayList<PerContextHandlerRegistry>(this.registrations);
-            this.registrations = Collections.emptyList();
-
-        }
-
-        for(final PerContextHandlerRegistry r : list)
-        {
-            r.removeAll();
-        }
-    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java?rev=1656701&r1=1656700&r2=1656701&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
Tue Feb  3 11:55:16 2015
@@ -120,6 +120,9 @@ public final class ServletContextHelperM
     private void activate(final ContextHandler handler)
     {
         handler.activate();
+
+        this.httpService.registerContext(handler);
+
         // context listeners first
         final List<WhiteboardServiceInfo<?>> services = new ArrayList<WhiteboardServiceInfo<?>>();
         for(final Map.Entry<WhiteboardServiceInfo<?>, List<ContextHandler>>
entry : this.servicesMap.entrySet())
@@ -150,6 +153,8 @@ public final class ServletContextHelperM
      */
     private void deactivate(final ContextHandler handler)
     {
+        this.httpService.unregisterContext(handler);
+
         // context listeners last
         final List<ServletContextListenerInfo> listeners = new ArrayList<ServletContextListenerInfo>();
         final Iterator<Map.Entry<WhiteboardServiceInfo<?>, List<ContextHandler>>>
i = this.servicesMap.entrySet().iterator();

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java?rev=1656701&r1=1656700&r2=1656701&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
Tue Feb  3 11:55:16 2015
@@ -201,4 +201,14 @@ public final class WhiteboardHttpService
         final ServletInfo servletInfo = new ServletInfo(resourceInfo);
         this.unregisterServlet(contextHandler, servletInfo);
     }
+
+    public void registerContext(@Nonnull final ContextHandler contextHandler)
+    {
+        this.handlerRegistry.add(contextHandler.getContextInfo());
+    }
+
+    public void unregisterContext(@Nonnull final ContextHandler contextHandler)
+    {
+        this.handlerRegistry.remove(contextHandler.getContextInfo());
+    }
 }



Mime
View raw message