Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc3 for class SenderAndTargetSessionIdStrategy.CompositeKeyImpl and SenderTargetAndSubSessionIdStrategy.CompositeKeyImpl, and externalize initial ConnectionId to EngineConfiguration #500

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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
// ---------------------
Expand Down Expand Up @@ -2063,6 +2077,11 @@ public int reproductionReplayStream()
return reproductionReplayStream;
}

public long initialConnectionId()
{
return initialConnectionId;
}

// ---------------------
// END GETTERS
// ---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -161,13 +165,19 @@ 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)
{
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)
Expand All @@ -194,17 +204,22 @@ public boolean equals(final Object obj)
return false;
}

public String toString()
private String compositKey()
{
return "CompositeKey{" +
"localCompId=" + localCompId() +
", remoteCompId=" + remoteCompId() +
'}';
"localCompId=" + localCompId() +
", remoteCompId=" + remoteCompId() +
'}';
}

public String toString()
{
return compositeKeyStr;
}

public String localCompId()
{
return new String(localCompID);
return localCompIDStr;
}

public String localSubId()
Expand All @@ -219,7 +234,7 @@ public String localLocationId()

public String remoteCompId()
{
return new String(remoteCompID);
return remoteCompIDStr;
}

public String remoteSubId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -215,23 +228,28 @@ public boolean equals(final Object obj)
return false;
}

public String toString()
private String compositKey()
{
return "CompositeKey{" +
"localCompId=" + localCompId() +
", localSubId=" + localSubId() +
", remoteCompId=" + remoteCompId() +
'}';
"localCompId=" + localCompId() +
", localSubId=" + localSubId() +
", remoteCompId=" + remoteCompId() +
'}';
}

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()
Expand All @@ -241,7 +259,7 @@ public String localLocationId()

public String remoteCompId()
{
return new String(remoteCompID);
return remoteCompIDStr;
}

public String remoteSubId()
Expand Down