Skip to content

Commit

Permalink
optimize ReconnectTimerTask's log output (apache#3162)
Browse files Browse the repository at this point in the history
* optimize log output

* Separate logs for reconnect and close

* remove reconnect exception log
  • Loading branch information
kexianjun authored and khanimteyaz committed Jan 18, 2019
1 parent 77dbfbe commit b727493
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,26 @@ public class ReconnectTimerTask extends AbstractTimerTask {

@Override
protected void doTask(Channel channel) {
try {
Long lastRead = lastRead(channel);
Long now = now();
if (lastRead != null && now - lastRead > heartbeatTimeout) {
logger.warn("Close channel " + channel + ", because heartbeat read idle time out: "
+ heartbeatTimeout + "ms");
if (channel instanceof Client) {
try {
((Client) channel).reconnect();
} catch (Exception e) {
//do nothing
}
} else {
Long lastRead = lastRead(channel);
Long now = now();
if (lastRead != null && now - lastRead > heartbeatTimeout) {
if (channel instanceof Client) {
try {
logger.warn("Reconnect to remote channel " + channel.getRemoteAddress() + ", because heartbeat read idle time out: "
+ heartbeatTimeout + "ms");
((Client) channel).reconnect();
} catch (Throwable t) {
// do nothing
}
} else {
try {
logger.warn("Close channel " + channel + ", because heartbeat read idle time out: "
+ heartbeatTimeout + "ms");
channel.close();
} catch (Throwable t) {
logger.warn("Exception when close channel " + channel, t);
}
}
} catch (Throwable t) {
logger.warn("Exception when reconnect to remote channel " + channel.getRemoteAddress(), t);
}
}
}

0 comments on commit b727493

Please sign in to comment.