Author: cziegeler
Date: Fri Sep 16 07:30:14 2016
New Revision: 1761006

URL: http://svn.apache.org/viewvc?rev=1761006&view=rev
Log:
FELIX-5349 : add ManagedServiceFactory to HTTP service

Modified:
    
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
    
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
    
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
    
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
    
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
    
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
    
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java
    
felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java

Modified: 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
 (original)
+++ 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
 Fri Sep 16 07:30:14 2016
@@ -16,10 +16,10 @@
  */
 package org.apache.felix.http.base.internal;
 
+import org.apache.felix.http.base.internal.logger.LogServiceLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.logger.LogServiceLogger;
 
 public abstract class AbstractActivator
     implements BundleActivator
@@ -32,11 +32,7 @@ public abstract class AbstractActivator
         return this.context;
     }
 
-    protected final void setBundleContext(BundleContext context)
-    {
-        this.context = context;
-    }
-
+    @Override
     public final void start(BundleContext context)
         throws Exception
     {
@@ -46,6 +42,7 @@ public abstract class AbstractActivator
         doStart();
     }
 
+    @Override
     public final void stop(BundleContext context)
         throws Exception
     {
@@ -57,5 +54,5 @@ public abstract class AbstractActivator
         throws Exception;
 
     protected abstract void doStop()
-        throws Exception;   
+        throws Exception;
 }

Modified: 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
 (original)
+++ 
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
 Fri Sep 16 07:30:14 2016
@@ -19,20 +19,8 @@ package org.apache.felix.http.base.inter
 public abstract class AbstractHttpActivator
     extends AbstractActivator
 {
-    private DispatcherServlet dispatcherServlet;
-    private EventDispatcher eventDispatcher;
     private HttpServiceController controller;
 
-    protected final DispatcherServlet getDispatcherServlet()
-    {
-        return this.dispatcherServlet;
-    }
-
-    protected final EventDispatcher getEventDispatcher()
-    {
-        return this.eventDispatcher;
-    }
-
     protected final HttpServiceController getHttpServiceController()
     {
         return this.controller;
@@ -43,8 +31,6 @@ public abstract class AbstractHttpActiva
         throws Exception
     {
         this.controller = new HttpServiceController(getBundleContext());
-        this.dispatcherServlet = new 
DispatcherServlet(this.controller.getDispatcher());
-        this.eventDispatcher = new EventDispatcher(this.controller);
     }
 
     @Override
@@ -52,6 +38,5 @@ public abstract class AbstractHttpActiva
         throws Exception
     {
         this.controller.unregister();
-        this.dispatcherServlet.destroy();
     }
 }

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=1761006&r1=1761005&r2=1761006&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 Sep 16 07:30:14 2016
@@ -37,20 +37,41 @@ public final class HttpServiceController
     private final BundleContext bundleContext;
     private final HandlerRegistry registry;
     private final Dispatcher dispatcher;
+    private final DispatcherServlet dispatcherServlet;
+    private final EventDispatcher eventDispatcher;
     private final HttpServiceFactory httpServiceFactory;
     private final WhiteboardManager whiteboardManager;
 
     private volatile HttpSessionListener httpSessionListener;
 
+
+    public DispatcherServlet getDispatcherServlet()
+    {
+        return this.dispatcherServlet;
+    }
+
+    public EventDispatcher getEventDispatcher()
+    {
+        return this.eventDispatcher;
+    }
+
     public HttpServiceController(final BundleContext bundleContext)
     {
         this.bundleContext = bundleContext;
         this.registry = new HandlerRegistry();
         this.dispatcher = new Dispatcher(this.registry);
+        this.dispatcherServlet = new DispatcherServlet(this.dispatcher);
+        this.eventDispatcher = new EventDispatcher(this);
         this.httpServiceFactory = new HttpServiceFactory(this.bundleContext, 
this.registry);
         this.whiteboardManager = new WhiteboardManager(bundleContext, 
this.httpServiceFactory, this.registry);
     }
 
+    public void stop()
+    {
+        this.unregister();
+        this.dispatcherServlet.destroy();
+    }
+
     public Dispatcher getDispatcher()
     {
         return this.dispatcher;

Modified: 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
 (original)
+++ 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
 Fri Sep 16 07:30:14 2016
@@ -60,7 +60,7 @@ public final class JettyActivator extend
                         // nothing to do
                     }
                 }, properties);
-        this.jetty = new JettyService(getBundleContext(), 
getDispatcherServlet(), getEventDispatcher(), getHttpServiceController());
+        this.jetty = new JettyService(getBundleContext(), 
getHttpServiceController());
         this.jetty.start();
 
         final Dictionary<String, Object> propertiesCustomizer = new 
Hashtable<String, Object>();
@@ -85,7 +85,7 @@ public final class JettyActivator extend
                         // nothing to do
                     }
                 }, propertiesCustomizer);
-        
+
         Dictionary<String, Object> factoryProps = new Hashtable<String, 
