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/14 17:24:27 UTC
[3/3] camel git commit: [CAMEL-8000] Remove
DefaultCamelContextRegistry.clear()
[CAMEL-8000] Remove DefaultCamelContextRegistry.clear()
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/01481234
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/01481234
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/01481234
Branch: refs/heads/master
Commit: 014812341175e3ed3868a7272c33a330baebcd9f
Parents: afb0831
Author: Thomas Diesler <th...@jboss.com>
Authored: Mon Nov 10 14:58:53 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Nov 14 17:22:28 2014 +0100
----------------------------------------------------------------------
.../camel/impl/DefaultCamelContextRegistry.java | 16 ++++----
.../camel/spi/CamelContextRegistryTest.java | 41 +++++++++++---------
2 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/01481234/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 e578a5f..75a2f5f 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
@@ -26,7 +26,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The default {@link CamelContextRegistry}
+ * The default {@link CamelContextRegistry}.
+ *
+ * This implementation gives package protected access to add/remove camel contexts
+ * to the camel runtime. Clients are not expected to manage the set of registered contexts.
+ *
+ * Registered listeners are owned by the client which registered the listener.
+ * Neither the camel runtime nor non-owning clients can control the set of registered listeners.
*/
public final class DefaultCamelContextRegistry implements CamelContextRegistry {
@@ -35,14 +41,6 @@ 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/01481234/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 eec9263..a702254 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
@@ -20,9 +20,9 @@ import java.util.ArrayList;
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 {
@@ -42,8 +42,6 @@ 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();
@@ -52,21 +50,26 @@ public class CamelContextRegistryTest extends TestCase {
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());
+ try {
+ 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());
+
+ } finally {
+ CamelContextRegistry.INSTANCE.removeListener(listener, true);
+ }
}
}