Skip to content

Commit

Permalink
optimize ReconnectTimerTask's log output (#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 carryxyh committed Jan 8, 2019
1 parent e632504 commit 2cbc83f
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 2cbc83f

Please sign in to comment.