diff --git a/artio-core/src/main/java/uk/co/real_logic/artio/engine/EngineConfiguration.java b/artio-core/src/main/java/uk/co/real_logic/artio/engine/EngineConfiguration.java index 816f8c4f59..b8a0a11354 100644 --- a/artio-core/src/main/java/uk/co/real_logic/artio/engine/EngineConfiguration.java +++ b/artio-core/src/main/java/uk/co/real_logic/artio/engine/EngineConfiguration.java @@ -235,6 +235,7 @@ public final class EngineConfiguration extends CommonConfiguration implements Au public static final int DEFAULT_INITIAL_SEQUENCE_INDEX = 0; public static final int DEFAULT_CANCEL_ON_DISCONNECT_TIMEOUT_WINDOW_IN_MS = 0; + public static final long DEFAULT_INITIAL_CONNECTION_ID = (long)(Math.random() * Long.MAX_VALUE); private String host = null; private int port; @@ -324,6 +325,7 @@ public final class EngineConfiguration extends CommonConfiguration implements Au private long timeIndexReplayFlushIntervalInNs = DEFAULT_TIME_INDEX_FLUSH_INTERVAL_IN_NS; private CancelOnDisconnectOption cancelOnDisconnectOption = DO_NOT_CANCEL_ON_DISCONNECT_OR_LOGOUT; private int cancelOnDisconnectTimeoutWindowInMs = DEFAULT_CANCEL_ON_DISCONNECT_TIMEOUT_WINDOW_IN_MS; + private long initialConnectionId = DEFAULT_INITIAL_CONNECTION_ID; private EngineReproductionConfiguration reproductionConfiguration; private ReproductionMessageHandler reproductionMessageHandler = (connectionId, bytes) -> @@ -1306,6 +1308,18 @@ public EngineConfiguration cancelOnDisconnectTimeoutWindowInMs(final int cancelO return this; } + /** + * Sets the initial connectionId to start with. + * + * @param initialConnectionId initial connection id + * @return this + */ + public EngineConfiguration initialConnectionId(final long initialConnectionId) + { + this.initialConnectionId = initialConnectionId; + return this; + } + // --------------------- // END SETTERS // --------------------- @@ -2063,6 +2077,11 @@ public int reproductionReplayStream() return reproductionReplayStream; } + public long initialConnectionId() + { + return initialConnectionId; + } + // --------------------- // END GETTERS // --------------------- diff --git a/artio-core/src/main/java/uk/co/real_logic/artio/engine/framer/Framer.java b/artio-core/src/main/java/uk/co/real_logic/artio/engine/framer/Framer.java index 51962f31c2..120056130e 100644 --- a/artio-core/src/main/java/uk/co/real_logic/artio/engine/framer/Framer.java +++ b/artio-core/src/main/java/uk/co/real_logic/artio/engine/framer/Framer.java @@ -187,7 +187,7 @@ class Framer implements Agent, EngineEndPointHandler, ProtocolHandler private final DeadlineTimerWheel timerWheel; private final TimerEventHandler timerEventHandler; - private long nextConnectionId = (long)(Math.random() * Long.MAX_VALUE); + private long nextConnectionId; private FixPProtocol fixPProtocol; private AbstractFixPParser fixPParser; private AbstractFixPProxy fixPProxy; @@ -274,6 +274,7 @@ class Framer implements Agent, EngineEndPointHandler, ProtocolHandler this.acceptsFixP = configuration.acceptsFixP(); this.fixPContexts = fixPContexts; this.fixCounters = fixCounters; + this.nextConnectionId = configuration.initialConnectionId(); replyTimeoutInNs = TimeUnit.MILLISECONDS.toNanos(configuration.replyTimeoutInMs()); timerEventHandler = new TimerEventHandler(errorHandler); diff --git a/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderAndTargetSessionIdStrategy.java b/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderAndTargetSessionIdStrategy.java index ab37d50cb2..d496a283f7 100644 --- a/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderAndTargetSessionIdStrategy.java +++ b/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderAndTargetSessionIdStrategy.java @@ -152,6 +152,10 @@ private static final class CompositeKeyImpl implements CompositeKey private final char[] remoteCompID; private final int hashCode; + private final String localCompIDStr; + private final String remoteCompIDStr; + private final String compositeKeyStr; + private CompositeKeyImpl( final char[] localCompID, final int localCompIDLength, @@ -161,6 +165,9 @@ private CompositeKeyImpl( this.localCompID = Arrays.copyOf(localCompID, localCompIDLength); this.remoteCompID = Arrays.copyOf(remoteCompID, remoteCompIDLength); hashCode = hash(this.localCompID, this.remoteCompID); + this.localCompIDStr = new String(this.localCompID); + this.remoteCompIDStr = new String(this.remoteCompID); + compositeKeyStr = compositKey(); } private CompositeKeyImpl(final byte[] localCompID, final byte[] remoteCompID) @@ -168,6 +175,9 @@ private CompositeKeyImpl(final byte[] localCompID, final byte[] remoteCompID) this.localCompID = CodecUtil.fromBytes(localCompID); this.remoteCompID = CodecUtil.fromBytes(remoteCompID); hashCode = hash(this.localCompID, this.remoteCompID); + this.localCompIDStr = new String(this.localCompID); + this.remoteCompIDStr = new String(this.remoteCompID); + compositeKeyStr = compositKey(); } private int hash(final char[] senderCompID, final char[] targetCompID) @@ -194,7 +204,7 @@ public boolean equals(final Object obj) return false; } - public String toString() + private String compositKey() { return "CompositeKey{" + "localCompId=" + localCompId() + @@ -202,9 +212,14 @@ public String toString() '}'; } + public String toString() + { + return compositeKeyStr; + } + public String localCompId() { - return new String(localCompID); + return localCompIDStr; } public String localSubId() @@ -219,7 +234,7 @@ public String localLocationId() public String remoteCompId() { - return new String(remoteCompID); + return remoteCompIDStr; } public String remoteSubId() diff --git a/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderTargetAndSubSessionIdStrategy.java b/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderTargetAndSubSessionIdStrategy.java index de498edba9..048e2673be 100644 --- a/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderTargetAndSubSessionIdStrategy.java +++ b/artio-core/src/main/java/uk/co/real_logic/artio/session/SenderTargetAndSubSessionIdStrategy.java @@ -164,6 +164,11 @@ private static final class CompositeKeyImpl implements CompositeKey private final char[] remoteCompID; private final int hashCode; + private final String localCompIDStr; + private final String localSubIDStr; + private final String remoteCompIDStr; + private final String compositeKeyStr; + private CompositeKeyImpl( final char[] localCompID, final int localCompIDLength, @@ -176,6 +181,10 @@ private CompositeKeyImpl( this.remoteCompID = Arrays.copyOf(remoteCompID, remoteCompIDLength); this.localSubID = Arrays.copyOf(localSubID, localSubIDLength); hashCode = hash(this.localCompID, this.localSubID, this.remoteCompID); + this.localCompIDStr = new String(this.localCompID); + this.localSubIDStr = new String(this.localSubID); + this.remoteCompIDStr = new String(this.remoteCompID); + compositeKeyStr = compositKey(); } private CompositeKeyImpl( @@ -187,6 +196,10 @@ private CompositeKeyImpl( this.localSubID = CodecUtil.fromBytes(localSubID); this.remoteCompID = CodecUtil.fromBytes(remoteCompID); hashCode = hash(this.localCompID, this.localSubID, this.remoteCompID); + this.localCompIDStr = new String(this.localCompID); + this.localSubIDStr = new String(this.localSubID); + this.remoteCompIDStr = new String(this.remoteCompID); + compositeKeyStr = compositKey(); } private int hash(final char[] localCompID, final char[] localSubID, final char[] remoteCompID) @@ -215,7 +228,7 @@ public boolean equals(final Object obj) return false; } - public String toString() + private String compositKey() { return "CompositeKey{" + "localCompId=" + localCompId() + @@ -224,14 +237,19 @@ public String toString() '}'; } + public String toString() + { + return compositeKeyStr; + } + public String localCompId() { - return new String(localCompID); + return localCompIDStr; } public String localSubId() { - return new String(localSubID); + return localSubIDStr; } public String localLocationId() @@ -241,7 +259,7 @@ public String localLocationId() public String remoteCompId() { - return new String(remoteCompID); + return remoteCompIDStr; } public String remoteSubId()