QuickFIX/J:如何检测连接何时失败? [英] QuickFIX/J: how to detect when connection fails?

查看:199
本文介绍了QuickFIX/J:如何检测连接何时失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过Initiator.start()方法使用SSL将启动器连接到FIX服务器时,它将启动一个单独的线程来建立连接.现在当失败时,例如由于SSL握手问题或服务器连接问题,该错误被丢弃到日志中,但是似乎无法将其捕获在代码中并进行管理.错误发生时如何检测/捕获?

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.

我在start方法周围有一个try-catch,但是由于异常发生在另一个线程中,因此无法捕获它.

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

推荐答案

您应在应用程序中实现quickfix.SessionStateListener接口.

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

在您的情况下,应调用onDisconnect()回调.

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

顺便说一下:围绕Initiator的start()方法的try-catch只会捕获在启动过程中发生的异常,例如配置错误.

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.

这篇关于QuickFIX/J:如何检测连接何时失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