Reputation: 117
I am using QuickFIX/J with Spring esanchezros/quickfixj-spring-boot-starter and I am trying to add a new session during the application runtime.
ThreadedSocketAcceptor threadedSocketAcceptor = new ThreadedSocketAcceptor(serverApplication, serverMessageStoreFactory, serverSessionSettings,
serverLogFactory, serverMessageFactory);
SessionID anySession = new SessionID(BEGINSTRING_FIX42, WILDCARD, WILDCARD);
threadedSocketAcceptor.setSessionProvider(
new InetSocketAddress("0.0.0.0", 9878),
new DynamicAcceptorSessionProvider(serverSessionSettings, anySession, serverApplication, serverMessageStoreFactory,
serverLogFactory, serverMessageFactory)
);
DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(serverApplication, serverMessageStoreFactory, serverLogFactory, serverMessageFactory);
SessionSettings sessionSettings = buildSessionSettings(session.get(), sessionID);
Session quickfixSession = defaultSessionFactory.create(sessionID, sessionSettings);
threadedSocketAcceptor.addDynamicSession(quickfixSession);
[4.] Update the session settings : removeDynamicSession (with logout and close) then addDynamicSession.
Is it the good way to proceed? Because, I can't update the settings for my session.
Upvotes: 0
Views: 932
Reputation: 3283
One (very) ugly way to do it is this:
Logout()
, disconnect()
and close()
the old session.
Remove the dynamic session and clean up the old session settings:
sessionConnector.removeDynamicSession( sessionID );
try {
Dictionary dictionary = sessionConnector.getSettings().get( sessionID );
Map<Object, Object> map = dictionary.toMap();
Set<Object> keySet = map.keySet();
for ( Object object : keySet ) {
sessionConnector.getSettings().removeSetting( sessionID, object.toString() );
}
} catch ( ConfigError e ) {
// ignore
}
Then add the new session settings:
acceptor.getSettings().set( sessionID, newSessionSettings );
Then add the new session:
Class<?> clazz = acceptor.getClass().getSuperclass().getSuperclass();
Method createSessionMethod = clazz.getDeclaredMethod( "createSession", SessionID.class );
createSessionMethod.setAccessible( true );
Session newSession = ( Session )createSessionMethod.invoke( acceptor, sessionID );
acceptor.addDynamicSession( newSession );
Hope that works for you. For me it did. ;)
Upvotes: 1