You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/01/30 13:06:58 UTC

svn commit: r1440364 - in /camel/branches/camel-2.10.x: ./ components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java

Author: davsclaus
Date: Wed Jan 30 12:06:57 2013
New Revision: 1440364

URL: http://svn.apache.org/viewvc?rev=1440364&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/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
    camel/branches/camel-2.10.x/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1440360

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java?rev=1440364&r1=1440363&r2=1440364&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java (original)
+++ camel/branches/camel-2.10.x/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java Wed Jan 30 12:06:57 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/branches/camel-2.10.x/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java?rev=1440364&r1=1440363&r2=1440364&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java (original)
+++ camel/branches/camel-2.10.x/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextPublisher.java Wed Jan 30 12:06:57 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();
     }