我正在尝试使用 MINA 2.0 RC1 在基于多路分解的客户端应用程序中执行同步写入/读取,但它似乎卡住了。这是我的代码:
public boolean login(final String username, final String password) {
// block inbound messages
session.getConfig().setUseReadOperation(true);
// send the login request
final LoginRequest loginRequest = new LoginRequest(username, password);
final WriteFuture writeFuture = session.write(loginRequest);
writeFuture.awaitUninterruptibly();
if (writeFuture.getException() != null) {
session.getConfig().setUseReadOperation(false);
return false;
}
// retrieve the login response
final ReadFuture readFuture = session.read();
readFuture.awaitUninterruptibly();
if (readFuture.getException() != null) {
session.getConfig().setUseReadOperation(false);
return false;
}
// stop blocking inbound messages
session.getConfig().setUseReadOperation(false);
// determine if the login info provided was valid
final LoginResponse loginResponse = (LoginResponse)readFuture.getMessage();
return loginResponse.getSuccess();
}
我可以在服务器端看到检索到 LoginRequest 对象,并发送了一条 LoginResponse 消息。在客户端,DemuxingProtocolCodecFactory
收到响应,但在输入一些日志记录后,我可以看到客户端卡在对 readFuture.awaitUninterruptibly()
的调用上。
根据我自己的代码,我一辈子都弄不明白为什么它会卡在这里。我在 session 配置中正确地将读取操作设置为 true,这意味着应该阻止消息。但是,当我尝试同步读取响应消息时,消息似乎不再存在。
关于为什么这对我不起作用的任何线索?
最佳答案
这对我不起作用的原因是我的代码中其他地方存在问题,我愚蠢地忽略了实现消息响应编码器/解码器。啊。无论如何,我的问题中的代码在我修复后立即起作用。
关于java - 米娜 : Performing synchronous write requests/read responses,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2550444/