[
https://issues.apache.org/jira/browse/DIRMINA-1071?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16174754#comment-16174754
]
Emmanuel Lecharny commented on DIRMINA-1071:
--------------------------------------------
Don't do that... You are going to block a thread for a long periof of time,
killing your server.
This is an Asynchronous framework, sor don't wait for a response, control the
delay before your server should consider the client has not answered.
Typically, when you send a message to the client, and if your protocol expects
a response from it, you just have to wait for a {{messageReceived}} event
corresponding to the client's response to arrive. Assuming it may takes a few
seconds, or even minutes, leverage the {{sessionIdle}} event that is sent every
second to your application : if you expect a response in the next 20 seconds
max, then after having received 20 {{sessionIdle}} events, you should consider
your client hasn't properly received the message.
Now, I assume you are using {{UDP}}, because otherwise, with {{TCP}}, the
client will always receive the message (unless it get disconnected brutally,
but in this case, that's not really a problem).
> ReadFuture.awaitUninterruptibly(20, TimeUnit.SECONDS) is no use
> ---------------------------------------------------------------
>
> Key: DIRMINA-1071
> URL: https://issues.apache.org/jira/browse/DIRMINA-1071
> Project: MINA
> Issue Type: Bug
> Affects Versions: 2.0.16
> Reporter: 西城
> Attachments: N8@`F_%~AEU2MYVTE]IG~IY.png
>
>
> Describe my problem:i want to send message to client for three times, when
> the first time I send to client,but client doesn't answer ,So I try to send
> again,When the second time I send,I can receive the answer ,But my core is
> struck in ReadFuture.awaitUninterruptibly(20, TimeUnit.SECONDS) until
> cancel.That is my code,Thanks to answer.
> if (future.isWritten()) {
> log.debug("成功发送数据" + protocolMsgVO.toByteString());
> ReadFuture readFuture = session.read();
> BaseProtocolMsgVO msgReceive = null;
> // 等待数据读取完成 等待10s 如果没有返回 关掉连接
> if (readFuture.awaitUninterruptibly(20,
> TimeUnit.SECONDS)) {
> msgReceive = (BaseProtocolMsgVO)
> readFuture.getMessage();
> } else {
> session.getConfig().setUseReadOperation(false);
> // 设置为不需要读取数据
> if(count >= 3){
> log.info("重发超过三次,断开连接");
> // 关掉连接
> session.closeNow();
> throw new BusiException("读取设备响应数据超时");
> }else{
> log.info("重发次数:"+count);
>
> session.getConfig().setUseReadOperation(false); // 设置为不需要读取数据
> sendCmd(deviceIp, protocolMsgVO,
> pk_user, openid);
> }
>
> }
> //重置重发次数
> session.setAttribute("count", 0);
> if (readFuture.getException() != null) {
> session.getConfig().setUseReadOperation(false);
> // 设置为不需要读取数据
> // 关掉连接
> session.closeNow();
> throw new
> BusiException(readFuture.getException().getMessage());
> }
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)