序言
- 我正在使用TooTallNate / Java-WebSocket很棒的库来实现Websocket客户端。
- 我正在使用rholder / guava-retrying实现重试机制。
- 我不能使用Spring框架。
目标
我想实现一种重试机制以获得更多可用性。
描述情况
引发异常时,将调用onError。如果发生致命错误,则会调用onClose并最终关闭套接字。
@Subcomponent.Factory
必须从另一个线程调用reconnect方法以进行清理。
@Override
public void onClose( int code,String reason,boolean remote ) {
// The codecodes are documented in class org.java_websocket.framing.CloseFrame
System.out.println( "Connection closed by " + ( remote ? "remote peer" : "us" ) + " Code: " + code + " Reason: " + reason );
}
@Override
public void onError( Exception ex ) {
ex.printStackTrace();
// if the error is fatal then onClose will be called additionally
}
问题
我无法实现从其他线程调用onClose的机制。