You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2016/05/01 21:36:41 UTC
[25/36] cxf git commit: [CXF-6887] Handle multiple busses and avoid
NPE
[CXF-6887] Handle multiple busses and avoid NPE
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a752ca60
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a752ca60
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a752ca60
Branch: refs/heads/master-jaxrs-2.1
Commit: a752ca60b3b430c02feb89eb7930c13c21b94b0e
Parents: 4786e83
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Apr 29 15:45:42 2016 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Apr 29 15:49:23 2016 +0200
----------------------------------------------------------------------
.../transport/http/asyncclient/Activator.java | 56 +++++++++++---------
1 file changed, 30 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/a752ca60/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
index 32f4321..13d1f52 100644
--- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
+++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
@@ -25,47 +25,36 @@ import java.util.Hashtable;
import java.util.Map;
import org.apache.cxf.Bus;
-import org.apache.cxf.transport.http.HTTPConduitFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.util.tracker.ServiceTracker;
public class Activator implements BundleActivator {
-
- private ServiceTracker tracker;
+ private ConduitConfigurer conduitConfigurer;
@Override
public void start(BundleContext context) throws Exception {
- tracker = new ServiceTracker(context, Bus.class.getName(), null);
- tracker.open();
- ConduitConfigurer conduitConfigurer = new ConduitConfigurer(context, tracker);
- registerManagedService(context, conduitConfigurer, "org.apache.cxf.transport.http.async");
- }
-
- private void registerManagedService(BundleContext context, ConduitConfigurer conduitConfigurer, String servicePid) {
+ conduitConfigurer = new ConduitConfigurer(context);
+ conduitConfigurer.open();
Dictionary<String, Object> properties = new Hashtable<String, Object>();
- properties.put(Constants.SERVICE_PID, servicePid);
+ properties.put(Constants.SERVICE_PID, "org.apache.cxf.transport.http.async");
context.registerService(ManagedService.class.getName(), conduitConfigurer, properties);
}
@Override
public void stop(BundleContext context) throws Exception {
- tracker.close();
+ conduitConfigurer.close();
}
- class ConduitConfigurer implements ManagedService {
- private AsyncHTTPConduitFactory conduitFactory;
- private ServiceTracker busTracker;
- private BundleContext context;
- private ServiceRegistration reg;
+ public class ConduitConfigurer extends ServiceTracker implements ManagedService {
+ private Map<String, Object> currentConfig;
- ConduitConfigurer(BundleContext context, ServiceTracker busTracker) {
- this.context = context;
- this.busTracker = busTracker;
+ public ConduitConfigurer(BundleContext context) {
+ super(context, Bus.class.getName(), null);
}
@SuppressWarnings({
@@ -73,12 +62,21 @@ public class Activator implements BundleActivator {
})
@Override
public void updated(Dictionary properties) throws ConfigurationException {
- if (reg != null) {
- reg.unregister();
+ this.currentConfig = toMap(properties);
+ Bus[] buses = (Bus[])getServices();
+ if (buses == null) {
+ return;
}
- conduitFactory = new AsyncHTTPConduitFactory((Bus)this.busTracker.getService());
- conduitFactory.update(toMap(properties));
- reg = context.registerService(HTTPConduitFactory.class.getName(), conduitFactory, null);
+ for (Bus bus : buses) {
+ configureConduitFactory(bus);
+ }
+ }
+
+ @Override
+ public Object addingService(ServiceReference reference) {
+ Bus bus = (Bus)super.addingService(reference);
+ configureConduitFactory(bus);
+ return bus;
}
private Map<String, Object> toMap(Dictionary<String, ?> properties) {
@@ -94,5 +92,11 @@ public class Activator implements BundleActivator {
return props;
}
+ private void configureConduitFactory(Bus bus) {
+ AsyncHTTPConduitFactory conduitFactory = bus.getExtension(AsyncHTTPConduitFactory.class);
+ conduitFactory.update(this.currentConfig);
+ }
+
+
}
}