b-user
b-user

Reputation: 117

QuickFIX/J - Update an Acceptor session during runtime

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.

  1. I create a Bean to initialise the ThreadSocketAcceptor then I add a SessionProvider. The application listens all the connections for FIX.4.2 sessions.
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)
                );
  1. The application is running and during the runtime, I build the session settings and add the dynamic session
DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(serverApplication, serverMessageStoreFactory, serverLogFactory, serverMessageFactory);
                SessionSettings sessionSettings = buildSessionSettings(session.get(), sessionID);
                Session quickfixSession = defaultSessionFactory.create(sessionID, sessionSettings);
                threadedSocketAcceptor.addDynamicSession(quickfixSession);
  1. OnLogon, I send a query to my database to know if the session is stored in my own table. If it is not present, I log out the session.

[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

Answers (1)

Christoph John
Christoph John

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

Related Questions