I didn't see any way to attach my svn diff file, so here is its contents:
Index: core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java
===================================================================
— core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java (revision 12810)
+++ core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java (revision 15471)
@@ -82,6 +82,7 @@
protected void createSessionInitiators(EventHandlingStrategy eventHandlingStrategy) throws ConfigError {
try {
createSessions();
+ SessionSettings settings = getSettings();
for (Session session : getSessionMap().values())
{
SessionID sessionID = session.getSessionID();
int reconnectingInterval = getReconnectIntervalInSeconds(sessionID);
@@ -91,6 +92,23 @@
throw new ConfigError("Must specify at least one socket address");
}
+ // Check if use of socket local/bind address
+ SocketAddress localAddress = null;
+ if (settings.isSetting(sessionID, Initiator.SETTING_SOCKET_LOCAL_HOST)) {
+ String host = settings.getString(sessionID, Initiator.SETTING_SOCKET_LOCAL_HOST);
+ if ("localhost".equals(host))
{
+ throw new ConfigError(Initiator.SETTING_SOCKET_LOCAL_HOST + " cannot be \"localhost\"!");
+ }
+ int port = 0;
+ if (settings.isSetting(sessionID, Initiator.SETTING_SOCKET_LOCAL_PORT))
{
+ port = (int) settings.getLong(sessionID, Initiator.SETTING_SOCKET_LOCAL_PORT);
+ }
+ localAddress = ProtocolFactory.createSocketAddress(TransportType.SOCKET, host, port);
+ if (log.isInfoEnabled())
{
+ log.info("Using initiator local host: " + localAddress);
+ }
+ }
+
NetworkingOptions networkingOptions = new NetworkingOptions(getSettings()
.getSessionProperties(sessionID));
@@ -103,7 +121,7 @@
String keyStorePassword = SSLSupport.getKeystorePasswd(getSettings(), sessionID);
IoSessionInitiator ioSessionInitiator = new IoSessionInitiator(session,
- socketAddresses, reconnectingInterval, getScheduledExecutorService(),
+ socketAddresses, localAddress, reconnectingInterval, getScheduledExecutorService(),
networkingOptions, eventHandlingStrategy, getIoFilterChainBuilder(),
sslEnabled, keyStoreName, keyStorePassword);
Index: core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java
===================================================================
— core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java (revision 12810)
+++ core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java (revision 15471)
@@ -56,13 +56,13 @@
private Future<?> reconnectFuture;
public IoSessionInitiator(Session fixSession, SocketAddress[] socketAddresses,
private static class ConnectTask implements Runnable {
private final SocketAddress[] socketAddresses;
+ private final SocketAddress localAddress;
private final IoConnector ioConnector;
private final Session fixSession;
private final long reconnectIntervalInMillis;
@@ -87,11 +88,12 @@
private ConnectFuture connectFuture;
public ConnectTask(boolean sslEnabled, SocketAddress[] socketAddresses,
- IoFilterChainBuilder userIoFilterChainBuilder, Session fixSession,
+ SocketAddress localAddress, IoFilterChainBuilder userIoFilterChainBuilder, Session fixSession,
long reconnectIntervalInMillis, NetworkingOptions networkingOptions,
EventHandlingStrategy eventHandlingStrategy, String keyStoreName,
String keyStorePassword) throws ConfigError, GeneralSecurityException {
this.socketAddresses = socketAddresses;
+ this.localAddress = localAddress;
this.fixSession = fixSession;
this.reconnectIntervalInMillis = reconnectIntervalInMillis;
this.keyStoreName = keyStoreName;
@@ -136,7 +138,11 @@
lastReconnectAttemptTime = SystemTime.currentTimeMillis();
SocketAddress nextSocketAddress = getNextSocketAddress();
try {
- connectFuture = ioConnector.connect(nextSocketAddress, ioHandler);
+ if (localAddress == null)
{
+ connectFuture = ioConnector.connect(nextSocketAddress, ioHandler);
+ }
else
{
+ connectFuture = ioConnector.connect(nextSocketAddress, localAddress, ioHandler);
+ }
pollConnectFuture();
} catch (Throwable e)
{
handleConnectException(e);
@@ -167,7 +173,7 @@
e = e.getCause();
}
if ((e instanceof IOException) && (e.getMessage() != null))
{
- fixSession.getLog().onEvent(e.getMessage());
+ fixSession.getLog().onEvent(e.getClass().getName() + ": " + e.getMessage());
}
else
{
String msg = "Exception during connection";
LogUtil.logThrowable(fixSession.getLog(), msg, e);
Index: core/src/main/java/quickfix/Initiator.java
===================================================================
--- core/src/main/java/quickfix/Initiator.java (revision 12810)
+++ core/src/main/java/quickfix/Initiator.java (revision 15471)
@@ -51,4 +51,20 @@
* @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
*/
public static final String SETTING_SOCKET_CONNECT_PORT = "SocketConnectPort";
-}
\ No newline at end of file
+
+ /**
+ * Initiator setting for local/bind host. Only valid when session connection
+ * type is "initiator".
+ *
+ * @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
+ */
+ public static final String SETTING_SOCKET_LOCAL_HOST = "SocketLocalHost";
+
+ /**
+ * Initiator setting for local/bind port. Only valid when session connection
+ * type is "initiator".
+ *
+ * @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
+ */
+ public static final String SETTING_SOCKET_LOCAL_PORT = "SocketLocalPort";
+}
|
And of course I included the wrong diff Here's the correct one (just delete the previous):
Index: core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java
===================================================================
— core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java (revision 926)
+++ core/src/main/java/quickfix/mina/initiator/AbstractSocketInitiator.java (working copy)
@@ -82,6 +82,7 @@
protected void createSessionInitiators(EventHandlingStrategy eventHandlingStrategy) throws ConfigError {
try {
createSessions();
+ SessionSettings settings = getSettings();
for (Session session : getSessionMap().values())
{
SessionID sessionID = session.getSessionID();
int reconnectingInterval = getReconnectIntervalInSeconds(sessionID);
@@ -91,6 +92,23 @@
throw new ConfigError("Must specify at least one socket address");
}
+ // Check if use of socket local/bind address
+ SocketAddress localAddress = null;
+ if (settings.isSetting(sessionID, Initiator.SETTING_SOCKET_LOCAL_HOST)) {
+ String host = settings.getString(sessionID, Initiator.SETTING_SOCKET_LOCAL_HOST);
+ if ("localhost".equals(host))
{
+ throw new ConfigError(Initiator.SETTING_SOCKET_LOCAL_HOST + " cannot be \"localhost\"!");
+ }
+ int port = 0;
+ if (settings.isSetting(sessionID, Initiator.SETTING_SOCKET_LOCAL_PORT))
{
+ port = (int) settings.getLong(sessionID, Initiator.SETTING_SOCKET_LOCAL_PORT);
+ }
+ localAddress = ProtocolFactory.createSocketAddress(TransportType.SOCKET, host, port);
+ if (log.isInfoEnabled())
{
+ log.info("Using initiator local host: " + localAddress);
+ }
+ }
+
NetworkingOptions networkingOptions = new NetworkingOptions(getSettings()
.getSessionProperties(sessionID));
@@ -103,7 +121,7 @@
String keyStorePassword = SSLSupport.getKeystorePasswd(getSettings(), sessionID);
IoSessionInitiator ioSessionInitiator = new IoSessionInitiator(session,
- socketAddresses, reconnectingInterval, getScheduledExecutorService(),
+ socketAddresses, localAddress, reconnectingInterval, getScheduledExecutorService(),
networkingOptions, eventHandlingStrategy, getIoFilterChainBuilder(),
sslEnabled, keyStoreName, keyStorePassword);
Index: core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java
===================================================================
— core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java (revision 926)
+++ core/src/main/java/quickfix/mina/initiator/IoSessionInitiator.java (working copy)
@@ -56,13 +56,13 @@
private Future<?> reconnectFuture;
public IoSessionInitiator(Session fixSession, SocketAddress[] socketAddresses,
private static class ConnectTask implements Runnable {
private final SocketAddress[] socketAddresses;
+ private final SocketAddress localAddress;
private final IoConnector ioConnector;
private final Session fixSession;
private final long reconnectIntervalInMillis;
@@ -87,11 +88,12 @@
private ConnectFuture connectFuture;
public ConnectTask(boolean sslEnabled, SocketAddress[] socketAddresses,
- IoFilterChainBuilder userIoFilterChainBuilder, Session fixSession,
+ SocketAddress localAddress, IoFilterChainBuilder userIoFilterChainBuilder, Session fixSession,
long reconnectIntervalInMillis, NetworkingOptions networkingOptions,
EventHandlingStrategy eventHandlingStrategy, String keyStoreName,
String keyStorePassword) throws ConfigError, GeneralSecurityException {
this.socketAddresses = socketAddresses;
+ this.localAddress = localAddress;
this.fixSession = fixSession;
this.reconnectIntervalInMillis = reconnectIntervalInMillis;
this.keyStoreName = keyStoreName;
@@ -136,7 +138,11 @@
lastReconnectAttemptTime = SystemTime.currentTimeMillis();
SocketAddress nextSocketAddress = getNextSocketAddress();
try {
- connectFuture = ioConnector.connect(nextSocketAddress, ioHandler);
+ if (localAddress == null)
{
+ connectFuture = ioConnector.connect(nextSocketAddress, ioHandler);
+ }
else
{
+ connectFuture = ioConnector.connect(nextSocketAddress, localAddress, ioHandler);
+ }
pollConnectFuture();
} catch (Throwable e)
{
handleConnectException(e);
@@ -167,7 +173,7 @@
e = e.getCause();
}
if ((e instanceof IOException) && (e.getMessage() != null))
{
- fixSession.getLog().onEvent(e.getMessage());
+ fixSession.getLog().onEvent(e.getClass().getName() + ": " + e.getMessage());
}
else
{
String msg = "Exception during connection";
LogUtil.logThrowable(fixSession.getLog(), msg, e);
Index: core/src/main/java/quickfix/Initiator.java
===================================================================
--- core/src/main/java/quickfix/Initiator.java (revision 926)
+++ core/src/main/java/quickfix/Initiator.java (working copy)
@@ -51,4 +51,20 @@
* @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
*/
public static final String SETTING_SOCKET_CONNECT_PORT = "SocketConnectPort";
-}
\ No newline at end of file
+
+ /**
+ * Initiator setting for local/bind host. Only valid when session connection
+ * type is "initiator".
+ *
+ * @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
+ */
+ public static final String SETTING_SOCKET_LOCAL_HOST = "SocketLocalHost";
+
+ /**
+ * Initiator setting for local/bind port. Only valid when session connection
+ * type is "initiator".
+ *
+ * @see quickfix.SessionFactory#SETTING_CONNECTION_TYPE
+ */
+ public static final String SETTING_SOCKET_LOCAL_PORT = "SocketLocalPort";
+}
|