camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1440360 - in /camel/trunk/components: camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java
Date Wed, 30 Jan 2013 12:04:13 GMT
Author: davsclaus
Date: Wed Jan 30 12:04:12 2013
New Revision: 1440360

URL: http://svn.apache.org/viewvc?rev=1440360&view=rev
Log:
CAMEL-6023: Fixed issue with camel bundle not starting properly if using blueprint-cm to reload
bundle due .cfg file change. Also ensure when stopping camel the publisher removes the context
from its map tracking.

Modified:
    camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java

Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java?rev=1440360&r1=1440359&r2=1440360&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
(original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
Wed Jan 30 12:04:12 2013
@@ -28,16 +28,20 @@ import org.apache.camel.spi.Registry;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.BlueprintEvent;
+import org.osgi.service.blueprint.container.BlueprintListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class BlueprintCamelContext extends DefaultCamelContext implements ServiceListener
{
+public class BlueprintCamelContext extends DefaultCamelContext implements ServiceListener,
BlueprintListener {
 
     private static final transient Logger LOG = LoggerFactory.getLogger(BlueprintCamelContext.class);
 
     private BundleContext bundleContext;
     private BlueprintContainer blueprintContainer;
+    private ServiceRegistration<?> registration;
 
     public BlueprintCamelContext() {
     }
@@ -78,16 +82,39 @@ public class BlueprintCamelContext exten
         // add service listener so we can be notified when blueprint container is done
         // and we would be ready to start CamelContext
         bundleContext.addServiceListener(this);
+        // add blueprint listener as service, as we need this for the blueprint container
+        // to support change events when it changes states
+        registration = bundleContext.registerService(BlueprintListener.class, this, null);
     }
 
     public void destroy() throws Exception {
         LOG.trace("destroy {}", this);
 
         // remove listener and stop this CamelContext
-        bundleContext.removeServiceListener(this);
+        try {
+            bundleContext.removeServiceListener(this);
+        } catch (Exception e) {
+            LOG.warn("Error removing ServiceListener " + this + ". This exception is ignored.",
e);
+        }
+        if (registration != null) {
+            try {
+                registration.unregister();
+            } catch (Exception e) {
+                LOG.warn("Error unregistering service registration " + registration + ".
This exception is ignored.", e);
+            }
+            registration = null;
+        }
+
+        // must stop Camel
         stop();
     }
 
+
+    @Override
+    public void blueprintEvent(BlueprintEvent event) {
+        // noop as we just needed to enlist the BlueprintListener to have events triggered
to serviceChanged method
+    }
+
     @Override
     public void serviceChanged(ServiceEvent event) {
         if (LOG.isDebugEnabled()) {

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java?rev=1440360&r1=1440359&r2=1440360&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java
Wed Jan 30 12:04:12 2013
@@ -58,18 +58,24 @@ public class OsgiCamelContextPublisher e
             props.put(CONTEXT_VERSION_PROPERTY, getBundleVersion(bundleContext.getBundle()));
             props.put(CONTEXT_NAME_PROPERTY, context.getName());
 
-            log.debug("Registering CamelContext [{}] of in OSGi registry", props);
+            if (log.isDebugEnabled()) {
+                log.debug("Registering CamelContext [{}] of in OSGi registry", context.getName());
+            }
 
             ServiceRegistration reg = bundleContext.registerService(CamelContext.class.getName(),
context, props);
             registrations.put(context, reg);
         } else if (event instanceof CamelContextStoppingEvent) {
             CamelContext context = ((CamelContextStoppingEvent) event).getContext();
-            ServiceRegistration reg = registrations.get(context);
+            ServiceRegistration reg = registrations.remove(context);
             if (reg != null) {
                 if (log.isDebugEnabled()) {
                     log.debug("Unregistering CamelContext [{}] from OSGi registry", context.getName());
                 }
-                reg.unregister();
+                try {
+                    reg.unregister();
+                } catch (Exception e) {
+                    log.warn("Error unregistering CamelContext [{}] from OSGi registry. This
exception will be ignored.", context.getName(), e);
+                }
             }
         }
     }
@@ -84,6 +90,10 @@ public class OsgiCamelContextPublisher e
 
     @Override
     protected void doStop() throws Exception {
+    }
+
+    @Override
+    protected void doShutdown() throws Exception {
         registrations.clear();
     }
 



Mime
View raw message