java - SocketInitiator getSession give session not at the same order as in the config file -
when try sessionconfig index exist in file contains sessionconfig (in our case "initiatorsettings.cfg")
[default] filestorepath=data filelogpath=log heartbtint=30 reconnectinterval=5 [session] sessionname=badisinit1 beginstring=fix.4.2 sendercompid=client1 targetcompid=server1 connectiontype=initiator socketconnectport=9878 socketconnecthost=localhost usedatadictionary=n [session] sessionname=init0badis beginstring=fix.4.2 sendercompid=client1 targetcompid=server12 connectiontype=initiator socketconnectport=9878 socketconnecthost=localhost usedatadictionary=n [session] sessionname=test211 beginstring=fix.4.2 sendercompid=badis targetcompid=server connectiontype=initiator socketconnectport=9878 socketconnecthost=localhost usedatadictionary=n
i sessions in different orders, in first 2 sessionids:
session id fix.4.2:client1->server12 session id fix.4.2:client1->server1 session id fix.4.2:badis->server
there code have used load sessions , print them don't know if normal have different orders in file , after load them, or there wrong config file ..
sessionsettings sessionsettings = new sessionsettings("initiatorsettings.cfg"); applicationimp mainapplication = new applicationimp(); filestorefactory filestorefactory = new filestorefactory(sessionsettings); filelogfactory logfactory = new filelogfactory(sessionsettings); messagefactory messagefactory = new defaultmessagefactory(); socketinitiator = new socketinitiator( mainapplication, filestorefactory, this.sessionsettings, logfactory, messagefactory); for(int i=0;i<socketinitiator.getsessions().size();i++) { system.out.println("get session id "+socketinitiator.getsessions().get(i)); }
thanks help.
it normal behavior sessions not ordered sessionid->sessions stored in hashmap , converted list on getsessions() method.
from sessionconnector (superclass of socketinitiator)
public arraylist<sessionid> getsessions() { return new arraylist<sessionid>(sessions.keyset()); }
(as reminder, hashmap doesn't guarantee order of put() call. need linkedhashmap that.)
a suggestion aside modifying core code, add property ordered list of sessionids , iterate through property , in getsessionmap()
Comments
Post a Comment