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 2018/08/02 12:37:41 UTC
svn commit: r1837292 - in
/felix/trunk/http/jetty/src/main/java/org/apache/felix/http/jetty/internal:
JettyActivator.java JettyManagedServiceFactory.java
Author: cziegeler
Date: Thu Aug 2 12:37:41 2018
New Revision: 1837292
URL: http://svn.apache.org/viewvc?rev=1837292&view=rev
Log:
FELIX-5858 : Additional server configured through OSGi factory configurations starts and stops immediately
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=1837292&r1=1837291&r2=1837292&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 Thu Aug 2 12:37:41 2018
@@ -16,6 +16,7 @@
*/
package org.apache.felix.http.jetty.internal;
+import java.io.Closeable;
import java.util.Dictionary;
import java.util.Hashtable;
@@ -30,9 +31,11 @@ public final class JettyActivator extend
{
private JettyService jetty;
- private ServiceRegistration<?> metatypeReg;
- private ServiceRegistration<LoadBalancerCustomizerFactory> loadBalancerCustomizerFactoryReg;
- private ServiceRegistration<?> jettyServiceFactoryReg;
+ private volatile ServiceRegistration<?> metatypeReg;
+ private volatile ServiceRegistration<LoadBalancerCustomizerFactory> loadBalancerCustomizerFactoryReg;
+ private volatile ServiceRegistration<?> jettyServiceFactoryReg;
+
+ private volatile Closeable managedServiceFactory;
@Override
protected void doStart() throws Exception
@@ -97,7 +100,14 @@ public final class JettyActivator extend
public Object getService(final Bundle bundle,
final ServiceRegistration registration)
{
- return new JettyManagedServiceFactory(getBundleContext());
+ synchronized ( jetty )
+ {
+ if ( managedServiceFactory == null )
+ {
+ managedServiceFactory = new JettyManagedServiceFactory(getBundleContext());
+ }
+ }
+ return managedServiceFactory;
}
@Override
@@ -105,7 +115,7 @@ public final class JettyActivator extend
final ServiceRegistration registration,
final Object service)
{
- ((JettyManagedServiceFactory)service).stop();
+ // do nothing
}
}, factoryProps);
@@ -114,6 +124,10 @@ public final class JettyActivator extend
@Override
protected void doStop() throws Exception
{
+ if ( this.managedServiceFactory != null )
+ {
+ this.managedServiceFactory.close();
+ }
this.jetty.stop();
if ( metatypeReg != null )
{
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=1837292&r1=1837291&r2=1837292&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 Thu Aug 2 12:37:41 2018
@@ -18,6 +18,7 @@
*/
package org.apache.felix.http.jetty.internal;
+import java.io.Closeable;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
@@ -29,7 +30,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
-public class JettyManagedServiceFactory implements ManagedServiceFactory
+public class JettyManagedServiceFactory implements ManagedServiceFactory, Closeable
{
private final Map<String, JettyServiceStarter> services = new HashMap<>();
private final BundleContext context;
@@ -39,7 +40,8 @@ public class JettyManagedServiceFactory
this.context = context;
}
- public synchronized void stop()
+ @Override
+ public synchronized void close()
{
final Set<String> pids = new HashSet<>(services.keySet());
for (final String pid : pids)