Skip to content

Commit

Permalink
log
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlinhui committed Mar 7, 2022
1 parent 8ede724 commit 7ecfcf7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ public void initChannel(SocketChannel channel) throws Exception {
}
});
try {
logger.info("客户端开始建立本地连接,本地绑定IP:{},本地绑定端口:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
logger.info("客户端开始建立本地连接,{}:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
localBootstrap.connect(remoteConfig.getLocalIp(), remoteConfig.getLocalPort()).get();
} catch (Exception exception) {
logger.error("客户端建立本地连接失败,本地绑定IP:{},本地绑定端口:{},{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort(), exception.getCause().getMessage());
logger.error("客户端建立本地连接失败,{}:{},{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort(), exception.getCause().getMessage());
}
}

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
logger.info("客户端-服务端连接中断{}:{}", Config.getClientConfig().getServerIp(), Config.getClientConfig().getServerPort());
logger.info("客户端-服务端连接中断,{}:{}", Config.getClientConfig().getServerIp(), Config.getClientConfig().getServerPort());
for (Channel channel : localChannelMap.values()) {
channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
Expand Down Expand Up @@ -169,7 +169,7 @@ private RetryTemplate getRetryTemplate() {
// 设置重试回退操作策略,主要设置重试间隔时间
FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
// 重试间隔时间大于重连的超时时间
fixedBackOffPolicy.setBackOffPeriod(30000L);
fixedBackOffPolicy.setBackOffPeriod(60000L);
retryTemplate.setRetryPolicy(policy);
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
return retryTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public LocalHandler(Channel channel, ClientConfig clientConfig) {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
RemoteConfig remoteConfig = clientConfig.getConfig().get(0);
logger.info("客户端建立本地连接成功,本地绑定IP:{},本地绑定端口:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
logger.info("客户端建立本地连接成功,{}:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
ctx.channel().config().setAutoRead(false);
send(MessageType.TYPE_CONNECTED, new byte[0]);
ctx.channel().config().setAutoRead(true);
Expand All @@ -49,7 +49,7 @@ protected void channelRead0(ChannelHandlerContext ctx, byte[] bytes) throws Exce
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
RemoteConfig remoteConfig = clientConfig.getConfig().get(0);
logger.info("客户端本地连接断开,本地绑定IP:{},本地绑定端口:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
logger.info("客户端本地连接断开,{}:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
ctx.channel().config().setAutoRead(true);
send(MessageType.TYPE_DISCONNECTED, new byte[0]);
}
Expand All @@ -59,8 +59,6 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
RemoteConfig remoteConfig = clientConfig.getConfig().get(0);
logger.info("客户端本地连接中断,本地绑定IP:{},本地绑定端口:{}", remoteConfig.getLocalIp(), remoteConfig.getLocalPort());
ctx.channel().close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.info("服务端端口[{}]连接中断", remoteConfig.getRemotePort());
ctx.channel().close();
}

Expand Down

0 comments on commit 7ecfcf7

Please sign in to comment.