Updated Branches: refs/heads/camel-2.10.x f0749e913 -> 224b675a6 refs/heads/camel-2.11.x 5e8235a80 -> 736db12a2 refs/heads/master 651709060 -> b2a4b54bc
CAMEL-6443: Fixed quickfix engines to only be reused when they are properly started, to avoid using broken engines. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b2a4b54b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b2a4b54b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b2a4b54b Branch: refs/heads/master Commit: b2a4b54bc1da56e0cd71316cdd1d296e1582e92d Parents: 6517090 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jul 23 10:48:23 2013 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jul 23 10:48:23 2013 +0200 ---------------------------------------------------------------------- .../component/quickfixj/QuickfixjComponent.java | 20 +++++++++++++++++++- .../quickfixj/QuickfixjComponentTest.java | 18 +++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b2a4b54b/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java b/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java index 6267613..9e9c7f1 100644 --- a/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java +++ b/components/camel-quickfix/src/main/java/org/apache/camel/component/quickfixj/QuickfixjComponent.java @@ -36,6 +36,7 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe private final Object engineInstancesLock = new Object(); private final Map<String, QuickfixjEngine> engines = new HashMap<String, QuickfixjEngine>(); + private final Map<String, QuickfixjEngine> provisionalEngines = new HashMap<String, QuickfixjEngine>(); private final Map<String, QuickfixjEndpoint> endpoints = new HashMap<String, QuickfixjEndpoint>(); private MessageStoreFactory messageStoreFactory; @@ -53,6 +54,9 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe if (endpoint == null) { engine = engines.get(remaining); if (engine == null) { + engine = provisionalEngines.get(remaining); + } + if (engine == null) { QuickfixjConfiguration configuration = configurations.get(remaining); if (configuration != null) { SessionSettings settings = configuration.createSessionSettings(); @@ -60,12 +64,15 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe } else { engine = new QuickfixjEngine(uri, remaining, messageStoreFactory, logFactory, messageFactory); } - engines.put(remaining, engine); // only start engine if CamelContext is already started, otherwise the engines gets started // automatic later when CamelContext has been started using the StartupListener if (getCamelContext().getStatus().isStarted()) { startQuickfixjEngine(engine); + engines.put(remaining, engine); + } else { + // engines to be started later + provisionalEngines.put(remaining, engine); } } @@ -99,6 +106,7 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe protected void doShutdown() throws Exception { // cleanup when shutting down engines.clear(); + provisionalEngines.clear(); endpoints.clear(); super.doShutdown(); } @@ -113,6 +121,11 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe return Collections.unmodifiableMap(engines); } + // Test Support + Map<String, QuickfixjEngine> getProvisionalEngines() { + return Collections.unmodifiableMap(provisionalEngines); + } + public void setMessageFactory(MessageFactory messageFactory) { this.messageFactory = messageFactory; } @@ -147,6 +160,11 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe for (QuickfixjEngine engine : engines.values()) { startQuickfixjEngine(engine); } + for (Map.Entry<String, QuickfixjEngine> entry : provisionalEngines.entrySet()) { + startQuickfixjEngine(entry.getValue()); + engines.put(entry.getKey(), entry.getValue()); + provisionalEngines.remove(entry.getKey()); + } } } } http://git-wip-us.apache.org/repos/asf/camel/blob/b2a4b54b/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java b/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java index 0193ba7..ca3ab79 100644 --- a/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java +++ b/components/camel-quickfix/src/test/java/org/apache/camel/component/quickfixj/QuickfixjComponentTest.java @@ -162,21 +162,24 @@ public class QuickfixjComponentTest { writeSettings(); Endpoint e1 = component.createEndpoint(getEndpointUri(settingsFile.getName(), null)); - assertThat(component.getEngines().size(), is(1)); - assertThat(component.getEngines().get(settingsFile.getName()), is(notNullValue())); - assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(false)); + assertThat(component.getProvisionalEngines().size(), is(1)); + assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue())); + assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false)); assertThat(((QuickfixjEndpoint)e1).getSessionID(), is(nullValue())); // Should used cached QFJ engine Endpoint e2 = component.createEndpoint(getEndpointUri(settingsFile.getName(), sessionID)); - assertThat(component.getEngines().size(), is(1)); - assertThat(component.getEngines().get(settingsFile.getName()), is(notNullValue())); - assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(false)); + assertThat(component.getProvisionalEngines().size(), is(1)); + assertThat(component.getProvisionalEngines().get(settingsFile.getName()), is(notNullValue())); + assertThat(component.getProvisionalEngines().get(settingsFile.getName()).isStarted(), is(false)); assertThat(((QuickfixjEndpoint)e2).getSessionID(), is(sessionID)); // will start the component camelContext.start(); + + assertThat(component.getProvisionalEngines().size(), is(0)); + assertThat(component.getEngines().size(), is(1)); assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(true)); // Move these too an endpoint testcase if one exists @@ -331,7 +334,8 @@ public class QuickfixjComponentTest { component.createEndpoint(getEndpointUri(settingsFile.getName(), null)); - component.start(); + // will start the component + camelContext.start(); assertThat(component.getEngines().size(), is(1)); QuickfixjEngine engine = component.getEngines().values().iterator().next();