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 2014/11/07 18:26:45 UTC

[1/5] camel git commit: [CAMEL-8000] Add global notion of CamelContextRegistry

Repository: camel
Updated Branches:
  refs/heads/master a770bbb24 -> cdee7809b


[CAMEL-8000] Add global notion of CamelContextRegistry


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ab750c95
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ab750c95
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ab750c95

Branch: refs/heads/master
Commit: ab750c951cb4ec6d0aab5e56e862396f2b076049
Parents: a770bbb
Author: Thomas Diesler <th...@jboss.com>
Authored: Fri Nov 7 10:48:15 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 7 17:16:37 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  |  16 ++-
 .../camel/impl/DefaultCamelContextRegistry.java | 123 +++++++++++++++++++
 .../apache/camel/spi/CamelContextRegistry.java  |  80 ++++++++++++
 .../java/org/apache/camel/spi/Container.java    |   3 +
 .../camel/spi/CamelContextRegistryTest.java     |  68 ++++++++++
 5 files changed, 289 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ab750c95/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 1ca5e19..b3f6ff3 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -93,6 +93,7 @@ import org.apache.camel.processor.interceptor.HandleFault;
 import org.apache.camel.processor.interceptor.StreamCaching;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.CamelContextNameStrategy;
+import org.apache.camel.spi.CamelContextRegistry;
 import org.apache.camel.spi.ClassResolver;
 import org.apache.camel.spi.ComponentResolver;
 import org.apache.camel.spi.Container;
@@ -267,9 +268,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         this.managementStrategy = createManagementStrategy();
         this.managementMBeanAssembler = createManagementMBeanAssembler();
 
+        // Register this context with the registry
+        // Note, this may register a partially constructed object
+    	((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).afterCreate(this);
+    	
+        // [TODO] Remove in 3.0
         Container.Instance.manage(this);
     }
