You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2016/09/18 09:16:52 UTC

svn commit: r1761310 - in /felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal: JettyActivator.java JettyManagedServiceFactory.java

Author: cziegeler
Date: Sun Sep 18 09:16:52 2016
New Revision: 1761310

URL: http://svn.apache.org/viewvc?rev=1761310&view=rev
Log:
FELIX-5349 : add ManagedServiceFactory to HTTP service. Apply 2nd patch from Derek Baum

Modified:
    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

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=1761310&r1=1761309&r2=1761310&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 Sun Sep 18 09:16:52 2016
@@ -33,7 +33,7 @@ public final class JettyActivator extend
 
     private ServiceRegistration<?> metatypeReg;
     private ServiceRegistration<LoadBalancerCustomizerFactory> loadBalancerCustomizerFactoryReg;
-    private ServiceRegistration<?> configServiceFactoryReg;
+    private JettyManagedServiceFactory jettyServiceFactory;
 
     @Override
     protected void doStart() throws Exception
@@ -86,10 +86,7 @@ public final class JettyActivator extend
                     }
                 }, propertiesCustomizer);
 
-        Dictionary<String, Object> factoryProps = new Hashtable<String, Object>();
-        factoryProps.put(Constants.SERVICE_PID, JettyService.PID);
-        this.configServiceFactoryReg = this.getBundleContext().registerService(
-        		ManagedServiceFactory.class.getName(), new JettyManagedServiceFactory(this.getBundleContext()), factoryProps);
+        this.jettyServiceFactory = new JettyManagedServiceFactory(this.getBundleContext());
     }
 
     @Override
@@ -106,10 +103,10 @@ public final class JettyActivator extend
             loadBalancerCustomizerFactoryReg.unregister();
             loadBalancerCustomizerFactoryReg = null;
         }
-        if ( configServiceFactoryReg != null )
+        if ( jettyServiceFactory != null )
         {
-            configServiceFactoryReg.unregister();
-            configServiceFactoryReg = null;
+            jettyServiceFactory.stop();
+            jettyServiceFactory = null;
         }
 
         super.doStop();

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=1761310&r1=1761309&r2=1761310&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 Sun Sep 18 09:16:52 2016
@@ -20,9 +20,14 @@ package org.apache.felix.http.jetty.inte
 
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Map;
+import java.util.Set;
 
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedServiceFactory;
 
@@ -30,10 +35,27 @@ public class JettyManagedServiceFactory
 {
 	private final Map<String, JettyServiceStarter> services = new HashMap<>();
 	private final BundleContext context;
+	private ServiceRegistration<?> serviceReg;
 
 	JettyManagedServiceFactory(BundleContext context)
 	{
 		this.context = context;
+		
+		Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(Constants.SERVICE_PID, JettyService.PID);
+        this.serviceReg = context.registerService(ManagedServiceFactory.class.getName(), this, props);
+	}
+	
+	public synchronized void stop()
+	{
+		this.serviceReg.unregister();
+		this.serviceReg = null;
+
+		Set<String> pids = new HashSet<>(services.keySet());
+		for (String pid : pids)
+		{
+			deleted(pid);
+		}
 	}
 
 	@Override
@@ -43,7 +65,7 @@ public class JettyManagedServiceFactory
 	}
 
 	@Override
-	public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException
+	public synchronized void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException
 	{
 		JettyServiceStarter jetty = services.get(pid);
 
@@ -66,7 +88,7 @@ public class JettyManagedServiceFactory
 	}
 
 	@Override
-	public void deleted(String pid)
+	public synchronized void deleted(String pid)
 	{
 		JettyServiceStarter jetty = services.remove(pid);