Object>();
         factoryProps.put(Constants.SERVICE_PID, JettyService.PID);
         this.configServiceFactoryReg = this.getBundleContext().registerService(

Modified: 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
 (original)
+++ 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyManagedServiceFactory.java
 Fri Sep 16 07:30:14 2016
@@ -53,7 +53,6 @@ public class JettyManagedServiceFactory
                        {
                                jetty = new JettyServiceStarter(context, 
properties);
                                services.put(pid, jetty);
-                               jetty.start();
                        }
                        else
                        {

Modified: 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
 (original)
+++ 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
 Fri Sep 16 07:30:14 2016
@@ -110,14 +110,12 @@ public final class JettyService extends
     private boolean registerManagedService = true;
 
     public JettyService(final BundleContext context,
-            final DispatcherServlet dispatcher,
-            final EventDispatcher eventDispatcher,
             final HttpServiceController controller)
     {
         this.context = context;
         this.config = new JettyConfig(this.context);
-        this.dispatcher = dispatcher;
-        this.eventDispatcher = eventDispatcher;
+        this.dispatcher = controller.getDispatcherServlet();
+        this.eventDispatcher = controller.getEventDispatcher();
         this.controller = controller;
         this.deployments = new LinkedHashMap<String, Deployment>();
         this.executor = Executors.newSingleThreadExecutor(new ThreadFactory()
@@ -133,12 +131,10 @@ public final class JettyService extends
     }
 
     public JettyService(final BundleContext context,
-            final DispatcherServlet dispatcher,
-            final EventDispatcher eventDispatcher,
             final HttpServiceController controller,
             final Dictionary<String,?> props)
     {
-       this(context, dispatcher, eventDispatcher, controller);
+       this(context, controller);
        this.config.update(props);
        this.registerManagedService = false;
     }

Modified: 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java
 (original)
+++ 
felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyServiceStarter.java
 Fri Sep 16 07:30:14 2016
@@ -20,40 +20,33 @@ package org.apache.felix.http.jetty.inte
 
 import java.util.Dictionary;
 
-import org.apache.felix.http.base.internal.AbstractHttpActivator;
+import org.apache.felix.http.base.internal.HttpServiceController;
 import org.osgi.framework.BundleContext;
 
-public class JettyServiceStarter extends AbstractHttpActivator
+public class JettyServiceStarter
 {
 
-       private final BundleContext context;
+       private final HttpServiceController controller;
        private final Dictionary<String, ?> props;
-    private JettyService jetty;
+    private final JettyService jetty;
 
     JettyServiceStarter(BundleContext context, Dictionary<String, ?> 
properties)
+    throws Exception
     {
-       this.context = context;
+       this.controller = new HttpServiceController(context);
                this.props = properties;
-    }
-    
-    public void start() throws Exception
-    {
-               super.setBundleContext(context);
-               super.doStart();
-               jetty = new JettyService(context, getDispatcherServlet(), 
getEventDispatcher(),
-                               getHttpServiceController(), props);
-               jetty.start();
+        this.jetty = new JettyService(context, this.controller, props);
+        this.jetty.start();
     }
 
     public void stop() throws Exception
     {
-       jetty.stop();
-       super.doStop();
+       this.jetty.stop();
+       this.controller.stop();
     }
 
     public void updated(Dictionary<String, ?> properties) throws Exception
     {
-       jetty.updated(properties);
+       this.jetty.updated(properties);
     }
-
 }

Modified: 
felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java?rev=1761006&r1=1761005&r2=1761006&view=diff
==============================================================================
--- 
felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
 (original)
+++ 
felix/trunk/http/jetty/src/test/java/org/apache/felix/http/jetty/internal/JettyServiceTest.java
 Fri Sep 16 07:30:14 2016
@@ -42,8 +42,6 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
-import org.apache.felix.http.base.internal.DispatcherServlet;
-import org.apache.felix.http.base.internal.EventDispatcher;
 import org.apache.felix.http.base.internal.HttpServiceController;
 import org.apache.felix.http.jetty.internal.JettyService.Deployment;
 import org.eclipse.jetty.servlet.FilterHolder;
@@ -71,10 +69,6 @@ public class JettyServiceTest
 
     private BundleContext mockBundleContext;
 
-    private DispatcherServlet dispatcherServlet;
-
-    private EventDispatcher mockEventDispatcher;
-
     private HttpServiceController httpServiceController;
 
     private Bundle mockBundle;
@@ -84,7 +78,6 @@ public class JettyServiceTest
     {
         //Setup Mocks
         mockBundleContext = mock(BundleContext.class);
-        mockEventDispatcher = mock(EventDispatcher.class);
         mockBundle = mock(Bundle.class);
 
         //Setup Behaviors
@@ -110,8 +103,7 @@ public class JettyServiceTest
                 Matchers.any(Dictionary.class))).thenReturn(reg);
 
         httpServiceController = new HttpServiceController(mockBundleContext);
-        dispatcherServlet = new 
DispatcherServlet(httpServiceController.getDispatcher());
-        jettyService = new JettyService(mockBundleContext, dispatcherServlet, 
mockEventDispatcher, httpServiceController);
+        jettyService = new JettyService(mockBundleContext, 
httpServiceController);
 
         jettyService.start();
     }


Reply via email to