当我尝试通过包含sessionConfig的文件中存在的索引获取sessionconfig时(在我们的例子中" 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
我在前两个sessionID中以不同的顺序获得会话:
get session id FIX.4.2:client1->server12
get session id FIX.4.2:client1->server1
get session id FIX.4.2:badis->server
我用来加载会话并打印它们的代码 我不知道在文件中加载不同的订单以及加载后是否正常,或者我的配置文件有问题。
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));
}
感谢您的帮助。
答案 0 :(得分:1)
会话未按顺序排列,因为SessionID-&gt;会话存储在HashMap中并在getSessions()方法上转换为List。
来自SessionConnector的(SocketInitiator的超类)
public ArrayList<SessionID> getSessions() {
return new ArrayList<SessionID>(sessions.keySet());
}
(提醒一下,HashMap不保证put()调用的顺序。你需要LinkedHashMap。)
除了修改核心代码之外,还有一个建议是添加一个属性,它将是一个有序的sessionID列表,并遍历该属性并在getSessionMap()中查找