|
@@ -52,12 +52,15 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
|
|
|
private Map<String, Set<Channel>> socketChannelMap;
|
|
|
|
|
|
+ private String location;
|
|
|
|
|
|
- public MsgHandler(ChattingUser chattingUser, EdgeKafkaProducer edgeKafkaProducer, Map<String, Set<Channel>> socketChannelMap) {
|
|
|
+
|
|
|
+ public MsgHandler(ChattingUser chattingUser, EdgeKafkaProducer edgeKafkaProducer, Map<String, Set<Channel>> socketChannelMap,String location) {
|
|
|
this.chattingUser =chattingUser;
|
|
|
this.edgeKafkaProducer=edgeKafkaProducer;
|
|
|
this.edgeKafkaProducer.producerMsg(messageQueue);
|
|
|
this.socketChannelMap= socketChannelMap;
|
|
|
+ this.location =location;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -76,7 +79,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
|
|
|
@Override
|
|
|
protected void channelRead0(ChannelHandlerContext ctx, NettyMessage<JSONObject> msg) throws Exception {
|
|
|
- log.info("收到[{}]消息:{}", ctx.channel().remoteAddress(), msg);
|
|
|
+ log.info(location+">>>收到[{}]消息:{}", ctx.channel().remoteAddress(), msg);
|
|
|
//super.channelRead(ctx, msg);
|
|
|
// nConnection.decrementAndGet();
|
|
|
|
|
@@ -104,7 +107,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
// if (Integer.valueOf(localport) == list.get(j).getPort() ){
|
|
|
obj.put("userid",chattingUser.getUserId());
|
|
|
obj.put("targetAddress",chattingUser.getIp());
|
|
|
- obj.put("channelID",chattingUser.getUserId()+"_"+localport);
|
|
|
+ obj.put("channelID",localport+"_"+chattingUser.getUserId());
|
|
|
|
|
|
// }
|
|
|
// }
|
|
@@ -188,7 +191,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
|
|
SocketAddress socketAddress = ctx.channel().remoteAddress();
|
|
|
String remoteAddress = socketAddress.toString();
|
|
|
- log.warn("--某个客户端绑定地址:[{}]--", remoteAddress);
|
|
|
+ log.warn(location+">>>--某个客户端绑定地址:[{}]--", remoteAddress);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -201,7 +204,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
*/
|
|
|
@Override
|
|
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
|
|
- log.error("netty 连接异常" + ctx.channel().remoteAddress(), cause);
|
|
|
+ log.error(location+">>>netty 连接异常" + ctx.channel().remoteAddress(), cause);
|
|
|
ctx.close();
|
|
|
}
|
|
|
|
|
@@ -212,10 +215,10 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
|
|
//NettyServer.socketChannelMap.put(ctx.channel().remoteAddress().toString(), ctx.channel());
|
|
|
channelGroup.add(ctx.channel());
|
|
|
- log.info("当前连接数:[{}],新建立连接为[{}]...", channelGroup.size(), ctx.channel().remoteAddress().toString());
|
|
|
+ log.info(location+">>>当前连接数:[{}],新建立连接为[{}]...", channelGroup.size(), ctx.channel().remoteAddress().toString());
|
|
|
if (CollectionUtil.isNotEmpty(channelGroup)) {
|
|
|
for (Channel channel : channelGroup) {
|
|
|
- log.info("已有连接地址为[{}]", channel.remoteAddress().toString());
|
|
|
+ log.info(location+">>>已有连接地址为[{}]", channel.remoteAddress().toString());
|
|
|
}
|
|
|
}
|
|
|
super.handlerAdded(ctx);
|
|
@@ -231,7 +234,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
//下面这行代码Netty会自动调用
|
|
|
channelGroup.remove(ctx.channel());
|
|
|
super.handlerRemoved(ctx);
|
|
|
- log.warn("----客户端[{}] ----离开", ctx.channel().remoteAddress().toString());
|
|
|
+ log.warn(location+">>>----客户端[{}] ----离开", ctx.channel().remoteAddress().toString());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -239,7 +242,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
*/
|
|
|
@Override
|
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
- log.warn("[{}]:channelActive", ctx.channel().remoteAddress());
|
|
|
+ log.warn(location+">>>[{}]:channelActive", ctx.channel().remoteAddress());
|
|
|
super.channelActive(ctx);
|
|
|
}
|
|
|
|
|
@@ -249,7 +252,7 @@ public class MsgHandler extends SimpleChannelInboundHandler<NettyMessage<JSONObj
|
|
|
@Override
|
|
|
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
|
ctx.channel().close();
|
|
|
- log.warn("[{}]:channelInactive", ctx.channel().remoteAddress());
|
|
|
+ log.warn(location+">>>[{}]:channelInactive", ctx.channel().remoteAddress());
|
|
|
super.channelInactive(ctx);
|
|
|
}
|
|
|
}
|