camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1033440 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/ camel-core/src/test/java/org/apache/camel/management/ components/ca...
Date Wed, 10 Nov 2010 12:52:23 GMT
Author: davsclaus
Date: Wed Nov 10 12:52:22 2010
New Revision: 1033440

URL: http://svn.apache.org/viewvc?rev=1033440&view=rev
Log:
CAMEL-3324: Camel will not automatic find next free name when registering in JMX to remedy
duplicate CamelContext id clashes. For exampling deploying multiple WARs where camel apps
may have same camel context id. OSGi will enforces using bundle id in the JMX name as well.


Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextNameStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
    camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextNameStrategy.java
    camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Wed Nov 10 12:52:22
2010
@@ -96,6 +96,24 @@ public interface CamelContext extends Su
     void setNameStrategy(CamelContextNameStrategy nameStrategy);
 
     /**
+     * Gets the name this {@link CamelContext} was registered in JMX.
+     * <p/>
+     * The reason that a {@link CamelContext} can have a different name in JMX is the fact
to remedy for name clash
+     * in JMX when having multiple {@link CamelContext}s in the same JVM. Camel will automatic
reassign and use
+     * a free name to avoid failing to start.
+     *
+     * @return the management name
+     */
+    String getManagementName();
+
+    /**
+     * Sets the name this {@link CamelContext} was registered in JMX.
+     *
+     * @param name  the actual name used when registering this {@link CamelContext} in JMX
+     */
+    void setManagementName(String name);
+
+    /**
      * Gets the version of the this context.
      *
      * @return the version

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed
Nov 10 12:52:22 2010
@@ -125,6 +125,7 @@ import org.apache.commons.logging.LogFac
 public class DefaultCamelContext extends ServiceSupport implements CamelContext, SuspendableService
{
     private static final transient Log LOG = LogFactory.getLog(DefaultCamelContext.class);
     private CamelContextNameStrategy nameStrategy = new DefaultCamelContextNameStrategy();
+    private String managementName;
     private ClassLoader applicationContextClassLoader;
     private final Map<String, Endpoint> endpoints = new EndpointRegistry();
     private final AtomicInteger endpointKeyCounter = new AtomicInteger();
@@ -241,6 +242,14 @@ public class DefaultCamelContext extends
         this.nameStrategy = nameStrategy;
     }
 
+    public String getManagementName() {
+        return managementName;
+    }
+
+    public void setManagementName(String managementName) {
+        this.managementName = managementName;
+    }
+
     public Component hasComponent(String componentName) {
         return components.get(componentName);
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextNameStrategy.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextNameStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextNameStrategy.java
Wed Nov 10 12:52:22 2010
@@ -27,20 +27,29 @@ import org.apache.camel.spi.CamelContext
  */
 public class DefaultCamelContextNameStrategy implements CamelContextNameStrategy {
 
-    private static final String NAME_PREFIX = "camel-";
     private static final AtomicInteger CONTEXT_COUNTER = new AtomicInteger(0);
+    private final String prefix;
     private String name;
 
     public DefaultCamelContextNameStrategy() {
-        name = getNextName();
+        this("camel");
+    }
+
+    public DefaultCamelContextNameStrategy(String prefix) {
+        this.prefix = prefix;
+        this.name = getNextName();
     }
 
     public String getName() {
         return name;
     }
 
-    public static String getNextName() {
-        return NAME_PREFIX + CONTEXT_COUNTER.incrementAndGet();
+    public String getNextName() {
+        return prefix + "-" + getNextCounter();
+    }
+
+    public static int getNextCounter() {
+        return CONTEXT_COUNTER.incrementAndGet();
     }
 
     /**

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
Wed Nov 10 12:52:22 2010
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicInteger;
 import javax.management.JMException;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -77,6 +78,7 @@ import org.apache.camel.processor.SendPr
 import org.apache.camel.processor.Throttler;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.spi.CamelContextNameStrategy;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementAware;
@@ -98,6 +100,7 @@ import org.apache.commons.logging.LogFac
 public class DefaultManagementLifecycleStrategy implements LifecycleStrategy, Service, CamelContextAware
{
 
     private static final Log LOG = LogFactory.getLog(DefaultManagementLifecycleStrategy.class);
+    private static final AtomicInteger CONTEXT_COUNTER = new AtomicInteger(0);
     private final Map<Processor, KeyValueHolder<ProcessorDefinition, InstrumentationProcessor>>
wrappedProcessors =
             new HashMap<Processor, KeyValueHolder<ProcessorDefinition, InstrumentationProcessor>>();
     private CamelContext camelContext;
@@ -122,6 +125,8 @@ public class DefaultManagementLifecycleS
         ManagedCamelContext mc = new ManagedCamelContext(context);
         mc.init(context.getManagementStrategy());
 
+        String managementName = context.getManagementName() != null ? context.getManagementName()
: context.getName();
+
         try {
             boolean done = false;
             while (!done) {
@@ -130,26 +135,32 @@ public class DefaultManagementLifecycleS
                 if (!exists) {
                     done = true;
                 } else {
-                    // okay there exists already a CamelContext with this name, we can try
to fix it
+                    // okay there exists already a CamelContext with this name, we can try
to fix it by finding a free name
                     boolean fixed = false;
-                    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy)
{
                         // if we use the default name strategy we can find a free name to
use
-                        String name = findFreeName(mc);
-                        if (name != null) {
+                    String name = findFreeName(mc, context.getNameStrategy(), managementName);
+                    if (name != null) {
+                        // use this as the fixed name
+                        fixed = true;
+                        done = true;
+                        managementName = name;
+                    }
+                    // we could not fix it so veto starting camel
+                    if (!fixed) {
+                        throw new VetoCamelContextStartException("CamelContext (" + context.getName()
+ ") with ObjectName[" + on + "] is already registered."
+                            + " Make sure to use unique names on CamelContext when using
multiple CamelContexts in the same MBeanServer.", context);
+                    } else {
+                        if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy)
{
                             // use this as the fixed name
                             LOG.warn("Reassigned auto assigned name on CamelContext from:
" + context.getName()
                                     + " to: " + name + " due to clash with existing name
already registered in MBeanServer.");
                             // now set the fixed name we are using onwards
                             context.setNameStrategy(new ExplicitCamelContextNameStrategy(name));
-                            fixed = true;
-                            done = true;
+                        } else {
+                            LOG.warn("This CamelContext(" + context.getName() + ") will be
registered using the name: " + managementName
+                                + " due to clash with an existing name already registered
in MBeanServer.");
                         }
                     }
-                    // we could not fix it so veto starting camel
-                    if (!fixed) {
-                        throw new VetoCamelContextStartException("CamelContext (" + context.getName()
+ ") with ObjectName[" + on + "] is already registered."
-                            + " Make sure to use unique names on CamelContext when using
multiple CamelContexts in the same MBeanServer.", context);
-                    }
                 }
             }
         } catch (VetoCamelContextStartException e) {
@@ -161,6 +172,9 @@ public class DefaultManagementLifecycleS
             throw ObjectHelper.wrapRuntimeCamelException(e);
         }
 
+        // set the name we are going to use
+        context.setManagementName(managementName);
+
         try {
             getManagementStrategy().manageObject(mc);
         } catch (Exception e) {
@@ -173,12 +187,20 @@ public class DefaultManagementLifecycleS
         initialized = true;
     }
 
-    private String findFreeName(ManagedCamelContext mc) throws MalformedObjectNameException
{
+    private String findFreeName(ManagedCamelContext mc, CamelContextNameStrategy strategy,
String managementName) throws MalformedObjectNameException {
         boolean done = false;
         String name = null;
+        // start from 2 as the existing name is considered the 1st
+        int counter = 2;
         while (!done) {
-            // try next name
-            name = DefaultCamelContextNameStrategy.getNextName();
+            // compute the next name
+            if (strategy instanceof DefaultCamelContextNameStrategy) {
+                // prefer to use the default naming strategy to compute the next free name
+                name = ((DefaultCamelContextNameStrategy) strategy).getNextName();
+            } else {
+                // if explict name then use a counter prefix
+                name = managementName + "-" + counter++;
+            }
             ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(name);
             done = !getManagementStrategy().isManaged(mc, on);
             if (LOG.isTraceEnabled()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
Wed Nov 10 12:52:22 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.management;
 
-import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.concurrent.ThreadPoolExecutor;
 import javax.management.MalformedObjectNameException;
@@ -37,6 +36,7 @@ import org.apache.camel.spi.EventNotifie
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.InetAddressUtil;
 import org.apache.camel.util.ObjectHelper;
 
 /**
@@ -72,7 +72,7 @@ public class DefaultManagementNamingStra
             this.domainName = domainName;
         }
         try {
-            hostName = InetAddress.getLocalHost().getHostName();
+            hostName = InetAddressUtil.getLocalHostName();
         } catch (UnknownHostException ex) {
             // ignore, use the default "localhost"
         }
@@ -287,8 +287,12 @@ public class DefaultManagementNamingStra
     }
 
     protected String getContextId(CamelContext context) {
-        String name = context != null ? context.getName() : VALUE_UNKNOWN;
-        return getContextId(name);
+        if (context == null) {
+            return getContextId(VALUE_UNKNOWN);
+        } else {
+            String name = context.getManagementName() != null ? context.getManagementName()
: context.getName();
+            return getContextId(name);
+        }
     }
 
     protected String getContextId(String name) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
Wed Nov 10 12:52:22 2010
@@ -21,7 +21,6 @@ import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.TestSupport;
-import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.impl.DefaultCamelContext;
 
 /**
@@ -52,15 +51,13 @@ public class TwoManagedCamelContextClash
         ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/foo,type=context,name=\"foo\"");
         assertTrue("Should be registered", mbeanServer.isRegistered(on));
 
-        try {
-            camel2.start();
-            fail("Should throw an exception");
-        } catch (VetoCamelContextStartException e) {
-            assertEquals("foo", e.getContext().getName());
-        }
-        assertFalse("Should not be started", camel2.getStatus().isStarted());
+        // camel will now automatic re assign the JMX name to avoid the clash
+        camel2.start();
+        ObjectName on2 = ObjectName.getInstance("org.apache.camel:context=localhost/foo-2,type=context,name=\"foo\"");
+        assertTrue("Should be registered", mbeanServer.isRegistered(on2));
 
         assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on));
+        assertTrue("Should still be registered after name clash", mbeanServer.isRegistered(on2));
     }
 
     @Override

Modified: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
(original)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
Wed Nov 10 12:52:22 2010
@@ -59,12 +59,14 @@ import org.apache.camel.model.SortDefini
 import org.apache.camel.model.UnmarshalDefinition;
 import org.apache.camel.model.WireTapDefinition;
 import org.apache.camel.model.language.ExpressionDefinition;
+import org.apache.camel.spi.CamelContextNameStrategy;
 import org.apache.camel.spi.ComponentResolver;
 import org.apache.camel.spi.DataFormatResolver;
 import org.apache.camel.spi.LanguageResolver;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.blueprint.container.BlueprintContainer;
@@ -117,7 +119,8 @@ public class CamelNamespaceHandler imple
             // lets avoid folks having to explicitly give an ID to a camel context
             if (ObjectHelper.isEmpty(contextId)) {
                 // if no explicit id was set then use a default auto generated name
-                contextId = DefaultCamelContextNameStrategy.getNextName();
+                CamelContextNameStrategy strategy = new DefaultCamelContextNameStrategy();
+                contextId = strategy.getName();
                 element.setAttribute("id", contextId);
                 implicitId = true;
             }

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextHelper.java
Wed Nov 10 12:52:22 2010
@@ -27,15 +27,17 @@ import org.osgi.framework.BundleContext;
 
 public final class OsgiCamelContextHelper {
     private static final transient Log LOG = LogFactory.getLog(OsgiCamelContextHelper.class);
-    
+
     private OsgiCamelContextHelper() {
         // helper class
     }
     
     public static void osgiUpdate(DefaultCamelContext camelContext, BundleContext bundleContext)
{
-        LOG.debug("Using the OsgiCamelContextNameStrategy");
+        ObjectHelper.notNull(bundleContext, "BundleContext");
+
+        LOG.debug("Using OsgiCamelContextNameStrategy");
         camelContext.setNameStrategy(new OsgiCamelContextNameStrategy(bundleContext));
-        LOG.debug("Using the OsgiClassResolver");
+        LOG.debug("Using OsgiClassResolver");
         camelContext.setClassResolver(new OsgiClassResolver(bundleContext));
         LOG.debug("Using OsgiFactoryFinderResolver");
         camelContext.setFactoryFinderResolver(new OsgiFactoryFinderResolver(bundleContext));
@@ -51,7 +53,8 @@ public final class OsgiCamelContextHelpe
     
     public static Registry wrapRegistry(CamelContext camelContext, Registry registry, BundleContext
bundleContext) {
         ObjectHelper.notNull(bundleContext, "BundleContext");
-        LOG.debug("Setting the OSGi ServiceRegistry");
+
+        LOG.debug("Setting up OSGi ServiceRegistry");
         OsgiServiceRegistry osgiServiceRegistry = new OsgiServiceRegistry(bundleContext);
         // Need to clean up the OSGi service when camel context is closed.
         camelContext.addLifecycleStrategy(osgiServiceRegistry);

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextNameStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextNameStrategy.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextNameStrategy.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiCamelContextNameStrategy.java
Wed Nov 10 12:52:22 2010
@@ -16,21 +16,14 @@
  */
 package org.apache.camel.core.osgi;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.camel.spi.CamelContextNameStrategy;
+import org.apache.camel.impl.DefaultCamelContextNameStrategy;
 import org.osgi.framework.BundleContext;
 
-public class OsgiCamelContextNameStrategy implements CamelContextNameStrategy {
+public class OsgiCamelContextNameStrategy extends DefaultCamelContextNameStrategy {
 
-    private static final AtomicInteger COUNTER = new AtomicInteger(0);
-    private final String name;
-    
     public OsgiCamelContextNameStrategy(BundleContext context) {
-        name = "camel-" + context.getBundle().getBundleId() + "-" + COUNTER.incrementAndGet();
+        // use bundle id in auto assigned names to make it unique
+        super("camel-" + context.getBundle().getBundleId() + "-");
     }
 
-    public String getName() {
-        return name;
-    }
 }

Modified: camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
(original)
+++ camel/trunk/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java
Wed Nov 10 12:52:22 2010
@@ -51,4 +51,10 @@ public class OsgiDefaultCamelContext ext
         return new OsgiTypeConverter(bundleContext, getInjector());
     }
 
+    @Override
+    public void setName(String name) {
+        super.setName(name);
+        // in OSGi append the bundle id to the management name so it will be unique in the
JVM
+        super.setManagementName(name + "-" + bundleContext.getBundle().getBundleId());
+    }
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
Wed Nov 10 12:52:22 2010
@@ -48,7 +48,7 @@ public class CamelContextFactoryBean ext
     
     protected SpringCamelContext createContext() {
         SpringCamelContext ctx = newCamelContext();
-        // we don't the the ImplicitId as it will override the OsgiCamelContextNameStratgy
+        // we don't the the ImplicitId as it will override the OsgiCamelContextNameStrategy
         if (!isImplicitId()) {
             ctx.setName(getId());
         }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java
Wed Nov 10 12:52:22 2010
@@ -43,4 +43,12 @@ public class OsgiSpringCamelContext exte
     protected Registry createRegistry() {
         return OsgiCamelContextHelper.wrapRegistry(this, super.createRegistry(), bundleContext);
     }
+
+    @Override
+    public void setName(String name) {
+        super.setName(name);
+        // in OSGi append the bundle id to the management name so it will be unique in the
JVM
+        super.setManagementName(name + "-" + bundleContext.getBundle().getBundleId());
+    }
+
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=1033440&r1=1033439&r2=1033440&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
Wed Nov 10 12:52:22 2010
@@ -17,7 +17,6 @@
 package org.apache.camel.spring.handler;
 
 import java.lang.reflect.Method;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -38,6 +37,7 @@ import org.apache.camel.core.xml.CamelPr
 import org.apache.camel.impl.DefaultCamelContextNameStrategy;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.SendDefinition;
+import org.apache.camel.spi.CamelContextNameStrategy;
 import org.apache.camel.spi.NamespaceAware;
 import org.apache.camel.spring.CamelBeanPostProcessor;
 import org.apache.camel.spring.CamelConsumerTemplateFactoryBean;
@@ -245,7 +245,8 @@ public class CamelNamespaceHandler exten
             // lets avoid folks having to explicitly give an ID to a camel context
             if (ObjectHelper.isEmpty(contextId)) {
                 // if no explicit id was set then use a default auto generated name
-                contextId = DefaultCamelContextNameStrategy.getNextName();
+                CamelContextNameStrategy strategy = new DefaultCamelContextNameStrategy();
+                contextId = strategy.getName();
                 element.setAttribute("id", contextId);
                 implicitId = true;
             }



Mime
View raw message