QuickFIX/J: how to detect when connection fails?

半城伤御伤魂 提交于 2020-07-09 11:56:06

问题


When I connect an initiator to a FIX server using SSL via the initiator.start() method, it fires up a separate thread to establish the connection. Now when this fails e.g. due to an SSL handshake issue or an issue with server connectivity, the error is thrown out to the logs but can't seemingly be trapped in code and managed. How can I detect/trap when the error happens?

Disconnecting: Socket exception (<server ip>): java.net.SocketException: Connection reset.

At the bottom of the stack trace is the threadpool executor.

I have a try-catch around the start method but as the exception happens in another thread it can't catch it.


回答1:


You should implement the quickfix.SessionStateListener interface in your application.

The onDisconnect() callback should get called in your case.

By the way: the try-catch around your Initiator's start() method will only catch Exceptions that occur during the startup process, e.g. configuration errors.



来源:https://stackoverflow.com/questions/61868398/quickfix-j-how-to-detect-when-connection-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!