[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 <davscl...@apache.org>
Authored: Fri Nov 7 17:32:05 2014 +0100
Committer: Claus Ibsen <davscl...@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());
     }
 }

Reply via email to