diff --git a/cim-boot-server/libs/cim-server-sdk-netty-4.2.0.jar b/cim-boot-server/libs/cim-server-sdk-netty-4.2.0.jar index 6b6f794..ee24f23 100644 Binary files a/cim-boot-server/libs/cim-server-sdk-netty-4.2.0.jar and b/cim-boot-server/libs/cim-server-sdk-netty-4.2.0.jar differ diff --git a/cim-boot-server/src/main/resources/application.properties b/cim-boot-server/src/main/resources/application.properties index 835704e..14ab7c7 100644 --- a/cim-boot-server/src/main/resources/application.properties +++ b/cim-boot-server/src/main/resources/application.properties @@ -67,7 +67,7 @@ cim.websocket.enable=true cim.websocket.port=34567 cim.websocket.path=/ ## json or protobuf -cim.websocket.protocol=json +cim.websocket.protocol=protobuf #please setting your p12 info and appId. cim.apns.p12.file=/apns/app.p12 diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/AppSocketAcceptor.java b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/AppSocketAcceptor.java index bad1617..bf24326 100644 --- a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/AppSocketAcceptor.java +++ b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/AppSocketAcceptor.java @@ -59,6 +59,7 @@ public class AppSocketAcceptor extends NioSocketAcceptor { bootstrap.childHandler(new ChannelInitializer() { @Override public void initChannel(SocketChannel ch){ + ch.pipeline().addLast(threadNamingHandler); ch.pipeline().addLast(new AppMessageDecoder()); ch.pipeline().addLast(new AppMessageEncoder()); ch.pipeline().addLast(loggingHandler); diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/NioSocketAcceptor.java b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/NioSocketAcceptor.java index 757c0b8..4d1803d 100644 --- a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/NioSocketAcceptor.java +++ b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/NioSocketAcceptor.java @@ -25,6 +25,7 @@ import com.farsunset.cim.constant.CIMConstant; import com.farsunset.cim.constant.ChannelAttr; import com.farsunset.cim.handler.CIMRequestHandler; import com.farsunset.cim.handler.LoggingHandler; +import com.farsunset.cim.handler.ThreadNamingHandler; import com.farsunset.cim.model.Ping; import com.farsunset.cim.model.SentBody; import io.netty.bootstrap.ServerBootstrap; @@ -48,6 +49,7 @@ abstract class NioSocketAcceptor extends SimpleChannelInboundHandler{ protected final Logger logger = LoggerFactory.getLogger(getClass()); protected final ChannelHandler loggingHandler = new LoggingHandler(); + protected final ChannelHandler threadNamingHandler = new ThreadNamingHandler(); private final EventLoopGroup bossGroup; private final EventLoopGroup workerGroup; @@ -71,13 +73,13 @@ abstract class NioSocketAcceptor extends SimpleChannelInboundHandler{ ThreadFactory bossThreadFactory = r -> { Thread thread = new Thread(r); - thread.setName("nio-boss-"); + thread.setName("nio-boss-" + thread.getId()); return thread; }; ThreadFactory workerThreadFactory = r -> { Thread thread = new Thread(r); - thread.setName("nio-worker-"); + thread.setName("nio-worker-" + thread.getId()); return thread; }; diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/WebsocketAcceptor.java b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/WebsocketAcceptor.java index 84f963e..47d122c 100644 --- a/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/WebsocketAcceptor.java +++ b/cim-server-sdk/src/main/java/com/farsunset/cim/acceptor/WebsocketAcceptor.java @@ -90,6 +90,7 @@ public class WebsocketAcceptor extends NioSocketAcceptor { @Override public void initChannel(SocketChannel ch){ + ch.pipeline().addLast(threadNamingHandler); ch.pipeline().addLast(new HttpServerCodec()); ch.pipeline().addLast(new ChunkedWriteHandler()); ch.pipeline().addLast(new HttpObjectAggregator(4 * 1024)); diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/handler/LoggingHandler.java b/cim-server-sdk/src/main/java/com/farsunset/cim/handler/LoggingHandler.java index 0a3ba19..f067257 100644 --- a/cim-server-sdk/src/main/java/com/farsunset/cim/handler/LoggingHandler.java +++ b/cim-server-sdk/src/main/java/com/farsunset/cim/handler/LoggingHandler.java @@ -34,6 +34,17 @@ public class LoggingHandler extends io.netty.handler.logging.LoggingHandler { super(LogLevel.INFO); } + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + super.channelRead(ctx,msg); + } + + @Override + public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { + super.channelRead(ctx,msg); + } + + @Override public void channelRegistered(ChannelHandlerContext ctx) { ctx.fireChannelRegistered(); @@ -63,5 +74,4 @@ public class LoggingHandler extends io.netty.handler.logging.LoggingHandler { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { logger.warn("EXCEPTION",cause); } - } diff --git a/cim-server-sdk/src/main/java/com/farsunset/cim/handler/ThreadNamingHandler.java b/cim-server-sdk/src/main/java/com/farsunset/cim/handler/ThreadNamingHandler.java new file mode 100644 index 0000000..bc2768e --- /dev/null +++ b/cim-server-sdk/src/main/java/com/farsunset/cim/handler/ThreadNamingHandler.java @@ -0,0 +1,111 @@ +/* + * Copyright 2013-2019 Xia Jun(3979434@qq.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *************************************************************************************** + * * + * Website : http://www.farsunset.com * + * * + *************************************************************************************** + */ +package com.farsunset.cim.handler; + + +import com.farsunset.cim.constant.ChannelAttr; +import io.netty.channel.*; + +@ChannelHandler.Sharable +public class ThreadNamingHandler extends ChannelInboundHandlerAdapter { + + @Override + public void channelRegistered(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelRegistered(ctx); + Thread.currentThread().setName(name); + } + + @Override + public void channelUnregistered(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelUnregistered(ctx); + Thread.currentThread().setName(name); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelActive(ctx); + Thread.currentThread().setName(name); + + } + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelInactive(ctx); + Thread.currentThread().setName(name); + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelRead(ctx,msg); + Thread.currentThread().setName(name); + } + + @Override + public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelReadComplete(ctx); + Thread.currentThread().setName(name); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.userEventTriggered(ctx,evt); + Thread.currentThread().setName(name); + } + + @Override + public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.channelWritabilityChanged(ctx); + Thread.currentThread().setName(name); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + String name = Thread.currentThread().getName(); + setThreadName(ctx); + super.exceptionCaught(ctx,cause); + Thread.currentThread().setName(name); + } + + + private void setThreadName(ChannelHandlerContext context){ + String uid = context.channel().attr(ChannelAttr.UID).get(); + if (uid != null){ + Thread.currentThread().setName("nio-uid-" + uid); + } + } +} diff --git a/cim-use-examples/cim-client-vue/README.txt b/cim-use-examples/cim-client-vue/README.txt new file mode 100644 index 0000000..20c9589 --- /dev/null +++ b/cim-use-examples/cim-client-vue/README.txt @@ -0,0 +1,13 @@ +## 注意!! +启动本本目录index.html 请确定服务端参数配置值为如下 +cim.websocket.protocol=protobuf + +https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz#ErmDP + + + +## 客户端文档 +https://www.yuque.com/yuanfangxiyang/ma4ytb/zwkr3m#oaLfQ + +## 服务端配置 +https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz#XAbTx \ No newline at end of file diff --git a/cim-use-examples/cim-client-web-json/README.txt b/cim-use-examples/cim-client-web-json/README.txt index b58448c..13a2e83 100644 --- a/cim-use-examples/cim-client-web-json/README.txt +++ b/cim-use-examples/cim-client-web-json/README.txt @@ -1,3 +1,9 @@ +## 注意!! +启动本本目录index.html 请确定服务端参数配置值为如下 +cim.websocket.protocol=json + +https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz#srHdB + ## 客户端文档 https://www.yuque.com/yuanfangxiyang/ma4ytb/zwkr3m#lE1R2 diff --git a/cim-use-examples/cim-client-web-protobuf/README.txt b/cim-use-examples/cim-client-web-protobuf/README.txt index 175624c..20c9589 100644 --- a/cim-use-examples/cim-client-web-protobuf/README.txt +++ b/cim-use-examples/cim-client-web-protobuf/README.txt @@ -1,3 +1,11 @@ +## 注意!! +启动本本目录index.html 请确定服务端参数配置值为如下 +cim.websocket.protocol=protobuf + +https://www.yuque.com/yuanfangxiyang/ma4ytb/vvy3iz#ErmDP + + + ## 客户端文档 https://www.yuque.com/yuanfangxiyang/ma4ytb/zwkr3m#oaLfQ