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 2013/07/23 10:50:07 UTC
[2/3] git commit: CAMEL-6443: Fixed quickfix engines to only be
reused when they are properly started, to avoid using broken engines.
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/736db12a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/736db12a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/736db12a
Branch: refs/heads/camel-2.11.x
Commit: 736db12a2915841b4c21cb2e6c285b00c31cd508
Parents: 5e8235a
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 23 10:48:23 2013 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 23 10:49:11 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/736db12a/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/736db12a/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();