-
+    
     /**
      * Creates the {@link CamelContext} using the given JNDI context as the registry
      *
@@ -1934,6 +1940,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             setApplicationContextClassLoader(cl);
         }
 
+        // We register the context again just before start. This ensures that is is registered on restart
+        // Listeners should only see one call to Listener.contextAdded(CamelContext)
+		((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).beforeStart(this);
+		
         if (log.isDebugEnabled()) {
             log.debug("Using ClassResolver={}, PackageScanClassResolver={}, ApplicationContextClassLoader={}",
                     new Object[]{getClassResolver(), getPackageScanClassResolver(), getApplicationContextClassLoader()});
@@ -2184,7 +2194,11 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         // and clear start date
         startDate = null;
 
+        // [TODO] Remove in 3.0
         Container.Instance.unmanage(this);
+
+        // Unregister this context from the registry
+        ((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).afterStop(this);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/ab750c95/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
new file mode 100644
index 0000000..9413050
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.CamelContextRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The default {@link CamelContextRegistry}
+ */
+public final class DefaultCamelContextRegistry implements CamelContextRegistry {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultCamelContextRegistry.class);
+    
+	private final Set<CamelContext> contexts = new LinkedHashSet<CamelContext>();
+    private final Set<Listener> listeners = new LinkedHashSet<Listener>();
+	
+    synchronized void afterCreate(CamelContext camelContext) {
+		registerContext(camelContext);
+    } 
+    
+    synchronized void beforeStart(CamelContext camelContext) {
+    	if (!contexts.contains(camelContext)) {
+    		registerContext(camelContext);
+    	}
+    }
+
+    synchronized void afterStop(CamelContext camelContext) {
+		unregisterContext(camelContext);
+    }
+
+	private void registerContext(CamelContext camelContext) {
+		contexts.add(camelContext);
+		for (Listener listener : listeners) {
+			try {
+				listener.contextAdded(camelContext);
+			} catch (Throwable th) {
+				LOG.error("Error calling registry listener", th);
+			}
+		}
+	}
+
+	private void unregisterContext(CamelContext camelContext) {
+		contexts.remove(camelContext);
+    	for (Listener listener : listeners) {
+    		try {
+				listener.contextRemoved(camelContext);
+			} catch (Throwable th) {
+				LOG.error("Error calling registry listener", th);
+			}
+    	}
+	}
+
+    @Override
+	public synchronized void addListener(Listener listener, boolean withCallback) {
+    	if (withCallback) {
+        	for (CamelContext ctx : contexts) {
+        		listener.contextAdded(ctx);
+        	}
+    	}
+    	listeners.add(listener);
+    } 
+    
+    @Override
+	public synchronized void removeListener(Listener listener, boolean withCallback) {
+    	listeners.add(listener);
+    	if (withCallback) {
+        	for (CamelContext ctx : contexts) {
+        		listener.contextAdded(ctx);
+        	}
+    	}
+    } 
+    
+    @Override
+	public synchronized Set<CamelContext> getContexts() {
+    	return new LinkedHashSet<CamelContext>(contexts);	
+    } 
+    
+    @Override
+	public synchronized Set<CamelContext> getContexts(String name) {
+    	Set<CamelContext> result = new LinkedHashSet<CamelContext>();
+    	for (CamelContext ctx : contexts) {
+    		if (ctx.getName().equals(name)) {
+    			result.add(ctx);
+    		}
+    	}
+    	return result;	
+    } 
+    
+    @Override
+	public synchronized CamelContext getRequiredContext(String name) {
+    	Iterator<CamelContext> itctx = getContexts(name).iterator();
+    	if (!itctx.hasNext())
+    		throw new IllegalStateException("Cannot obtain context for name: " + name);
+    	return itctx.next();
+    }
+    
+    @Override
+	public synchronized CamelContext getContext(String name) {
+    	Iterator<CamelContext> itctx = getContexts(name).iterator();
+    	return itctx.hasNext() ? itctx.next() : null;
+    } 
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ab750c95/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
new file mode 100644
index 0000000..a27ca35
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
@@ -0,0 +1,80 @@
+package org.apache.camel.spi;
+
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultCamelContextRegistry;
+
+/**
+ * A global registry for camel contexts.
+ *
+ * The runtime registeres all contexts that derive from {@link DefaultCamelContext} automatically.
+ */
+public interface CamelContextRegistry {
+
+	/**
+	 * The registry singleton
+	 */
+	static final CamelContextRegistry INSTANCE = new DefaultCamelContextRegistry();
+	
+	/**
+	 * A listener that can be registered witht he registry
+	 */
+	public class Listener {
+
+		/**
+		 * Called when a context is added to the registry
+		 */
+		public void contextAdded(CamelContext camelContext) {
+		}
+		
+		/**
+		 * Called when a context is removed from the registry
+		 */
+		public void contextRemoved(CamelContext camelContext) {
+		}
+	}
+
+	/**
+	 * Add the given listener to the registry
+	 * @param withCallback If true, the given listener is called with the set of already registered contexts
+	 */
+	void addListener(Listener listener, boolean withCallback);
+
+	/**
+	 * Remove the given listener from the registry
+	 * @param withCallback If true, the given listener is called with the set of already registered contexts
+	 */
+	void removeListener(Listener listener, boolean withCallback);
+
+	/**
+	 * Get the set of registerd contexts
+	 */
+	Set<CamelContext> getContexts();
+
+	/**
+	 * Get the set of registered contexts for the given name.
+	 * 
+	 * Because the camel context name property is neither unique nor immutable
+	 * the returned set may vary for the same name.
+	 */
+	Set<CamelContext> getContexts(String name);
+
+	/**
+	 * Get the registered context for the given name.
+	 * 
+	 * @return The first context in the set
+	 * @throws IllegalStateException when there is no registered context for the given name
+	 * @see CamelContextRegistry#getContexts(String)
+	 */
+	CamelContext getRequiredContext(String name);
+	
+	/**
+	 * Get the registered context for the given name.
+	 * 
+	 * @return The first context in the set or null
+	 * @see CamelContextRegistry#getContexts(String)
+	 */
+	CamelContext getContext(String name);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ab750c95/camel-core/src/main/java/org/apache/camel/spi/Container.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/Container.java b/camel-core/src/main/java/org/apache/camel/spi/Container.java
index bcfc2da..ba0a258 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/Container.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/Container.java
@@ -34,7 +34,10 @@ import org.slf4j.LoggerFactory;
  * This implementation is <b>not</b> thread-safe. The {@link #manage(org.apache.camel.CamelContext)} method
  * may be invoked concurrently if multiple Camel applications is being started concurrently, such as from
  * application servers that may start deployments concurrently.
+ * 
+ * @deprecated use {@link CamelContextRegistry}
  */
+// [TODO] Remove in 3.0
 public interface Container {
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/ab750c95/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
new file mode 100644
index 0000000..d64ca8f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+
+public class CamelContextRegistryTest extends TestCase {
+
+    private final class MyListener extends CamelContextRegistry.Listener {
+
+        private List<String> names = new ArrayList<String>();
+
+        @Override
+		public void contextAdded(CamelContext camelContext) {
+            names.add(camelContext.getName());
+		}
+
+		@Override
+		public void contextRemoved(CamelContext camelContext) {
+            names.remove(camelContext.getName());
+		}
+    }
+
+    public void testContainerSet() throws Exception {
+        MyListener listener = new MyListener();
+        
+        CamelContext camel1 = new DefaultCamelContext();
+        CamelContext camel2 = new DefaultCamelContext();
+
+        assertEquals(0, listener.names.size());
+        
+        CamelContextRegistry.INSTANCE.addListener(listener, true);
+        
+        // after we set, then we should manage the 2 pending contexts
+        assertEquals(2, listener.names.size());
+
+        CamelContext camel3 = new DefaultCamelContext();
+        assertEquals(3, listener.names.size());
+        assertEquals(camel1.getName(), listener.names.get(0));
+        assertEquals(camel2.getName(), listener.names.get(1));
+        assertEquals(camel3.getName(), listener.names.get(2));
+
+        camel1.stop();
+        camel2.stop();
+        camel3.stop();
+        
+        assertEquals(0, listener.names.size());
+    }
+}


[5/5] camel git commit: [CAMEL-8000]: Fixed test

Posted by da...@apache.org.
[CAMEL-8000]: Fixed test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cdee7809
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cdee7809
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cdee7809

Branch: refs/heads/master
Commit: cdee7809bf801faf504d06047d5763d57bc4067f
Parents: 6c488d3
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 7 18:06:58 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 7 18:06:58 2014 +0100

----------------------------------------------------------------------
 .../org/apache/camel/impl/DefaultCamelContextRegistry.java   | 8 ++++++++
 .../java/org/apache/camel/spi/CamelContextRegistryTest.java  | 4 ++++
 2 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cdee7809/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
index f9170af..e578a5f 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
@@ -35,6 +35,14 @@ public final class DefaultCamelContextRegistry implements CamelContextRegistry {
     private final Set<CamelContext> contexts = new LinkedHashSet<CamelContext>();
     private final Set<Listener> listeners = new LinkedHashSet<Listener>();
 
+    /**
+     * Clear all contexts and listeners, such as for testing purpose.
+     */
+    public synchronized void clear() {
+        contexts.clear();
+        listeners.clear();
+    }
+
     synchronized void afterCreate(CamelContext camelContext) {
         registerContext(camelContext);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/cdee7809/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
index d35a98b..eec9263 100644
--- a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
+++ b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
@@ -22,6 +22,7 @@ import java.util.List;
 import junit.framework.TestCase;
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultCamelContextRegistry;
 
 public class CamelContextRegistryTest extends TestCase {
 
@@ -41,6 +42,9 @@ public class CamelContextRegistryTest extends TestCase {
     }
 
     public void testContainerSet() throws Exception {
+        // need to clear the listener for testing
+        ((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).clear();
+
         MyListener listener = new MyListener();
 
         CamelContext camel1 = new DefaultCamelContext();


[4/5] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6c488d31
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6c488d31
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6c488d31

Branch: refs/heads/master
Commit: 6c488d3136b84348290e7f7417d41850b3ae4378
Parents: ccec24f
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 7 17:33:07 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 7 17:35:56 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/management/mbean/ManagedEndpoint.java  | 4 ++--
 .../apache/camel/management/mbean/ManagedEndpointRegistry.java   | 4 +---
 camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java | 2 ++
 3 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6c488d31/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpoint.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpoint.java
index 59cddf9..3e2b881 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpoint.java
@@ -99,8 +99,8 @@ public class ManagedEndpoint implements ManagedInstance, ManagedEndpointMBean {
                 String description = row.get("description") != null ? row.get("description") : "";
 
                 CompositeType ct = CamelOpenMBeanTypes.explainEndpointsCompositeType();
-                CompositeData data = new CompositeDataSupport(ct, new String[]
-                        {"option", "type", "java type", "value", "description"},
+                CompositeData data = new CompositeDataSupport(ct,
+                        new String[]{"option", "type", "java type", "value", "description"},
                         new Object[]{option, type, javaType, value, description});
                 answer.put(data);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/6c488d31/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpointRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpointRegistry.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpointRegistry.java
index 7468b09..9f0c3c0 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpointRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEndpointRegistry.java
@@ -72,9 +72,7 @@ public class ManagedEndpointRegistry extends ManagedService implements ManagedEn
                 CompositeType ct = CamelOpenMBeanTypes.listEndpointsCompositeType();
                 String url = endpoint.getEndpointUri();
 
-                CompositeData data = new CompositeDataSupport(ct, new String[]
-                        {"url"},
-                        new Object[]{url});
+                CompositeData data = new CompositeDataSupport(ct, new String[]{"url"}, new Object[]{url});
                 answer.put(data);
             }
             return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/6c488d31/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
index baeba4f..3162d38 100644
--- a/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
@@ -819,6 +819,7 @@ public final class ObjectHelper {
      * @param name the name of the class to load
      * @return the class or <tt>null</tt> if it could not be loaded
      */
+    //CHECKSTYLE:OFF
     public static Class<?> loadSimpleType(String name) {
         // special for byte[] or Object[] as its common to use
         if ("java.lang.byte[]".equals(name) || "byte[]".equals(name)) {
@@ -867,6 +868,7 @@ public final class ObjectHelper {
         }
         return null;
     }
+    //CHECKSTYLE:ON
 
     /**
      * Loads the given class with the provided classloader (may be null).


[3/5] camel git commit: [CAMEL-8000]: Fixed CS

Posted by da...@apache.org.
[CAMEL-8000]: Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ccec24f6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ccec24f6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ccec24f6

Branch: refs/heads/master
Commit: ccec24f6127ad66c2b05bc11c080030a1de8095b
Parents: 6bb3666
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 7 17:32:05 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 7 17:32:05 2014 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  |   8 +-
 .../camel/impl/DefaultCamelContextRegistry.java | 148 ++++++++++---------
 .../apache/camel/spi/CamelContextRegistry.java  | 139 +++++++++--------
 .../camel/spi/CamelContextRegistryTest.java     |  18 +--
 4 files changed, 167 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ccec24f6/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 5738381..76bc0d8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -270,8 +270,8 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
 
         // Register this context with the registry
         // Note, this may register a partially constructed object
-    	((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).afterCreate(this);
-    	
+        ((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).afterCreate(this);
+
         // [TODO] Remove in 3.0
         Container.Instance.manage(this);
     }
@@ -1942,8 +1942,8 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
 
         // We register the context again just before start. This ensures that is is registered on restart
         // Listeners should only see one call to Listener.contextAdded(CamelContext)
-		((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).beforeStart(this);
-		
+        ((DefaultCamelContextRegistry) CamelContextRegistry.INSTANCE).beforeStart(this);
+
         if (log.isDebugEnabled()) {
             log.debug("Using ClassResolver={}, PackageScanClassResolver={}, ApplicationContextClassLoader={}",
                     new Object[]{getClassResolver(), getPackageScanClassResolver(), getApplicationContextClassLoader()});

http://git-wip-us.apache.org/repos/asf/camel/blob/ccec24f6/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
index 9413050..f9170af 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContextRegistry.java
@@ -31,93 +31,95 @@ import org.slf4j.LoggerFactory;
 public final class DefaultCamelContextRegistry implements CamelContextRegistry {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultCamelContextRegistry.class);
-    
-	private final Set<CamelContext> contexts = new LinkedHashSet<CamelContext>();
+
+    private final Set<CamelContext> contexts = new LinkedHashSet<CamelContext>();
     private final Set<Listener> listeners = new LinkedHashSet<Listener>();
-	
+
     synchronized void afterCreate(CamelContext camelContext) {
-		registerContext(camelContext);
-    } 
-    
+        registerContext(camelContext);
+    }
+
     synchronized void beforeStart(CamelContext camelContext) {
-    	if (!contexts.contains(camelContext)) {
-    		registerContext(camelContext);
-    	}
+        if (!contexts.contains(camelContext)) {
+            registerContext(camelContext);
+        }
     }
 
     synchronized void afterStop(CamelContext camelContext) {
-		unregisterContext(camelContext);
+        unregisterContext(camelContext);
     }
 
-	private void registerContext(CamelContext camelContext) {
-		contexts.add(camelContext);
-		for (Listener listener : listeners) {
-			try {
-				listener.contextAdded(camelContext);
-			} catch (Throwable th) {
-				LOG.error("Error calling registry listener", th);
-			}
-		}
-	}
-
-	private void unregisterContext(CamelContext camelContext) {
-		contexts.remove(camelContext);
-    	for (Listener listener : listeners) {
-    		try {
-				listener.contextRemoved(camelContext);
-			} catch (Throwable th) {
-				LOG.error("Error calling registry listener", th);
-			}
-    	}
-	}
+    private void registerContext(CamelContext camelContext) {
+        contexts.add(camelContext);
+        for (Listener listener : listeners) {
+            try {
+                listener.contextAdded(camelContext);
+            } catch (Throwable e) {
+                LOG.warn("Error calling registry listener. This exception is ignored.", e);
+            }
+        }
+    }
+
+    private void unregisterContext(CamelContext camelContext) {
+        contexts.remove(camelContext);
+        for (Listener listener : listeners) {
+            try {
+                listener.contextRemoved(camelContext);
+            } catch (Throwable e) {
+                LOG.warn("Error calling registry listener. This exception is ignored.", e);
+            }
+        }
+    }
 
     @Override
-	public synchronized void addListener(Listener listener, boolean withCallback) {
-    	if (withCallback) {
-        	for (CamelContext ctx : contexts) {
-        		listener.contextAdded(ctx);
-        	}
-    	}
-    	listeners.add(listener);
-    } 
-    
+    public synchronized void addListener(Listener listener, boolean withCallback) {
+        if (withCallback) {
+            for (CamelContext ctx : contexts) {
+                listener.contextAdded(ctx);
+            }
+        }
+        listeners.add(listener);
+    }
+
     @Override
-	public synchronized void removeListener(Listener listener, boolean withCallback) {
-    	listeners.add(listener);
-    	if (withCallback) {
-        	for (CamelContext ctx : contexts) {
-        		listener.contextAdded(ctx);
-        	}
-    	}
-    } 
-    
+    public synchronized void removeListener(Listener listener, boolean withCallback) {
+        listeners.add(listener);
+        if (withCallback) {
+            for (CamelContext ctx : contexts) {
+                listener.contextAdded(ctx);
+            }
+        }
+    }
+
     @Override
-	public synchronized Set<CamelContext> getContexts() {
-    	return new LinkedHashSet<CamelContext>(contexts);	
-    } 
-    
+    public synchronized Set<CamelContext> getContexts() {
+        return new LinkedHashSet<CamelContext>(contexts);
+    }
+
     @Override
-	public synchronized Set<CamelContext> getContexts(String name) {
-    	Set<CamelContext> result = new LinkedHashSet<CamelContext>();
-    	for (CamelContext ctx : contexts) {
-    		if (ctx.getName().equals(name)) {
-    			result.add(ctx);
-    		}
-    	}
-    	return result;	
-    } 
-    
+    public synchronized Set<CamelContext> getContexts(String name) {
+        Set<CamelContext> result = new LinkedHashSet<CamelContext>();
+        for (CamelContext ctx : contexts) {
+            if (ctx.getName().equals(name)) {
+                result.add(ctx);
+            }
+        }
+        return result;
+    }
+
     @Override
-	public synchronized CamelContext getRequiredContext(String name) {
-    	Iterator<CamelContext> itctx = getContexts(name).iterator();
-    	if (!itctx.hasNext())
-    		throw new IllegalStateException("Cannot obtain context for name: " + name);
-    	return itctx.next();
+    public synchronized CamelContext getRequiredContext(String name) {
+        Iterator<CamelContext> it = getContexts(name).iterator();
+        if (!it.hasNext()) {
+            throw new IllegalStateException("Cannot find CamelContext with name: " + name);
+        }
+        return it.next();
     }
-    
+
     @Override
-	public synchronized CamelContext getContext(String name) {
-    	Iterator<CamelContext> itctx = getContexts(name).iterator();
-    	return itctx.hasNext() ? itctx.next() : null;
-    } 
+    public synchronized CamelContext getContext(String name) {
+        Iterator<CamelContext> it = getContexts(name).iterator();
+        return it.hasNext() ? it.next() : null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/ccec24f6/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
index a27ca35..78d10ca 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/CamelContextRegistry.java
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.camel.spi;
 
 import java.util.Set;
@@ -8,73 +24,76 @@ import org.apache.camel.impl.DefaultCamelContextRegistry;
 
 /**
  * A global registry for camel contexts.
- *
- * The runtime registeres all contexts that derive from {@link DefaultCamelContext} automatically.
+ * <p/>
+ * The runtime registers all contexts that derive from {@link DefaultCamelContext} automatically.
  */
 public interface CamelContextRegistry {
 
-	/**
-	 * The registry singleton
-	 */
-	static final CamelContextRegistry INSTANCE = new DefaultCamelContextRegistry();
-	
-	/**
-	 * A listener that can be registered witht he registry
-	 */
-	public class Listener {
+    /**
+     * The registry singleton
+     */
+    CamelContextRegistry INSTANCE = new DefaultCamelContextRegistry();
+
+    /**
+     * A listener that can be registered with he registry
+     */
+    public class Listener {
+
+        /**
+         * Called when a context is added to the registry
+         */
+        public void contextAdded(CamelContext camelContext) {
+        }
+
+        /**
+         * Called when a context is removed from the registry
+         */
+        public void contextRemoved(CamelContext camelContext) {
+        }
+    }
+
+    /**
+     * Add the given listener to the registry
+     *
+     * @param withCallback If true, the given listener is called with the set of already registered contexts
+     */
+    void addListener(Listener listener, boolean withCallback);
 
-		/**
-		 * Called when a context is added to the registry
-		 */
-		public void contextAdded(CamelContext camelContext) {
-		}
-		
-		/**
-		 * Called when a context is removed from the registry
-		 */
-		public void contextRemoved(CamelContext camelContext) {
-		}
-	}
+    /**
+     * Remove the given listener from the registry
+     *
+     * @param withCallback If true, the given listener is called with the set of already registered contexts
+     */
+    void removeListener(Listener listener, boolean withCallback);
 
-	/**
-	 * Add the given listener to the registry
-	 * @param withCallback If true, the given listener is called with the set of already registered contexts
-	 */
-	void addListener(Listener listener, boolean withCallback);
+    /**
+     * Get the set of registered contexts
+     */
+    Set<CamelContext> getContexts();
 
-	/**
-	 * Remove the given listener from the registry
-	 * @param withCallback If true, the given listener is called with the set of already registered contexts
-	 */
-	void removeListener(Listener listener, boolean withCallback);
+    /**
+     * Get the set of registered contexts for the given name.
+     * <p/>
+     * Because the camel context name property is neither unique nor immutable
+     * the returned set may vary for the same name.
+     */
+    Set<CamelContext> getContexts(String name);
 
-	/**
-	 * Get the set of registerd contexts
-	 */
-	Set<CamelContext> getContexts();
+    /**
+     * Get the registered context for the given name.
+     *
+     * @return The first context in the set
+     * @throws IllegalStateException when there is no registered context for the given name
+     * @see CamelContextRegistry#getContexts(String)
+     */
+    CamelContext getRequiredContext(String name);
 
-	/**
-	 * Get the set of registered contexts for the given name.
-	 * 
-	 * Because the camel context name property is neither unique nor immutable
-	 * the returned set may vary for the same name.
-	 */
-	Set<CamelContext> getContexts(String name);
+    /**
+     * Get the registered context for the given name.
+     *
+     * @return The first context in the set or null
+     * @see CamelContextRegistry#getContexts(String)
+     */
+    CamelContext getContext(String name);
 
-	/**
-	 * Get the registered context for the given name.
-	 * 
-	 * @return The first context in the set
-	 * @throws IllegalStateException when there is no registered context for the given name
-	 * @see CamelContextRegistry#getContexts(String)
-	 */
-	CamelContext getRequiredContext(String name);
-	
-	/**
-	 * Get the registered context for the given name.
-	 * 
-	 * @return The first context in the set or null
-	 * @see CamelContextRegistry#getContexts(String)
-	 */
-	CamelContext getContext(String name);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ccec24f6/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
index d64ca8f..d35a98b 100644
--- a/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
+++ b/camel-core/src/test/java/org/apache/camel/spi/CamelContextRegistryTest.java
@@ -30,26 +30,26 @@ public class CamelContextRegistryTest extends TestCase {
         private List<String> names = new ArrayList<String>();
 
         @Override
-		public void contextAdded(CamelContext camelContext) {
+        public void contextAdded(CamelContext camelContext) {
             names.add(camelContext.getName());
-		}
+        }
 
-		@Override
-		public void contextRemoved(CamelContext camelContext) {
+        @Override
+        public void contextRemoved(CamelContext camelContext) {
             names.remove(camelContext.getName());
-		}
+        }
     }
 
     public void testContainerSet() throws Exception {
         MyListener listener = new MyListener();
-        
+
         CamelContext camel1 = new DefaultCamelContext();
         CamelContext camel2 = new DefaultCamelContext();
 
         assertEquals(0, listener.names.size());
-        
+
         CamelContextRegistry.INSTANCE.addListener(listener, true);
-        
+
         // after we set, then we should manage the 2 pending contexts
         assertEquals(2, listener.names.size());
 
@@ -62,7 +62,7 @@ public class CamelContextRegistryTest extends TestCase {
         camel1.stop();
         camel2.stop();
         camel3.stop();
-        
+
         assertEquals(0, listener.names.size());
     }
 }


[2/5] camel git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6bb3666c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6bb3666c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6bb3666c

Branch: refs/heads/master
Commit: 6bb3666cd06ed32125a82f2485723facaa76620a
Parents: ab750c9
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Nov 7 17:21:59 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 7 17:21:59 2014 +0100

----------------------------------------------------------------------
 .../org/apache/camel/component/file/GenericFileEndpoint.java     | 4 +---
 .../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 2 +-
 .../src/main/java/org/apache/camel/util/JsonSchemaHelper.java    | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6bb3666c/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
index 3b61ab6..b3e96e7 100644
--- a/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
@@ -320,7 +320,7 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
     }
 
     public Set<PosixFilePermission> getPermissions() {
-        Set<PosixFilePermission> permissions = new HashSet<>();
+        Set<PosixFilePermission> permissions = new HashSet<PosixFilePermission>();
         if (ObjectHelper.isEmpty(chmod)) {
             return permissions;
         }
@@ -364,8 +364,6 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
         return permissions;
     }
 
-
-
     public boolean isNoop() {
         return noop;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6bb3666c/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index b3f6ff3..5738381 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1154,7 +1154,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(json);
 
             // selected rows to use for answer
-            Map<String, String[]> selected = new LinkedHashMap<>();
+            Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
 
             // insert values from uri
             Map<String, Object> options = URISupport.parseParameters(u);

http://git-wip-us.apache.org/repos/asf/camel/blob/6bb3666c/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
index 6ce3a34..8690939 100644
--- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
@@ -126,7 +126,7 @@ public final class JsonSchemaHelper {
         for (int i = 2; i < lines.length; i++) {
             String line = lines[i];
 
-            Map<String, String> row = new LinkedHashMap<>();
+            Map<String, String> row = new LinkedHashMap<String, String>();
             Matcher matcher = PATTERN.matcher(line);
             // the first key is the name of the option
             String key = "name";