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/224b675a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/224b675a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/224b675a Branch: refs/heads/camel-2.10.x Commit: 224b675a6742bbfbb7ba422d99a18afd155c955c Parents: f0749e9 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:49:25 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/224b675a/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 01be138..48a2325 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; @@ -54,6 +55,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(); @@ -61,12 +65,15 @@ public class QuickfixjComponent extends DefaultComponent implements StartupListe } else { engine = new QuickfixjEngine(uri, remaining, forcedShutdown, 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); } } @@ -100,6 +107,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(); } @@ -114,6 +122,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; } @@ -145,6 +158,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/224b675a/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 f0239f2..ad939e6 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 @@ -329,7 +332,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();