From 9672ca2e1a2ccd50e71535283f88c9d8acdc5fb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 16 Nov 2018 17:28:26 +0800 Subject: [PATCH 001/151] update --- LICENSE | 201 ------------------------------------------------------ README.md | 2 + 2 files changed, 2 insertions(+), 201 deletions(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/README.md b/README.md index dbafcba..ac0ef9a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ >The entire MAVEN toolkit is still under construction.... +**master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** + ## Summery ***(InChat)Iot Netty Chat*** From fda644c1fe9ce1051b9441fb3bd7ab15c4c6ec1b Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 17 Nov 2018 11:02:05 +0800 Subject: [PATCH 002/151] updateAndRefactoringCode --- README.md | 4 + doc/document.md | 0 .../bootstrap/AbstractBootstrapServer.java | 92 +---- .../handler/DefaultWebSocketHandler.java | 10 + .../bootstrap/scan/ScanRunnable.java | 1 - .../common/properties/InitNetty.java | 10 +- .../common/websockets/WebSocketHandler.java | 51 +++ .../websockets/WebSocketHandlerApi.java | 21 + .../common/zookeeper/ZkStateListener.java | 22 -- .../nettychat/common/zookeeper/ZkUtils.java | 366 ------------------ .../nettychat/common/zookeeper/testZk.java | 256 ------------ src/main/resources/application.yml | 19 +- 12 files changed, 110 insertions(+), 742 deletions(-) create mode 100644 doc/document.md create mode 100644 src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java create mode 100644 src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java create mode 100644 src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java delete mode 100644 src/main/java/com/myself/nettychat/common/zookeeper/ZkStateListener.java delete mode 100644 src/main/java/com/myself/nettychat/common/zookeeper/ZkUtils.java delete mode 100644 src/main/java/com/myself/nettychat/common/zookeeper/testZk.java diff --git a/README.md b/README.md index ac0ef9a..30ca98e 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ A lightweight, efficient communication framework that supports chat and the Internet of things, you can use it to quickly build a chat server with the background and quickly customize your own communication APIs, including physical networks with different protocols that can be supported. +## Tutorial + +* [中文文档说明](doc/document.md) + ## Branch demo:Stop updates Original Project Core demo, you can first run to understand, imitation WeChat chat application, step by step update, based on Springboot-websocket General framework, combined with Netty to chat social, and record chat logs, asynchronous storage, front-end provisional sui Mobile, add implementation tcp/ diff --git a/doc/document.md b/doc/document.md new file mode 100644 index 0000000..e69de29 diff --git a/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java index a647848..7082275 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java @@ -1,28 +1,14 @@ package com.myself.nettychat.bootstrap; -import com.myself.nettychat.bootstrap.coder.ByteBufToWebSocketFrameEncoder; -import com.myself.nettychat.bootstrap.coder.WebSocketFrameToByteBufDecoder; import com.myself.nettychat.common.properties.InitNetty; -import com.myself.nettychat.common.ssl.SecureSocketSslContextFactory; import com.myself.nettychat.common.utils.SpringBeanUtils; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; -import io.netty.handler.codec.mqtt.MqttDecoder; -import io.netty.handler.codec.mqtt.MqttEncoder; -import io.netty.handler.ssl.SslHandler; +import io.netty.handler.stream.ChunkedWriteHandler; import io.netty.handler.timeout.IdleStateHandler; -import org.apache.commons.lang3.ObjectUtils; -import org.jboss.netty.util.internal.SystemPropertyUtil; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import java.security.KeyStore; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; /** * @author MySelf @@ -31,87 +17,21 @@ **/ public abstract class AbstractBootstrapServer implements BootstrapServer { - private String PROTOCOL = "TLS"; - - private SSLContext SERVER_CONTEXT; - - private static final String MQTT_CSV_LIST = "mqtt, mqttv3.1, mqttv3.1.1"; - - /** - * * @param channelPipeline channelPipeline * @param serverBean 服务配置参数 */ protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ - if(serverBean.isSsl()){ - if(!ObjectUtils.allNotNull(serverBean.getJksCertificatePassword(),serverBean.getJksFile(),serverBean.getJksStorePassword())){ - throw new NullPointerException("SSL file and password is null"); - } - initSsl(serverBean); - SSLEngine engine = - SERVER_CONTEXT.createSSLEngine(); - engine.setUseClientMode(false); - channelPipeline.addLast("ssl", new SslHandler(engine)); - } - intProtocolHandler(channelPipeline,serverBean); channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast( SpringBeanUtils.getBean(serverBean.getMqttHander())); - + channelPipeline.addLast(SpringBeanUtils.getBean(serverBean.getWebSocketHandler())); } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ - switch (serverBean.getProtocol()){ - case MQTT: - channelPipeline.addLast("encoder", MqttEncoder.INSTANCE); - channelPipeline.addLast("decoder", new MqttDecoder()); - break; - case MQTT_WS_MQTT: - channelPipeline.addLast("httpCode", new HttpServerCodec()); - channelPipeline.addLast("aggregator", new HttpObjectAggregator(65536)); - channelPipeline.addLast("webSocketHandler", - new WebSocketServerProtocolHandler("/", MQTT_CSV_LIST)); - channelPipeline.addLast("wsDecoder", new WebSocketFrameToByteBufDecoder()); - channelPipeline.addLast("wsEncoder", new ByteBufToWebSocketFrameEncoder()); - channelPipeline.addLast("decoder", new MqttDecoder()); - channelPipeline.addLast("encoder", MqttEncoder.INSTANCE); - break; - case MQTT_WS_PAHO: - channelPipeline.addLast("httpCode", new HttpServerCodec()); - channelPipeline.addLast("aggregator", new HttpObjectAggregator(65536)); - channelPipeline.addLast("webSocketHandler", - new WebSocketServerProtocolHandler("/mqtt", MQTT_CSV_LIST)); - channelPipeline.addLast("wsDecoder", new WebSocketFrameToByteBufDecoder()); - channelPipeline.addLast("wsEncoder", new ByteBufToWebSocketFrameEncoder()); - channelPipeline.addLast("decoder", new MqttDecoder()); - channelPipeline.addLast("encoder", MqttEncoder.INSTANCE); - break; - } - } - - private void initSsl(InitNetty serverBean){ - ExecutorService executorService = Executors.newCachedThreadPool(); - executorService.submit(() -> {}); - String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm"); - if (algorithm == null) { - algorithm = "SunX509"; - } - SSLContext serverContext; - try { - // - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load( SecureSocketSslContextFactory.class.getResourceAsStream(serverBean.getJksFile()), - serverBean.getJksStorePassword().toCharArray()); - KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); - kmf.init(ks,serverBean.getJksCertificatePassword().toCharArray()); - serverContext = SSLContext.getInstance(PROTOCOL); - serverContext.init(kmf.getKeyManagers(), null, null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the server-side SSLContext", e); - } - SERVER_CONTEXT = serverContext; + channelPipeline.addLast("httpCode",new HttpServerCodec()); + channelPipeline.addLast("aggregator", new HttpObjectAggregator(serverBean.getMaxContext())); + channelPipeline.addLast("chunkedWrite",new ChunkedWriteHandler()); + channelPipeline.addLast("webSocketHandler",new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java new file mode 100644 index 0000000..95a4168 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -0,0 +1,10 @@ +package com.myself.nettychat.bootstrap.handler; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:15 2018\11\16 0016 + */ +public class DefaultWebSocketHandler { +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java b/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java index 4d4cc8c..fdd6dbe 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java +++ b/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java @@ -24,7 +24,6 @@ public boolean addQueues(List ts){ return queue.addAll(ts); } - @Override public void run() { for(;;){ diff --git a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java index ad88014..cdaca4f 100644 --- a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java +++ b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java @@ -1,10 +1,8 @@ package com.myself.nettychat.common.properties; +import com.myself.nettychat.common.websockets.WebSocketHandler; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; -import com.myself.nettychat.common.enums.ProtocolEnum; -import com.myself.nettychat.common.mqtts.MqttHander; /** * @Author:UncleCatMySelf @@ -38,4 +36,10 @@ public class InitNetty { private int initalDelay; + private int maxContext; + + private String webSocketPath; + + private Class webSocketHandler; + } diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java new file mode 100644 index 0000000..c4cd4aa --- /dev/null +++ b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java @@ -0,0 +1,51 @@ +package com.myself.nettychat.common.websockets; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:19 2018\11\16 0016 + */ +@Slf4j +public abstract class WebSocketHandler extends SimpleChannelInboundHandler { + + WebSocketHandlerApi webSocketHandlerApi; + + public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof TextWebSocketFrame){ + textdoMessage(ctx,(TextWebSocketFrame)msg); + }else if (msg instanceof WebSocketFrame){ + webdoMessage(ctx,(WebSocketFrame)msg); + } + } + + protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); + + protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + webSocketHandlerApi.close(ctx.channel()); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent){ + webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); + } + super.userEventTriggered(ctx, evt); + } +} diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java new file mode 100644 index 0000000..ac36601 --- /dev/null +++ b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java @@ -0,0 +1,21 @@ +package com.myself.nettychat.common.websockets; + +import io.netty.channel.Channel; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:22 2018\11\16 0016 + */ +public interface WebSocketHandlerApi { + + void close(Channel channel); + + void sendText(Channel channel, TextWebSocketFrame webSocketFrame); + + void doTimeOut(Channel channel, IdleStateEvent evt); + +} diff --git a/src/main/java/com/myself/nettychat/common/zookeeper/ZkStateListener.java b/src/main/java/com/myself/nettychat/common/zookeeper/ZkStateListener.java deleted file mode 100644 index b2658fa..0000000 --- a/src/main/java/com/myself/nettychat/common/zookeeper/ZkStateListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.myself.nettychat.common.zookeeper; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.state.ConnectionState; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc zookeeper 监听 - **/ -public interface ZkStateListener { - - default void connectedEvent(CuratorFramework curator, ConnectionState state) { - } - - default void ReconnectedEvent(CuratorFramework curator, ConnectionState state) { - } - - default void lostEvent(CuratorFramework curator, ConnectionState state) { - } - -} diff --git a/src/main/java/com/myself/nettychat/common/zookeeper/ZkUtils.java b/src/main/java/com/myself/nettychat/common/zookeeper/ZkUtils.java deleted file mode 100644 index 1cc853b..0000000 --- a/src/main/java/com/myself/nettychat/common/zookeeper/ZkUtils.java +++ /dev/null @@ -1,366 +0,0 @@ -package com.myself.nettychat.common.zookeeper; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -import com.google.common.base.Charsets; -import com.google.common.base.Objects; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.api.GetDataBuilder; -import org.apache.curator.framework.recipes.cache.NodeCache; -import org.apache.curator.framework.recipes.cache.PathChildrenCache; -import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent; -import org.apache.curator.framework.recipes.cache.TreeCache; -import org.apache.curator.framework.state.ConnectionState; -import org.apache.curator.retry.RetryNTimes; -import org.apache.curator.utils.CloseableUtils; -import org.apache.curator.utils.ZKPaths; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.data.Stat; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.BiConsumer; -import java.util.function.Function; -import java.util.stream.Collectors; - -@Slf4j -@Data -@NoArgsConstructor -public class ZkUtils { - - private CuratorFramework zkClient = null; - - ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); - - List pathChildrenCaches = new CopyOnWriteArrayList<>(); - - List nodeCaches = new CopyOnWriteArrayList<>(); - - List treeCaches = new CopyOnWriteArrayList<>(); - - - /** - * 初始化zk链接 - * - * @param zookeeperServer - * @param connectionTimeout - * @param sessionTimeout - * @param maxRetries - * @param retriesSleepTime - * @param namespace - * @param listener - */ - public void init(String zookeeperServer, - int connectionTimeout, - int sessionTimeout, - int maxRetries, int retriesSleepTime, - String namespace, - ZkStateListener listener) { - if (zkClient == null) { - zkClient = CuratorFrameworkFactory.builder() - .connectString(zookeeperServer) - .connectionTimeoutMs(connectionTimeout) - .sessionTimeoutMs(sessionTimeout) - .namespace(namespace) - .retryPolicy(new RetryNTimes(maxRetries, retriesSleepTime)) - .build(); - } - zkClient.getConnectionStateListenable().addListener((curatorFramework, connectionState) -> { - pathChildrenCaches.clear(); - nodeCaches.clear(); - treeCaches.clear(); - if (connectionState == ConnectionState.CONNECTED) { - listener.connectedEvent(curatorFramework, connectionState); - } else if (connectionState == ConnectionState.RECONNECTED) { - listener.ReconnectedEvent(curatorFramework, connectionState); - } else if (connectionState == ConnectionState.LOST) { - listener.lostEvent(curatorFramework, connectionState); - } - }); - zkClient.start(); - } - /** - * 销毁所有 - */ - public void destory() { - pathChildrenCaches.stream().forEach(cache -> CloseableUtils.closeQuietly(cache)); - pathChildrenCaches.clear(); - pathChildrenCaches = null; - nodeCaches.stream().forEach(cache -> CloseableUtils.closeQuietly(cache)); - nodeCaches.clear(); - nodeCaches = null; - treeCaches.stream().forEach(cache -> CloseableUtils.closeQuietly(cache)); - treeCaches.clear(); - treeCaches = null; - if (zkClient != null) { - CloseableUtils.closeQuietly(zkClient); - } - } - - - /** - * 创建节点 - * - * @param path - * @param data - * @param mode - * @return - */ - public boolean createNode(String path, String data, CreateMode mode) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return Boolean.FALSE; - } - try { - Stat stat = exists(path); - if (stat == null) { - mode = mode == null ? CreateMode.PERSISTENT : mode; - String opResult; - if (ObjectUtils.allNotNull(data)) { - opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path, data.getBytes(Charsets.UTF_8)); - } else { - opResult = zkClient.create().creatingParentContainersIfNeeded().withMode(mode).forPath(path); - } - return Objects.equal(opResult, path); - } - return Boolean.TRUE; - } catch (Exception e) { - log.error("create node fail! path: {}, error: {}", path, e); - } - return Boolean.FALSE; - } - - - /** - * 删除节点 递归删除子节点 - * - * @param path - * @param version - * @return - */ - public boolean deleteNode(String path, Integer version) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return Boolean.FALSE; - } - try { - Stat stat = exists(path); - if (stat != null) { - if (version == null) { - zkClient.delete().deletingChildrenIfNeeded().forPath(path); - } else { - zkClient.delete().deletingChildrenIfNeeded().withVersion(version).forPath(path); - } - } - return Boolean.TRUE; - } catch (Exception e) { - log.error("delete node fail! path: {}, error: {}", path, e); - } - return Boolean.FALSE; - } - - /** - * 删除节点 - * - * @param path - * @return - */ - public boolean deleteNode(String path) { - return deleteNode(path, null); - } - - /** - * 获取指定节点的值 - * - * @param path - * @return - */ - public byte[] getNodeData(String path) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return null; - } - try { - Stat stat = exists(path); - if (stat != null) { - return zkClient.getData().forPath(path); - } - } catch (Exception e) { - log.error("get node data fail! path: {}, error: {}", path, e); - } - return null; - } - - /** - * 获取指定节点的值 - * - * @param path - * @return - */ - public String getNodeDataStr(String path) { - byte[] val = getNodeData(path); - return val == null ? null : new String(val, Charsets.UTF_8); - } - - /** - * 检查节点是否存在 - * - * @param path - * @return - */ - public Stat exists(String path) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return null; - } - try { - return zkClient.checkExists().forPath(path); - } catch (Exception e) { - log.error("check node exists fail! path: {}, error: {}", path, e); - } - return null; - } - - /** - * 检查节点是否存在 - * - * @param path - * @return - */ - public boolean checkExists(String path) { - return exists(path) == null ? Boolean.FALSE : Boolean.TRUE; - } - - /** - * 设置节点数据 - * - * @param path - * @param data - * @return - */ - public boolean setNodeData(String path, String data) { - return setNodeData(path, data.getBytes(Charsets.UTF_8), null); - } - - /** - * 设置节点数据 - * - * @param path - * @param data - * @param version - * @return - */ - public boolean setNodeData(String path, byte[] data, Integer version) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return Boolean.FALSE; - } - try { - Stat stat = exists(path); - if (stat != null) { - if (version == null) { - zkClient.setData().forPath(path, data); - } else { - zkClient.setData().withVersion(version).forPath(path, data); - } - return Boolean.TRUE; - } - } catch (Exception e) { - log.error("set node data fail! path: {}, error: {}", path, e); - } - return Boolean.FALSE; - } - - /** - * 设置子节点更改监听 - * - * @param path - * @throws Exception - */ - public boolean listenerPathChildrenCache(String path, BiConsumer biConsumer) { - - if (!ObjectUtils.allNotNull(zkClient, path, biConsumer)) { - return Boolean.FALSE; - } - try { - Stat stat = exists(path); - if (stat != null) { - PathChildrenCache watcher = new PathChildrenCache(zkClient, path, true); - watcher.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT); - //该模式下 watcher在重连的时候会自动 rebuild - watcher.getListenable().addListener(biConsumer::accept, pool); - if (!pathChildrenCaches.contains(watcher)) { - pathChildrenCaches.add(watcher); - } -// else{ -// watcher.rebuild(); -// } - return Boolean.TRUE; - } - } catch (Exception e) { - log.error("listen path children cache fail! path:{} , error:{}", path, e); - } - return Boolean.FALSE; - } - - - /** - * 读取指定节点的子菜单的值 - * - * @param path - * @return - */ - public Map readTargetChildsData(String path) { - if (!ObjectUtils.allNotNull(zkClient, path)) { - return null; - } - Map map = null; - try { - Stat stat = exists(path); - if (stat != null) { - List childrens = zkClient.getChildren().forPath(path); - GetDataBuilder dataBuilder = zkClient.getData(); - if (childrens != null) { - map = childrens.stream().collect(Collectors.toMap(Function.identity(), (child) -> { - try { - return new String(dataBuilder.forPath(ZKPaths.makePath(path, child)), Charsets.UTF_8); - } catch (Exception e1) { - return null; - } - })); - } - } - } catch (Exception e) { - log.error("get target childs data fail!, path:{} , error:{}", path, e); - } - return map; - - } - - - public static void main(String[] a) throws Exception { - ZkUtils zkUtils = new ZkUtils(); - zkUtils.init("127.0.0.1:2181", 1000, 2000, 5, 1000, "test", new ZkStateListener() { - @Override - public void connectedEvent(CuratorFramework curator, ConnectionState state) { - - } - - @Override - public void ReconnectedEvent(CuratorFramework curator, ConnectionState state) { - - } - - @Override - public void lostEvent(CuratorFramework curator, ConnectionState state) { - - } - }); - zkUtils.getZkClient().create().creatingParentContainersIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/yy/uu/ii"); - - Thread.sleep(Long.MAX_VALUE); - } - -} diff --git a/src/main/java/com/myself/nettychat/common/zookeeper/testZk.java b/src/main/java/com/myself/nettychat/common/zookeeper/testZk.java deleted file mode 100644 index e51292b..0000000 --- a/src/main/java/com/myself/nettychat/common/zookeeper/testZk.java +++ /dev/null @@ -1,256 +0,0 @@ -package com.myself.nettychat.common.zookeeper; - -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.framework.api.ACLProvider; -import org.apache.curator.framework.api.CuratorEvent; -import org.apache.curator.framework.api.CuratorListener; -import org.apache.curator.framework.recipes.cache.*; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.retry.RetryNTimes; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.ACL; -import org.apache.zookeeper.data.Id; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 测试 - **/ -public class testZk { - - /** - * 先测试玩玩 - * @描述:XXXXXXX - * @param args - * @return void - * @exception - * @createTime:2016年5月17日 - * @author: songqinghu - * @throws Exception - */ - public static void main(String[] args) throws Exception { - CuratorFramework client = clientTwo(); - //setListenterDateNode(); - //setListenterThreeOne(client); - // setListenterThreeTwo(client); - setListenterThreeThree(client); - // getDataNode(client, "/two"); - // setDataNode(client, "/two", "sss"); - - } - - /** - * - * @描述:创建一个zookeeper连接---连接方式一: 最简单的连接 - * @return void - * @exception - * @createTime:2016年5月17日 - * @author: songqinghu - */ - private static CuratorFramework clientOne(){ - //zk 地址 - String connectString = "10.125.2.44:2181"; - // 连接时间 和重试次数 - RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); - CuratorFramework client = CuratorFrameworkFactory.newClient(connectString, retryPolicy); - client.start(); - return client; - } - - /** - * - * @描述:创建一个zookeeper连接---连接方式二:优选这个 - * @return void - * @exception - * @createTime:2016年5月17日 - * @author: songqinghu - */ - private static CuratorFramework clientTwo(){ - - //默认创建的根节点是没有做权限控制的--需要自己手动加权限???---- - ACLProvider aclProvider = new ACLProvider() { - private List acl ; - @Override - public List getDefaultAcl() { - if(acl ==null){ - ArrayList acl = ZooDefs.Ids.CREATOR_ALL_ACL; - acl.clear(); - acl.add(new ACL(ZooDefs.Perms.ALL, new Id("auth", "admin:admin") )); - this.acl = acl; - } - return acl; - } - @Override - public List getAclForPath(String path) { - return acl; - } - }; - String scheme = "digest"; - byte[] auth = "admin:admin".getBytes(); - int connectionTimeoutMs = 5000; - String connectString = "127.0.0.1:2181"; - String namespace = "testnamespace"; - CuratorFramework client = CuratorFrameworkFactory.builder().aclProvider(aclProvider). - authorization(scheme, auth). - connectionTimeoutMs(connectionTimeoutMs). - connectString(connectString). - namespace(namespace). - retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000)).build(); - client.start(); - return client; - } - - - /** - * - * @描述:第一种监听器的添加方式: 对指定的节点进行添加操作 - * 仅仅能监控指定的本节点的数据修改,删除 操作 并且只能监听一次 --->不好 - * @return void - * @exception - * @createTime:2016年5月18日 - * @author: songqinghu - * @throws Exception - */ - private static void setListenterOne(CuratorFramework client) throws Exception{ - // 注册观察者,当节点变动时触发 - byte[] data = client.getData().usingWatcher(new Watcher() { - @Override - public void process(WatchedEvent event) { - System.out.println("获取 two 节点 监听器 : " + event); - } - }).forPath("/two"); - System.out.println("two 节点数据: "+ new String(data)); - } - /** - * - * @描述:第二种监听器的添加方式: - * 也是一次性的监听操作,使用后就无法在继续监听了 - * @return void - * @exception - * @createTime:2016年5月18日 - * @author: songqinghu - * @throws Exception - */ - private static void setListenterTwo(CuratorFramework client) throws Exception{ - - ExecutorService pool = Executors.newCachedThreadPool(); - - CuratorListener listener = new CuratorListener() { - @Override - public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception { - System.out.println("监听器 : "+ event.toString()); - } - }; - client.getCuratorListenable().addListener(listener,pool); - client.getData().inBackground().forPath("/two"); - client.getData().inBackground().forPath("/two"); - client.getData().inBackground().forPath("/two"); - client.getData().inBackground().forPath("/two"); - Thread.sleep(Long.MAX_VALUE ); - } - /** - * - * @描述:第三种监听器的添加方式: Cache 的三种实现 实践 - * Path Cache:监视一个路径下1)孩子结点的创建、2)删除,3)以及结点数据的更新。 - * 产生的事件会传递给注册的PathChildrenCacheListener。 - * Node Cache:监视一个结点的创建、更新、删除,并将结点的数据缓存在本地。 - * Tree Cache:Path Cache和Node Cache的“合体”,监视路径下的创建、更新、删除事件,并缓存路径下所有孩子结点的数据。 - * @return void - * @exception - * @createTime:2016年5月18日 - * @author: songqinghu - * @throws Exception - */ - //1.path Cache 连接 路径 是否获取数据 - //能监听所有的字节点 且是无限监听的模式 但是 指定目录下节点的子节点不再监听 - private static void setListenterThreeOne(CuratorFramework client) throws Exception{ - ExecutorService pool = Executors.newCachedThreadPool(); - PathChildrenCache childrenCache = new PathChildrenCache(client, "/test", true); - PathChildrenCacheListener childrenCacheListener = new PathChildrenCacheListener() { - @Override - public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception { - System.out.println("开始进行事件分析:-----"); - ChildData data = event.getData(); - switch (event.getType()) { - case CHILD_ADDED: - System.out.println("CHILD_ADDED : "+ data.getPath() +" 数据:"+ data.getData()); - break; - case CHILD_REMOVED: - System.out.println("CHILD_REMOVED : "+ data.getPath() +" 数据:"+ data.getData()); - break; - case CHILD_UPDATED: - System.out.println("CHILD_UPDATED : "+ data.getPath() +" 数据:"+ data.getData()); - break; - default: - break; - } - } - }; - childrenCache.getListenable().addListener(childrenCacheListener); - System.out.println("Register zk watcher successfully!"); - childrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT); - } - - //2.Node Cache 监控本节点的变化情况 连接 目录 是否压缩 - //监听本节点的变化 节点可以进行修改操作 删除节点后会再次创建(空节点) - private static void setListenterThreeTwo(CuratorFramework client) throws Exception{ - ExecutorService pool = Executors.newCachedThreadPool(); - //设置节点的cache - final NodeCache nodeCache = new NodeCache(client, "/test", false); - nodeCache.getListenable().addListener(new NodeCacheListener() { - @Override - public void nodeChanged() throws Exception { - System.out.println("the test node is change and result is :"); - System.out.println("path : "+nodeCache.getCurrentData().getPath()); - System.out.println("data : "+new String(nodeCache.getCurrentData().getData())); - System.out.println("stat : "+nodeCache.getCurrentData().getStat()); - } - }); - nodeCache.start(); - } - //3.Tree Cache - // 监控 指定节点和节点下的所有的节点的变化--无限监听 可以进行本节点的删除(不在创建) - private static void setListenterThreeThree(CuratorFramework client) throws Exception{ - ExecutorService pool = Executors.newCachedThreadPool(); - //设置节点的cache - TreeCache treeCache = new TreeCache(client, "/test"); - //设置监听器和处理过程 - treeCache.getListenable().addListener(new TreeCacheListener() { - @Override - public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception { - ChildData data = event.getData(); - if(data !=null){ - switch (event.getType()) { - case NODE_ADDED: - System.out.println("NODE_ADDED : "+ data.getPath() +" 数据:"+ new String(data.getData())); - break; - case NODE_REMOVED: - System.out.println("NODE_REMOVED : "+ data.getPath() +" 数据:"+ new String(data.getData())); - break; - case NODE_UPDATED: - System.out.println("NODE_UPDATED : "+ data.getPath() +" 数据:"+ new String(data.getData())); - break; - - default: - break; - } - }else{ - System.out.println( "data is null : "+ event.getType()); - } - } - }); - //开始监听 - treeCache.start(); - - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d941b0c..38f5d9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,14 +7,17 @@ spring: jpa: show-sql: true netty: - webport: 8090 # Websocket port + webport: 8090 # Websocket 监听端口 bossThread: 1 workerThread: 2 - keepalive: true # Socket parameter, connection warranty, default value is False. When this feature is enabled, TCP proactively detects the validity of idle connections. You can consider this feature as a heartbeat mechanism for TCP, and it is important to note that the default heartbeat interval is 7200s, or 2 hours. Netty Turn off this feature by default - backlog: 1024 # Socket parameter, server accepts the queue length of the connection, and if the queue is full, the client connection will be rejected - sndbuf: 10485760 # TCP data send buffer size. - revbuf: 10485760 # TCP data receive buffer size. - heart: 180 # Read timeout - period: 10 # Cycle of re-hair + keepalive: true # 套接字参数, 连接保修, 默认值为 false。启用此功能后, tcp 会主动检测空闲连接的有效性。您可以将此功能视为 tcp 的检测信号机制, 请务必注意, 默认检测信号间隔为 7200s, 即2小时。netty 默认关闭此功能 + backlog: 1024 # 套接字参数, 服务器接受连接的队列长度, 如果队列已满, 则客户端连接将被拒绝 + sndbuf: 10485760 # tcp 数据发送缓冲区大小。 + revbuf: 10485760 # tcp 数据接收缓冲区大小。 + heart: 180 # 读取超时 + period: 10 # 重新发送周期 serverName: iot-netty-chat - initalDelay: 10 # Reset delay \ No newline at end of file + initalDelay: 10 # 重置延迟 + maxContext: 65536 + webSocketPath: "/ws" + webSocketHandler: com.myself.nettychat.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 From 3f50d38ed2e78c436689fd472de0615c035571a2 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 17 Nov 2018 11:20:21 +0800 Subject: [PATCH 003/151] updateMd --- README.md | 5 +++++ doc/netty-study.md | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 doc/netty-study.md diff --git a/README.md b/README.md index 30ca98e..e6df0f9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,10 @@ A lightweight, efficient communication framework that supports chat and the Inte * [中文文档说明](doc/document.md) +## Learning Resources(欢迎贡献) + +* [netty4通信原理](doc/netty-study.md) + ## Branch demo:Stop updates Original Project Core demo, you can first run to understand, imitation WeChat chat application, step by step update, based on Springboot-websocket General framework, combined with Netty to chat social, and record chat logs, asynchronous storage, front-end provisional sui Mobile, add implementation tcp/ @@ -59,3 +63,4 @@ QQ Group:628793702 ## About the author ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E5%85%AC%E4%BC%97%E5%8F%B7.png) + diff --git a/doc/netty-study.md b/doc/netty-study.md new file mode 100644 index 0000000..aa6354b --- /dev/null +++ b/doc/netty-study.md @@ -0,0 +1,40 @@ +## netty4通信步骤,原理 + +> 感谢 贡献者:@@Noseparte + +### 服务端依次发生的步骤 + +* 1.建立服务端监听套接字ServerSocketChannel,以及对应的管道pipeline; +* 2.启动boss线程,将ServerSocketChannel注册到boss线程持有的selector中,并将注册返回的selectionKey赋值给ServerSocketChannel关联的selectionKey变量; +* 3.在ServerSocketChannel对应的管道中触发channelRegistered事件; +* 4.绑定IP和端口 +* 5.触发channelActive事件,并将ServerSocketChannel关联的selectionKey的OP_ACCEPT位置为1。 +* 6.客户端发起connect请求后,boss线程正在运行的select循环检测到了该ServerSocketChannel的ACCEPT事件就绪,则通过accept系统调用建立一个已连接套接字SocketChannel,并为其创建对应的管道; +* 7.在服务端监听套接字对应的管道中触发channelRead事件; +* 8.channelRead事件由ServerBootstrapAcceptor的channelRead方法响应:为已连接套接字对应的管道加入ChannelInitializer处理器; +启动一个worker线程,并将已连接套接字的注册任务加入到worker线程的任务队列中; +* 9.worker线程执行已连接套接字的注册任务:将已连接套接字注册到worker线程持有的selector中,并将注册返回的selectionKey赋值给已连接套接字关联的selectionKey变量; +在已连接套接字对应的管道中触发channelRegistered事件;channelRegistered事件由ChannelInitializer的channelRegistered方法响应: +将自定义的处理器(譬如EchoServerHandler)加入到已连接套接字对应的管道中;在已连接套接字对应的管道中触发channelActive事件;c +hannelActive事件由已连接套接字对应的管道中的inbound处理器的channelActive方法响应;将已连接套接字关联的selectionKey的OP_READ位置为1;至此,worker线程关联的selector就开始监听已连接套接字的READ事件了。 +* 10.在worker线程运行的同时,Boss线程接着在服务端监听套接字对应的管道中触发channelReadComplete事件。 +* 11.客户端向服务端发送消息后,worker线程正在运行的selector循环会检测到已连接套接字的READ事件就绪。则通过read系统调用将消息从套接字的接受缓冲区中读到AdaptiveRecvByteBufAllocator(可以自适应调整分配的缓存的大小)分配的缓存中; +* 12.在已连接套接字对应的管道中触发channelRead事件; +* 13.channelRead事件由EchoServerHandler处理器的channelRead方法响应:执行write操作将消息存储到ChannelOutboundBuffer中; +* 14.在已连接套接字对应的管道中触发ChannelReadComplete事件; +* 15.ChannelReadComplete事件由EchoServerHandler处理器的channelReadComplete方法响应:执行flush操作将消息从ChannelOutboundBuffer中flush到套接字的发送缓冲区中; + + + +### 客户端依次发生的步骤 + +* 1.建立套接字SocketChannel,以及对应的管道pipeline; +* 2.启动客户端线程,将SocketChannel注册到客户端线程持有的selector中,并将注册返回的selectionKey赋值给SocketChannel关联的selectionKey变量; +* 3.触发channelRegistered事件; +* 4.channelRegistered事件由ChannelInitializer的channelRegistered方法响应:将客户端自定义的处理器(譬如EchoClientHandler)按顺序加入到管道中; +* 5.向服务端发起connect请求,并将SocketChannel关联的selectionKey的OP_CONNECT位置为1; +* 6.开始三次握手,客户端线程正在运行的select循环检测到了该SocketChannel的CONNECT事件就绪,则将关联的selectionKey的OP_CONNECT位置为0,再通过调用finishConnect完成连接的建立; +* 7.触发channelActive事件; +* 8.channelActive事件由EchoClientHandler的channelActive方法响应,通过调用ctx.writeAndFlush方法将消息发往服务端; +* 9.首先将消息存储到ChannelOutboundBuffer中;(如果ChannelOutboundBuffer存储的所有未flush的消息的大小超过高水位线writeBufferHighWaterMark(默认值为64 * 1024),则会触发ChannelWritabilityChanged事件) +* 10.然后将消息从ChannelOutboundBuffer中flush到套接字的发送缓冲区中;(如果ChannelOutboundBuffer存储的所有未flush的消息的大小小于低水位线,则会触发ChannelWritabilityChanged事件) \ No newline at end of file From 2d21a5530c8aa0f99277e55d9771fad5be8dc0b9 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 17 Nov 2018 11:22:09 +0800 Subject: [PATCH 004/151] updateDocument --- doc/document.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/document.md b/doc/document.md index e69de29..85d4c88 100644 --- a/doc/document.md +++ b/doc/document.md @@ -0,0 +1,3 @@ +# InChat 中文文档说明 + +> 目前正在撰写中。 \ No newline at end of file From fff5f38f5bb5542ba33b1e921b5e2ba532cb6a3c Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 17 Nov 2018 11:42:32 +0800 Subject: [PATCH 005/151] uodate --- README.md | 8 ++++---- doc/document.md | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e6df0f9..237812f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ A lightweight, efficient communication framework that supports chat and the Inte * [netty4通信原理](doc/netty-study.md) -## Branch demo:Stop updates +## Branch demo Original Project Core demo, you can first run to understand, imitation WeChat chat application, step by step update, based on Springboot-websocket General framework, combined with Netty to chat social, and record chat logs, asynchronous storage, front-end provisional sui Mobile, add implementation tcp/ IP back-end communication port (MQTT protocol, real-time and single-chip computer and other TCP hardware communication), add picture processing stream, chat implementation text and picture sending function, API call Netty long link execution Send message (number of online, user list) @@ -38,15 +38,15 @@ IP back-end communication port (MQTT protocol, real-time and single-chip compute ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) -## Branch im-api:Stop updates +## Branch im-api Tencent im (cloud communications) backend imitation project, are docked in the form of APIs, if there is a front-end want to dock can run this branch, this branch is expected to end up for a single service concurrent 300,000 users of IM background project -## Branch paho-mqtt:Stop updates +## Branch paho-mqtt Based on the small program end or mobile Web end of the Paho.js and Java MQTT Client simulation of message subscriptions and communications, small program IoT demo, currently supports WS format -## Branch tcp-wechat:Stop updates +## Branch tcp-wechat Based on the main communication between the small program end and the single chip computer and other hardware TCP/IP, IoT Center as a relay, this demo will fully implement the specific functions, please see the Branch home page for details diff --git a/doc/document.md b/doc/document.md index 85d4c88..e3c0dfd 100644 --- a/doc/document.md +++ b/doc/document.md @@ -1,3 +1,46 @@ # InChat 中文文档说明 -> 目前正在撰写中。 \ No newline at end of file +> 目前正在撰写中。 + +## 简介 + +***(InChat)Iot Netty Chat*** + +> master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目 + +一个轻量级、高效的通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 + +## 学习资料 + +* [netty4通信原理](netty-study.md) + +## 关于demo分支 + +原始项目核心演示, 您可以先运行了解, 模仿微聊天聊天应用程序, 逐步更新, 基于 springbot-web 套接字的一般框架, 结合 netty 聊天社交, 并记录聊天日志, 异步存储, 前端临时 sui mobile, 添加实现 tcp/后端通信端口 (mqtt 协议、实时和单片机等 tcp 硬件通信), 添加图片处理流、聊天实现文本和图片发送功能,api 调用 netty 长链接执行发送消息 (联机、用户列表的数量) + +## demo分支演示效果图 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(5).png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(3).png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(4).png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(2).png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(1).png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/9.png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) + +## 关于im-api分支 + +腾讯 im (云通信) 后端仿真项目, 以 api 的形式对接, 如果有前端想要停靠可以运行此分支, 预计该分支最终将为一个单一的服务并发 300, 000个用户的 im 后台项目 + +## 关于paho-mqtt分支 + +基于 paho. js 和 java mqtt 客户端消息订阅和通信的小型程序端或移动 web 端, 小程序物联网演示目前支持 ws 格式 + +## 关于tcp-wechat分支 + +基于小程序端与单片机等硬件 tcp/ip 的主要通信, 将物联网中心作为中转, 本演示将充分实现具体功能 + +## 联系 + +QQ群:628793702 \ No newline at end of file From 8ef5220fb05a3bcbc082e05e1f5e3804a6545edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 11:50:11 +0800 Subject: [PATCH 006/151] update --- .../nettychat/bootstrap/ChannelService.java | 2 + .../bootstrap/NettyBootstrapServer.java | 8 +-- .../bootstrap/bean/RetainMessage.java | 1 + .../bootstrap/bean/SendMqttMessage.java | 8 ++- .../bootstrap/bean/SendWebMessage.java | 28 +++++++++++ .../nettychat/bootstrap/bean/WebChannel.java | 49 +++++++++++++++++++ .../common/properties/InitNetty.java | 4 ++ .../ServerWebSocketHandlerService.java | 22 +++++++++ src/main/resources/application.yml | 2 + 9 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java create mode 100644 src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java create mode 100644 src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java diff --git a/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java index 3b86515..86bddfd 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java @@ -17,6 +17,8 @@ public interface ChannelService { MqttChannel getMqttChannel(String deviceId); + + boolean connectSuccess(String s, MqttChannel build); void suscribeSuccess(String deviceId, Set topics); diff --git a/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java b/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java index 816eea7..78275d0 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java @@ -65,11 +65,11 @@ protected void initChannel(SocketChannel ch) throws Exception { .childOption(ChannelOption.TCP_NODELAY, serverBean.isNodelay()) .childOption(ChannelOption.SO_KEEPALIVE, serverBean.isKeepalive()) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); - bootstrap.bind(IpUtils.getHost(),serverBean.getMqttport()).addListener((ChannelFutureListener) channelFuture -> { + bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) - log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getMqttport() + "】"); + log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); else - log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getMqttport() + "】"); + log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); }); } /** @@ -121,7 +121,7 @@ public void shutdown() { bossGroup.shutdownGracefully().sync();// 优雅关闭 workGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { - log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getMqttport() + "】"); + log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); } } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java b/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java index 814696a..68ca021 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java +++ b/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java @@ -11,6 +11,7 @@ public class RetainMessage { private byte[] byteBuf; private MqttQoS qoS; + public String getString(){ return new String(byteBuf); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java b/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java index ac5faef..c516abf 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java +++ b/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java @@ -1,6 +1,5 @@ package com.myself.nettychat.bootstrap.bean; - import io.netty.channel.Channel; import io.netty.handler.codec.mqtt.MqttQoS; import lombok.Builder; @@ -9,15 +8,14 @@ import com.myself.nettychat.common.enums.ConfirmStatus; /** - * @author MySelf - * @create 2018/9/22 + * @author MySelf + * @create 2018/9/22 * @desc mqtts 消息 **/ @Builder @Data public class SendMqttMessage { - private int messageId; private Channel channel; @@ -26,7 +24,7 @@ public class SendMqttMessage { private long time; - private byte[] byteBuf; + private byte[] byteBuf; private boolean isRetain; diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java b/src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java new file mode 100644 index 0000000..1cf7625 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java @@ -0,0 +1,28 @@ +package com.myself.nettychat.bootstrap.bean; + +import com.myself.nettychat.common.enums.ConfirmStatus; +import io.netty.channel.Channel; +import lombok.Builder; +import lombok.Data; + +/** + * WebSocket 消息 + * Created by MySelf on 2018/11/21. + */ +@Data +@Builder +public class SendWebMessage { + + private int messageId; + + private Channel channel; + + private volatile ConfirmStatus confirmStatus; + + private long time; + + private byte[] byteBuf; + + private boolean isRetain; + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java b/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java new file mode 100644 index 0000000..030fcc7 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java @@ -0,0 +1,49 @@ +package com.myself.nettychat.bootstrap.bean; + +import com.myself.nettychat.common.enums.SessionStatus; +import io.netty.channel.Channel; +import io.netty.util.AttributeKey; +import io.swagger.models.auth.In; +import lombok.Builder; +import lombok.Data; + +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * 聊天消息channel 封装类 + * Created by MySelf on 2018/11/21. + */ +@Data +@Builder +public class WebChannel { + + private transient volatile Channel channel; + + private String msgId; + + private boolean isWill; + + private volatile SessionStatus sessionStatus; //在线 - 离线 + + private volatile boolean cleanSession; //当为 true 时channel close 时 从缓存中删除 此channel + + private ConcurrentHashMap message;// messageId - message(toid) //待确认消息 + + private Set receive; + + /** + * 判断当前channel是否登录过 + * @return + */ + public boolean isLogin(){ + return Optional.ofNullable(this.channel).map(channel1 -> { + AttributeKey _login = AttributeKey.valueOf("login"); + return channel1.isActive() && channel1.hasAttr(_login); + }).orElse(false); + } + + + +} diff --git a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java index cdaca4f..cd292ff 100644 --- a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java +++ b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java @@ -24,6 +24,10 @@ public class InitNetty { private int backlog; + private boolean nodelay; + + private boolean reuseaddr; + private int sndbuf; private int revbuf; diff --git a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java new file mode 100644 index 0000000..e01541e --- /dev/null +++ b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java @@ -0,0 +1,22 @@ +package com.myself.nettychat.common.websockets; + +import io.netty.channel.Channel; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; + +/** + * Created by MySelf on 2018/11/21. + */ +public abstract class ServerWebSocketHandlerService implements WebSocketHandlerApi { + + public abstract boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame); + + public abstract void sendText(Channel channel, TextWebSocketFrame webSocketFrame); + + public abstract void pong(Channel channel); + + public abstract void disconnect(Channel channel); + + public abstract void doTimeOut(Channel channel, IdleStateEvent evt); + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 38f5d9b..c61107b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,6 +12,8 @@ netty: workerThread: 2 keepalive: true # 套接字参数, 连接保修, 默认值为 false。启用此功能后, tcp 会主动检测空闲连接的有效性。您可以将此功能视为 tcp 的检测信号机制, 请务必注意, 默认检测信号间隔为 7200s, 即2小时。netty 默认关闭此功能 backlog: 1024 # 套接字参数, 服务器接受连接的队列长度, 如果队列已满, 则客户端连接将被拒绝 + nodelay: true #TCP参数,立即发送数据,默认值为Ture(Netty默认为True而操作系统默认为False)。该值设置Nagle算法的启用,改算法将小的碎片数据连接成更大的报文来最小化所发送的报文的数量,如果需要发送一些较小的报文,则需要禁用该算法。Netty默认禁用该算法,从而最小化报文传输延时。 + reuseaddr: true #地址复用,默认值False。有四种情况可以使用:(1).当有一个有相同本地地址和端口的socket1处于TIME_WAIT状态时,而你希望启动的程序的socket2要占用该地址和端口,比如重启服务且保持先前端口。(2).有多块网卡或用IP Alias技术的机器在同一端口启动多个进程,但每个进程绑定的本地IP地址不能相同。(3).单个进程绑定相同的端口到多个socket上,但每个socket绑定的ip地址不同。(4).完全相同的地址和端口的重复绑定。但这只用于UDP的多播,不用于TCP。 sndbuf: 10485760 # tcp 数据发送缓冲区大小。 revbuf: 10485760 # tcp 数据接收缓冲区大小。 heart: 180 # 读取超时 From 25bdb8e21ebab6f354c2b782a6ea19432af0620b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 13:46:01 +0800 Subject: [PATCH 007/151] webChannel --- .../nettychat/bootstrap/bean/WebChannel.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java b/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java index 030fcc7..9d8b4f1 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java +++ b/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java @@ -3,7 +3,6 @@ import com.myself.nettychat.common.enums.SessionStatus; import io.netty.channel.Channel; import io.netty.util.AttributeKey; -import io.swagger.models.auth.In; import lombok.Builder; import lombok.Data; @@ -44,6 +43,19 @@ public boolean isLogin(){ }).orElse(false); } + /** + * 非正常关闭 + */ + public void close(){ + Optional.ofNullable(this.channel).ifPresent(channel1 -> channel1.close()); + } + /** + * 通过是否活跃 + * @return + */ + public boolean isActive(){ + return channel!=null&&this.channel.isActive(); + } } From 20472c90ad6eeb2d30b0f96f6e25e8f723111d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 14:55:10 +0800 Subject: [PATCH 008/151] websocketHandlerService --- pom.xml | 22 ++- .../nettychat/NettychatApplication.java | 32 +--- .../nettychat/bootstrap/ChannelService.java | 2 - .../channel/WebSocketHandlerService.java | 62 ++++++++ .../handler/DefaultWebSocketHandler.java | 52 ++++++- .../nettychat/common/utils/ResultVOUtil.java | 30 ---- .../myself/nettychat/config/NettyConfig.java | 2 +- .../config/NettyTcpChannelInitializer.java | 4 +- .../nettychat/config/NettyTcpConfig.java | 94 ++++++------ .../NettyWebSocketChannelInitializer.java | 4 +- .../myself/nettychat/config/TCPServer.java | 2 +- .../nettychat/config/TCPServerHandler.java | 6 +- .../config/TextWebSocketFrameHandler.java | 21 ++- .../constont/LikeSomeCacheTemplate.java | 36 ----- .../controller/NCBackController.java | 58 ------- .../controller/NcChangeController.java | 88 ----------- .../controller/NcChatController.java | 76 --------- .../controller/NcLoginController.java | 145 ------------------ .../com/myself/nettychat/dataobject/User.java | 39 ----- .../myself/nettychat/dataobject/UserMsg.java | 38 ----- .../com/myself/nettychat/form/LoginForm.java | 20 --- .../repository/UserMsgRepository.java | 13 -- .../nettychat/repository/UserRepository.java | 16 -- .../myself/nettychat/service/UserService.java | 22 --- .../service/impl/UserServiceImpl.java | 43 ------ .../myself/nettychat/task/MsgAsyncTesk.java | 50 ------ .../myself/nettychat/tcptest/CRC16myself.java | 101 ------------ .../nettychat/tcptest/TCPTestClient.java | 82 ---------- .../com/myself/nettychat/vo/ResultVo.java | 28 ---- src/main/resources/application.yml | 8 - 30 files changed, 190 insertions(+), 1006 deletions(-) create mode 100644 src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java delete mode 100644 src/main/java/com/myself/nettychat/common/utils/ResultVOUtil.java delete mode 100644 src/main/java/com/myself/nettychat/constont/LikeSomeCacheTemplate.java delete mode 100644 src/main/java/com/myself/nettychat/controller/NCBackController.java delete mode 100644 src/main/java/com/myself/nettychat/controller/NcChangeController.java delete mode 100644 src/main/java/com/myself/nettychat/controller/NcChatController.java delete mode 100644 src/main/java/com/myself/nettychat/controller/NcLoginController.java delete mode 100644 src/main/java/com/myself/nettychat/dataobject/User.java delete mode 100644 src/main/java/com/myself/nettychat/dataobject/UserMsg.java delete mode 100644 src/main/java/com/myself/nettychat/form/LoginForm.java delete mode 100644 src/main/java/com/myself/nettychat/repository/UserMsgRepository.java delete mode 100644 src/main/java/com/myself/nettychat/repository/UserRepository.java delete mode 100644 src/main/java/com/myself/nettychat/service/UserService.java delete mode 100644 src/main/java/com/myself/nettychat/service/impl/UserServiceImpl.java delete mode 100644 src/main/java/com/myself/nettychat/task/MsgAsyncTesk.java delete mode 100644 src/main/java/com/myself/nettychat/tcptest/CRC16myself.java delete mode 100644 src/main/java/com/myself/nettychat/tcptest/TCPTestClient.java delete mode 100644 src/main/java/com/myself/nettychat/vo/ResultVo.java diff --git a/pom.xml b/pom.xml index 458d0cf..7fd7f05 100644 --- a/pom.xml +++ b/pom.xml @@ -25,17 +25,21 @@ + - org.springframework.boot - spring-boot-starter-tomcat + org.aspectj + aspectjrt + 1.9.2 + - org.springframework.boot - spring-boot-starter-data-jpa + org.aspectj + aspectjweaver + 1.9.2 - mysql - mysql-connector-java + org.springframework.boot + spring-boot-starter-tomcat org.springframework.boot @@ -80,12 +84,6 @@ curator-framework 2.9.1 - - - - - - org.springframework.boot spring-boot-starter-freemarker diff --git a/src/main/java/com/myself/nettychat/NettychatApplication.java b/src/main/java/com/myself/nettychat/NettychatApplication.java index 9c679bd..1f0033e 100644 --- a/src/main/java/com/myself/nettychat/NettychatApplication.java +++ b/src/main/java/com/myself/nettychat/NettychatApplication.java @@ -1,11 +1,7 @@ package com.myself.nettychat; -import com.myself.nettychat.config.NettyConfig; -import com.myself.nettychat.config.NettyTcpConfig; -import com.myself.nettychat.config.TCPServer; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.scheduling.annotation.EnableScheduling; import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -17,33 +13,7 @@ public class NettychatApplication { public static void main(String[] args) throws Exception{ -// SpringApplication.run(NettychatApplication.class, args); - ConfigurableApplicationContext context = SpringApplication.run(NettychatApplication.class, args); - NettyConfig nettyConfig = context.getBean(NettyConfig.class); - NettyTcpConfig nettyTcpConfig = context.getBean(NettyTcpConfig.class); - TCPServer tcpServer = context.getBean(TCPServer.class); - new Thread(new Runnable() { - @Override - public void run() { - try { - System.out.println("Web端Netty通信服务端启动成功!端口:8090"); - tcpServer.startWeb(); - }catch (Exception e){ - e.printStackTrace(); - } - } - }).start(); - new Thread(new Runnable() { - @Override - public void run() { - try { - System.out.println("TCP端Netty通信服务端启动成功!端口:8092"); - tcpServer.startTcp(); - }catch (Exception e){ - e.printStackTrace(); - } - } - }).start(); + SpringApplication.run(NettychatApplication.class, args); } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java index 86bddfd..3b86515 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/ChannelService.java @@ -17,8 +17,6 @@ public interface ChannelService { MqttChannel getMqttChannel(String deviceId); - - boolean connectSuccess(String s, MqttChannel build); void suscribeSuccess(String deviceId, Set topics); diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java new file mode 100644 index 0000000..550cd73 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -0,0 +1,62 @@ +package com.myself.nettychat.bootstrap.channel; + +import com.myself.nettychat.bootstrap.BaseApi; +import com.myself.nettychat.bootstrap.BaseAuthService; +import com.myself.nettychat.bootstrap.ChannelService; +import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; +import io.netty.channel.Channel; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Created by MySelf on 2018/11/21. + */ +@Slf4j +@Component +public class WebSocketHandlerService extends ServerWebSocketHandlerService implements BaseApi { + + @Autowired + ChannelService websocketChannelService; + + private final BaseAuthService baseAuthService; + + public WebSocketHandlerService(BaseAuthService baseAuthService){ + this.baseAuthService = baseAuthService; + } + + @Override + public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { + //校验规则,自定义校验规则 + System.out.println("login-"+textWebSocketFrame.text()); + return true; + } + + @Override + public void sendText(Channel channel, TextWebSocketFrame webSocketFrame) { + System.out.println("sendText-"+webSocketFrame.text()); + } + + @Override + public void pong(Channel channel) { + + } + + @Override + public void disconnect(Channel channel) { + + } + + @Override + public void doTimeOut(Channel channel, IdleStateEvent evt) { + log.info("【PingPongService:doTimeOut 心跳超时】" + channel.remoteAddress() + "【channel 关闭】"); + + } + + @Override + public void close(Channel channel) { + + } +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index 95a4168..6b66c85 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -1,10 +1,60 @@ package com.myself.nettychat.bootstrap.handler; +import com.myself.nettychat.common.exception.NoFindHandlerException; +import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; +import com.myself.nettychat.common.websockets.WebSocketHandler; +import com.myself.nettychat.common.websockets.WebSocketHandlerApi; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + /** * @Author:UncleCatMySelf * @Email:zhupeijie_java@126.com * @QQ:1341933031 * @Date:Created in 20:15 2018\11\16 0016 */ -public class DefaultWebSocketHandler { +@Slf4j +@Component +@ChannelHandler.Sharable +public class DefaultWebSocketHandler extends WebSocketHandler { + + private final WebSocketHandlerApi webSocketHandlerApi; + + public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { + super(webSocketHandlerApi); + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { + + } + + @Override + protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { + Channel channel = ctx.channel(); + ServerWebSocketHandlerService serverWebSocketHandlerService; + if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ + serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; + }else{ + throw new NoFindHandlerException("Server Handler 不匹配"); + } + System.out.println("textdoMessage--"+msg.text()); + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ + log.error("exception",cause); + webSocketHandlerApi.close(ctx.channel()); + } } diff --git a/src/main/java/com/myself/nettychat/common/utils/ResultVOUtil.java b/src/main/java/com/myself/nettychat/common/utils/ResultVOUtil.java deleted file mode 100644 index b2b678d..0000000 --- a/src/main/java/com/myself/nettychat/common/utils/ResultVOUtil.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.myself.nettychat.common.utils; - -import com.myself.nettychat.vo.ResultVo; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:59 2018\10\7 0007 - */ -public class ResultVOUtil { - public static ResultVo success(Object object){ - ResultVo resultVO = new ResultVo(); - resultVO.setData(object); - resultVO.setCode(200); - resultVO.setMsg("成功"); - return resultVO; - } - - public static ResultVo success(){ - return success(null); - } - - public static ResultVo error(Integer code, String msg){ - ResultVo resultVO = new ResultVo(); - resultVO.setCode(code); - resultVO.setMsg(msg); - return resultVO; - } -} diff --git a/src/main/java/com/myself/nettychat/config/NettyConfig.java b/src/main/java/com/myself/nettychat/config/NettyConfig.java index 2648087..3a71119 100644 --- a/src/main/java/com/myself/nettychat/config/NettyConfig.java +++ b/src/main/java/com/myself/nettychat/config/NettyConfig.java @@ -23,7 +23,7 @@ * @QQ:1341933031 * @Date:Created in 11:00 2018\8\14 0014 */ -@Component +//@Component public class NettyConfig { @Autowired diff --git a/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java b/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java index ceb8ed9..d07f1be 100644 --- a/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java +++ b/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java @@ -15,8 +15,8 @@ * @QQ:1341933031 * @Date:Created in 19:26 2018\9\20 0020 */ -@Component -@Qualifier("tcpChannelInitializer") +//@Component +//@Qualifier("tcpChannelInitializer") public class NettyTcpChannelInitializer extends ChannelInitializer { @Autowired diff --git a/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java b/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java index f6ce2d2..6a50776 100644 --- a/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java +++ b/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java @@ -23,54 +23,54 @@ * @QQ:1341933031 * @Date:Created in 19:27 2018\9\20 0020 */ -@Component +//@Component public class NettyTcpConfig { - @Autowired - private InitNetty nettyAccountConfig; - - @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully") - public NioEventLoopGroup bossGroup(){ - return new NioEventLoopGroup(nettyAccountConfig.getBossThread()); - } - - @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully") - public NioEventLoopGroup workerGroup(){ - return new NioEventLoopGroup(nettyAccountConfig.getWorkerThread()); - } - - @Bean(name = "tcpSocketAddress") - public InetSocketAddress tcpPost(){ - return new InetSocketAddress(nettyAccountConfig.getTcpport()); - } - - @Bean(name = "tcpChannelOptions") - public Map, Object> tcpChannelOptions(){ - Map, Object> options = new HashMap<>(); - options.put(ChannelOption.TCP_NODELAY,nettyAccountConfig.isNodelay()); - options.put(ChannelOption.SO_KEEPALIVE, nettyAccountConfig.isKeepalive()); - options.put(ChannelOption.SO_BACKLOG, nettyAccountConfig.getBacklog()); - options.put(ChannelOption.SO_REUSEADDR,nettyAccountConfig.isReuseaddr()); - return options; - } - - @Autowired - @Qualifier("tcpChannelInitializer") - private NettyTcpChannelInitializer nettyTcpChannelInitializer; - - @Bean(name = "tcpServerBootstrap") - public ServerBootstrap bootstrap(){ - ServerBootstrap b = new ServerBootstrap(); - b.group(bossGroup(), workerGroup()) - .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.DEBUG)) - .childHandler(nettyTcpChannelInitializer); - Map, Object> tcpChannelOptions = tcpChannelOptions(); - Set> keySet = tcpChannelOptions.keySet(); - for (@SuppressWarnings("rawtypes") ChannelOption option : keySet) { - b.option(option, tcpChannelOptions.get(option)); - } - return b; - } +// @Autowired +// private InitNetty nettyAccountConfig; +// +// @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully") +// public NioEventLoopGroup bossGroup(){ +// return new NioEventLoopGroup(nettyAccountConfig.getBossThread()); +// } +// +// @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully") +// public NioEventLoopGroup workerGroup(){ +// return new NioEventLoopGroup(nettyAccountConfig.getWorkerThread()); +// } +// +// @Bean(name = "tcpSocketAddress") +// public InetSocketAddress tcpPost(){ +// return new InetSocketAddress(nettyAccountConfig.getTcpport()); +// } +// +// @Bean(name = "tcpChannelOptions") +// public Map, Object> tcpChannelOptions(){ +// Map, Object> options = new HashMap<>(); +// options.put(ChannelOption.TCP_NODELAY,nettyAccountConfig.isNodelay()); +// options.put(ChannelOption.SO_KEEPALIVE, nettyAccountConfig.isKeepalive()); +// options.put(ChannelOption.SO_BACKLOG, nettyAccountConfig.getBacklog()); +// options.put(ChannelOption.SO_REUSEADDR,nettyAccountConfig.isReuseaddr()); +// return options; +// } +// +// @Autowired +// @Qualifier("tcpChannelInitializer") +// private NettyTcpChannelInitializer nettyTcpChannelInitializer; +// +// @Bean(name = "tcpServerBootstrap") +// public ServerBootstrap bootstrap(){ +// ServerBootstrap b = new ServerBootstrap(); +// b.group(bossGroup(), workerGroup()) +// .channel(NioServerSocketChannel.class) +// .handler(new LoggingHandler(LogLevel.DEBUG)) +// .childHandler(nettyTcpChannelInitializer); +// Map, Object> tcpChannelOptions = tcpChannelOptions(); +// Set> keySet = tcpChannelOptions.keySet(); +// for (@SuppressWarnings("rawtypes") ChannelOption option : keySet) { +// b.option(option, tcpChannelOptions.get(option)); +// } +// return b; +// } } diff --git a/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java b/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java index a2f2eb4..7037050 100644 --- a/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java +++ b/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java @@ -18,8 +18,8 @@ * @QQ:1341933031 * @Date:Created in 11:00 2018\8\14 0014 */ -@Component -@Qualifier("somethingChannelInitializer") +//@Component +//@Qualifier("somethingChannelInitializer") public class NettyWebSocketChannelInitializer extends ChannelInitializer { @Autowired diff --git a/src/main/java/com/myself/nettychat/config/TCPServer.java b/src/main/java/com/myself/nettychat/config/TCPServer.java index ae478f4..fbf7580 100644 --- a/src/main/java/com/myself/nettychat/config/TCPServer.java +++ b/src/main/java/com/myself/nettychat/config/TCPServer.java @@ -17,7 +17,7 @@ * @Date:Created in 11:00 2018\8\14 0014 */ @Data -@Component +//@Component public class TCPServer { @Autowired diff --git a/src/main/java/com/myself/nettychat/config/TCPServerHandler.java b/src/main/java/com/myself/nettychat/config/TCPServerHandler.java index f5afdfc..735b200 100644 --- a/src/main/java/com/myself/nettychat/config/TCPServerHandler.java +++ b/src/main/java/com/myself/nettychat/config/TCPServerHandler.java @@ -23,9 +23,9 @@ * @QQ:1341933031 * @Date:Created in 19:29 2018\9\20 0020 */ -@Component -@Qualifier("tcpServerHandler") -@ChannelHandler.Sharable +//@Component +//@Qualifier("tcpServerHandler") +//@ChannelHandler.Sharable public class TCPServerHandler extends ChannelInboundHandlerAdapter { static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); diff --git a/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java b/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java index a47c5aa..01901b1 100644 --- a/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java +++ b/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java @@ -1,8 +1,7 @@ package com.myself.nettychat.config; -import com.myself.nettychat.task.MsgAsyncTesk; + import com.myself.nettychat.constont.LikeRedisTemplate; -import com.myself.nettychat.constont.LikeSomeCacheTemplate; import com.myself.nettychat.common.utils.StringUtil; import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; @@ -28,19 +27,19 @@ * @QQ:1341933031 * @Date:Created in 11:01 2018\8\14 0014 */ -@Component -@Qualifier("textWebSocketFrameHandler") -@ChannelHandler.Sharable +//@Component +//@Qualifier("textWebSocketFrameHandler") +//@ChannelHandler.Sharable public class TextWebSocketFrameHandler extends SimpleChannelInboundHandler{ public static ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); @Autowired private LikeRedisTemplate redisTemplate; - @Autowired - private LikeSomeCacheTemplate cacheTemplate; - @Autowired - private MsgAsyncTesk msgAsyncTesk; +// @Autowired +// private LikeSomeCacheTemplate cacheTemplate; +// @Autowired +// private MsgAsyncTesk msgAsyncTesk; @Override protected void channelRead0(ChannelHandlerContext ctx, @@ -82,7 +81,7 @@ private void textWebSocketFrame(ChannelHandlerContext ctx, TextWebSocketFrame ms //用户登录判断 if (redisTemplate.check(incoming.id(),rName)){ //临时存储聊天数据 - cacheTemplate.save(rName,rMsg); + // cacheTemplate.save(rName,rMsg); //存储随机链接ID与对应登录用户名 redisTemplate.save(incoming.id(),rName); //存储登录用户名与链接实例,方便API调用链接实例 @@ -128,7 +127,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { //掉线 - msgAsyncTesk.saveChatMsgTask(); + //msgAsyncTesk.saveChatMsgTask(); } @Override diff --git a/src/main/java/com/myself/nettychat/constont/LikeSomeCacheTemplate.java b/src/main/java/com/myself/nettychat/constont/LikeSomeCacheTemplate.java deleted file mode 100644 index e1ca623..0000000 --- a/src/main/java/com/myself/nettychat/constont/LikeSomeCacheTemplate.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.myself.nettychat.constont; - -import com.myself.nettychat.dataobject.UserMsg; -import org.omg.CORBA.OBJ_ADAPTER; -import org.springframework.stereotype.Component; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 聊天内容临时存储 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 13:38 2018\8\14 0014 - */ -@Component -public class LikeSomeCacheTemplate { - - private List SomeCache = new LinkedList<>(); - - public void save(Object user,Object msg){ - UserMsg userMsg = new UserMsg(); - userMsg.setName(String.valueOf(user)); - userMsg.setMsg(String.valueOf(msg)); - SomeCache.add(userMsg); - } - - public List cloneCacheMap(){ - return SomeCache; - } - - public void clearCacheMap(){ - SomeCache.clear(); - } -} diff --git a/src/main/java/com/myself/nettychat/controller/NCBackController.java b/src/main/java/com/myself/nettychat/controller/NCBackController.java deleted file mode 100644 index 579cd9e..0000000 --- a/src/main/java/com/myself/nettychat/controller/NCBackController.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.myself.nettychat.controller; - -import com.myself.nettychat.common.utils.ResultVOUtil; -import com.myself.nettychat.common.utils.SendUtil; -import com.myself.nettychat.constont.LikeRedisTemplate; -import com.myself.nettychat.vo.ResultVo; -import io.netty.channel.Channel; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:55 2018\10\7 0007 - */ -@RestController -@RequestMapping("/back") -public class NCBackController { - - @Autowired - private LikeRedisTemplate redisTemplate; - - /** - * 获取在线用户数 - * @return {@link ResultVo} - */ - @GetMapping("/size") - public ResultVo getSize(){ - return ResultVOUtil.success(redisTemplate.getSize()); - } - - /** - * 获取在线用户列表 - * @return {@link ResultVo} - */ - @GetMapping("/online") - public ResultVo getOnline(){ - return ResultVOUtil.success(redisTemplate.getOnline()); - } - - /** - * API调用向在线用户发送消息 - * @param name 用户名 - * @param msg 消息 - * @return {@link ResultVo} - */ - @PostMapping("/send") - public ResultVo send(@RequestParam String name,@RequestParam String msg){ - Channel channel = (Channel) redisTemplate.getChannel(name); - if (channel == null){ - return ResultVOUtil.error(555,"当前用户连接已断开"); - } - String result = SendUtil.sendTest(msg,channel); - return ResultVOUtil.success(result); - } - -} diff --git a/src/main/java/com/myself/nettychat/controller/NcChangeController.java b/src/main/java/com/myself/nettychat/controller/NcChangeController.java deleted file mode 100644 index feb492b..0000000 --- a/src/main/java/com/myself/nettychat/controller/NcChangeController.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.myself.nettychat.controller; - -import com.myself.nettychat.constont.CookieConstant; -import com.myself.nettychat.constont.H5Constant; -import com.myself.nettychat.dataobject.User; -import com.myself.nettychat.service.UserService; -import com.myself.nettychat.store.TokenStore; -import com.myself.nettychat.common.utils.CookieUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import java.util.Map; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:59 2018\9\5 0005 - */ -@Controller -@RequestMapping("/su") -public class NcChangeController { - - @Autowired - private UserService userService; - - /** - * 我的中心界面 - * @param map - * @return - */ - @GetMapping("/me") - public ModelAndView Me(Map map){ - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN); - if (cookie == null){ - map.put("msg","cookie中不存在token"); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - Integer userId = (Integer) TokenStore.get(cookie.getValue()); - if (userId == null){ - map.put("msg","用户信息不存在"); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - User user = userService.findOne(userId); - map.put("userName",user.getUserName()); - return new ModelAndView(H5Constant.ME,map); - } - - /** - * 发现 - * @param map - * @return - */ - @GetMapping("/find") - public ModelAndView find(Map map){ - return new ModelAndView(H5Constant.FIND); - } - - /** - * 聊天 - * @param map - * @return - */ - @GetMapping("/chat") - public ModelAndView chat(Map map){ - return new ModelAndView(H5Constant.CHAT); - } - - /** - * 主页 - * @param map - * @return - */ - @GetMapping("/home") - public ModelAndView home(Map map){ - return new ModelAndView(H5Constant.HOME); - } - -} diff --git a/src/main/java/com/myself/nettychat/controller/NcChatController.java b/src/main/java/com/myself/nettychat/controller/NcChatController.java deleted file mode 100644 index 3a7d79b..0000000 --- a/src/main/java/com/myself/nettychat/controller/NcChatController.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.myself.nettychat.controller; - -import com.myself.nettychat.constont.CookieConstant; -import com.myself.nettychat.constont.H5Constant; -import com.myself.nettychat.dataobject.User; -import com.myself.nettychat.dataobject.UserMsg; -import com.myself.nettychat.repository.UserMsgRepository; -import com.myself.nettychat.service.UserService; -import com.myself.nettychat.store.TokenStore; -import com.myself.nettychat.common.utils.CookieUtil; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 14:32 2018\8\14 0014 - */ -@Controller -@RequestMapping("/chat") -public class NcChatController { - - @Autowired - private UserMsgRepository userMsgRepository; - - @Autowired - private UserService userService; - - @GetMapping("/netty") - public ModelAndView netty(@RequestParam(value = "page",defaultValue = "1") Integer page, - @RequestParam(value = "size",defaultValue = "10") Integer size, - Map map){ - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN); - if (cookie == null){ - map.put("msg","cookie中不存在token"); - return new ModelAndView(H5Constant.LOGIN,map); - } - Integer userId = (Integer) TokenStore.get(cookie.getValue()); - if (userId == null){ - map.put("msg","用户信息不存在"); - return new ModelAndView(H5Constant.LOGIN,map); - } - User user = userService.findOne(userId); - Sort sort = new Sort(Sort.Direction.DESC,"id"); - Pageable pageable = new PageRequest(page-1,size,sort); - Page userMsgPage = userMsgRepository.findAll(pageable); - //日期颠倒 - List userMsgList = new ArrayList<>(); - for (int i = 0,j = userMsgPage.getContent().size()-1; i < userMsgPage.getContent().size();i++,j--){ - userMsgList.add(userMsgPage.getContent().get(j)); - } - map.put("userName",user.getUserName()); - map.put("userMsgList",userMsgList); - return new ModelAndView(H5Constant.ALLCHAT,map); - } - -} diff --git a/src/main/java/com/myself/nettychat/controller/NcLoginController.java b/src/main/java/com/myself/nettychat/controller/NcLoginController.java deleted file mode 100644 index 2db26fb..0000000 --- a/src/main/java/com/myself/nettychat/controller/NcLoginController.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.myself.nettychat.controller; - -import com.myself.nettychat.constont.CookieConstant; -import com.myself.nettychat.constont.H5Constant; -import com.myself.nettychat.dataobject.User; -import com.myself.nettychat.form.LoginForm; -import com.myself.nettychat.repository.UserMsgRepository; -import com.myself.nettychat.service.UserService; -import com.myself.nettychat.store.TokenStore; -import com.myself.nettychat.common.utils.CookieUtil; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 16:01 2018\8\18 0018 - */ -@Controller -@RequestMapping("/admin") -public class NcLoginController { - - @Autowired - private UserService userService; - @Autowired - private UserMsgRepository userMsgRepository; - - /** - * 登录页面 - * @return - */ -// @GetMapping("/login") -// public ModelAndView login(Map map){ -// return new ModelAndView(H5Constant.LOGIN); -// } - - - /** - * 登录页面SUI - * @return - */ - @GetMapping("/loginsui") - public ModelAndView loginSui(Map map){ - return new ModelAndView(H5Constant.LOGIN_SUI); - } - - /** - * 注册页面 - * @return - */ - @GetMapping("/regis") - public ModelAndView register(){ - return new ModelAndView(H5Constant.LOGIN_SUI); - } - - - - /** - * 执行注册 - * @param form - * @param bindingResult - * @param response - * @param map - * @return - */ - @PostMapping("/toRegister") - public ModelAndView toRegister(@Valid LoginForm form, BindingResult bindingResult , HttpServletResponse response, - Map map){ - if (bindingResult.hasErrors()){ - map.put("msg",bindingResult.getFieldError().getDefaultMessage()); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - List userList = userService.findAll(); - for (User item:userList){ - if (item.getUserName().equals(form.getFUserName())){ - map.put("msg","用户名已存在,请重新填写唯一用户名"); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - } - User user = new User(); - BeanUtils.copyProperties(form,user); - userService.save(user); - map.put("userName",user.getUserName()); - map.put("passWord",user.getPassWord()); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - - /** - * 登录判断 - * @return - */ - @PostMapping("/toLogin") - public ModelAndView toLogin(@RequestParam(value = "page",defaultValue = "1") Integer page, - @RequestParam(value = "size",defaultValue = "10") Integer size, - @Valid LoginForm form, BindingResult bindingResult , HttpServletResponse response, - Map map){ - if (bindingResult.hasErrors()){ - map.put("msg",bindingResult.getFieldError().getDefaultMessage()); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - try { - User user = userService.findByUserName(form.getFUserName()); - if (user.getPassWord().equals(form.getFPassWord())){ - //登录成功 - String token = UUID.randomUUID().toString(); - //将token信息添加到系统缓存中 - TokenStore.add(token,user.getId()); - //将Token信息添加到Cookie中 - CookieUtil.set(response, CookieConstant.TOKEN,token,CookieConstant.EXPIRE); -// Sort sort = new Sort(Sort.Direction.DESC,"id"); -// Pageable pageable = new PageRequest(page-1,size,sort); -// Page userMsgPage = userMsgRepository.findAll(pageable); -// //日期颠倒 -// List userMsgList = new ArrayList<>(); -// for (int i = 0,j = userMsgPage.getContent().size()-1; i < userMsgPage.getContent().size();i++,j--){ -// userMsgList.add(userMsgPage.getContent().get(j)); -// } -// map.put("userMsgList",userMsgList); -// map.put("userName",user.getUserName()); - return new ModelAndView(H5Constant.HOME); - }else{ - map.put("msg","密码错误"); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - }catch (Exception e){ - map.put("msg","用户不存在"); - return new ModelAndView(H5Constant.LOGIN_SUI,map); - } - } - -} diff --git a/src/main/java/com/myself/nettychat/dataobject/User.java b/src/main/java/com/myself/nettychat/dataobject/User.java deleted file mode 100644 index d00bbad..0000000 --- a/src/main/java/com/myself/nettychat/dataobject/User.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.myself.nettychat.dataobject; - -import lombok.Data; -import org.hibernate.annotations.DynamicUpdate; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import java.io.Serializable; -import java.util.Date; - -/** - * 主用户信息表 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:44 2018\8\13 0013 - */ -@Data -@Entity -@DynamicUpdate -public class User implements Serializable { - - private static final long serialVersionUID = 8143981246513357880L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - private String userName; - - private String passWord; - - private Date createTime; - - private Date updateTime; - -} diff --git a/src/main/java/com/myself/nettychat/dataobject/UserMsg.java b/src/main/java/com/myself/nettychat/dataobject/UserMsg.java deleted file mode 100644 index a651839..0000000 --- a/src/main/java/com/myself/nettychat/dataobject/UserMsg.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.myself.nettychat.dataobject; - -import lombok.Data; -import org.hibernate.annotations.DynamicUpdate; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import java.io.Serializable; -import java.util.Date; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 14:03 2018\8\14 0014 - */ -@Data -@Entity -@DynamicUpdate -public class UserMsg implements Serializable { - - private static final long serialVersionUID = 4133316147283239759L; - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Integer id; - - private String name; - - private String msg; - - private Date createTime; - - private Date updateTime; - -} diff --git a/src/main/java/com/myself/nettychat/form/LoginForm.java b/src/main/java/com/myself/nettychat/form/LoginForm.java deleted file mode 100644 index 2792a74..0000000 --- a/src/main/java/com/myself/nettychat/form/LoginForm.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.myself.nettychat.form; - -import lombok.Data; - -import javax.validation.constraints.NotEmpty; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 16:02 2018\8\13 0013 - */ -@Data -public class LoginForm { - @NotEmpty(message = "用户名不能为空") - private String fUserName; - @NotEmpty(message = "密码不能为空") - private String fPassWord; - -} diff --git a/src/main/java/com/myself/nettychat/repository/UserMsgRepository.java b/src/main/java/com/myself/nettychat/repository/UserMsgRepository.java deleted file mode 100644 index 6e98ace..0000000 --- a/src/main/java/com/myself/nettychat/repository/UserMsgRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.myself.nettychat.repository; - -import com.myself.nettychat.dataobject.UserMsg; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 14:06 2018\8\14 0014 - */ -public interface UserMsgRepository extends JpaRepository { -} diff --git a/src/main/java/com/myself/nettychat/repository/UserRepository.java b/src/main/java/com/myself/nettychat/repository/UserRepository.java deleted file mode 100644 index be6c18a..0000000 --- a/src/main/java/com/myself/nettychat/repository/UserRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.myself.nettychat.repository; - -import com.myself.nettychat.dataobject.User; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:47 2018\8\13 0013 - */ -public interface UserRepository extends JpaRepository { - - User findByUserName(String userName); - -} diff --git a/src/main/java/com/myself/nettychat/service/UserService.java b/src/main/java/com/myself/nettychat/service/UserService.java deleted file mode 100644 index d106993..0000000 --- a/src/main/java/com/myself/nettychat/service/UserService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.myself.nettychat.service; - -import com.myself.nettychat.dataobject.User; - -import java.util.List; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:52 2018\8\18 0018 - */ -public interface UserService { - - User findOne(Integer id); - - User save(User user); - - User findByUserName(String userName); - - List findAll(); -} diff --git a/src/main/java/com/myself/nettychat/service/impl/UserServiceImpl.java b/src/main/java/com/myself/nettychat/service/impl/UserServiceImpl.java deleted file mode 100644 index 951cc04..0000000 --- a/src/main/java/com/myself/nettychat/service/impl/UserServiceImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.myself.nettychat.service.impl; - -import com.myself.nettychat.dataobject.User; -import com.myself.nettychat.repository.UserRepository; -import com.myself.nettychat.service.UserService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:52 2018\8\18 0018 - */ -@Service -public class UserServiceImpl implements UserService { - - @Autowired - private UserRepository repository; - - - @Override - public User findOne(Integer id) { - return repository.getOne(id); - } - - @Override - public User save(User user) { - return repository.save(user); - } - - @Override - public User findByUserName(String userName) { - return repository.findByUserName(userName); - } - - @Override - public List findAll() { - return repository.findAll(); - } -} diff --git a/src/main/java/com/myself/nettychat/task/MsgAsyncTesk.java b/src/main/java/com/myself/nettychat/task/MsgAsyncTesk.java deleted file mode 100644 index 445e50b..0000000 --- a/src/main/java/com/myself/nettychat/task/MsgAsyncTesk.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.myself.nettychat.task; - -import com.myself.nettychat.constont.LikeSomeCacheTemplate; -import com.myself.nettychat.dataobject.User; -import com.myself.nettychat.dataobject.UserMsg; -import com.myself.nettychat.repository.UserMsgRepository; -import com.myself.nettychat.repository.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.concurrent.Future; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 13:50 2018\8\14 0014 - */ -@Component -public class MsgAsyncTesk { - - @Autowired - private LikeSomeCacheTemplate cacheTemplate; - - @Autowired - private UserMsgRepository userMsgRepository; - - @Autowired - private UserRepository userRepository; - - @Async - public Future saveChatMsgTask() throws Exception{ - - List userMsgList = cacheTemplate.cloneCacheMap(); - for (UserMsg item:userMsgList){ - //保护措施 - User user = userRepository.findByUserName(item.getName()); - if (user != null){ - userMsgRepository.save(item); - } - } - //清空临时缓存 - cacheTemplate.clearCacheMap(); - return new AsyncResult<>(true); - } - -} diff --git a/src/main/java/com/myself/nettychat/tcptest/CRC16myself.java b/src/main/java/com/myself/nettychat/tcptest/CRC16myself.java deleted file mode 100644 index 9f50137..0000000 --- a/src/main/java/com/myself/nettychat/tcptest/CRC16myself.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.myself.nettychat.tcptest; - -import java.math.BigInteger; - -/** - * 获取数据格式,请勿乱更改test的值或长度 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:39 2018\9\20 0020 - */ -public class CRC16myself { - - public static void main(String[] args) { - String test = "F5690137563CC8syyyyyyyyyyyyyyyyynnnnnnn"; - System.out.println("原始内容字符串:" + test); - String crcString = getCRC(test.getBytes()); - System.out.println("str:" + crcString); - int crc = getCRCInt(test.getBytes()); - System.out.println("hex:" + crc); - CRC16myself myself = new CRC16myself(); - float crc16 = myself.parseHex2Float(crcString); - System.out.println("10进制浮点型:" + crc16); - String crc16String = myself.parseFloat2Hex(crc16); - System.out.println("十六进制浮点型:" + crc16String); - System.out.println("输出字符串:" + "gz" + test + crcString + "xr"); - } - - /** - * 计算CRC16校验码 - * - * @param bytes 字节数组 - * @return {@link String} 校验码 - * @since 1.0 - */ - public static String getCRC(byte[] bytes) { - int CRC = 0x0000ffff; - int POLYNOMIAL = 0x0000a001; - int i, j; - for (i = 0; i < bytes.length; i++) { - CRC ^= ((int) bytes[i] & 0x000000ff); - for (j = 0; j < 8; j++) { - if ((CRC & 0x00000001) != 0) { - CRC >>= 1; - CRC ^= POLYNOMIAL; - } else { - CRC >>= 1; - } - } - } - return Integer.toHexString(CRC); - } - - - /** - * 计算CRC16校验码 - * - * @param bytes 字节数组 - * @return {@link String} 校验码 - * @since 1.0 - */ - public static Integer getCRCInt(byte[] bytes) { - int CRC = 0x0000ffff; - int POLYNOMIAL = 0x0000a001; - int i, j; - for (i = 0; i < bytes.length; i++) { - CRC ^= ((int) bytes[i] & 0x000000ff); - for (j = 0; j < 8; j++) { - if ((CRC & 0x00000001) != 0) { - CRC >>= 1; - CRC ^= POLYNOMIAL; - } else { - CRC >>= 1; - } - } - } - return CRC; - } - - /** - * 将16进制单精度浮点型转换为10进制浮点型 - * - * @return float - * @since 1.0 - */ - private float parseHex2Float(String hexStr) { - BigInteger bigInteger = new BigInteger(hexStr, 16); - return Float.intBitsToFloat(bigInteger.intValue()); - } - - /** - * 将十进制浮点型转换为十六进制浮点型 - * - * @return String - * @since 1.0 - */ - private String parseFloat2Hex(float data) { - return Integer.toHexString(Float.floatToIntBits(data)); - } - -} diff --git a/src/main/java/com/myself/nettychat/tcptest/TCPTestClient.java b/src/main/java/com/myself/nettychat/tcptest/TCPTestClient.java deleted file mode 100644 index 083983a..0000000 --- a/src/main/java/com/myself/nettychat/tcptest/TCPTestClient.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.myself.nettychat.tcptest; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.net.Socket; -import java.net.SocketTimeoutException; - -/** - * 先去同包下CRC16myself下执行获取数据,数据格式有规定 - * TCP端测试模拟,建议放置在另一个项目 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:40 2018\9\20 0020 - */ -public class TCPTestClient { - - public static void main(String[] args) throws IOException { - //10万测试 - for (int i = 0;i<100000;i++){ - new Thread(new Runnable() { - @Override - public void run() { - try { - runtest(); - }catch (Exception e){ - e.printStackTrace(); - } - } - }).start(); - sleep(100); - } - } - - private static void runtest() throws IOException{ - //客户端请求与本机在18866端口建立TCP连接 - Socket client = new Socket("127.0.0.1", 8092); - client.setSoTimeout(10000); - //获取键盘输入 - BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); - //获取Socket的输出流,用来发送数据到服务端 - PrintStream out = new PrintStream(client.getOutputStream()); - //获取Socket的输入流,用来接收从服务端发送过来的数据 - BufferedReader buf = new BufferedReader(new InputStreamReader(client.getInputStream())); - boolean flag = true; - int i = 1; - while(flag){ - //if (i == 1){ - //帧头+ID+数据类型+24把锁状态+crc校验+帧尾 - String str = "test"; - //发送数据到服务端 - out.println(str); - if("bye".equals(str)){ - flag = false; - }else{ - try{ - //从服务器端接收数据有个时间限制(系统自设,也可以自己设置),超过了这个时间,便会抛出该异常 - String echo = buf.readLine(); - System.out.println(echo); - }catch(SocketTimeoutException e){ - System.out.println("Time out, No response"); - } - } - sleep(5000); - } - input.close(); - if(client != null){ - //如果构造函数建立起了连接,则关闭套接字,如果没有建立起连接,自然不用关闭 - client.close(); //只关闭socket,其关联的输入输出流也会被关闭 - } - } - - private static void sleep(Integer time){ - try { - Thread.sleep(time); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } -} diff --git a/src/main/java/com/myself/nettychat/vo/ResultVo.java b/src/main/java/com/myself/nettychat/vo/ResultVo.java deleted file mode 100644 index a83c84e..0000000 --- a/src/main/java/com/myself/nettychat/vo/ResultVo.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.myself.nettychat.vo; - -import lombok.Data; - -import java.io.Serializable; - -/** - * API 统一返回对象 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:58 2018\10\7 0007 - */ -@Data -public class ResultVo implements Serializable { - - private static final long serialVersionUID = -1020280450330091843L; - - /** 错误码. */ - private Integer code; - - /** 提示信息. */ - private String msg; - - /** 具体内容. */ - private T data; - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c61107b..963af12 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,11 +1,3 @@ -spring: - datasource: - driver-class-name: com.mysql.jdbc.Driver - username: root - password: root - url: jdbc:mysql://localhost:3306/nettychat?characterEncoding=utf-8&useSSL=false - jpa: - show-sql: true netty: webport: 8090 # Websocket 监听端口 bossThread: 1 From dbef42029095d21cda2b061316cb2937d1a6325d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 14:56:03 +0800 Subject: [PATCH 009/151] deletesql --- sql/nettychat.sql | 71 ----------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 sql/nettychat.sql diff --git a/sql/nettychat.sql b/sql/nettychat.sql deleted file mode 100644 index 452c711..0000000 --- a/sql/nettychat.sql +++ /dev/null @@ -1,71 +0,0 @@ -/* -Navicat MySQL Data Transfer - -Source Server : mypc -Source Server Version : 50717 -Source Host : localhost:3306 -Source Database : nettychat - -Target Server Type : MYSQL -Target Server Version : 50717 -File Encoding : 65001 - -Date: 2018-08-23 10:32:48 -*/ - -SET FOREIGN_KEY_CHECKS=0; - --- ---------------------------- --- Table structure for user --- ---------------------------- -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `user_name` varchar(255) DEFAULT NULL, - `pass_word` varchar(255) DEFAULT NULL, - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; - --- ---------------------------- --- Records of user --- ---------------------------- -INSERT INTO `user` VALUES ('2', 'Myself', '123456', '2018-08-14 19:47:49', '2018-08-14 19:47:49'); -INSERT INTO `user` VALUES ('3', 'Chen', '123456abc', '2018-08-20 16:31:49', '2018-08-20 16:31:49'); - --- ---------------------------- --- Table structure for user_msg --- ---------------------------- -DROP TABLE IF EXISTS `user_msg`; -CREATE TABLE `user_msg` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(255) DEFAULT NULL, - `msg` varchar(255) DEFAULT NULL, - `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8mb4; - --- ---------------------------- --- Records of user_msg --- ---------------------------- -INSERT INTO `user_msg` VALUES ('8', 'Myself', '你好呀', '2018-08-20 17:26:58', '2018-08-20 17:26:58'); -INSERT INTO `user_msg` VALUES ('9', 'Myself', '你是谁?', '2018-08-20 17:27:13', '2018-08-20 17:27:13'); -INSERT INTO `user_msg` VALUES ('10', 'Myself', '在吗?', '2018-08-21 17:54:12', '2018-08-21 17:54:12'); -INSERT INTO `user_msg` VALUES ('11', 'Chen', '嗯呢', '2018-08-21 17:54:12', '2018-08-21 17:54:12'); -INSERT INTO `user_msg` VALUES ('13', 'Myself', 'yo', '2018-08-21 18:01:26', '2018-08-21 18:01:26'); -INSERT INTO `user_msg` VALUES ('14', 'Myself', '你好', '2018-08-22 16:24:22', '2018-08-22 16:24:22'); -INSERT INTO `user_msg` VALUES ('30', 'Myself', '你好呀!', '2018-08-22 17:03:42', '2018-08-22 17:03:42'); -INSERT INTO `user_msg` VALUES ('31', 'Myself', '我很好!', '2018-08-22 17:03:42', '2018-08-22 17:03:42'); -INSERT INTO `user_msg` VALUES ('32', 'Myself', '哈哈哈哈', '2018-08-22 17:11:56', '2018-08-22 17:11:56'); -INSERT INTO `user_msg` VALUES ('33', 'Myself', '哇哈哈哈哈', '2018-08-22 17:11:56', '2018-08-22 17:11:56'); -INSERT INTO `user_msg` VALUES ('34', 'Myself', 'asdf', '2018-08-22 17:22:19', '2018-08-22 17:22:19'); -INSERT INTO `user_msg` VALUES ('35', 'Myself', '厉害 厉害', '2018-08-22 17:23:20', '2018-08-22 17:23:20'); -INSERT INTO `user_msg` VALUES ('36', 'Myself', '哈哈', '2018-08-22 17:23:43', '2018-08-22 17:23:43'); -INSERT INTO `user_msg` VALUES ('37', 'Myself', '你好!', '2018-08-23 10:19:14', '2018-08-23 10:19:14'); -INSERT INTO `user_msg` VALUES ('38', 'Chen', '收到。', '2018-08-23 10:19:15', '2018-08-23 10:19:15'); -INSERT INTO `user_msg` VALUES ('39', 'Myself', '前端框架用Vue?', '2018-08-23 10:19:15', '2018-08-23 10:19:15'); -INSERT INTO `user_msg` VALUES ('40', 'Chen', '可以试试', '2018-08-23 10:19:15', '2018-08-23 10:19:15'); -INSERT INTO `user_msg` VALUES ('41', 'Myself', '下版再加一些新的功能', '2018-08-23 10:19:15', '2018-08-23 10:19:15'); -INSERT INTO `user_msg` VALUES ('42', 'Chen', 'okay', '2018-08-23 10:19:15', '2018-08-23 10:19:15'); From 11c5436d30e7beea24490bad66f0e26f22eca6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 15:29:02 +0800 Subject: [PATCH 010/151] update --- README.md | 6 ++++++ .../bootstrap/channel/WebSocketHandlerService.java | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 237812f..5e45aa3 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,12 @@ IP back-end communication port (MQTT protocol, real-time and single-chip compute ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) +## Branch webrtc + +A Netty and web RTC combined to achieve Voice video communication function Branch. + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/webrtc/TIM%E5%9B%BE%E7%89%8720181121150540.png) + ## Branch im-api Tencent im (cloud communications) backend imitation project, are docked in the form of APIs, if there is a front-end want to dock can run this branch, this branch is expected to end up for a single service concurrent 300,000 users of IM background project diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 550cd73..07f395c 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -41,12 +41,12 @@ public void sendText(Channel channel, TextWebSocketFrame webSocketFrame) { @Override public void pong(Channel channel) { - + log.info("【pong】"+channel.remoteAddress()); } @Override public void disconnect(Channel channel) { - + log.info("【disconnect】"+channel.remoteAddress()); } @Override @@ -57,6 +57,6 @@ public void doTimeOut(Channel channel, IdleStateEvent evt) { @Override public void close(Channel channel) { - + log.info("【close】"+channel.remoteAddress()); } } From f398d3be9b75b1b7b9ce7eef799f187cfeeaa755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 15:32:24 +0800 Subject: [PATCH 011/151] update --- README.md | 1 + doc/work.md | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 doc/work.md diff --git a/README.md b/README.md index 5e45aa3..02b8b0c 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ A lightweight, efficient communication framework that supports chat and the Inte ## Tutorial * [中文文档说明](doc/document.md) +* [业务场景技术实现分析](doc/work.md) ## Learning Resources(欢迎贡献) diff --git a/doc/work.md b/doc/work.md new file mode 100644 index 0000000..9ffd579 --- /dev/null +++ b/doc/work.md @@ -0,0 +1,4 @@ +## 业务场景技术实现分析 + +> 欢迎加入QQ群628793702,贡献想法 + From eb9fadbe6eac26db12907b01f953a81e415019ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 21 Nov 2018 17:04:14 +0800 Subject: [PATCH 012/151] update --- README.md | 2 ++ doc/design.md | 8 ++++++++ doc/design_cn.md | 7 +++++++ .../bootstrap/handler/DefaultWebSocketHandler.java | 2 +- 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 doc/design.md create mode 100644 doc/design_cn.md diff --git a/README.md b/README.md index 02b8b0c..f1aabf5 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ A lightweight, efficient communication framework that supports chat and the Inte * [中文文档说明](doc/document.md) * [业务场景技术实现分析](doc/work.md) +* [Project design Ideas](doc/design.md) +* [项目设计思路](doc/design_cn.md) ## Learning Resources(欢迎贡献) diff --git a/doc/design.md b/doc/design.md new file mode 100644 index 0000000..d1760b9 --- /dev/null +++ b/doc/design.md @@ -0,0 +1,8 @@ +# Project design Ideas + +## About Login + +About Inchat Unified Login interface design, design for small programs, apps, web-side login role, so will be token as the form of login Inchat websocket long connection, User server to do SSO authentication login after getting token to send login information directly to Inchat, the user server needs to override the Verifytoken method in Inchat to verify whether their token information is valid, normal start long connection. +In view of the token failure problem, WebSocket long connected login only for the first time login, then consider maintaining the link state (pingpong) in the form of heartbeat, the use of token authentication is to protect Inchat link routine (currently temporarily such design after changing the design according to usage) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) \ No newline at end of file diff --git a/doc/design_cn.md b/doc/design_cn.md new file mode 100644 index 0000000..1e78010 --- /dev/null +++ b/doc/design_cn.md @@ -0,0 +1,7 @@ +# 项目设计思路 + +## 关于登录 + +关于InChat统一登录的接口设计,设计针对小程序、APP、Web端的登录作用,所以将作为token的形式登录InChat的WebSocket长连接,用户服务器做sso的认证登录后得到token后直接发送login信息到InChat,用户服务器需要重写InChat中的verifyToken方法校验自己的的Token信息是否有效,正常则启动长连接。考虑到token失效问题,WebSocket长连接的登录仅做初次登录,接下来考虑以心跳形式保持链接状态(pingpong),使用token认证是为保护InChat链接的常规化(目前暂时这样设计后面根据使用情况更改设计) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) \ No newline at end of file diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index 6b66c85..5c2f9a8 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -44,7 +44,7 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) }else{ throw new NoFindHandlerException("Server Handler 不匹配"); } - System.out.println("textdoMessage--"+msg.text()); + } @Override From e482e69d1928ee3c964bfd9ae67bb86c892d21c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 22 Nov 2018 16:26:25 +0800 Subject: [PATCH 013/151] codingForLogin --- Front-End-Testing/chat.html | 102 ++++++++++++++++++ README.md | 5 + doc/Project-Log-cn.md | 4 + doc/Project-Log.md | 4 + pom.xml | 12 +++ .../channel/WebSocketHandlerService.java | 26 ++++- .../handler/DefaultWebSocketHandler.java | 12 ++- .../user/InChatVerifyServiceImpl.java | 22 ++++ .../nettychat/verify/InChatVerifyService.java | 11 ++ 9 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 Front-End-Testing/chat.html create mode 100644 doc/Project-Log-cn.md create mode 100644 doc/Project-Log.md create mode 100644 src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java create mode 100644 src/main/java/com/myself/nettychat/verify/InChatVerifyService.java diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html new file mode 100644 index 0000000..acee56a --- /dev/null +++ b/Front-End-Testing/chat.html @@ -0,0 +1,102 @@ + + + + + WebSocket Chat + + + + +
+

SpringBoot netty 聊天室

+ +
+ + +
+
+
+ + \ No newline at end of file diff --git a/README.md b/README.md index f1aabf5..2fc0253 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ A lightweight, efficient communication framework that supports chat and the Internet of things, you can use it to quickly build a chat server with the background and quickly customize your own communication APIs, including physical networks with different protocols that can be supported. +## Project Log + +* [Project Log](doc/Project-Log.md) +* [项目研发日志更新](doc/Project-Log-cn.md) + ## Tutorial * [中文文档说明](doc/document.md) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md new file mode 100644 index 0000000..d4b190f --- /dev/null +++ b/doc/Project-Log-cn.md @@ -0,0 +1,4 @@ +# 项目研发日志更新 + +* 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) +* 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,撰写说明文档 \ No newline at end of file diff --git a/doc/Project-Log.md b/doc/Project-Log.md new file mode 100644 index 0000000..576078e --- /dev/null +++ b/doc/Project-Log.md @@ -0,0 +1,4 @@ +# Project Log Updates + +* 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) +* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, write a description document \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7fd7f05..e3e228e 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,18 @@ + + + com.alibaba + fastjson + 1.2.53 + + + + com.google.code.gson + gson + 2.8.5 + org.aspectj diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 07f395c..c7110b4 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -1,9 +1,12 @@ package com.myself.nettychat.bootstrap.channel; +import com.alibaba.fastjson.JSON; +import com.google.gson.Gson; import com.myself.nettychat.bootstrap.BaseApi; import com.myself.nettychat.bootstrap.BaseAuthService; import com.myself.nettychat.bootstrap.ChannelService; import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; +import com.myself.nettychat.verify.InChatVerifyService; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; @@ -11,6 +14,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.HashMap; +import java.util.Map; + /** * Created by MySelf on 2018/11/21. */ @@ -18,6 +24,9 @@ @Component public class WebSocketHandlerService extends ServerWebSocketHandlerService implements BaseApi { + @Autowired + InChatVerifyService inChatVerifyService; + @Autowired ChannelService websocketChannelService; @@ -30,8 +39,22 @@ public WebSocketHandlerService(BaseAuthService baseAuthService){ @Override public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { //校验规则,自定义校验规则 + Map maps = (Map) JSON.parse(textWebSocketFrame.text()); System.out.println("login-"+textWebSocketFrame.text()); - return true; + String token = maps.get("token"); + Gson gson = new Gson(); + Map backMap = new HashMap<>(); + if (inChatVerifyService.verifyToken(token)){ + backMap.put("type","login"); + backMap.put("success","true"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + return true; + } + backMap.put("type","login"); + backMap.put("success","false"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + close(channel); + return false; } @Override @@ -58,5 +81,6 @@ public void doTimeOut(Channel channel, IdleStateEvent evt) { @Override public void close(Channel channel) { log.info("【close】"+channel.remoteAddress()); + channel.close(); } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index 5c2f9a8..c8b353d 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -1,5 +1,6 @@ package com.myself.nettychat.bootstrap.handler; +import com.alibaba.fastjson.JSON; import com.myself.nettychat.common.exception.NoFindHandlerException; import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; import com.myself.nettychat.common.websockets.WebSocketHandler; @@ -12,6 +13,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; +import java.util.Map; + /** * @Author:UncleCatMySelf * @Email:zhupeijie_java@126.com @@ -44,7 +47,14 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) }else{ throw new NoFindHandlerException("Server Handler 不匹配"); } - + Map maps = (Map) JSON.parse(msg.text()); + switch (maps.get("type")){ + case "login": + serverWebSocketHandlerService.login(channel,msg); + break; + default: + break; + } } @Override diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java new file mode 100644 index 0000000..e63bf20 --- /dev/null +++ b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java @@ -0,0 +1,22 @@ +package com.myself.nettychat.user; + +import com.myself.nettychat.verify.InChatVerifyService; +import org.springframework.stereotype.Service; + +/** + * 不属于项目代码 + * Created by MySelf on 2018/11/22. + */ +@Service +public class InChatVerifyServiceImpl implements InChatVerifyService { + + @Override + public boolean verifyToken(String token) { + //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 + System.out.println("verify---"+token); + if ("3333".equals(token)){ + return true; + } + return false; + } +} diff --git a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java new file mode 100644 index 0000000..64582c3 --- /dev/null +++ b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java @@ -0,0 +1,11 @@ +package com.myself.nettychat.verify; + +/** + * 用户校验层 + * Created by MySelf on 2018/11/22. + */ +public interface InChatVerifyService { + + boolean verifyToken(String token); + +} From 7db319f75e8ce88e98ed1fb6af2769c770c5d12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 22 Nov 2018 17:32:36 +0800 Subject: [PATCH 014/151] updateWrite --- doc/Project-Log-cn.md | 2 +- doc/Project-Log.md | 2 +- doc/design.md | 4 +- doc/design_cn.md | 4 +- doc/detail/Login-cn.md | 210 ++++++++++++++++++++++++++++++++++++++++ doc/detail/Login.md | 213 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 431 insertions(+), 4 deletions(-) create mode 100644 doc/detail/Login-cn.md create mode 100644 doc/detail/Login.md diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index d4b190f..547bc88 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -1,4 +1,4 @@ # 项目研发日志更新 * 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) -* 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,撰写说明文档 \ No newline at end of file +* 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) \ No newline at end of file diff --git a/doc/Project-Log.md b/doc/Project-Log.md index 576078e..9d320df 100644 --- a/doc/Project-Log.md +++ b/doc/Project-Log.md @@ -1,4 +1,4 @@ # Project Log Updates * 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) -* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, write a description document \ No newline at end of file +* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) \ No newline at end of file diff --git a/doc/design.md b/doc/design.md index d1760b9..af9a164 100644 --- a/doc/design.md +++ b/doc/design.md @@ -5,4 +5,6 @@ About Inchat Unified Login interface design, design for small programs, apps, web-side login role, so will be token as the form of login Inchat websocket long connection, User server to do SSO authentication login after getting token to send login information directly to Inchat, the user server needs to override the Verifytoken method in Inchat to verify whether their token information is valid, normal start long connection. In view of the token failure problem, WebSocket long connected login only for the first time login, then consider maintaining the link state (pingpong) in the form of heartbeat, the use of token authentication is to protect Inchat link routine (currently temporarily such design after changing the design according to usage) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) \ No newline at end of file +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) + +* 【2018-11-22】 Encoding implementation And [Detailed implementation Documentation](detail/Login.md) \ No newline at end of file diff --git a/doc/design_cn.md b/doc/design_cn.md index 1e78010..e15ca8d 100644 --- a/doc/design_cn.md +++ b/doc/design_cn.md @@ -4,4 +4,6 @@ 关于InChat统一登录的接口设计,设计针对小程序、APP、Web端的登录作用,所以将作为token的形式登录InChat的WebSocket长连接,用户服务器做sso的认证登录后得到token后直接发送login信息到InChat,用户服务器需要重写InChat中的verifyToken方法校验自己的的Token信息是否有效,正常则启动长连接。考虑到token失效问题,WebSocket长连接的登录仅做初次登录,接下来考虑以心跳形式保持链接状态(pingpong),使用token认证是为保护InChat链接的常规化(目前暂时这样设计后面根据使用情况更改设计) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) \ No newline at end of file +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) + +* 【2018-11-22】 编码实现和[详细实现文档](detail/Login-cn.md) \ No newline at end of file diff --git a/doc/detail/Login-cn.md b/doc/detail/Login-cn.md new file mode 100644 index 0000000..ce2b21b --- /dev/null +++ b/doc/detail/Login-cn.md @@ -0,0 +1,210 @@ +## 只给你最值得的信息 + +小弟正在做的一个开源IM项目,目标是实现一个轻量级、高效率的支持聊天与物联网的通讯框架。昨天刚刚出的设计稿并再今天做了实现。 + +项目是基于Netty的二次开发,关于Netty我这里就不再介绍了,懂的人自然都懂。我的预算是做一个所有企业或组织可以引用的Maven项目,并且是基本上开箱即用,简单实现对应的配置与重写方法就可以搭建自己的IM项目(某Q、某信的效果)。 + +本文着重介绍的是登录接口的设计与实现。 + +## 设计信息 + +关于InChat统一登录的接口设计,设计针对小程序、APP、Web端的登录作用,所以将作为token的形式登录InChat的WebSocket长连接,用户服务器做sso的认证登录后得到token后直接发送login信息到InChat,用户服务器需要重写InChat中的verifyToken方法校验自己的的Token信息是否有效,正常则启动长连接。考虑到token失效问题,WebSocket长连接的登录仅做初次登录,接下来考虑以心跳形式保持链接状态(pingpong),使用token认证是为保护InChat链接的常规化(目前暂时这样设计后面根据使用情况更改设计) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(13).png) + +由于目前大部分的Web项目或基于IM的项目登录可能存在多端的单点登录,所以我选用了Token的形式,为什么登录后还需要用token再来websocket这边校验一次呢? + +因为你登录的是web应用程序端的,而websocket而言,只要别人知道你的地址,那么就可以链接上,我们不希望存在过多的死链接(无效链接),所以我们需要将token再次发给InChat登录,由InChat来检验是否是合法登录链接,如果无效则关闭链接。 + +## 代码实现 + +由于是想要做给别人用的,那么我们自己本身就要封装的好一点,对于配置我选了足够多的类型。 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171455.png) + +对于netty监听与初始化,我使用的方式是扫描与AspectJ,你可以在项目的auto包中看到扫描启动,这种启动思路我也是参考了其他的开源项目(具体忘记了地址)。 + +```java +@Bean +@ConditionalOnMissingBean(name = "sacnScheduled") +public ScanRunnable initRunable(@Autowired InitNetty serverBean){ + long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); + ScanRunnable sacnScheduled = new SacnScheduled(time); + Thread scanRunnable = new Thread(sacnScheduled); + scanRunnable.setDaemon(true); + scanRunnable.start(); + return sacnScheduled; +} + + +@Bean(initMethod = "open", destroyMethod = "close") +@ConditionalOnMissingBean +public InitServer initServer(InitNetty serverBean){ + if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ + throw new NullPointerException("not set port"); + } + if(serverBean.getBacklog()<1){ + serverBean.setBacklog(_BLACKLOG); + } + if(serverBean.getBossThread()<1){ + serverBean.setBossThread(CPU); + } + if(serverBean.getInitalDelay()<0){ + serverBean.setInitalDelay(SEDU_DAY); + } + if(serverBean.getPeriod()<1){ + serverBean.setPeriod(SEDU_DAY); + } + if(serverBean.getHeart()<1){ + serverBean.setHeart(TIMEOUT); + } + if(serverBean.getRevbuf()<1){ + serverBean.setRevbuf(BUF_SIZE); + } + if(serverBean.getWorkerThread()<1){ + serverBean.setWorkerThread(CPU*2); + } + return new InitServer(serverBean); +} +``` + + +在上图中存在一个DefaultWebSocketHandler,这个是默认的netty启动处理。 + +当然在执行它之前,还需要执行到一个抽象的类WebSocketHandler。 + +它将会为我做一些基本的功能操作。 + +```java +@Slf4j +public abstract class WebSocketHandler extends SimpleChannelInboundHandler { + + WebSocketHandlerApi webSocketHandlerApi; + + public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof TextWebSocketFrame){ + textdoMessage(ctx,(TextWebSocketFrame)msg); + }else if (msg instanceof WebSocketFrame){ + webdoMessage(ctx,(WebSocketFrame)msg); + } + } + + protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); + + protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + webSocketHandlerApi.close(ctx.channel()); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent){ + webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); + } + super.userEventTriggered(ctx, evt); + } +} +``` + +对于登录接口,他是基于WebSocket的,且是TextWebSocketFrame类型的,WebSocketFrame是后期的图片聊天功能,所以我们的DefaultWebSocketHandler暂时只需要实现textdoMessage。 + +对于websocket的传输我们推荐使用json形式,这对于前后端都是由好处的。 + +```java + @Override + protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { + Channel channel = ctx.channel(); + ServerWebSocketHandlerService serverWebSocketHandlerService; + if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ + serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; + }else{ + throw new NoFindHandlerException("Server Handler 不匹配"); + } + Map maps = (Map) JSON.parse(msg.text()); + switch (maps.get("type")){ + case "login": + serverWebSocketHandlerService.login(channel,msg); + break; + default: + break; + } + } +``` + +由上面的代码,你也许才想到了前端登录的大致json内容,没错是这样的。 + +``` +{ + type: "login", + token: value +} +``` + +ServerWebSocketHandlerService是一个自己定义的后端WebSocket存在的接口实现服务,我们现在使用到他的登录接口,让我们来看看他的登录实现方法。 + +```java + + @Autowired + InChatVerifyService inChatVerifyService; + + @Override + public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { + //校验规则,自定义校验规则 + Map maps = (Map) JSON.parse(textWebSocketFrame.text()); + System.out.println("login-"+textWebSocketFrame.text()); + String token = maps.get("token"); + Gson gson = new Gson(); + Map backMap = new HashMap<>(); + if (inChatVerifyService.verifyToken(token)){ + backMap.put("type","login"); + backMap.put("success","true"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + return true; + } + backMap.put("type","login"); + backMap.put("success","false"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + close(channel); + return false; + } +``` + +由以上可看出,我们会将token和inChatVerifyService.verifyToken做校验,这是一个接口,我并没有写实现,因为这个是用户的事情了,它需要实现并重写我的verifyToken方法,并返回给我一个值,如下是我测试的时候写的模拟实现。 + +```java +/** + * 不属于项目代码 + * Created by MySelf on 2018/11/22. + */ +@Service +public class InChatVerifyServiceImpl implements InChatVerifyService { + + @Override + public boolean verifyToken(String token) { + //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 + System.out.println("verify---"+token); + if ("3333".equals(token)){ + return true; + } + return false; + } +} +``` + +我仅仅做了普通的校验,对于用户可以注入RedisTemplate然后进行校验等工作。到此我们的登录接口就实现好了! + +## 看看效果 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171241.png) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171245.png) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171247.png) diff --git a/doc/detail/Login.md b/doc/detail/Login.md new file mode 100644 index 0000000..41279a2 --- /dev/null +++ b/doc/detail/Login.md @@ -0,0 +1,213 @@ +## Just give you the most worthwhile information. + +Little brother is working on an open source IM project with the goal of achieving a lightweight, efficient communication framework that supports chat and the internet of things. + +The design manuscript just produced yesterday has been realized today. The project is based on Netty two development, about Netty I will not introduce here, understand the people naturally understand. + +My budget is to do a MAVEN project that all enterprises or organizations can reference, and is basically out-of-the-box, simply implement the corresponding configuration and override method can build their own IM project (a Q, the effect of a letter). This paper mainly introduces the design and implementation of the login interface. + +## Design Info + +About Inchat Unified Login interface design, design for small programs, apps, web-side login role, so will be token as the form of login Inchat websocket long connection, User server to do SSO authentication login after getting token to send login information directly to Inchat, the user server needs to override the Verifytoken method in Inchat to verify whether their token information is valid, normal start long connection. +In view of the token failure problem, WebSocket long connected login only for the first time login, then consider maintaining the link state (pingpong) in the form of heartbeat, the use of token authentication is to protect Inchat link routine (currently temporarily such design after changing the design according to usage) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(13).png) + +Because most of the current Web projects or IM-based project logins may have multi-terminal single sign-on, so I chose the form of token, why do you need to use token to websocket this side of the verification once? Because you are logged on to the Web application side, and WebSocket, as long as others know your address, then you can link on, we do not want to have too many dead links (invalid links), so we need to send token again to Inchat login, +It is up to inchat to check if it is a legitimate login link and close the link if it is not valid. + +## Code implementation + +Because we want to do it for others, then we ourselves have to encapsulate a little better, for the configuration I chose enough types. + + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171455.png) + +For Netty listening and initialization, I use the way to scan and ASPECTJ, you can see the scan start in the project's auto package, this startup idea I also refer to other open source projects (specifically forgot the address). + +```java +@Bean +@ConditionalOnMissingBean(name = "sacnScheduled") +public ScanRunnable initRunable(@Autowired InitNetty serverBean){ + long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); + ScanRunnable sacnScheduled = new SacnScheduled(time); + Thread scanRunnable = new Thread(sacnScheduled); + scanRunnable.setDaemon(true); + scanRunnable.start(); + return sacnScheduled; +} + + +@Bean(initMethod = "open", destroyMethod = "close") +@ConditionalOnMissingBean +public InitServer initServer(InitNetty serverBean){ + if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ + throw new NullPointerException("not set port"); + } + if(serverBean.getBacklog()<1){ + serverBean.setBacklog(_BLACKLOG); + } + if(serverBean.getBossThread()<1){ + serverBean.setBossThread(CPU); + } + if(serverBean.getInitalDelay()<0){ + serverBean.setInitalDelay(SEDU_DAY); + } + if(serverBean.getPeriod()<1){ + serverBean.setPeriod(SEDU_DAY); + } + if(serverBean.getHeart()<1){ + serverBean.setHeart(TIMEOUT); + } + if(serverBean.getRevbuf()<1){ + serverBean.setRevbuf(BUF_SIZE); + } + if(serverBean.getWorkerThread()<1){ + serverBean.setWorkerThread(CPU*2); + } + return new InitServer(serverBean); +} +``` + + +There is a defaultwebsockethandler in the figure above, which is the default Netty startup processing. + +Of course, before executing it, you also need to perform to an abstract class Websockethandler. It will do some basic functional operations for me. + +```java +@Slf4j +public abstract class WebSocketHandler extends SimpleChannelInboundHandler { + + WebSocketHandlerApi webSocketHandlerApi; + + public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof TextWebSocketFrame){ + textdoMessage(ctx,(TextWebSocketFrame)msg); + }else if (msg instanceof WebSocketFrame){ + webdoMessage(ctx,(WebSocketFrame)msg); + } + } + + protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); + + protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + webSocketHandlerApi.close(ctx.channel()); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent){ + webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); + } + super.userEventTriggered(ctx, evt); + } +} +``` + +For the login interface, he is based on WebSocket, and is the Textwebsocketframe type, Websocketframe is the late image chat function, + +So our Defaultwebsockethandler only need to implement textdomessage for the time being. +For the transmission of WebSocket we recommend the use of JSON form, which is beneficial for both the front and back ends. + +```java + @Override + protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { + Channel channel = ctx.channel(); + ServerWebSocketHandlerService serverWebSocketHandlerService; + if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ + serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; + }else{ + throw new NoFindHandlerException("Server Handler 不匹配"); + } + Map maps = (Map) JSON.parse(msg.text()); + switch (maps.get("type")){ + case "login": + serverWebSocketHandlerService.login(channel,msg); + break; + default: + break; + } + } +``` + +By the above code, you may have thought of the approximate JSON content of the front-end login, that's right. + + +``` +{ + type: "login", + token: value +} +``` + +Serverwebsockethandlerservice is a self-defined interface implementation service for the back-end websocket, and we now use it to his login interface, let's take a look at his login implementation method. + + +```java + + @Autowired + InChatVerifyService inChatVerifyService; + + @Override + public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { + //校验规则,自定义校验规则 + Map maps = (Map) JSON.parse(textWebSocketFrame.text()); + System.out.println("login-"+textWebSocketFrame.text()); + String token = maps.get("token"); + Gson gson = new Gson(); + Map backMap = new HashMap<>(); + if (inChatVerifyService.verifyToken(token)){ + backMap.put("type","login"); + backMap.put("success","true"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + return true; + } + backMap.put("type","login"); + backMap.put("success","false"); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + close(channel); + return false; + } +``` + +As can be seen from the above, +We will token and Inchatverifyservice.verifytoken do checksum, this is an interface, I did not write the implementation, because this is the user's thing, it needs to implement and rewrite my Verifytoken method, and return to me a value, the following is my test when writing the simulation implementation. + +```java +/** + * 不属于项目代码 + * Created by MySelf on 2018/11/22. + */ +@Service +public class InChatVerifyServiceImpl implements InChatVerifyService { + + @Override + public boolean verifyToken(String token) { + //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 + System.out.println("verify---"+token); + if ("3333".equals(token)){ + return true; + } + return false; + } +} +``` + +I just did a normal checksum, for the user can inject redistemplate and then do the checksum work. +To this, our login interface will be achieved! + +## Look at the effect. + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171241.png) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171245.png) + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171247.png) From 70b10a168423be85410b22b3708e415e1241bb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 23 Nov 2018 16:18:21 +0800 Subject: [PATCH 015/151] =?UTF-8?q?QQ=E8=B4=A1=E7=8C=AE=E5=BB=BA=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/advice/advice.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 doc/advice/advice.md diff --git a/doc/advice/advice.md b/doc/advice/advice.md new file mode 100644 index 0000000..1d33b23 --- /dev/null +++ b/doc/advice/advice.md @@ -0,0 +1,18 @@ +## QQ群贡献建议 + +> 贡献者:小斑马 + +* 一个netty在物联网的应用,质量很高,有些模块可以直接拿来用 +* https://github.com/cosmoplat-dev + +* 可以考虑把长连接单独做成一个模块,上行下行数据可以直接放到消息队列里面去,上行数据上来后直接放到消息队列里,其他模块接收存数据库,长连接模块监听其他模块放到消息队列里的下发数据 + +> 贡献者:夜殇 + +* 加了规则引擎的物联网项目 +* https://github.com/thingsboard/thingsboard + +* 对上方项目的修改 +* https://github.com/JaryZhen/rulegin + + From fdf68c5f3bf565049210eec4190f96edfda865b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 23 Nov 2018 16:20:24 +0800 Subject: [PATCH 016/151] log --- doc/Project-Log-cn.md | 3 ++- doc/Project-Log.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 547bc88..3c65f11 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -1,4 +1,5 @@ # 项目研发日志更新 * 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) -* 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) \ No newline at end of file +* 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) +* 【2018-11-23】 添加贡献建议信息 \ No newline at end of file diff --git a/doc/Project-Log.md b/doc/Project-Log.md index 9d320df..7bf0ae4 100644 --- a/doc/Project-Log.md +++ b/doc/Project-Log.md @@ -1,4 +1,5 @@ # Project Log Updates * 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) -* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) \ No newline at end of file +* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) +* 【2018-11-23】 Add contribution suggestion Information \ No newline at end of file From 2b69c0a436103d63856e376de003b0bbfd6733be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 23 Nov 2018 16:23:08 +0800 Subject: [PATCH 017/151] update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2fc0253..ee393f1 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ A lightweight, efficient communication framework that supports chat and the Inte ## Learning Resources(欢迎贡献) * [netty4通信原理](doc/netty-study.md) +* [QQ群建议贡献](doc/advice/advice.md) ## Branch demo From 49d5849375bc144fb978fd1222e0f2abea59d5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 23 Nov 2018 17:16:48 +0800 Subject: [PATCH 018/151] update --- .../backmsg/InChatBackMapService.java | 15 +++++++++ .../channel/WebSocketHandlerService.java | 16 ++++------ .../user/InChatBackMapServiceImpl.java | 32 +++++++++++++++++++ .../user/InChatVerifyServiceImpl.java | 9 ++++++ .../nettychat/verify/InChatVerifyService.java | 1 + 5 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java create mode 100644 src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java diff --git a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java new file mode 100644 index 0000000..e6cd42e --- /dev/null +++ b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java @@ -0,0 +1,15 @@ +package com.myself.nettychat.backmsg; + +import java.util.Map; + +/** + * 消息返回 + * Created by MySelf on 2018/11/23. + */ +public interface InChatBackMapService { + + Map loginSuccess(); + + Map loginError(); + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index c7110b4..712f451 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.google.gson.Gson; +import com.myself.nettychat.backmsg.InChatBackMapService; import com.myself.nettychat.bootstrap.BaseApi; import com.myself.nettychat.bootstrap.BaseAuthService; import com.myself.nettychat.bootstrap.ChannelService; @@ -27,6 +28,9 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService imple @Autowired InChatVerifyService inChatVerifyService; + @Autowired + InChatBackMapService inChatBackMapService; + @Autowired ChannelService websocketChannelService; @@ -40,19 +44,13 @@ public WebSocketHandlerService(BaseAuthService baseAuthService){ public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { //校验规则,自定义校验规则 Map maps = (Map) JSON.parse(textWebSocketFrame.text()); - System.out.println("login-"+textWebSocketFrame.text()); - String token = maps.get("token"); + String token = maps.get(inChatVerifyService.getVerifyLogin()); Gson gson = new Gson(); - Map backMap = new HashMap<>(); if (inChatVerifyService.verifyToken(token)){ - backMap.put("type","login"); - backMap.put("success","true"); - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); return true; } - backMap.put("type","login"); - backMap.put("success","false"); - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); close(channel); return false; } diff --git a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java new file mode 100644 index 0000000..90ed582 --- /dev/null +++ b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java @@ -0,0 +1,32 @@ +package com.myself.nettychat.user; + +import com.myself.nettychat.backmsg.InChatBackMapService; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * 不属于项目代码 + * Created by MySelf on 2018/11/23. + */ +@Service +public class InChatBackMapServiceImpl implements InChatBackMapService { + + + @Override + public Map loginSuccess() { + Map backMap = new HashMap<>(); + backMap.put("type","login"); + backMap.put("success","true"); + return backMap; + } + + @Override + public Map loginError() { + Map backMap = new HashMap<>(); + backMap.put("type","login"); + backMap.put("success","false"); + return backMap; + } +} diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java index e63bf20..fbfeae9 100644 --- a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java @@ -19,4 +19,13 @@ public boolean verifyToken(String token) { } return false; } + + /** + * 用户期望校验的自定义名称、openid、token、cookie、或者公司自定义的名称等 + * @return + */ + @Override + public String getVerifyLogin() { + return "token"; + } } diff --git a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java index 64582c3..2084404 100644 --- a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java @@ -8,4 +8,5 @@ public interface InChatVerifyService { boolean verifyToken(String token); + String getVerifyLogin(); } From 9cdf05499fd7ed14180e59587dd9e8ca7ca9acb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 23 Nov 2018 17:30:21 +0800 Subject: [PATCH 019/151] log --- doc/Project-Log-cn.md | 2 +- doc/Project-Log.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 3c65f11..227193a 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -2,4 +2,4 @@ * 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) * 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) -* 【2018-11-23】 添加贡献建议信息 \ No newline at end of file +* 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 \ No newline at end of file diff --git a/doc/Project-Log.md b/doc/Project-Log.md index 7bf0ae4..851f59e 100644 --- a/doc/Project-Log.md +++ b/doc/Project-Log.md @@ -2,4 +2,4 @@ * 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) * 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) -* 【2018-11-23】 Add contribution suggestion Information \ No newline at end of file +* 【2018-11-23】 Add contribution suggestion Information, Refactoring modified login Detection constant code, extracted into interface form \ No newline at end of file From 549950bab3c6abb5e030ca149fbb6770732cbe2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 16:16:49 +0800 Subject: [PATCH 020/151] cacheWsChannel --- .../nettychat/bootstrap/WsChannelService.java | 13 +++++++ .../bootstrap/channel/MqttChannelService.java | 2 +- .../bootstrap/channel/MqttHandlerService.java | 2 +- .../channel/WebSocketChannelService.java | 27 +++++++++++++++ .../channel/WebSocketHandlerService.java | 4 ++- .../bootstrap/channel/WillService.java | 2 +- .../bootstrap/channel/cache/WsCacheMap.java | 34 +++++++++++++++++++ .../bootstrap/handler/DefaultMqttHandler.java | 2 +- 8 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java create mode 100644 src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java create mode 100644 src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java diff --git a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java new file mode 100644 index 0000000..4c7d164 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java @@ -0,0 +1,13 @@ +package com.myself.nettychat.bootstrap; + +import io.netty.channel.Channel; + +/** + * WebSocket 聊天业务消息处理 + * Created by MySelf on 2018/11/26. + */ +public interface WsChannelService { + + void loginWsSuccess(Channel channel, String token); + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java index fa5ec21..ef7b308 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java @@ -31,7 +31,7 @@ * @desc Channel事件处理service **/ @Slf4j -@Component +//@Component public class MqttChannelService extends AbstractChannelService { @Autowired diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java index abc4d56..f404aac 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java @@ -21,7 +21,7 @@ import java.util.stream.Collectors; @Slf4j -@Component +//@Component public class MqttHandlerService extends ServerMqttHandlerService implements BaseApi { @Autowired diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java new file mode 100644 index 0000000..3da1f97 --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java @@ -0,0 +1,27 @@ +package com.myself.nettychat.bootstrap.channel; + +import com.myself.nettychat.bootstrap.WsChannelService; +import com.myself.nettychat.bootstrap.channel.cache.WsCacheMap; +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; + +/** + * Created by MySelf on 2018/11/26. + */ +@Slf4j +@Component +public class WebSocketChannelService implements WsChannelService { + + @Autowired + WsCacheMap wsCacheMap; + + @Override + public void loginWsSuccess(Channel channel, String token) { + wsCacheMap.saveWs(token,channel); + } + + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 712f451..8de4f78 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -6,6 +6,7 @@ import com.myself.nettychat.bootstrap.BaseApi; import com.myself.nettychat.bootstrap.BaseAuthService; import com.myself.nettychat.bootstrap.ChannelService; +import com.myself.nettychat.bootstrap.WsChannelService; import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; import com.myself.nettychat.verify.InChatVerifyService; import io.netty.channel.Channel; @@ -32,7 +33,7 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService imple InChatBackMapService inChatBackMapService; @Autowired - ChannelService websocketChannelService; + WsChannelService websocketChannelService; private final BaseAuthService baseAuthService; @@ -48,6 +49,7 @@ public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { Gson gson = new Gson(); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); + websocketChannelService.loginWsSuccess(channel,token); return true; } channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java index 3aa4213..8c16068 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java @@ -13,7 +13,7 @@ import java.util.concurrent.ConcurrentHashMap; @Slf4j -@Component +//@Component @Data @NoArgsConstructor public class WillService implements BaseApi { diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java new file mode 100644 index 0000000..d2e7abf --- /dev/null +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -0,0 +1,34 @@ +package com.myself.nettychat.bootstrap.channel.cache; + +import io.netty.channel.Channel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by MySelf on 2018/11/26. + */ +@Slf4j +@Component +public class WsCacheMap { + + Map maps = new ConcurrentHashMap(); + + public void saveWs(String token,Channel channel){ + log.info("【新增用户链接:】"+token); + maps.put(token,channel); + } + + public Channel getByToken(String token){ + log.info("【获取用户链接:】"+token); + return maps.get(token); + } + + public void deleteWs(String token){ + log.info("【删除用户链接:】"+token); + maps.remove(token); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java index 8c4fbee..a3cb6f7 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java @@ -21,7 +21,7 @@ * @desc 默认MQTTHandler处理 **/ @Slf4j -@Component +//@Component @ChannelHandler.Sharable public class DefaultMqttHandler extends MqttHander { From 64a655255b6a52332cc4ef499008f205289be324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 16:45:09 +0800 Subject: [PATCH 021/151] updateRefactoring --- .../bootstrap/channel/WebSocketHandlerService.java | 11 ++++++----- .../bootstrap/handler/DefaultWebSocketHandler.java | 2 +- .../myself/nettychat/common/properties/InitNetty.java | 4 +++- .../websockets/ServerWebSocketHandlerService.java | 6 ++++-- .../common/websockets/WebSocketHandlerApi.java | 4 +++- src/main/resources/application.yml | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 8de4f78..e63c9bb 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -24,7 +24,7 @@ */ @Slf4j @Component -public class WebSocketHandlerService extends ServerWebSocketHandlerService implements BaseApi { +public class WebSocketHandlerService extends ServerWebSocketHandlerService{ @Autowired InChatVerifyService inChatVerifyService; @@ -42,9 +42,8 @@ public WebSocketHandlerService(BaseAuthService baseAuthService){ } @Override - public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { + public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 - Map maps = (Map) JSON.parse(textWebSocketFrame.text()); String token = maps.get(inChatVerifyService.getVerifyLogin()); Gson gson = new Gson(); if (inChatVerifyService.verifyToken(token)){ @@ -58,13 +57,15 @@ public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { } @Override - public void sendText(Channel channel, TextWebSocketFrame webSocketFrame) { - System.out.println("sendText-"+webSocketFrame.text()); + public void sendText(Channel channel, Map maps) { + System.out.println("sendText-"+maps.get("value")); + } @Override public void pong(Channel channel) { log.info("【pong】"+channel.remoteAddress()); + } @Override diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index c8b353d..2db982e 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -50,7 +50,7 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) Map maps = (Map) JSON.parse(msg.text()); switch (maps.get("type")){ case "login": - serverWebSocketHandlerService.login(channel,msg); + serverWebSocketHandlerService.login(channel,maps); break; default: break; diff --git a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java index cd292ff..ff57529 100644 --- a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java +++ b/src/main/java/com/myself/nettychat/common/properties/InitNetty.java @@ -1,8 +1,10 @@ package com.myself.nettychat.common.properties; import com.myself.nettychat.common.websockets.WebSocketHandler; +import lombok.Builder; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; /** * @Author:UncleCatMySelf @@ -11,7 +13,7 @@ * @Date:Created in 10:54 2018\8\14 0014 */ @Data -@ConfigurationProperties(prefix = "netty") +@ConfigurationProperties(prefix = "inchat") public class InitNetty { private int webport; diff --git a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java index e01541e..b17a712 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java @@ -4,14 +4,16 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; +import java.util.Map; + /** * Created by MySelf on 2018/11/21. */ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerApi { - public abstract boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame); + public abstract boolean login(Channel channel, Map map); - public abstract void sendText(Channel channel, TextWebSocketFrame webSocketFrame); + public abstract void sendText(Channel channel,Map maps); public abstract void pong(Channel channel); diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java index ac36601..59375d0 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java @@ -4,6 +4,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; +import java.util.Map; + /** * @Author:UncleCatMySelf * @Email:zhupeijie_java@126.com @@ -14,7 +16,7 @@ public interface WebSocketHandlerApi { void close(Channel channel); - void sendText(Channel channel, TextWebSocketFrame webSocketFrame); + void sendText(Channel channel, Map maps); void doTimeOut(Channel channel, IdleStateEvent evt); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 963af12..e3f6e8f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,4 @@ -netty: +inchat: webport: 8090 # Websocket 监听端口 bossThread: 1 workerThread: 2 From bf729079358aa88e051f0ee963e743ef4b989947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 17:05:20 +0800 Subject: [PATCH 022/151] update --- Front-End-Testing/chat.html | 17 +++++++++++++++++ .../channel/WebSocketHandlerService.java | 8 +++++++- .../handler/DefaultWebSocketHandler.java | 3 +++ .../ServerWebSocketHandlerService.java | 4 +++- .../common/websockets/WebSocketHandlerApi.java | 4 +++- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index acee56a..c30f702 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -85,6 +85,22 @@ alert("连接没有开启."); } } + + function sendToMe(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "sendMe", + value: value + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } + } + window.onbeforeunload = function(event) { event.returnValue = "刷新提醒"; }; @@ -95,6 +111,7 @@

SpringBoot netty 聊天室


+

diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index e63c9bb..f301893 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -57,11 +57,17 @@ public boolean login(Channel channel, Map maps) { } @Override - public void sendText(Channel channel, Map maps) { + public void sendMeText(Channel channel, Map maps) { System.out.println("sendText-"+maps.get("value")); } + @Override + public void sendToText(Channel channel, Map maps) { + System.out.println("sendText-"+maps.get("value")); + } + + @Override public void pong(Channel channel) { log.info("【pong】"+channel.remoteAddress()); diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index 2db982e..60d9d2d 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -52,6 +52,9 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) case "login": serverWebSocketHandlerService.login(channel,maps); break; + case "sendMe": + serverWebSocketHandlerService.sendMeText(channel,maps); + break; default: break; } diff --git a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java index b17a712..476b853 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java @@ -13,7 +13,9 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA public abstract boolean login(Channel channel, Map map); - public abstract void sendText(Channel channel,Map maps); + public abstract void sendMeText(Channel channel,Map maps); + + public abstract void sendToText(Channel channel, Map maps); public abstract void pong(Channel channel); diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java index 59375d0..b19d381 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java @@ -16,7 +16,9 @@ public interface WebSocketHandlerApi { void close(Channel channel); - void sendText(Channel channel, Map maps); + void sendMeText(Channel channel, Map maps); + + void sendToText(Channel channel, Map maps); void doTimeOut(Channel channel, IdleStateEvent evt); From 746a6c23cf24bf08b0a5f810e89ec8d5d713ff3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 17:10:20 +0800 Subject: [PATCH 023/151] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=85=A8=E5=B1=80Gso?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/WebSocketChannelService.java | 1 - .../bootstrap/channel/WebSocketHandlerService.java | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java index 3da1f97..b415cda 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java @@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.stereotype.Service; /** * Created by MySelf on 2018/11/26. diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index f301893..b62e32d 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -35,17 +35,19 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService{ @Autowired WsChannelService websocketChannelService; + private final Gson gson; + private final BaseAuthService baseAuthService; - public WebSocketHandlerService(BaseAuthService baseAuthService){ + public WebSocketHandlerService(BaseAuthService baseAuthService,Gson gson){ this.baseAuthService = baseAuthService; + this.gson = gson; } @Override public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 String token = maps.get(inChatVerifyService.getVerifyLogin()); - Gson gson = new Gson(); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); websocketChannelService.loginWsSuccess(channel,token); @@ -58,7 +60,7 @@ public boolean login(Channel channel, Map maps) { @Override public void sendMeText(Channel channel, Map maps) { - System.out.println("sendText-"+maps.get("value")); + } From 10115c15f31e228fad10a209ea99ed9637448a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 17:22:48 +0800 Subject: [PATCH 024/151] sendMe --- .../myself/nettychat/backmsg/InChatBackMapService.java | 1 + .../bootstrap/channel/WebSocketHandlerService.java | 6 +++--- .../myself/nettychat/user/InChatBackMapServiceImpl.java | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java index e6cd42e..1349309 100644 --- a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java +++ b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java @@ -12,4 +12,5 @@ public interface InChatBackMapService { Map loginError(); + Map sendTo(String value); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index b62e32d..55fe163 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -60,13 +60,13 @@ public boolean login(Channel channel, Map maps) { @Override public void sendMeText(Channel channel, Map maps) { - - + channel.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendTo(maps.get("value"))))); } @Override public void sendToText(Channel channel, Map maps) { - System.out.println("sendText-"+maps.get("value")); + System.out.println("sendTOText-"+maps.get("value")); } diff --git a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java index 90ed582..6412a05 100644 --- a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java @@ -13,7 +13,6 @@ @Service public class InChatBackMapServiceImpl implements InChatBackMapService { - @Override public Map loginSuccess() { Map backMap = new HashMap<>(); @@ -29,4 +28,12 @@ public Map loginError() { backMap.put("success","false"); return backMap; } + + @Override + public Map sendTo(String value) { + Map backMap = new HashMap<>(); + backMap.put("type","send"); + backMap.put("value",value); + return backMap; + } } From c61f9be893a19dde3397b153a5fb510bd7beba04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 26 Nov 2018 17:25:21 +0800 Subject: [PATCH 025/151] log --- doc/Project-Log-cn.md | 3 ++- doc/Project-Log.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 227193a..2d044de 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -2,4 +2,5 @@ * 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) * 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) -* 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 \ No newline at end of file +* 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 +* 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 \ No newline at end of file diff --git a/doc/Project-Log.md b/doc/Project-Log.md index 851f59e..8c677f2 100644 --- a/doc/Project-Log.md +++ b/doc/Project-Log.md @@ -2,4 +2,5 @@ * 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) * 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) -* 【2018-11-23】 Add contribution suggestion Information, Refactoring modified login Detection constant code, extracted into interface form \ No newline at end of file +* 【2018-11-23】 Add contribution suggestion Information, Refactoring modified login Detection constant code, extracted into interface form +* 【2018-11-26】 Login storage User Token with linked instances, sent to their own feature API, some functional code refactoring \ No newline at end of file From 6515030ac07403fa66591ddccfa526a96c16ad0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 09:58:48 +0800 Subject: [PATCH 026/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=91=E9=80=81API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 18 +++++++++++ .../backmsg/InChatBackMapService.java | 31 +++++++++++++++++- .../nettychat/bootstrap/WsChannelService.java | 18 +++++++++++ .../channel/WebSocketChannelService.java | 10 ++++++ .../channel/WebSocketHandlerService.java | 15 +++++++-- .../bootstrap/channel/cache/WsCacheMap.java | 32 +++++++++++++++++++ .../handler/DefaultWebSocketHandler.java | 3 ++ .../user/InChatBackMapServiceImpl.java | 21 +++++++++++- .../user/InChatVerifyServiceImpl.java | 9 +++--- 9 files changed, 149 insertions(+), 8 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index c30f702..d0f698d 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -101,6 +101,23 @@ } } + function sendToOne(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "sendTo", + me: "3333", + value: value, + one: "2222", + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } + } + window.onbeforeunload = function(event) { event.returnValue = "刷新提醒"; }; @@ -112,6 +129,7 @@

SpringBoot netty 聊天室

+

diff --git a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java index 1349309..a01fc1e 100644 --- a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java +++ b/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java @@ -8,9 +8,38 @@ */ public interface InChatBackMapService { + /** + * 登录成功返回信息 + * @return {@link Map} Json + */ Map loginSuccess(); + /** + * 登录失败返回信息 + * @return {@link Map} Json + */ Map loginError(); - Map sendTo(String value); + /** + * 发送给自己 + * @param value {@link String} 通讯消息 + * @return {@link Map} Json + */ + Map sendMe(String value); + + /** + * 发送给某人的信息,返回给自己 + * @param otherOne {@link String} 某人Token + * @param value {@link String} 通讯消息 + * @return {@link Map} Json + */ + Map sendBack(String otherOne, String value); + + /** + * 某人接收到他人发送给他的消息 + * @param me {@link String} 发送人的标签 + * @param value {@link String} 通讯消息 + * @return + */ + Map getMsg(String me, String value); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java index 4c7d164..6ea1729 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java @@ -8,6 +8,24 @@ */ public interface WsChannelService { + /** + * 登录成功存储到本地缓存 + * @param channel {@link Channel} 链接实例 + * @param token {@link String} 用户标识 + */ void loginWsSuccess(Channel channel, String token); + /** + * 判断是否存在当前在线用户 + * @param otherOne {@link String} 某人的用户标识 + * @return {@link Boolean} 是否存在 + */ + boolean hasOther(String otherOne); + + /** + * 获取某人的链接实例 + * @param otherOne {@link String} 用户唯一标识 + * @return {@link Channel} 链接实例 + */ + Channel getChannel(String otherOne); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java index b415cda..30a6ad2 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java @@ -22,5 +22,15 @@ public void loginWsSuccess(Channel channel, String token) { wsCacheMap.saveWs(token,channel); } + @Override + public boolean hasOther(String otherOne) { + return wsCacheMap.hasToken(otherOne); + } + + @Override + public Channel getChannel(String otherOne) { + return wsCacheMap.getByToken(otherOne); + } + } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 55fe163..3105256 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -61,12 +61,23 @@ public boolean login(Channel channel, Map maps) { @Override public void sendMeText(Channel channel, Map maps) { channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendTo(maps.get("value"))))); + gson.toJson(inChatBackMapService.sendMe(maps.get("value"))))); } @Override public void sendToText(Channel channel, Map maps) { - System.out.println("sendTOText-"+maps.get("value")); + String otherOne = maps.get("one"); + String value = maps.get("value"); + String me = maps.get("me"); + if (websocketChannelService.hasOther(otherOne)){ + //发送给对方 + Channel other = websocketChannelService.getChannel(otherOne); + other.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.getMsg(me,value)))); + //返回给自己 + channel.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); + } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java index d2e7abf..1432e6b 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -8,6 +8,7 @@ import java.util.concurrent.ConcurrentHashMap; /** + * WebSocket链接实例本地存储 * Created by MySelf on 2018/11/26. */ @Slf4j @@ -16,19 +17,50 @@ public class WsCacheMap { Map maps = new ConcurrentHashMap(); + /** + * 存储链接 + * @param token {@link String} 用户标签 + * @param channel {@link Channel} 链接实例 + */ public void saveWs(String token,Channel channel){ log.info("【新增用户链接:】"+token); maps.put(token,channel); } + /** + * 获取链接数据 + * @param token {@link String} 用户标识 + * @return {@link Channel} 链接实例 + */ public Channel getByToken(String token){ log.info("【获取用户链接:】"+token); return maps.get(token); } + /** + * 删除链接数据 + * @param token {@link String} 用户标识 + */ public void deleteWs(String token){ log.info("【删除用户链接:】"+token); maps.remove(token); } + /** + * 获取链接数 + * @return {@link Integer} 链接数 + */ + public Integer getSize(){ + return maps.size(); + } + + /** + * 判断是否存在链接账号 + * @param token {@link String} 用户标识 + * @return {@link Boolean} 是否存在 + */ + public boolean hasToken(String token){ + return maps.containsKey(token); + } + } diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index 60d9d2d..c70bb04 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -55,6 +55,9 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) case "sendMe": serverWebSocketHandlerService.sendMeText(channel,maps); break; + case "sendTo": + serverWebSocketHandlerService.sendToText(channel,maps); + break; default: break; } diff --git a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java index 6412a05..2b97c5b 100644 --- a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java @@ -30,10 +30,29 @@ public Map loginError() { } @Override - public Map sendTo(String value) { + public Map sendMe(String value) { Map backMap = new HashMap<>(); backMap.put("type","send"); backMap.put("value",value); return backMap; } + + @Override + public Map sendBack(String otherOne, String value) { + Map backMap = new HashMap<>(); + backMap.put("type","sendTo"); + backMap.put("value",value); + backMap.put("one",otherOne); + return backMap; + } + + @Override + public Map getMsg(String me, String value) { + Map backMap = new HashMap<>(); + backMap.put("type","get"); + backMap.put("from",me); + backMap.put("value",value); + return backMap; + } + } diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java index fbfeae9..c7dbab3 100644 --- a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java @@ -14,10 +14,11 @@ public class InChatVerifyServiceImpl implements InChatVerifyService { public boolean verifyToken(String token) { //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 System.out.println("verify---"+token); - if ("3333".equals(token)){ - return true; - } - return false; + //为了方便多人登录,暂不校验 +// if ("3333".equals(token)){ +// return true; +// } + return true; } /** From dba4dc0918776324681f03b7f14ff22c24db57b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 11:24:16 +0800 Subject: [PATCH 027/151] update --- README.md | 50 +++++----- doc/Project-Log-cn.md | 3 +- doc/Project-Log.md | 6 -- doc/design.md | 10 -- doc/detail/Login.md | 213 ------------------------------------------ 5 files changed, 23 insertions(+), 259 deletions(-) delete mode 100644 doc/Project-Log.md delete mode 100644 doc/design.md delete mode 100644 doc/detail/Login.md diff --git a/README.md b/README.md index ee393f1..691dfe2 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,34 @@ # InChat -#### [Developer Chat](https://gitter.im/In-Chat/Lobby) - ->The entire MAVEN toolkit is still under construction.... +#### [在线通讯](https://gitter.im/In-Chat/Lobby) **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** -## Summery +## 简介 ***(InChat)Iot Netty Chat*** -> 2018-11-15 began to change to MAVEN project package, currently not released, please see the demo branch for details, thank you. - -A lightweight, efficient communication framework that supports chat and the Internet of things, you can use it to quickly build a chat server with the background and quickly customize your own communication APIs, including physical networks with different protocols that can be supported. +一个轻量级、高效的通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 -## Project Log +## 项目日志 -* [Project Log](doc/Project-Log.md) * [项目研发日志更新](doc/Project-Log-cn.md) -## Tutorial +## 教程 -* [中文文档说明](doc/document.md) * [业务场景技术实现分析](doc/work.md) -* [Project design Ideas](doc/design.md) * [项目设计思路](doc/design_cn.md) -## Learning Resources(欢迎贡献) +## 相关资料(欢迎贡献) * [netty4通信原理](doc/netty-study.md) * [QQ群建议贡献](doc/advice/advice.md) -## Branch demo +## demo分支介绍 -Original Project Core demo, you can first run to understand, imitation WeChat chat application, step by step update, based on Springboot-websocket General framework, combined with Netty to chat social, and record chat logs, asynchronous storage, front-end provisional sui Mobile, add implementation tcp/ -IP back-end communication port (MQTT protocol, real-time and single-chip computer and other TCP hardware communication), add picture processing stream, chat implementation text and picture sending function, API call Netty long link execution Send message (number of online, user list) +原始项目核心演示, 您可以先运行了解, 模仿微聊天聊天应用程序, 逐步更新, 基于 springbot-web 套接字的一般框架, 结合 netty 聊天社交, 并记录聊天日志, 异步存储, 前端临时 sui mobile, 添加实现 tcp/后端通信端口 (mqtt 协议、实时和单片机等 tcp 硬件通信), 添加图片处理流、聊天实现文本和图片发送功能,api 调用 netty 长链接执行发送消息 (联机、用户列表的数量) -## Demo Effect Diagram +## demo分支效果演示 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(5).png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(3).png) @@ -47,35 +39,35 @@ IP back-end communication port (MQTT protocol, real-time and single-chip compute ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) -## Branch webrtc +## webrtc分支介绍 -A Netty and web RTC combined to achieve Voice video communication function Branch. +一个基于web RTC和Netty相结合的例子,实现语音与视频流通讯。 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/webrtc/TIM%E5%9B%BE%E7%89%8720181121150540.png) -## Branch im-api +## im-api分支介绍 -Tencent im (cloud communications) backend imitation project, are docked in the form of APIs, if there is a front-end want to dock can run this branch, this branch is expected to end up for a single service concurrent 300,000 users of IM background project +腾讯 im (云通信) 后端仿真项目, 以 api 的形式对接, 如果有前端想要停靠可以运行此分支, 预计该分支最终将为一个单一的服务并发 300, 000个用户的 im 后台项目 -## Branch paho-mqtt +## paho-mqtt分支介绍 -Based on the small program end or mobile Web end of the Paho.js and Java MQTT Client simulation of message subscriptions and communications, small program IoT demo, currently supports WS format +基于 paho. js 和 java mqtt 客户端消息订阅和通信的小型程序端或移动 web 端, 小程序物联网演示目前支持 ws 格式 -## Branch tcp-wechat +## tcp-wechat分支介绍 -Based on the main communication between the small program end and the single chip computer and other hardware TCP/IP, IoT Center as a relay, this demo will fully implement the specific functions, please see the Branch home page for details +基于小程序端与单片机等硬件 tcp/ip 的主要通信, 将物联网中心作为中转, 本演示将充分实现具体功能 -## Download Address +## 下载地址 -Download Address:https://github.com/UncleCatMySelf/SBToNettyChat/releases +下载地址:https://github.com/UncleCatMySelf/SBToNettyChat/releases -## Issues & Questions +## 下载 & 问题 https://github.com/UncleCatMySelf/SBToNettyChat/issues QQ Group:628793702 -## About the author +## 关于作者 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E5%85%AC%E4%BC%97%E5%8F%B7.png) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 2d044de..8af86d8 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -3,4 +3,5 @@ * 【2018-11-21】 目前Maven包开发目标,设计WebSocket登录接口[详情请看设计文档](design_cn.md) * 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) * 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 -* 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 \ No newline at end of file +* 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 +* 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释 diff --git a/doc/Project-Log.md b/doc/Project-Log.md deleted file mode 100644 index 8c677f2..0000000 --- a/doc/Project-Log.md +++ /dev/null @@ -1,6 +0,0 @@ -# Project Log Updates - -* 【2018-11-21】 Current MAVEN package Development Goals, design WebSocket login interface[see design documentation for details](design.md) -* 【2018-11-22】 Encoding to implement the login process of WebSocket chat communication, [write a description document](detail/Login.md) -* 【2018-11-23】 Add contribution suggestion Information, Refactoring modified login Detection constant code, extracted into interface form -* 【2018-11-26】 Login storage User Token with linked instances, sent to their own feature API, some functional code refactoring \ No newline at end of file diff --git a/doc/design.md b/doc/design.md deleted file mode 100644 index af9a164..0000000 --- a/doc/design.md +++ /dev/null @@ -1,10 +0,0 @@ -# Project design Ideas - -## About Login - -About Inchat Unified Login interface design, design for small programs, apps, web-side login role, so will be token as the form of login Inchat websocket long connection, User server to do SSO authentication login after getting token to send login information directly to Inchat, the user server needs to override the Verifytoken method in Inchat to verify whether their token information is valid, normal start long connection. -In view of the token failure problem, WebSocket long connected login only for the first time login, then consider maintaining the link state (pingpong) in the form of heartbeat, the use of token authentication is to protect Inchat link routine (currently temporarily such design after changing the design according to usage) - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) - -* 【2018-11-22】 Encoding implementation And [Detailed implementation Documentation](detail/Login.md) \ No newline at end of file diff --git a/doc/detail/Login.md b/doc/detail/Login.md deleted file mode 100644 index 41279a2..0000000 --- a/doc/detail/Login.md +++ /dev/null @@ -1,213 +0,0 @@ -## Just give you the most worthwhile information. - -Little brother is working on an open source IM project with the goal of achieving a lightweight, efficient communication framework that supports chat and the internet of things. - -The design manuscript just produced yesterday has been realized today. The project is based on Netty two development, about Netty I will not introduce here, understand the people naturally understand. - -My budget is to do a MAVEN project that all enterprises or organizations can reference, and is basically out-of-the-box, simply implement the corresponding configuration and override method can build their own IM project (a Q, the effect of a letter). This paper mainly introduces the design and implementation of the login interface. - -## Design Info - -About Inchat Unified Login interface design, design for small programs, apps, web-side login role, so will be token as the form of login Inchat websocket long connection, User server to do SSO authentication login after getting token to send login information directly to Inchat, the user server needs to override the Verifytoken method in Inchat to verify whether their token information is valid, normal start long connection. -In view of the token failure problem, WebSocket long connected login only for the first time login, then consider maintaining the link state (pingpong) in the form of heartbeat, the use of token authentication is to protect Inchat link routine (currently temporarily such design after changing the design according to usage) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(13).png) - -Because most of the current Web projects or IM-based project logins may have multi-terminal single sign-on, so I chose the form of token, why do you need to use token to websocket this side of the verification once? Because you are logged on to the Web application side, and WebSocket, as long as others know your address, then you can link on, we do not want to have too many dead links (invalid links), so we need to send token again to Inchat login, -It is up to inchat to check if it is a legitimate login link and close the link if it is not valid. - -## Code implementation - -Because we want to do it for others, then we ourselves have to encapsulate a little better, for the configuration I chose enough types. - - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171455.png) - -For Netty listening and initialization, I use the way to scan and ASPECTJ, you can see the scan start in the project's auto package, this startup idea I also refer to other open source projects (specifically forgot the address). - -```java -@Bean -@ConditionalOnMissingBean(name = "sacnScheduled") -public ScanRunnable initRunable(@Autowired InitNetty serverBean){ - long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); - ScanRunnable sacnScheduled = new SacnScheduled(time); - Thread scanRunnable = new Thread(sacnScheduled); - scanRunnable.setDaemon(true); - scanRunnable.start(); - return sacnScheduled; -} - - -@Bean(initMethod = "open", destroyMethod = "close") -@ConditionalOnMissingBean -public InitServer initServer(InitNetty serverBean){ - if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ - throw new NullPointerException("not set port"); - } - if(serverBean.getBacklog()<1){ - serverBean.setBacklog(_BLACKLOG); - } - if(serverBean.getBossThread()<1){ - serverBean.setBossThread(CPU); - } - if(serverBean.getInitalDelay()<0){ - serverBean.setInitalDelay(SEDU_DAY); - } - if(serverBean.getPeriod()<1){ - serverBean.setPeriod(SEDU_DAY); - } - if(serverBean.getHeart()<1){ - serverBean.setHeart(TIMEOUT); - } - if(serverBean.getRevbuf()<1){ - serverBean.setRevbuf(BUF_SIZE); - } - if(serverBean.getWorkerThread()<1){ - serverBean.setWorkerThread(CPU*2); - } - return new InitServer(serverBean); -} -``` - - -There is a defaultwebsockethandler in the figure above, which is the default Netty startup processing. - -Of course, before executing it, you also need to perform to an abstract class Websockethandler. It will do some basic functional operations for me. - -```java -@Slf4j -public abstract class WebSocketHandler extends SimpleChannelInboundHandler { - - WebSocketHandlerApi webSocketHandlerApi; - - public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ - this.webSocketHandlerApi = webSocketHandlerApi; - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof TextWebSocketFrame){ - textdoMessage(ctx,(TextWebSocketFrame)msg); - }else if (msg instanceof WebSocketFrame){ - webdoMessage(ctx,(WebSocketFrame)msg); - } - } - - protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); - - protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - webSocketHandlerApi.close(ctx.channel()); - } - - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if(evt instanceof IdleStateEvent){ - webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); - } - super.userEventTriggered(ctx, evt); - } -} -``` - -For the login interface, he is based on WebSocket, and is the Textwebsocketframe type, Websocketframe is the late image chat function, - -So our Defaultwebsockethandler only need to implement textdomessage for the time being. -For the transmission of WebSocket we recommend the use of JSON form, which is beneficial for both the front and back ends. - -```java - @Override - protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { - Channel channel = ctx.channel(); - ServerWebSocketHandlerService serverWebSocketHandlerService; - if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ - serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; - }else{ - throw new NoFindHandlerException("Server Handler 不匹配"); - } - Map maps = (Map) JSON.parse(msg.text()); - switch (maps.get("type")){ - case "login": - serverWebSocketHandlerService.login(channel,msg); - break; - default: - break; - } - } -``` - -By the above code, you may have thought of the approximate JSON content of the front-end login, that's right. - - -``` -{ - type: "login", - token: value -} -``` - -Serverwebsockethandlerservice is a self-defined interface implementation service for the back-end websocket, and we now use it to his login interface, let's take a look at his login implementation method. - - -```java - - @Autowired - InChatVerifyService inChatVerifyService; - - @Override - public boolean login(Channel channel, TextWebSocketFrame textWebSocketFrame) { - //校验规则,自定义校验规则 - Map maps = (Map) JSON.parse(textWebSocketFrame.text()); - System.out.println("login-"+textWebSocketFrame.text()); - String token = maps.get("token"); - Gson gson = new Gson(); - Map backMap = new HashMap<>(); - if (inChatVerifyService.verifyToken(token)){ - backMap.put("type","login"); - backMap.put("success","true"); - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); - return true; - } - backMap.put("type","login"); - backMap.put("success","false"); - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(backMap))); - close(channel); - return false; - } -``` - -As can be seen from the above, -We will token and Inchatverifyservice.verifytoken do checksum, this is an interface, I did not write the implementation, because this is the user's thing, it needs to implement and rewrite my Verifytoken method, and return to me a value, the following is my test when writing the simulation implementation. - -```java -/** - * 不属于项目代码 - * Created by MySelf on 2018/11/22. - */ -@Service -public class InChatVerifyServiceImpl implements InChatVerifyService { - - @Override - public boolean verifyToken(String token) { - //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 - System.out.println("verify---"+token); - if ("3333".equals(token)){ - return true; - } - return false; - } -} -``` - -I just did a normal checksum, for the user can inject redistemplate and then do the checksum work. -To this, our login interface will be achieved! - -## Look at the effect. - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171241.png) - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171245.png) - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171247.png) From bc715ac88987641f882035cc9a31a4e3f89cdc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 14:09:41 +0800 Subject: [PATCH 028/151] update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 691dfe2..2546252 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ * [业务场景技术实现分析](doc/work.md) * [项目设计思路](doc/design_cn.md) +> * [登录模块详细设计](doc/detail/Login-cn.md) + ## 相关资料(欢迎贡献) * [netty4通信原理](doc/netty-study.md) From 5864fef9cf57b0a56373a802edb9a04d79dd417a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 14:49:29 +0800 Subject: [PATCH 029/151] update --- README.md | 3 ++- doc/detail/Login-cn.md | 3 +++ doc/detail/login_rect.md | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 doc/detail/login_rect.md diff --git a/README.md b/README.md index 2546252..f28bcbd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # InChat -#### [在线通讯](https://gitter.im/In-Chat/Lobby) +#### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** @@ -20,6 +20,7 @@ * [项目设计思路](doc/design_cn.md) > * [登录模块详细设计](doc/detail/Login-cn.md) +> * [登录模块整改版V0.1](doc/detail/login_rect.md) ## 相关资料(欢迎贡献) diff --git a/doc/detail/Login-cn.md b/doc/detail/Login-cn.md index ce2b21b..2aa63e7 100644 --- a/doc/detail/Login-cn.md +++ b/doc/detail/Login-cn.md @@ -208,3 +208,6 @@ public class InChatVerifyServiceImpl implements InChatVerifyService { ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171245.png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181122171247.png) + + +> 2017-11-25 end. \ No newline at end of file diff --git a/doc/detail/login_rect.md b/doc/detail/login_rect.md new file mode 100644 index 0000000..2106932 --- /dev/null +++ b/doc/detail/login_rect.md @@ -0,0 +1,34 @@ +## 前言 + +本文旨在更新上一节设计中的不合理进行整改,关于登录的不足还有扩展功能的添加。 + +前文:[登录模块详细设计](Login-cn.md) + +对于前文中的登录原核心思路是正确的,不过对于后期的部分业务功能的扩展是比较麻烦的,比如发送给其他人,发送离线消息,判断系统用户是否离线等。 +的确,上文只是设计登录而言,但是我们还要考虑到后续功能接口的封装还有业务流程,所以一开始多磨是有好处的。 + +## 设计整改 + +这次的架构流程我们大致是这样的。 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/login.png) + +我们可能需要中心整理一下: + +* 客户端是小程序、APP、Web端等的统称 +* 客户端向服务器登录请求获取服务器分配的token +* 同时服务器将用户信息与token存入redis +* 客户端登录的同时还要登录InChat,发送json格式向websocket模拟登录 + +``` +{ + type:login + token:**** +} +``` + +* InChat接收根据Type进行登录流程的执行,用户重写verifyToken方法去用户自定义的Redis中判断,返回真假 +* 校验登录成功,InChat本地存储链接与用户信息,这里的用户信息应该是User唯一标识,而不能是Token + +> 在我写到这里的时候,脑子中突然觉得说不定可以使用token,甚至想到更多,导致我没有继续写完本章 +> 2018-11-27 end. \ No newline at end of file From 1c349b896723934283aee8c854104dd2d147722e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 16:28:36 +0800 Subject: [PATCH 030/151] =?UTF-8?q?=E9=87=8C=E7=A8=8B=E7=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++++ doc/Project-Log-cn.md | 3 ++- doc/goal/goal.md | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 doc/goal/goal.md diff --git a/README.md b/README.md index f28bcbd..407b97e 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ > * [登录模块详细设计](doc/detail/Login-cn.md) > * [登录模块整改版V0.1](doc/detail/login_rect.md) +## 里程碑 + +* [InChat项目里程碑](doc/goal/goal.md) + ## 相关资料(欢迎贡献) * [netty4通信原理](doc/netty-study.md) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 8af86d8..d53326a 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -4,4 +4,5 @@ * 【2018-11-22】 编码实现WebSocket聊天通讯的登录流程,[撰写说明文档](detail/Login-cn.md) * 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 -* 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释 +* 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 + diff --git a/doc/goal/goal.md b/doc/goal/goal.md new file mode 100644 index 0000000..ff72d84 --- /dev/null +++ b/doc/goal/goal.md @@ -0,0 +1,11 @@ +# InChat项目里程碑 + +> 项目研发的开放目标,以Maven包为基本的发布(兼对应版本的文档输出)设定为每个里程碑的产出。 + +## V1.0.0版本 + +> 版本昵称:赤猫 + +版本目标:完成基本的消息通讯(仅支持文本消息),离线消息存储,历史消息查询,一对一聊天、自我聊天、群聊等 + +> 目前正在重构中····· \ No newline at end of file From e9e3257d34749c22384386bd0997ff63bd265159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 27 Nov 2018 17:04:23 +0800 Subject: [PATCH 031/151] update --- Front-End-Testing/chat.html | 2 +- README.md | 4 ++- .../channel/WebSocketHandlerService.java | 5 ++++ .../bootstrap/channel/cache/WsCacheMap.java | 6 ++--- .../handler/DefaultWebSocketHandler.java | 9 +++++++ .../ServerWebSocketHandlerService.java | 26 +++++++++++++++++++ .../user/InChatVerifyServiceImpl.java | 4 ++- 7 files changed, 50 insertions(+), 6 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index d0f698d..18d1223 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -36,7 +36,7 @@ outline: none; } .btn { - width: 78px; + width: 140px; height: 46px; background-color: #d8f1f9; border-radius: 6px; diff --git a/README.md b/README.md index 407b97e..91893f3 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ #### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) +#### QQ群:628793702(欢迎参与交流与提供建议、业务场景、需求功能等) + **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** ## 简介 @@ -72,7 +74,7 @@ https://github.com/UncleCatMySelf/SBToNettyChat/issues -QQ Group:628793702 +QQ群:628793702 ## 关于作者 diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 3105256..2d4f22a 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -98,6 +98,11 @@ public void doTimeOut(Channel channel, IdleStateEvent evt) { } + @Override + public void sendGroupText(Channel channel, Map maps) { + + } + @Override public void close(Channel channel) { log.info("【close】"+channel.remoteAddress()); diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java index 1432e6b..2637509 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -23,7 +23,7 @@ public class WsCacheMap { * @param channel {@link Channel} 链接实例 */ public void saveWs(String token,Channel channel){ - log.info("【新增用户链接:】"+token); + log.info("【新增用户链接实例:】"+token); maps.put(token,channel); } @@ -33,7 +33,7 @@ public void saveWs(String token,Channel channel){ * @return {@link Channel} 链接实例 */ public Channel getByToken(String token){ - log.info("【获取用户链接:】"+token); + log.info("【获取用户链接实例:】"+token); return maps.get(token); } @@ -42,7 +42,7 @@ public Channel getByToken(String token){ * @param token {@link String} 用户标识 */ public void deleteWs(String token){ - log.info("【删除用户链接:】"+token); + log.info("【删除用户链接实例:】"+token); maps.remove(token); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java index c70bb04..c78409e 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java @@ -50,14 +50,23 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) Map maps = (Map) JSON.parse(msg.text()); switch (maps.get("type")){ case "login": + log.info("【用户链接登录操作】"); serverWebSocketHandlerService.login(channel,maps); break; + //针对个人,发送给自己 case "sendMe": + log.info("【用户链接发送给自己】"); serverWebSocketHandlerService.sendMeText(channel,maps); break; + //针对个人,发送给某人 case "sendTo": + log.info("【用户链接发送给某人】"); serverWebSocketHandlerService.sendToText(channel,maps); break; + case "sendGroup": + log.info("【用户链接发送给群聊】"); + serverWebSocketHandlerService.sendGroupText(channel,maps); + break; default: break; } diff --git a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java index 476b853..adb7f56 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java @@ -11,16 +11,42 @@ */ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerApi { + /** + * 登录类型 + * @param channel {@link Channel} 链接实例 + * @param map {@link Map} 数据信息 + * @return {@link Boolean} 成功失败 + */ public abstract boolean login(Channel channel, Map map); + /** + * 发送给自己 + * @param channel {@link Channel} 链接实例 + * @param maps {@link Map} 数据信息 + */ public abstract void sendMeText(Channel channel,Map maps); + /** + * 发送给某人 + * @param channel {@link Channel} 链接实例 + * @param maps {@link Map} 数据信息 + */ public abstract void sendToText(Channel channel, Map maps); public abstract void pong(Channel channel); + /** + * 主动关闭 + * @param channel {@link Channel} 链接实例 + */ public abstract void disconnect(Channel channel); public abstract void doTimeOut(Channel channel, IdleStateEvent evt); + /** + * 发送给群聊 + * @param channel {@link Channel} 链接实例 + * @param maps {@link Map} 数据信息 + */ + public abstract void sendGroupText(Channel channel, Map maps); } diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java index c7dbab3..c8adcf5 100644 --- a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java @@ -1,19 +1,21 @@ package com.myself.nettychat.user; import com.myself.nettychat.verify.InChatVerifyService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; /** * 不属于项目代码 * Created by MySelf on 2018/11/22. */ +@Slf4j @Service public class InChatVerifyServiceImpl implements InChatVerifyService { @Override public boolean verifyToken(String token) { //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 - System.out.println("verify---"+token); + log.info("verify---"+token); //为了方便多人登录,暂不校验 // if ("3333".equals(token)){ // return true; From 85546efcf44cf4e90beb53e81b37d55eedd1926e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 29 Nov 2018 14:00:50 +0800 Subject: [PATCH 032/151] update --- .../bootstrap/channel/WebSocketHandlerService.java | 1 + .../nettychat/bootstrap/channel/cache/WsCacheMap.java | 6 +++--- .../com/myself/nettychat/verify/InChatVerifyService.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index 2d4f22a..f1d524b 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -90,6 +90,7 @@ public void pong(Channel channel) { @Override public void disconnect(Channel channel) { log.info("【disconnect】"+channel.remoteAddress()); + } @Override diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java index 2637509..91aaba7 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -23,7 +23,7 @@ public class WsCacheMap { * @param channel {@link Channel} 链接实例 */ public void saveWs(String token,Channel channel){ - log.info("【新增用户链接实例:】"+token); + log.info("【新增用户链接实例】"+token); maps.put(token,channel); } @@ -33,7 +33,7 @@ public void saveWs(String token,Channel channel){ * @return {@link Channel} 链接实例 */ public Channel getByToken(String token){ - log.info("【获取用户链接实例:】"+token); + log.info("【获取用户链接实例】"+token); return maps.get(token); } @@ -42,7 +42,7 @@ public Channel getByToken(String token){ * @param token {@link String} 用户标识 */ public void deleteWs(String token){ - log.info("【删除用户链接实例:】"+token); + log.info("【删除用户链接实例】"+token); maps.remove(token); } diff --git a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java index 2084404..6718867 100644 --- a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java @@ -9,4 +9,4 @@ public interface InChatVerifyService { boolean verifyToken(String token); String getVerifyLogin(); -} +} \ No newline at end of file From 08e610168036c301b8fafa2ac2312edb4f756a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 29 Nov 2018 14:28:32 +0800 Subject: [PATCH 033/151] update --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index d53326a..d88bed6 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -5,4 +5,4 @@ * 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 - +* 【2018-11-29】 修复登录下线关闭channel异常BUG From 26689e2811b6ee920270392f9746669a1df85b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 29 Nov 2018 14:51:47 +0800 Subject: [PATCH 034/151] update --- .../bootstrap/channel/cache/WsCacheMap.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java index 91aaba7..71c5f07 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -15,8 +15,16 @@ @Component public class WsCacheMap { + /** + * 存储用户标识与链接实例 + */ Map maps = new ConcurrentHashMap(); + /** + * 存储链接地址与用户标识 + */ + Map addMaps = new ConcurrentHashMap<>(); + /** * 存储链接 * @param token {@link String} 用户标签 @@ -27,6 +35,10 @@ public void saveWs(String token,Channel channel){ maps.put(token,channel); } + public void saveAd(String address,String token){ + addMaps.put(address, token); + } + /** * 获取链接数据 * @param token {@link String} 用户标识 From 38de1e05495c6fdc15073c12153ac1412538a489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 29 Nov 2018 16:54:11 +0800 Subject: [PATCH 035/151] update --- .../nettychat/bootstrap/WsChannelService.java | 6 +++++ .../channel/WebSocketChannelService.java | 10 +++++++++ .../channel/WebSocketHandlerService.java | 2 +- .../bootstrap/channel/cache/WsCacheMap.java | 22 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java index 6ea1729..ba7925b 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java @@ -28,4 +28,10 @@ public interface WsChannelService { * @return {@link Channel} 链接实例 */ Channel getChannel(String otherOne); + + /** + * 删除链接与本地存储信息 + * @param channel {@link Channel} 链接实例 + */ + void close(Channel channel); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java index 30a6ad2..b5bd3ff 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java @@ -20,6 +20,7 @@ public class WebSocketChannelService implements WsChannelService { @Override public void loginWsSuccess(Channel channel, String token) { wsCacheMap.saveWs(token,channel); + wsCacheMap.saveAd(channel.remoteAddress().toString(),token); } @Override @@ -32,5 +33,14 @@ public Channel getChannel(String otherOne) { return wsCacheMap.getByToken(otherOne); } + @Override + public void close(Channel channel) { + log.info("【退出统一移除】"); + String token = wsCacheMap.getByAddress(channel.remoteAddress().toString()); + wsCacheMap.deleteAd(channel.remoteAddress().toString()); + wsCacheMap.deleteWs(token); + channel.close(); + } + } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index f1d524b..a239403 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -107,6 +107,6 @@ public void sendGroupText(Channel channel, Map maps) { @Override public void close(Channel channel) { log.info("【close】"+channel.remoteAddress()); - channel.close(); + websocketChannelService.close(channel); } } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java index 71c5f07..c40cfdd 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java @@ -35,6 +35,11 @@ public void saveWs(String token,Channel channel){ maps.put(token,channel); } + /** + * 存储登录信息 + * @param address 登录地址 + * @param token 用户标签 + */ public void saveAd(String address,String token){ addMaps.put(address, token); } @@ -49,6 +54,15 @@ public Channel getByToken(String token){ return maps.get(token); } + /** + * 获取对应token标签 + * @param address {@link String} 链接地址 + * @return {@link String} + */ + public String getByAddress(String address){ + return addMaps.get(address); + } + /** * 删除链接数据 * @param token {@link String} 用户标识 @@ -58,6 +72,14 @@ public void deleteWs(String token){ maps.remove(token); } + /** + * 删除链接地址 + * @param address + */ + public void deleteAd(String address){ + addMaps.remove(address); + } + /** * 获取链接数 * @return {@link Integer} 链接数 From dcc59a2fdbdcd57697ee6afd2f2781f66fb17d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Thu, 29 Nov 2018 17:21:13 +0800 Subject: [PATCH 036/151] cache --- doc/Project-Log-cn.md | 2 +- pom.xml | 14 - .../nettychat/NettychatApplication.java | 2 - .../nettychat/auto/ServerAutoConfigure.java | 3 +- .../myself/nettychat/config/NettyConfig.java | 75 ----- .../config/NettyTcpChannelInitializer.java | 34 --- .../nettychat/config/NettyTcpConfig.java | 76 ----- .../NettyWebSocketChannelInitializer.java | 40 --- .../myself/nettychat/config/TCPServer.java | 58 ---- .../nettychat/config/TCPServerHandler.java | 260 ------------------ .../config/TextWebSocketFrameHandler.java | 140 ---------- .../nettychat/constont/CookieConstant.java | 15 - .../myself/nettychat/constont/H5Constant.java | 29 -- .../nettychat/constont/LikeRedisTemplate.java | 106 ------- .../myself/nettychat/store/TokenStore.java | 45 --- 15 files changed, 2 insertions(+), 897 deletions(-) delete mode 100644 src/main/java/com/myself/nettychat/config/NettyConfig.java delete mode 100644 src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java delete mode 100644 src/main/java/com/myself/nettychat/config/NettyTcpConfig.java delete mode 100644 src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java delete mode 100644 src/main/java/com/myself/nettychat/config/TCPServer.java delete mode 100644 src/main/java/com/myself/nettychat/config/TCPServerHandler.java delete mode 100644 src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java delete mode 100644 src/main/java/com/myself/nettychat/constont/CookieConstant.java delete mode 100644 src/main/java/com/myself/nettychat/constont/H5Constant.java delete mode 100644 src/main/java/com/myself/nettychat/constont/LikeRedisTemplate.java delete mode 100644 src/main/java/com/myself/nettychat/store/TokenStore.java diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index d88bed6..c5ee8a3 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -5,4 +5,4 @@ * 【2018-11-23】 添加贡献建议信息,重构修改登录检测常量代码,提取成接口形式 * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 -* 【2018-11-29】 修复登录下线关闭channel异常BUG +* 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 diff --git a/pom.xml b/pom.xml index e3e228e..f42fac3 100644 --- a/pom.xml +++ b/pom.xml @@ -96,20 +96,6 @@ curator-framework 2.9.1 - - org.springframework.boot - spring-boot-starter-freemarker - - - io.springfox - springfox-swagger2 - 2.8.0 - - - io.springfox - springfox-swagger-ui - 2.8.0 - org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/myself/nettychat/NettychatApplication.java b/src/main/java/com/myself/nettychat/NettychatApplication.java index 1f0033e..31434df 100644 --- a/src/main/java/com/myself/nettychat/NettychatApplication.java +++ b/src/main/java/com/myself/nettychat/NettychatApplication.java @@ -4,12 +4,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.scheduling.annotation.EnableScheduling; -import springfox.documentation.swagger2.annotations.EnableSwagger2; @SpringBootApplication @EnableScheduling //定时任务支持 @EnableAspectJAutoProxy //注解开启对aspectJ的支持 -@EnableSwagger2 //Swagger自动生成文档 public class NettychatApplication { public static void main(String[] args) throws Exception{ diff --git a/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java b/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java index 50d4513..361a6d2 100644 --- a/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java +++ b/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java @@ -2,7 +2,6 @@ import com.myself.nettychat.bootstrap.scan.SacnScheduled; import com.myself.nettychat.bootstrap.scan.ScanRunnable; -import com.myself.nettychat.common.enums.ProtocolEnum; import com.myself.nettychat.common.properties.InitNetty; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +39,7 @@ public ServerAutoConfigure(){ @Bean @ConditionalOnMissingBean(name = "sacnScheduled") - public ScanRunnable initRunable(@Autowired InitNetty serverBean){ + public ScanRunnable initRunable(@Autowired InitNetty serverBean){ long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); ScanRunnable sacnScheduled = new SacnScheduled(time); Thread scanRunnable = new Thread(sacnScheduled); diff --git a/src/main/java/com/myself/nettychat/config/NettyConfig.java b/src/main/java/com/myself/nettychat/config/NettyConfig.java deleted file mode 100644 index 3a71119..0000000 --- a/src/main/java/com/myself/nettychat/config/NettyConfig.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.myself.nettychat.config; - -import com.myself.nettychat.common.properties.InitNetty; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelOption; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; - -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:00 2018\8\14 0014 - */ -//@Component -public class NettyConfig { - - @Autowired - private InitNetty nettyAccountConfig; - - @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully") - public NioEventLoopGroup bossGroup(){ - return new NioEventLoopGroup(nettyAccountConfig.getBossThread()); - } - - @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully") - public NioEventLoopGroup workerGroup(){ - return new NioEventLoopGroup(nettyAccountConfig.getWorkerThread()); - } - - @Bean(name = "webSocketAddress") - public InetSocketAddress tcpPost(){ - return new InetSocketAddress(nettyAccountConfig.getWebport()); - } - - @Bean(name = "tcpChannelOptions") - public Map, Object> tcpChannelOptions(){ - Map, Object> options = new HashMap, Object>(); - options.put(ChannelOption.TCP_NODELAY,nettyAccountConfig.isNodelay()); - options.put(ChannelOption.SO_KEEPALIVE, nettyAccountConfig.isKeepalive()); - options.put(ChannelOption.SO_BACKLOG, nettyAccountConfig.getBacklog()); - options.put(ChannelOption.SO_REUSEADDR,nettyAccountConfig.isReuseaddr()); - return options; - } - - @Autowired - @Qualifier("somethingChannelInitializer") - private NettyWebSocketChannelInitializer nettyWebSocketChannelInitializer; - - @Bean(name = "serverBootstrap") - public ServerBootstrap bootstrap(){ - ServerBootstrap b = new ServerBootstrap(); - b.group(bossGroup(), workerGroup()) - .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.DEBUG)) - .childHandler(nettyWebSocketChannelInitializer); - Map, Object> tcpChannelOptions = tcpChannelOptions(); - Set> keySet = tcpChannelOptions.keySet(); - for (@SuppressWarnings("rawtypes") ChannelOption option : keySet) { - b.option(option, tcpChannelOptions.get(option)); - } - return b; - } -} diff --git a/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java b/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java deleted file mode 100644 index d07f1be..0000000 --- a/src/main/java/com/myself/nettychat/config/NettyTcpChannelInitializer.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.myself.nettychat.config; - -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.LineBasedFrameDecoder; -import io.netty.handler.codec.string.StringDecoder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:26 2018\9\20 0020 - */ -//@Component -//@Qualifier("tcpChannelInitializer") -public class NettyTcpChannelInitializer extends ChannelInitializer { - - @Autowired - @Qualifier("tcpServerHandler") - private TCPServerHandler tcpServerHandler; - - @Override - public void initChannel(SocketChannel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new LineBasedFrameDecoder(1024)); - pipeline.addLast(new StringDecoder()); - pipeline.addLast(tcpServerHandler); - } - -} \ No newline at end of file diff --git a/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java b/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java deleted file mode 100644 index 6a50776..0000000 --- a/src/main/java/com/myself/nettychat/config/NettyTcpConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.myself.nettychat.config; - -import com.myself.nettychat.common.properties.InitNetty; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.ChannelOption; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Component; - -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:27 2018\9\20 0020 - */ -//@Component -public class NettyTcpConfig { - -// @Autowired -// private InitNetty nettyAccountConfig; -// -// @Bean(name = "bossGroup", destroyMethod = "shutdownGracefully") -// public NioEventLoopGroup bossGroup(){ -// return new NioEventLoopGroup(nettyAccountConfig.getBossThread()); -// } -// -// @Bean(name = "workerGroup", destroyMethod = "shutdownGracefully") -// public NioEventLoopGroup workerGroup(){ -// return new NioEventLoopGroup(nettyAccountConfig.getWorkerThread()); -// } -// -// @Bean(name = "tcpSocketAddress") -// public InetSocketAddress tcpPost(){ -// return new InetSocketAddress(nettyAccountConfig.getTcpport()); -// } -// -// @Bean(name = "tcpChannelOptions") -// public Map, Object> tcpChannelOptions(){ -// Map, Object> options = new HashMap<>(); -// options.put(ChannelOption.TCP_NODELAY,nettyAccountConfig.isNodelay()); -// options.put(ChannelOption.SO_KEEPALIVE, nettyAccountConfig.isKeepalive()); -// options.put(ChannelOption.SO_BACKLOG, nettyAccountConfig.getBacklog()); -// options.put(ChannelOption.SO_REUSEADDR,nettyAccountConfig.isReuseaddr()); -// return options; -// } -// -// @Autowired -// @Qualifier("tcpChannelInitializer") -// private NettyTcpChannelInitializer nettyTcpChannelInitializer; -// -// @Bean(name = "tcpServerBootstrap") -// public ServerBootstrap bootstrap(){ -// ServerBootstrap b = new ServerBootstrap(); -// b.group(bossGroup(), workerGroup()) -// .channel(NioServerSocketChannel.class) -// .handler(new LoggingHandler(LogLevel.DEBUG)) -// .childHandler(nettyTcpChannelInitializer); -// Map, Object> tcpChannelOptions = tcpChannelOptions(); -// Set> keySet = tcpChannelOptions.keySet(); -// for (@SuppressWarnings("rawtypes") ChannelOption option : keySet) { -// b.option(option, tcpChannelOptions.get(option)); -// } -// return b; -// } - -} diff --git a/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java b/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java deleted file mode 100644 index 7037050..0000000 --- a/src/main/java/com/myself/nettychat/config/NettyWebSocketChannelInitializer.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.myself.nettychat.config; - -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpServerCodec; -import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; -import io.netty.handler.stream.ChunkedWriteHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:00 2018\8\14 0014 - */ -//@Component -//@Qualifier("somethingChannelInitializer") -public class NettyWebSocketChannelInitializer extends ChannelInitializer { - - @Autowired - private TextWebSocketFrameHandler textWebSocketFrameHandler; - - @Override - public void initChannel(SocketChannel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - pipeline.addLast(new HttpServerCodec()); - pipeline.addLast(new HttpObjectAggregator(65536)); - pipeline.addLast(new ChunkedWriteHandler()); - pipeline.addLast(new WebSocketServerProtocolHandler("/ws")); - pipeline.addLast(textWebSocketFrameHandler); //这里不能使用new,不然在handler中不能注入依赖 - - } - -} diff --git a/src/main/java/com/myself/nettychat/config/TCPServer.java b/src/main/java/com/myself/nettychat/config/TCPServer.java deleted file mode 100644 index fbf7580..0000000 --- a/src/main/java/com/myself/nettychat/config/TCPServer.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.myself.nettychat.config; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.Channel; -import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import javax.annotation.PreDestroy; -import java.net.InetSocketAddress; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:00 2018\8\14 0014 - */ -@Data -//@Component -public class TCPServer { - - @Autowired - @Qualifier("serverBootstrap") - private ServerBootstrap serverBootstrap; - - @Autowired - @Qualifier("tcpServerBootstrap") - private ServerBootstrap tcpServerBootstrap; - - @Autowired - @Qualifier("webSocketAddress") - private InetSocketAddress webPort; - - @Autowired - @Qualifier("tcpSocketAddress") - private InetSocketAddress tcpTcpPort; - - private Channel serverChannel; - - private Channel tcpServerChannel; - - public void startWeb() throws Exception { - serverChannel = serverBootstrap.bind(webPort).sync().channel().closeFuture().sync().channel(); - } - - public void startTcp() throws Exception { - tcpServerChannel = tcpServerBootstrap.bind(tcpTcpPort).sync().channel().closeFuture().sync().channel(); - } - - @PreDestroy - public void stop() throws Exception { - serverChannel.close(); - serverChannel.parent().close(); - tcpServerChannel.close(); - tcpServerChannel.parent().close(); - } -} diff --git a/src/main/java/com/myself/nettychat/config/TCPServerHandler.java b/src/main/java/com/myself/nettychat/config/TCPServerHandler.java deleted file mode 100644 index 735b200..0000000 --- a/src/main/java/com/myself/nettychat/config/TCPServerHandler.java +++ /dev/null @@ -1,260 +0,0 @@ -package com.myself.nettychat.config; - -import com.myself.nettychat.common.utils.*; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.util.ReferenceCountUtil; -import io.netty.util.concurrent.GlobalEventExecutor; -import io.netty.util.concurrent.ScheduledFuture; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:29 2018\9\20 0020 - */ -//@Component -//@Qualifier("tcpServerHandler") -//@ChannelHandler.Sharable -public class TCPServerHandler extends ChannelInboundHandlerAdapter { - - static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - String ChannelID = null; - try{ - String data = (String)msg; - System.out.println(data); - if (DataValida.ValidateHeadAndFeet(data)){ - data = DataResction.ResctionHeadAndFeet(data); - if (DataValida.ValidateCRCCode(DataResction.ResctionData(data),DataResction.ResctionCRCCode(data))){ - data = DataResction.ResctionData(data); - ChannelID = DataResction.ResctionID(data); - System.out.println("Const.hasChannelID(ChannelID):"+ Const.hasChannelID(ChannelID)); - //更换连接ID - if (!Const.hasChannelID(ChannelID)){ - String realChannelID = Const.isChannel(ctx.channel()); - System.out.println(realChannelID); - Const.ChangeClientId(realChannelID,ChannelID); - } - //检查重复链接ID 不同实例 切换实例 - if(Const.hasChannelID(ChannelID)){ - Const.changeChannel(ChannelID,ctx.channel()); - } - data = DataResction.ResctionDataNoID(data); - String type = DataResction.ResctionType(data); - String RealData = DataResction.ResctionRealData(data); - //数据类型判断 - switch (type){ - case "s": - //控制类型 - futureByController(ctx,RealData,ChannelID); - break; - case "g": - //经纬度传输 - futureByLoLa(ctx,RealData,ChannelID); - break; - case "v": - //设备电量信息 - RealData = DataResction.ResctionPower(RealData); - futureByCharge(ctx,RealData,ChannelID); - break; - case "p": - //设备检测物体信息 - futureByPStates(ctx,RealData,ChannelID); - break; - case "r": - //设备开关异常 - futureByException(ctx,RealData,ChannelID); - break; - case "j": - //客户端执行结果 - futureByChlientResult(ctx,RealData,ChannelID); - break; - case "t": - futureBYTesting(ctx,RealData,ChannelID); - break; - default: - //其他类型 - ctx.writeAndFlush(CallBackMessage.sendString( - CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.ERROR))); - break; - } - } else { - ctx.writeAndFlush(CallBackMessage.ERROR.duplicate()); - ctx.close(); - } - } else { - ctx.writeAndFlush(CallBackMessage.ERROR.duplicate()); - ctx.close(); - } - }finally { - ReferenceCountUtil.release(msg); - } - } - - - /** - * 客户端执行开锁测试执行方法 - * @param ctx - * @param realData - * @param ChannelID - */ - private void futureBYTesting(ChannelHandlerContext ctx, String realData, String ChannelID) { - Set ids = Const.getIdList(); - System.out.println("测试广播事件执行"); - for (String item : ids){ - SendUtil sendUtil = new SendUtil(); - Channel channel = Const.get(item); - if (channel != null){ - sendUtil.sendAll(realData,channel,item,Const.RESULT_TEXT); - } - } - } - - /** - * 客户端执行结果执行方法 - * @param ctx - * @param realData - */ - private void futureByChlientResult(ChannelHandlerContext ctx, String realData,String ChannelID) { - //测试方法 - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------客户端执行结果"); - } - },0, TimeUnit.SECONDS); - ctx.writeAndFlush(CallBackMessage.sendString( - CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.SUCCESS))); - } - - /** - * 开关异常执行方法 - * @param ctx - * @param realData - */ - private void futureByException(ChannelHandlerContext ctx,final String realData,final String ChannelID) { - //测试方法 - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------开关异常"); - } - },0,TimeUnit.SECONDS); - ctx.writeAndFlush(CallBackMessage.sendString( - CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.SUCCESS))); - } - - /** - * 设备电量执行方法 - * @param ctx - * @param realData - */ - private void futureByCharge(ChannelHandlerContext ctx,final String realData,final String ChannelID) { - //测试方法 - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------设备电量"); - } - },0,TimeUnit.SECONDS); - ctx.writeAndFlush(CallBackMessage.sendString( - CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.SUCCESS))); - } - - /** - * 经纬度传输执行方法 - * @param ctx - * @param realData - */ - private void futureByLoLa(ChannelHandlerContext ctx, String realData, final String ChannelID) { - final String Longitude = DataResction.ResctionLongitude(realData); - final String Latitude = DataResction.ResctionLatitude(realData); - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------经纬度传输"); - } - },0,TimeUnit.SECONDS); - ctx.writeAndFlush(CallBackMessage.sendString( - CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.SUCCESS))); - } - - /** - * 控制类执行方法 - * @param ctx - * @param realData - */ - private void futureByController(ChannelHandlerContext ctx,final String realData, final String ChannelID) { - //SQL入库操作 - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------控制类型"); -// - } - },0,TimeUnit.SECONDS); -// ctx.writeAndFlush(CallBackMessage.sendString( -// CRC16MySelf.getAllString(ChannelID,Const.RESULT_TYPE,Const.SUCCESS))); - ctx.writeAndFlush(CallBackMessage.Check1_test.duplicate()); - } - - private void futureByPStates(ChannelHandlerContext ctx,final String realData,final String channelID) { - System.out.println("检测物体事件执行"); - ScheduledFuture future = ctx.channel().eventLoop().schedule( - new Runnable() { - @Override - public void run() { - System.out.println("-------尝试执行SQL操作--------物体检测类型"); - } - },0,TimeUnit.SECONDS); - } - - private String getUpdateKey(String channelID, String pstates, String realData) { - Integer openid = null; - for (int i = 0; i < realData.length(); i++){ - if(pstates.charAt(i) != realData.charAt(i)){ - openid = i; - break; - } - } - return channelID + "_" + openid; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - cause.printStackTrace(); - ctx.close(); - System.out.println(cause.getMessage()); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - Const.add(String.valueOf(UUID.randomUUID()),ctx.channel()); - channels.add(ctx.channel()); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - System.out.println("Disconnected client " + ctx.channel().remoteAddress()); - Const.remove(ctx.channel()); - } -} - diff --git a/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java b/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java deleted file mode 100644 index 01901b1..0000000 --- a/src/main/java/com/myself/nettychat/config/TextWebSocketFrameHandler.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.myself.nettychat.config; - - -import com.myself.nettychat.constont.LikeRedisTemplate; -import com.myself.nettychat.common.utils.StringUtil; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.util.concurrent.GlobalEventExecutor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -import java.io.FileOutputStream; - - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:01 2018\8\14 0014 - */ -//@Component -//@Qualifier("textWebSocketFrameHandler") -//@ChannelHandler.Sharable -public class TextWebSocketFrameHandler extends SimpleChannelInboundHandler{ - - public static ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); - - @Autowired - private LikeRedisTemplate redisTemplate; -// @Autowired -// private LikeSomeCacheTemplate cacheTemplate; -// @Autowired -// private MsgAsyncTesk msgAsyncTesk; - - @Override - protected void channelRead0(ChannelHandlerContext ctx, - Object msg) throws Exception { - if(msg instanceof TextWebSocketFrame){ - textWebSocketFrame(ctx, (TextWebSocketFrame) msg); - }else if(msg instanceof WebSocketFrame){ //websocket帧类型 已连接 - handleWebSocketFrame(ctx, (WebSocketFrame) msg); - } - } - - private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) { - if(frame instanceof BinaryWebSocketFrame){ - //返回客户端 - BinaryWebSocketFrame imgBack= (BinaryWebSocketFrame) frame.copy(); - for (Channel channel : channels){ - channel.writeAndFlush(imgBack.retain()); - } - //保存服务器 - BinaryWebSocketFrame img= (BinaryWebSocketFrame) frame; - ByteBuf byteBuf=img.content(); - try { - FileOutputStream outputStream=new FileOutputStream("D:\\a.jpg"); - byteBuf.readBytes(outputStream,byteBuf.capacity()); - byteBuf.clear(); - }catch (Exception e){ - e.printStackTrace(); - } - } - } - - private void textWebSocketFrame(ChannelHandlerContext ctx, TextWebSocketFrame msg) { - Channel incoming = ctx.channel(); - String rName = StringUtil.getName(msg.text()); - String rMsg = StringUtil.getMsg(msg.text()); - if (rMsg.equals("")){ - return; - } - //用户登录判断 - if (redisTemplate.check(incoming.id(),rName)){ - //临时存储聊天数据 - // cacheTemplate.save(rName,rMsg); - //存储随机链接ID与对应登录用户名 - redisTemplate.save(incoming.id(),rName); - //存储登录用户名与链接实例,方便API调用链接实例 - redisTemplate.saveChannel(rName,incoming); - }else{ - incoming.writeAndFlush(new TextWebSocketFrame("存在二次登陆,系统已为你自动断开本次链接")); - channels.remove(ctx.channel()); - ctx.close(); - return; - } - for (Channel channel : channels) { - //将当前每个聊天内容进行存储 - if (channel != incoming){ - channel.writeAndFlush(new TextWebSocketFrame( "[" + rName + "]" + rMsg)); - } else { - channel.writeAndFlush(new TextWebSocketFrame(rMsg + "[" + rName + "]" )); - } - } - } - - @Override - public void handlerAdded(ChannelHandlerContext ctx) throws Exception { - System.out.println(ctx.channel().remoteAddress()); - channels.add(ctx.channel()); - } - - @Override - public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { - //删除存储池对应实例 - String name = (String) redisTemplate.getName(ctx.channel().id()); - redisTemplate.deleteChannel(name); - //删除默认存储对应关系 - redisTemplate.delete(ctx.channel().id()); - channels.remove(ctx.channel()); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - //在线 - } - - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - //掉线 - //msgAsyncTesk.saveChatMsgTask(); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - throws Exception { - //异常 - cause.printStackTrace(); - ctx.close(); - } -} diff --git a/src/main/java/com/myself/nettychat/constont/CookieConstant.java b/src/main/java/com/myself/nettychat/constont/CookieConstant.java deleted file mode 100644 index 14cb499..0000000 --- a/src/main/java/com/myself/nettychat/constont/CookieConstant.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.myself.nettychat.constont; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 18:09 2018\8\13 0013 - */ -public interface CookieConstant { - - String TOKEN = "token"; - - Integer EXPIRE = 3600;//半小时 - -} diff --git a/src/main/java/com/myself/nettychat/constont/H5Constant.java b/src/main/java/com/myself/nettychat/constont/H5Constant.java deleted file mode 100644 index d5fc6da..0000000 --- a/src/main/java/com/myself/nettychat/constont/H5Constant.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.myself.nettychat.constont; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:58 2018\8\13 0013 - */ -public interface H5Constant { - //登录页面 - String LOGIN = "login/login"; - //登录页面 - String LOGIN_SUI = "login/loginSui"; - - //首页2 - String HOME = "home/home"; - //首页 - String INDEX = "index"; - //聊天界面 - //String CHAT = "h5"; - - String ME = "me/me"; - - String FIND = "find/find"; - - String CHAT = "chat/chat"; - - String ALLCHAT = "chat/allchat"; -} diff --git a/src/main/java/com/myself/nettychat/constont/LikeRedisTemplate.java b/src/main/java/com/myself/nettychat/constont/LikeRedisTemplate.java deleted file mode 100644 index f9d3ad3..0000000 --- a/src/main/java/com/myself/nettychat/constont/LikeRedisTemplate.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.myself.nettychat.constont; - -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:46 2018\8\14 0014 - */ -@Component -public class LikeRedisTemplate { - - private Map RedisMap = new ConcurrentHashMap<>(); - - private Map SecondRedisMap = new ConcurrentHashMap<>(); - - /**存放链接池实例*/ - private Map ChannelRedisMap = new ConcurrentHashMap<>(); - - public void save(Object id,Object name){ - RedisMap.put(id,name); - SecondRedisMap.put(name,id); - } - - /** - * 存储对应的用户名与Netty链接实例 - * @param name 登录用户名 - * @param channel Netty链接实例 - */ - public void saveChannel(Object name,Object channel){ - ChannelRedisMap.put(name,channel); - } - - /** - * 删除存储池实例 - * @param name 登录用户名 - */ - public void deleteChannel(Object name){ - ChannelRedisMap.remove(name); - } - - /** - * 获取存储池中的链接实例 - * @param name 登录用户名 - * @return {@link io.netty.channel.Channel 链接实例} - */ - public Object getChannel(Object name){ - return ChannelRedisMap.get(name); - } - - /** - * 获取储存池链接数 - * @return 在线数 - */ - public Integer getSize(){ - return ChannelRedisMap.size(); - } - - /** - * 获取连接对应用户名称 - * @param id 连接Id - * @return 用户名称 - */ - public Object getName(Object id){ - return RedisMap.get(id); - } - - - public boolean check(Object id,Object name){ - if (SecondRedisMap.get(name) == null){ - return true; - } - if (id.equals(SecondRedisMap.get(name))){ - return true; - }else{ - return false; - } - } - - public void delete(Object id){ - try { - SecondRedisMap.remove(RedisMap.get(id)); - RedisMap.remove(id); - }catch (NullPointerException e){ - e.printStackTrace(); - } - } - - /** - * 返回在线用户列表信息 - * @return 用户名列表 - */ - public Object getOnline() { - List result = new ArrayList<>(); - for (Object key:ChannelRedisMap.keySet()){ - result.add(key); - } - return result; - } -} diff --git a/src/main/java/com/myself/nettychat/store/TokenStore.java b/src/main/java/com/myself/nettychat/store/TokenStore.java deleted file mode 100644 index 224cb97..0000000 --- a/src/main/java/com/myself/nettychat/store/TokenStore.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.myself.nettychat.store; - -import lombok.Data; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 全局Token存储环境实例 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 18:00 2018\8\13 0013 - */ -@Data -public class TokenStore { - - private static Map TokenStoreMap = new ConcurrentHashMap(); - - /** - * 添加到全局Token缓存中 - * @param token - * @param userId - */ - public static void add(String token,Object userId){ - TokenStoreMap.put(token,userId); - } - - /** - * 从全局Token缓存中移除 - * @param token - */ - public static void remove(String token){ - TokenStoreMap.remove(token); - } - - /** - * 获取Token对象 - * @param token - * @return - */ - public static Object get(String token){ - return TokenStoreMap.get(token); - } -} From 5612d33856f4d67da3c1771a8266848b6bb21bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 16:18:50 +0800 Subject: [PATCH 037/151] update --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 91893f3..2116aa4 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,13 @@ https://github.com/UncleCatMySelf/SBToNettyChat/issues QQ群:628793702 +## 赞助 + +打赏时请记得备注上你的github账号或者其他链接,谢谢支持! + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E4%BB%98%E6%AC%BE.png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E6%94%AF%E4%BB%98%E5%AE%9D.png) + ## 关于作者 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E5%85%AC%E4%BC%97%E5%8F%B7.png) From ffb667a41d7752b7369fdc468b5881775142b161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 16:32:30 +0800 Subject: [PATCH 038/151] log --- doc/Project-Log-cn.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index c5ee8a3..f17bcf1 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -6,3 +6,4 @@ * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 * 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 +* 【2018-11-30】 启动赞助功能, \ No newline at end of file From 3f8cef287f75458f47d0f3d99b051887a75c8e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 16:41:57 +0800 Subject: [PATCH 039/151] update --- .../{ => bootstrap}/backmsg/InChatBackMapService.java | 2 +- .../bootstrap/channel/WebSocketHandlerService.java | 8 ++------ .../{ => bootstrap}/verify/InChatVerifyService.java | 2 +- .../myself/nettychat/user/InChatBackMapServiceImpl.java | 2 +- .../myself/nettychat/user/InChatVerifyServiceImpl.java | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) rename src/main/java/com/myself/nettychat/{ => bootstrap}/backmsg/InChatBackMapService.java (95%) rename src/main/java/com/myself/nettychat/{ => bootstrap}/verify/InChatVerifyService.java (78%) diff --git a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java b/src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java similarity index 95% rename from src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java rename to src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java index a01fc1e..d78df16 100644 --- a/src/main/java/com/myself/nettychat/backmsg/InChatBackMapService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.backmsg; +package com.myself.nettychat.bootstrap.backmsg; import java.util.Map; diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java index a239403..ab53211 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java @@ -1,14 +1,11 @@ package com.myself.nettychat.bootstrap.channel; -import com.alibaba.fastjson.JSON; import com.google.gson.Gson; -import com.myself.nettychat.backmsg.InChatBackMapService; -import com.myself.nettychat.bootstrap.BaseApi; +import com.myself.nettychat.bootstrap.backmsg.InChatBackMapService; import com.myself.nettychat.bootstrap.BaseAuthService; -import com.myself.nettychat.bootstrap.ChannelService; import com.myself.nettychat.bootstrap.WsChannelService; import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; -import com.myself.nettychat.verify.InChatVerifyService; +import com.myself.nettychat.bootstrap.verify.InChatVerifyService; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; @@ -16,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.HashMap; import java.util.Map; /** diff --git a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java b/src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java similarity index 78% rename from src/main/java/com/myself/nettychat/verify/InChatVerifyService.java rename to src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java index 6718867..87c6ad6 100644 --- a/src/main/java/com/myself/nettychat/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.verify; +package com.myself.nettychat.bootstrap.verify; /** * 用户校验层 diff --git a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java index 2b97c5b..ac3e15c 100644 --- a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java @@ -1,6 +1,6 @@ package com.myself.nettychat.user; -import com.myself.nettychat.backmsg.InChatBackMapService; +import com.myself.nettychat.bootstrap.backmsg.InChatBackMapService; import org.springframework.stereotype.Service; import java.util.HashMap; diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java index c8adcf5..a257109 100644 --- a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java @@ -1,6 +1,6 @@ package com.myself.nettychat.user; -import com.myself.nettychat.verify.InChatVerifyService; +import com.myself.nettychat.bootstrap.verify.InChatVerifyService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; From ead0734a0f05255f7506475a12a14632f155962a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 16:47:44 +0800 Subject: [PATCH 040/151] update --- doc/netty-study.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/netty-study.md b/doc/netty-study.md index aa6354b..e9a55cb 100644 --- a/doc/netty-study.md +++ b/doc/netty-study.md @@ -1,6 +1,6 @@ ## netty4通信步骤,原理 -> 感谢 贡献者:@@Noseparte +> 感谢 贡献者:[Noseparte](https://github.com/noseparte) ### 服务端依次发生的步骤 From d5d239a90bacda82574d90fc90742f74c8f68480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 17:10:41 +0800 Subject: [PATCH 041/151] sendfromserver --- doc/Project-Log-cn.md | 2 +- .../nettychat/bootstrap/WsChannelService.java | 10 +++++++++ .../channel/WebSocketChannelService.java | 21 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index f17bcf1..227ac85 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -6,4 +6,4 @@ * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 * 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 -* 【2018-11-30】 启动赞助功能, \ No newline at end of file +* 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 \ No newline at end of file diff --git a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java index ba7925b..56faebf 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java @@ -2,6 +2,8 @@ import io.netty.channel.Channel; +import java.util.Map; + /** * WebSocket 聊天业务消息处理 * Created by MySelf on 2018/11/26. @@ -34,4 +36,12 @@ public interface WsChannelService { * @param channel {@link Channel} 链接实例 */ void close(Channel channel); + + /** + * 以服务端API调用向链接发送信息 + * @param channel {@link } + * @param map + * @return + */ + boolean sendFromServer(Channel channel, Map map); } diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java index b5bd3ff..60f4fef 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java @@ -1,12 +1,16 @@ package com.myself.nettychat.bootstrap.channel; +import com.google.gson.Gson; import com.myself.nettychat.bootstrap.WsChannelService; import com.myself.nettychat.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Map; + /** * Created by MySelf on 2018/11/26. */ @@ -17,6 +21,12 @@ public class WebSocketChannelService implements WsChannelService { @Autowired WsCacheMap wsCacheMap; + private final Gson gson; + + public WebSocketChannelService(Gson gson){ + this.gson = gson; + } + @Override public void loginWsSuccess(Channel channel, String token) { wsCacheMap.saveWs(token,channel); @@ -42,5 +52,16 @@ public void close(Channel channel) { channel.close(); } + @Override + public boolean sendFromServer(Channel channel, Map map) { + try { + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(map))); + return true; + }catch (Exception e){ + log.error("【发送异常】:" + e.getMessage()); + return false; + } + } + } From bd0e383adba9d8e76ef47e45614c020e68c8888d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 17:27:10 +0800 Subject: [PATCH 042/151] updateGroup --- pom.xml | 6 +- .../DefaultAutoService.java | 38 +- .../NettychatApplication.java | 2 +- .../auto/InitServer.java | 76 +- .../auto/ServerAutoConfigure.java | 164 ++-- .../bootstrap/AbstractBootstrapServer.java | 74 +- .../bootstrap/BaseApi.java | 150 ++- .../bootstrap/BaseAuthService.java | 26 +- .../bootstrap/BootstrapServer.java | 36 +- .../bootstrap/ChannelService.java | 80 +- .../bootstrap/NettyBootstrapServer.java | 268 ++--- .../bootstrap/WsChannelService.java | 2 +- .../backmsg/InChatBackMapService.java | 2 +- .../bootstrap/bean/MqttChannel.java | 230 ++--- .../bootstrap/bean/RetainMessage.java | 38 +- .../bootstrap/bean/SendMqttMessage.java | 70 +- .../bootstrap/bean/SendWebMessage.java | 4 +- .../bootstrap/bean/SessionMessage.java | 58 +- .../bootstrap/bean/WebChannel.java | 4 +- .../bootstrap/bean/WillMeaasge.java | 46 +- .../channel/AbstractChannelService.java | 224 ++--- .../channel/ClientSessionService.java | 72 +- .../bootstrap/channel/MqttChannelService.java | 879 +++++++++-------- .../bootstrap/channel/MqttHandlerService.java | 445 +++++---- .../bootstrap/channel/PublishApiSevice.java | 324 +++---- .../channel/WebSocketChannelService.java | 6 +- .../channel/WebSocketHandlerService.java | 12 +- .../bootstrap/channel/WillService.java | 103 +- .../bootstrap/channel/cache/CacheMap.java | 274 +++--- .../bootstrap/channel/cache/WsCacheMap.java | 2 +- .../coder/ByteBufToWebSocketFrameEncoder.java | 52 +- .../coder/WebSocketFrameToByteBufDecoder.java | 50 +- .../bootstrap/handler/DefaultMqttHandler.java | 209 ++-- .../handler/DefaultWebSocketHandler.java | 170 ++-- .../bootstrap/scan/SacnScheduled.java | 118 +-- .../bootstrap/scan/ScanRunnable.java | 86 +- .../bootstrap/verify/InChatVerifyService.java | 2 +- .../common/enums/ConfirmStatus.java | 26 +- .../common/enums/ProtocolEnum.java | 28 +- .../common/enums/QosStatus.java | 28 +- .../common/enums/SessionStatus.java | 26 +- .../common/enums/SubStatus.java | 22 +- .../common/exception/ConnectionException.java | 28 +- .../exception/NoFindHandlerException.java | 28 +- .../common/ip/IpUtils.java | 136 +-- .../mqtts/ClientMqttHandlerService.java | 54 +- .../common/mqtts/MqttHander.java | 100 +- .../common/mqtts/MqttHandlerIntf.java | 52 +- .../mqtts/ServerMqttHandlerService.java | 56 +- .../common/pool/DefaultThreadFactory.java | 86 +- .../common/pool/ExecutorQueue.java | 114 +-- .../common/pool/Scheduled.java | 30 +- .../common/pool/StandardThreadExecutor.java | 200 ++-- .../common/properties/InitNetty.java | 100 +- .../common/ssl/SecureSocketKeyStore.java | 912 +++++++++--------- .../ssl/SecureSocketSslContextFactory.java | 178 ++-- .../ssl/SecureSokcetTrustManagerFactory.java | 126 +-- .../common/ssl/StreamReader.java | 50 +- .../common/ssl/X509CertTool.java | 138 +-- .../common/utils/ByteBufUtil.java | 38 +- .../common/utils/CRC16MySelf.java | 146 +-- .../common/utils/CallBackMessage.java | 70 +- .../common/utils/Const.java | 362 +++---- .../common/utils/CookieUtil.java | 130 +-- .../common/utils/DataResction.java | 212 ++-- .../common/utils/DataValida.java | 102 +- .../common/utils/IdWorker.java | 300 +++--- .../common/utils/MessageId.java | 54 +- .../common/utils/RandomNameUtil.java | 40 +- .../common/utils/RemotingUtil.java | 374 +++---- .../common/utils/SendUtil.java | 168 ++-- .../common/utils/SpringBeanUtils.java | 90 +- .../common/utils/StringUtil.java | 42 +- .../ServerWebSocketHandlerService.java | 3 +- .../common/websockets/WebSocketHandler.java | 102 +- .../websockets/WebSocketHandlerApi.java | 49 +- .../task/ScheduledPool.java | 66 +- .../user/InChatBackMapServiceImpl.java | 4 +- .../user/InChatVerifyServiceImpl.java | 4 +- src/main/resources/application.yml | 2 +- .../NettychatApplicationTests.java | 2 +- 81 files changed, 4635 insertions(+), 4645 deletions(-) rename src/main/java/com/myself/{nettychat => unclecatmyself}/DefaultAutoService.java (74%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/NettychatApplication.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/auto/InitServer.java (71%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/auto/ServerAutoConfigure.java (89%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/AbstractBootstrapServer.java (87%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/BaseApi.java (91%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/BaseAuthService.java (76%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/BootstrapServer.java (63%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/ChannelService.java (82%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/NettyBootstrapServer.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/WsChannelService.java (96%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/backmsg/InChatBackMapService.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/MqttChannel.java (89%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/RetainMessage.java (80%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/SendMqttMessage.java (78%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/SendWebMessage.java (77%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/SessionMessage.java (83%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/WebChannel.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/bean/WillMeaasge.java (80%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/AbstractChannelService.java (86%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/ClientSessionService.java (88%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/MqttChannelService.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/MqttHandlerService.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/PublishApiSevice.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/WebSocketChannelService.java (90%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/WebSocketHandlerService.java (88%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/WillService.java (81%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/cache/CacheMap.java (94%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/channel/cache/WsCacheMap.java (97%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java (90%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/coder/WebSocketFrameToByteBufDecoder.java (90%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/handler/DefaultMqttHandler.java (85%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/handler/DefaultWebSocketHandler.java (87%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/scan/SacnScheduled.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/scan/ScanRunnable.java (83%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/bootstrap/verify/InChatVerifyService.java (76%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/enums/ConfirmStatus.java (72%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/enums/ProtocolEnum.java (71%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/enums/QosStatus.java (78%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/enums/SessionStatus.java (70%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/enums/SubStatus.java (69%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/exception/ConnectionException.java (77%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/exception/NoFindHandlerException.java (79%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ip/IpUtils.java (94%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/mqtts/ClientMqttHandlerService.java (90%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/mqtts/MqttHander.java (94%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/mqtts/MqttHandlerIntf.java (89%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/mqtts/ServerMqttHandlerService.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/pool/DefaultThreadFactory.java (94%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/pool/ExecutorQueue.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/pool/Scheduled.java (79%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/pool/StandardThreadExecutor.java (96%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/properties/InitNetty.java (77%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ssl/SecureSocketKeyStore.java (98%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ssl/SecureSocketSslContextFactory.java (96%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ssl/SecureSokcetTrustManagerFactory.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ssl/StreamReader.java (87%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/ssl/X509CertTool.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/ByteBufUtil.java (84%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/CRC16MySelf.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/CallBackMessage.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/Const.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/CookieUtil.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/DataResction.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/DataValida.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/IdWorker.java (96%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/MessageId.java (88%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/RandomNameUtil.java (85%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/RemotingUtil.java (96%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/SendUtil.java (95%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/SpringBeanUtils.java (93%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/utils/StringUtil.java (87%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/websockets/ServerWebSocketHandlerService.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/websockets/WebSocketHandler.java (94%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/common/websockets/WebSocketHandlerApi.java (78%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/task/ScheduledPool.java (80%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/user/InChatBackMapServiceImpl.java (92%) rename src/main/java/com/myself/{nettychat => unclecatmyself}/user/InChatVerifyServiceImpl.java (87%) rename src/test/java/com/myself/{nettychat => unclecatmyself}/NettychatApplicationTests.java (89%) diff --git a/pom.xml b/pom.xml index f42fac3..52cc944 100644 --- a/pom.xml +++ b/pom.xml @@ -3,12 +3,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.myself - nettychat + com.myself.UncleCatMySelf + inchat 0.0.1-SNAPSHOT jar - nettychat + inchat Demo project for Spring Boot diff --git a/src/main/java/com/myself/nettychat/DefaultAutoService.java b/src/main/java/com/myself/unclecatmyself/DefaultAutoService.java similarity index 74% rename from src/main/java/com/myself/nettychat/DefaultAutoService.java rename to src/main/java/com/myself/unclecatmyself/DefaultAutoService.java index e4b4cc7..46dbb63 100644 --- a/src/main/java/com/myself/nettychat/DefaultAutoService.java +++ b/src/main/java/com/myself/unclecatmyself/DefaultAutoService.java @@ -1,19 +1,19 @@ -package com.myself.nettychat; - -import com.myself.nettychat.bootstrap.BaseAuthService; -import org.springframework.stereotype.Service; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 默认权限 - **/ -@Service -public class DefaultAutoService implements BaseAuthService { - - @Override - public boolean authorized(String username, String password) { - return true; - } -} +package com.myself.unclecatmyself; + +import com.myself.unclecatmyself.bootstrap.BaseAuthService; +import org.springframework.stereotype.Service; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 默认权限 + **/ +@Service +public class DefaultAutoService implements BaseAuthService { + + @Override + public boolean authorized(String username, String password) { + return true; + } +} diff --git a/src/main/java/com/myself/nettychat/NettychatApplication.java b/src/main/java/com/myself/unclecatmyself/NettychatApplication.java similarity index 93% rename from src/main/java/com/myself/nettychat/NettychatApplication.java rename to src/main/java/com/myself/unclecatmyself/NettychatApplication.java index 31434df..e0190dc 100644 --- a/src/main/java/com/myself/nettychat/NettychatApplication.java +++ b/src/main/java/com/myself/unclecatmyself/NettychatApplication.java @@ -1,4 +1,4 @@ -package com.myself.nettychat; +package com.myself.unclecatmyself; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/com/myself/nettychat/auto/InitServer.java b/src/main/java/com/myself/unclecatmyself/auto/InitServer.java similarity index 71% rename from src/main/java/com/myself/nettychat/auto/InitServer.java rename to src/main/java/com/myself/unclecatmyself/auto/InitServer.java index 3729fc3..145d346 100644 --- a/src/main/java/com/myself/nettychat/auto/InitServer.java +++ b/src/main/java/com/myself/unclecatmyself/auto/InitServer.java @@ -1,38 +1,38 @@ -package com.myself.nettychat.auto; - - -import com.myself.nettychat.bootstrap.BootstrapServer; -import com.myself.nettychat.bootstrap.NettyBootstrapServer; -import com.myself.nettychat.common.properties.InitNetty; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 初始化服务 - **/ -public class InitServer { - - private InitNetty serverBean; - - public InitServer(InitNetty serverBean) { - this.serverBean = serverBean; - } - - BootstrapServer bootstrapServer; - - public void open(){ - if(serverBean!=null){ - bootstrapServer = new NettyBootstrapServer(); - bootstrapServer.setServerBean(serverBean); - bootstrapServer.start(); - } - } - - - public void close(){ - if(bootstrapServer!=null){ - bootstrapServer.shutdown(); - } - } - -} +package com.myself.unclecatmyself.auto; + + +import com.myself.unclecatmyself.bootstrap.BootstrapServer; +import com.myself.unclecatmyself.bootstrap.NettyBootstrapServer; +import com.myself.unclecatmyself.common.properties.InitNetty; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 初始化服务 + **/ +public class InitServer { + + private InitNetty serverBean; + + public InitServer(InitNetty serverBean) { + this.serverBean = serverBean; + } + + BootstrapServer bootstrapServer; + + public void open(){ + if(serverBean!=null){ + bootstrapServer = new NettyBootstrapServer(); + bootstrapServer.setServerBean(serverBean); + bootstrapServer.start(); + } + } + + + public void close(){ + if(bootstrapServer!=null){ + bootstrapServer.shutdown(); + } + } + +} diff --git a/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java similarity index 89% rename from src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java rename to src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java index 361a6d2..4e896b0 100644 --- a/src/main/java/com/myself/nettychat/auto/ServerAutoConfigure.java +++ b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java @@ -1,82 +1,82 @@ -package com.myself.nettychat.auto; - -import com.myself.nettychat.bootstrap.scan.SacnScheduled; -import com.myself.nettychat.bootstrap.scan.ScanRunnable; -import com.myself.nettychat.common.properties.InitNetty; -import org.apache.commons.lang3.ObjectUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 自动化配置初始化服务 - **/ -@Configuration -@ConditionalOnClass -@EnableConfigurationProperties({InitNetty.class}) -public class ServerAutoConfigure { - - private static final int _BLACKLOG = 1024; - - private static final int CPU =Runtime.getRuntime().availableProcessors(); - - private static final int SEDU_DAY =10; - - private static final int TIMEOUT =120; - - private static final int BUF_SIZE=10*1024*1024; - - - public ServerAutoConfigure(){ - - } - - @Bean - @ConditionalOnMissingBean(name = "sacnScheduled") - public ScanRunnable initRunable(@Autowired InitNetty serverBean){ - long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); - ScanRunnable sacnScheduled = new SacnScheduled(time); - Thread scanRunnable = new Thread(sacnScheduled); - scanRunnable.setDaemon(true); - scanRunnable.start(); - return sacnScheduled; - } - - - @Bean(initMethod = "open", destroyMethod = "close") - @ConditionalOnMissingBean - public InitServer initServer(InitNetty serverBean){ - if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ - throw new NullPointerException("not set port"); - } - if(serverBean.getBacklog()<1){ - serverBean.setBacklog(_BLACKLOG); - } - if(serverBean.getBossThread()<1){ - serverBean.setBossThread(CPU); - } - if(serverBean.getInitalDelay()<0){ - serverBean.setInitalDelay(SEDU_DAY); - } - if(serverBean.getPeriod()<1){ - serverBean.setPeriod(SEDU_DAY); - } - if(serverBean.getHeart()<1){ - serverBean.setHeart(TIMEOUT); - } - if(serverBean.getRevbuf()<1){ - serverBean.setRevbuf(BUF_SIZE); - } - if(serverBean.getWorkerThread()<1){ - serverBean.setWorkerThread(CPU*2); - } - return new InitServer(serverBean); - } - -} +package com.myself.unclecatmyself.auto; + +import com.myself.unclecatmyself.bootstrap.scan.SacnScheduled; +import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; +import com.myself.unclecatmyself.common.properties.InitNetty; +import org.apache.commons.lang3.ObjectUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 自动化配置初始化服务 + **/ +@Configuration +@ConditionalOnClass +@EnableConfigurationProperties({InitNetty.class}) +public class ServerAutoConfigure { + + private static final int _BLACKLOG = 1024; + + private static final int CPU =Runtime.getRuntime().availableProcessors(); + + private static final int SEDU_DAY =10; + + private static final int TIMEOUT =120; + + private static final int BUF_SIZE=10*1024*1024; + + + public ServerAutoConfigure(){ + + } + + @Bean + @ConditionalOnMissingBean(name = "sacnScheduled") + public ScanRunnable initRunable(@Autowired InitNetty serverBean){ + long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); + ScanRunnable sacnScheduled = new SacnScheduled(time); + Thread scanRunnable = new Thread(sacnScheduled); + scanRunnable.setDaemon(true); + scanRunnable.start(); + return sacnScheduled; + } + + + @Bean(initMethod = "open", destroyMethod = "close") + @ConditionalOnMissingBean + public InitServer initServer(InitNetty serverBean){ + if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ + throw new NullPointerException("not set port"); + } + if(serverBean.getBacklog()<1){ + serverBean.setBacklog(_BLACKLOG); + } + if(serverBean.getBossThread()<1){ + serverBean.setBossThread(CPU); + } + if(serverBean.getInitalDelay()<0){ + serverBean.setInitalDelay(SEDU_DAY); + } + if(serverBean.getPeriod()<1){ + serverBean.setPeriod(SEDU_DAY); + } + if(serverBean.getHeart()<1){ + serverBean.setHeart(TIMEOUT); + } + if(serverBean.getRevbuf()<1){ + serverBean.setRevbuf(BUF_SIZE); + } + if(serverBean.getWorkerThread()<1){ + serverBean.setWorkerThread(CPU*2); + } + return new InitServer(serverBean); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java similarity index 87% rename from src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 7082275..840e00e 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -1,37 +1,37 @@ -package com.myself.nettychat.bootstrap; - - -import com.myself.nettychat.common.properties.InitNetty; -import com.myself.nettychat.common.utils.SpringBeanUtils; -import io.netty.channel.ChannelPipeline; -import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpServerCodec; -import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; -import io.netty.handler.stream.ChunkedWriteHandler; -import io.netty.handler.timeout.IdleStateHandler; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象类,负责加载edec handler - **/ -public abstract class AbstractBootstrapServer implements BootstrapServer { - - /** - * @param channelPipeline channelPipeline - * @param serverBean 服务配置参数 - */ - protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ - intProtocolHandler(channelPipeline,serverBean); - channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast(SpringBeanUtils.getBean(serverBean.getWebSocketHandler())); - } - - private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ - channelPipeline.addLast("httpCode",new HttpServerCodec()); - channelPipeline.addLast("aggregator", new HttpObjectAggregator(serverBean.getMaxContext())); - channelPipeline.addLast("chunkedWrite",new ChunkedWriteHandler()); - channelPipeline.addLast("webSocketHandler",new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); - } - -} +package com.myself.unclecatmyself.bootstrap; + + +import com.myself.unclecatmyself.common.properties.InitNetty; +import com.myself.unclecatmyself.common.utils.SpringBeanUtils; +import io.netty.channel.ChannelPipeline; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpServerCodec; +import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; +import io.netty.handler.stream.ChunkedWriteHandler; +import io.netty.handler.timeout.IdleStateHandler; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 抽象类,负责加载edec handler + **/ +public abstract class AbstractBootstrapServer implements BootstrapServer { + + /** + * @param channelPipeline channelPipeline + * @param serverBean 服务配置参数 + */ + protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ + intProtocolHandler(channelPipeline,serverBean); + channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); + channelPipeline.addLast(SpringBeanUtils.getBean(serverBean.getWebSocketHandler())); + } + + private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ + channelPipeline.addLast("httpCode",new HttpServerCodec()); + channelPipeline.addLast("aggregator", new HttpObjectAggregator(serverBean.getMaxContext())); + channelPipeline.addLast("chunkedWrite",new ChunkedWriteHandler()); + channelPipeline.addLast("webSocketHandler",new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/BaseApi.java b/src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java similarity index 91% rename from src/main/java/com/myself/nettychat/bootstrap/BaseApi.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java index edd8720..49984ec 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/BaseApi.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java @@ -1,76 +1,74 @@ -package com.myself.nettychat.bootstrap; - -import javax.validation.constraints.NotNull; -import java.util.Arrays; -import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Predicate; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 逻辑操作封装 - **/ -public interface BaseApi { - - default void doIfElse(T t, Predicate predicate, Consumer consumer){ - if(t!=null){ - if(predicate.test(t)){ - consumer.accept(t); - } - } - } - - - default void doIfElse(T t, Predicate predicate, Consumer consumer, Consumer consumer2){ - if(t!=null){ - if(predicate.test(t)){ - consumer.accept(t); - } - else{ - consumer2.accept(t); - } - } - } - default boolean doIf(T t, Predicate... predicates){ - if(t!=null){ - for(Predicate p:predicates){ - if(!p.test(t)){ - return false; - } - } - return true; - } - return false; - } - - default void doIfAnd(T t, Consumer consumer2, Predicate... predicates){ - boolean flag =true; - if(t!=null){ - for(Predicate p:predicates){ - if(!p.test(t)){ - flag= false; - break; - } - } - } - if(flag){ - consumer2.accept(t); - } - } - - default void doIfAnd1(@NotNull T t, @NotNull Consumer consumer2, @NotNull Predicate... predicates){ - Predicate one = predicates[0]; - int l; - if((l=predicates.length)>1){ - for(int i=1;i void doIfElse(T t, Predicate predicate, Consumer consumer){ + if(t!=null){ + if(predicate.test(t)){ + consumer.accept(t); + } + } + } + + + default void doIfElse(T t, Predicate predicate, Consumer consumer, Consumer consumer2){ + if(t!=null){ + if(predicate.test(t)){ + consumer.accept(t); + } + else{ + consumer2.accept(t); + } + } + } + default boolean doIf(T t, Predicate... predicates){ + if(t!=null){ + for(Predicate p:predicates){ + if(!p.test(t)){ + return false; + } + } + return true; + } + return false; + } + + default void doIfAnd(T t, Consumer consumer2, Predicate... predicates){ + boolean flag =true; + if(t!=null){ + for(Predicate p:predicates){ + if(!p.test(t)){ + flag= false; + break; + } + } + } + if(flag){ + consumer2.accept(t); + } + } + + default void doIfAnd1(@NotNull T t, @NotNull Consumer consumer2, @NotNull Predicate... predicates){ + Predicate one = predicates[0]; + int l; + if((l=predicates.length)>1){ + for(int i=1;i topics); - - void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage); - - void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage); - - void closeSuccess(String deviceId,boolean isDisconnect); - - void sendWillMsg(WillMeaasge willMeaasge); - - String getDeviceId(Channel channel); - - void unsubscribe(String deviceId, List topics1); - - void doPubrel(Channel channel, int mqttMessage); - - void doPubrec(Channel channel, int mqttMessage); - -} +package com.myself.unclecatmyself.bootstrap; + +import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; +import com.myself.unclecatmyself.bootstrap.bean.WillMeaasge; +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; + +import java.util.List; +import java.util.Set; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 消息处理 + **/ +public interface ChannelService { + + MqttChannel getMqttChannel(String deviceId); + + boolean connectSuccess(String s, MqttChannel build); + + void suscribeSuccess(String deviceId, Set topics); + + void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage); + + void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage); + + void closeSuccess(String deviceId,boolean isDisconnect); + + void sendWillMsg(WillMeaasge willMeaasge); + + String getDeviceId(Channel channel); + + void unsubscribe(String deviceId, List topics1); + + void doPubrel(Channel channel, int mqttMessage); + + void doPubrec(Channel channel, int mqttMessage); + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java similarity index 93% rename from src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java index 78275d0..0227263 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -1,134 +1,134 @@ -package com.myself.nettychat.bootstrap; - -import com.myself.nettychat.common.ip.IpUtils; -import com.myself.nettychat.common.properties.InitNetty; -import com.myself.nettychat.common.utils.RemotingUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.epoll.Epoll; -import io.netty.channel.epoll.EpollEventLoopGroup; -import io.netty.channel.epoll.EpollServerSocketChannel; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioServerSocketChannel; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc mtqq netty启动服务类 - **/ -@Slf4j -@Data -public class NettyBootstrapServer extends AbstractBootstrapServer { - - private InitNetty serverBean; - - public InitNetty getServerBean() { - return serverBean; - } - - public void setServerBean(InitNetty serverBean) { - this.serverBean = serverBean; - } - - private EventLoopGroup bossGroup; - - private EventLoopGroup workGroup; - - ServerBootstrap bootstrap=null ;// 启动辅助类 - - /** - * 服务开启 - */ - public void start() { - initEventPool(); - bootstrap.group(bossGroup, workGroup) - .channel(useEpoll()?EpollServerSocketChannel.class:NioServerSocketChannel.class) - .option(ChannelOption.SO_REUSEADDR, serverBean.isReuseaddr()) - .option(ChannelOption.SO_BACKLOG, serverBean.getBacklog()) - .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) - .option(ChannelOption.SO_RCVBUF, serverBean.getRevbuf()) - .childHandler(new ChannelInitializer() { - protected void initChannel(SocketChannel ch) throws Exception { - initHandler(ch.pipeline(),serverBean); - } - }) - .childOption(ChannelOption.TCP_NODELAY, serverBean.isNodelay()) - .childOption(ChannelOption.SO_KEEPALIVE, serverBean.isKeepalive()) - .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); - bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { - if (channelFuture.isSuccess()) - log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); - else - log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); - }); - } - /** - * 初始化EnentPool 参数 - */ - private void initEventPool(){ - bootstrap= new ServerBootstrap(); - if(useEpoll()){ - bossGroup = new EpollEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { - private AtomicInteger index = new AtomicInteger(0); - - public Thread newThread(Runnable r) { - return new Thread(r, "LINUX_BOSS_" + index.incrementAndGet()); - } - }); - workGroup = new EpollEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { - private AtomicInteger index = new AtomicInteger(0); - - public Thread newThread(Runnable r) { - return new Thread(r, "LINUX_WORK_" + index.incrementAndGet()); - } - }); - - } - else { - bossGroup = new NioEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { - private AtomicInteger index = new AtomicInteger(0); - - public Thread newThread(Runnable r) { - return new Thread(r, "BOSS_" + index.incrementAndGet()); - } - }); - workGroup = new NioEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { - private AtomicInteger index = new AtomicInteger(0); - - public Thread newThread(Runnable r) { - return new Thread(r, "WORK_" + index.incrementAndGet()); - } - }); - } - } - - /** - * 关闭资源 - */ - public void shutdown() { - if(workGroup!=null && bossGroup!=null ){ - try { - bossGroup.shutdownGracefully().sync();// 优雅关闭 - workGroup.shutdownGracefully().sync(); - } catch (InterruptedException e) { - log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); - } - } - } - - private boolean useEpoll() { - return RemotingUtil.isLinuxPlatform() - && Epoll.isAvailable(); - } - -} +package com.myself.unclecatmyself.bootstrap; + +import com.myself.unclecatmyself.common.ip.IpUtils; +import com.myself.unclecatmyself.common.properties.InitNetty; +import com.myself.unclecatmyself.common.utils.RemotingUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.PooledByteBufAllocator; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.epoll.Epoll; +import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.epoll.EpollServerSocketChannel; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc mtqq netty启动服务类 + **/ +@Slf4j +@Data +public class NettyBootstrapServer extends AbstractBootstrapServer { + + private InitNetty serverBean; + + public InitNetty getServerBean() { + return serverBean; + } + + public void setServerBean(InitNetty serverBean) { + this.serverBean = serverBean; + } + + private EventLoopGroup bossGroup; + + private EventLoopGroup workGroup; + + ServerBootstrap bootstrap=null ;// 启动辅助类 + + /** + * 服务开启 + */ + public void start() { + initEventPool(); + bootstrap.group(bossGroup, workGroup) + .channel(useEpoll()?EpollServerSocketChannel.class:NioServerSocketChannel.class) + .option(ChannelOption.SO_REUSEADDR, serverBean.isReuseaddr()) + .option(ChannelOption.SO_BACKLOG, serverBean.getBacklog()) + .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) + .option(ChannelOption.SO_RCVBUF, serverBean.getRevbuf()) + .childHandler(new ChannelInitializer() { + protected void initChannel(SocketChannel ch) throws Exception { + initHandler(ch.pipeline(),serverBean); + } + }) + .childOption(ChannelOption.TCP_NODELAY, serverBean.isNodelay()) + .childOption(ChannelOption.SO_KEEPALIVE, serverBean.isKeepalive()) + .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { + if (channelFuture.isSuccess()) + log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + else + log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + }); + } + /** + * 初始化EnentPool 参数 + */ + private void initEventPool(){ + bootstrap= new ServerBootstrap(); + if(useEpoll()){ + bossGroup = new EpollEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { + private AtomicInteger index = new AtomicInteger(0); + + public Thread newThread(Runnable r) { + return new Thread(r, "LINUX_BOSS_" + index.incrementAndGet()); + } + }); + workGroup = new EpollEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { + private AtomicInteger index = new AtomicInteger(0); + + public Thread newThread(Runnable r) { + return new Thread(r, "LINUX_WORK_" + index.incrementAndGet()); + } + }); + + } + else { + bossGroup = new NioEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { + private AtomicInteger index = new AtomicInteger(0); + + public Thread newThread(Runnable r) { + return new Thread(r, "BOSS_" + index.incrementAndGet()); + } + }); + workGroup = new NioEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { + private AtomicInteger index = new AtomicInteger(0); + + public Thread newThread(Runnable r) { + return new Thread(r, "WORK_" + index.incrementAndGet()); + } + }); + } + } + + /** + * 关闭资源 + */ + public void shutdown() { + if(workGroup!=null && bossGroup!=null ){ + try { + bossGroup.shutdownGracefully().sync();// 优雅关闭 + workGroup.shutdownGracefully().sync(); + } catch (InterruptedException e) { + log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + } + } + } + + private boolean useEpoll() { + return RemotingUtil.isLinuxPlatform() + && Epoll.isAvailable(); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java similarity index 96% rename from src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java index 56faebf..c898994 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/WsChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.bootstrap; +package com.myself.unclecatmyself.bootstrap; import io.netty.channel.Channel; diff --git a/src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java similarity index 95% rename from src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java index d78df16..e150031 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/backmsg/InChatBackMapService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.bootstrap.backmsg; +package com.myself.unclecatmyself.bootstrap.backmsg; import java.util.Map; diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/MqttChannel.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java similarity index 89% rename from src/main/java/com/myself/nettychat/bootstrap/bean/MqttChannel.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java index 9c830ce..1d794c2 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/MqttChannel.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java @@ -1,115 +1,115 @@ -package com.myself.nettychat.bootstrap.bean; - -import io.netty.channel.Channel; -import io.netty.util.AttributeKey; -import lombok.Builder; -import lombok.Data; - -import com.myself.nettychat.common.enums.SubStatus; -import com.myself.nettychat.common.enums.SessionStatus; - -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc channel 封装类 - **/ -@Builder -@Data -public class MqttChannel { - - private transient volatile Channel channel; - - - private String deviceId; - - - private boolean isWill; - - - private volatile SubStatus subStatus; // 是否订阅过主题 - - - private Set topic ; - - - - private volatile SessionStatus sessionStatus; // 在线 - 离线 - - - - private volatile boolean cleanSession; // 当为 true 时 channel close 时 从缓存中删除 此channel - - - - - private ConcurrentHashMap message ; // messageId - message(qos1) // 待确认消息 - - - private Set receive; - - public void addRecevice(int messageId){ - receive.add(messageId); - } - - public boolean checkRecevice(int messageId){ - return receive.contains(messageId); - } - - public boolean removeRecevice(int messageId){ - return receive.remove(messageId); - } - - - public void addSendMqttMessage(int messageId,SendMqttMessage msg){ - message.put(messageId,msg); - } - - - public SendMqttMessage getSendMqttMessage(int messageId){ - return message.get(messageId); - } - - - public void removeSendMqttMessage(int messageId){ - message.remove(messageId); - } - - - /** - * 判断当前channel 是否登录过 - * @return - */ - public boolean isLogin(){ - return Optional.ofNullable(this.channel).map(channel1 -> { - AttributeKey _login = AttributeKey.valueOf("login"); - return channel1.isActive() && channel1.hasAttr(_login); - }).orElse(false); - } - - /** - * 非正常关闭 - */ - public void close(){ - Optional.ofNullable(this.channel).ifPresent(channel1 -> channel1.close()); - } - - /** - * 通道是否活跃 - * @return - */ - public boolean isActive(){ - return channel!=null&&this.channel.isActive(); - } - - - - public boolean addTopic(Set topics){ - return topic.addAll(topics); - } - - -} +package com.myself.unclecatmyself.bootstrap.bean; + +import io.netty.channel.Channel; +import io.netty.util.AttributeKey; +import lombok.Builder; +import lombok.Data; + +import com.myself.unclecatmyself.common.enums.SubStatus; +import com.myself.unclecatmyself.common.enums.SessionStatus; + +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc channel 封装类 + **/ +@Builder +@Data +public class MqttChannel { + + private transient volatile Channel channel; + + + private String deviceId; + + + private boolean isWill; + + + private volatile SubStatus subStatus; // 是否订阅过主题 + + + private Set topic ; + + + + private volatile SessionStatus sessionStatus; // 在线 - 离线 + + + + private volatile boolean cleanSession; // 当为 true 时 channel close 时 从缓存中删除 此channel + + + + + private ConcurrentHashMap message ; // messageId - message(qos1) // 待确认消息 + + + private Set receive; + + public void addRecevice(int messageId){ + receive.add(messageId); + } + + public boolean checkRecevice(int messageId){ + return receive.contains(messageId); + } + + public boolean removeRecevice(int messageId){ + return receive.remove(messageId); + } + + + public void addSendMqttMessage(int messageId,SendMqttMessage msg){ + message.put(messageId,msg); + } + + + public SendMqttMessage getSendMqttMessage(int messageId){ + return message.get(messageId); + } + + + public void removeSendMqttMessage(int messageId){ + message.remove(messageId); + } + + + /** + * 判断当前channel 是否登录过 + * @return + */ + public boolean isLogin(){ + return Optional.ofNullable(this.channel).map(channel1 -> { + AttributeKey _login = AttributeKey.valueOf("login"); + return channel1.isActive() && channel1.hasAttr(_login); + }).orElse(false); + } + + /** + * 非正常关闭 + */ + public void close(){ + Optional.ofNullable(this.channel).ifPresent(channel1 -> channel1.close()); + } + + /** + * 通道是否活跃 + * @return + */ + public boolean isActive(){ + return channel!=null&&this.channel.isActive(); + } + + + + public boolean addTopic(Set topics){ + return topic.addAll(topics); + } + + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java similarity index 80% rename from src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java index 68ca021..e094abf 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/RetainMessage.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java @@ -1,19 +1,19 @@ -package com.myself.nettychat.bootstrap.bean; - -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - -@Builder -@Data -public class RetainMessage { - - private byte[] byteBuf; - - private MqttQoS qoS; - - public String getString(){ - return new String(byteBuf); - } - -} +package com.myself.unclecatmyself.bootstrap.bean; + +import io.netty.handler.codec.mqtt.MqttQoS; +import lombok.Builder; +import lombok.Data; + +@Builder +@Data +public class RetainMessage { + + private byte[] byteBuf; + + private MqttQoS qoS; + + public String getString(){ + return new String(byteBuf); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java similarity index 78% rename from src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java index c516abf..dbc6738 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/SendMqttMessage.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java @@ -1,35 +1,35 @@ -package com.myself.nettychat.bootstrap.bean; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - -import com.myself.nettychat.common.enums.ConfirmStatus; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc mqtts 消息 - **/ -@Builder -@Data -public class SendMqttMessage { - - private int messageId; - - private Channel channel; - - private volatile ConfirmStatus confirmStatus; - - private long time; - - private byte[] byteBuf; - - private boolean isRetain; - - private MqttQoS qos; - - private String topic; - -} +package com.myself.unclecatmyself.bootstrap.bean; + +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.MqttQoS; +import lombok.Builder; +import lombok.Data; + +import com.myself.unclecatmyself.common.enums.ConfirmStatus; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc mqtts 消息 + **/ +@Builder +@Data +public class SendMqttMessage { + + private int messageId; + + private Channel channel; + + private volatile ConfirmStatus confirmStatus; + + private long time; + + private byte[] byteBuf; + + private boolean isRetain; + + private MqttQoS qos; + + private String topic; + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java similarity index 77% rename from src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java index 1cf7625..bc1fe4e 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/SendWebMessage.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java @@ -1,6 +1,6 @@ -package com.myself.nettychat.bootstrap.bean; +package com.myself.unclecatmyself.bootstrap.bean; -import com.myself.nettychat.common.enums.ConfirmStatus; +import com.myself.unclecatmyself.common.enums.ConfirmStatus; import io.netty.channel.Channel; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/SessionMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java similarity index 83% rename from src/main/java/com/myself/nettychat/bootstrap/bean/SessionMessage.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java index 2613cd6..36a1460 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/SessionMessage.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java @@ -1,29 +1,29 @@ -package com.myself.nettychat.bootstrap.bean; - - -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Session会话数据保存 - **/ -@Builder -@Data -public class SessionMessage { - - private byte[] byteBuf; - - private MqttQoS qoS; - - private String topic; - - - public String getString(){ - return new String(byteBuf); - } - -} +package com.myself.unclecatmyself.bootstrap.bean; + + +import io.netty.handler.codec.mqtt.MqttQoS; +import lombok.Builder; +import lombok.Data; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc Session会话数据保存 + **/ +@Builder +@Data +public class SessionMessage { + + private byte[] byteBuf; + + private MqttQoS qoS; + + private String topic; + + + public String getString(){ + return new String(byteBuf); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java similarity index 92% rename from src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java index 9d8b4f1..164b0f9 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/WebChannel.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java @@ -1,6 +1,6 @@ -package com.myself.nettychat.bootstrap.bean; +package com.myself.unclecatmyself.bootstrap.bean; -import com.myself.nettychat.common.enums.SessionStatus; +import com.myself.unclecatmyself.common.enums.SessionStatus; import io.netty.channel.Channel; import io.netty.util.AttributeKey; import lombok.Builder; diff --git a/src/main/java/com/myself/nettychat/bootstrap/bean/WillMeaasge.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java similarity index 80% rename from src/main/java/com/myself/nettychat/bootstrap/bean/WillMeaasge.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java index 4022d28..d72fa5e 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/bean/WillMeaasge.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java @@ -1,23 +1,23 @@ -package com.myself.nettychat.bootstrap.bean; - -import lombok.Builder; -import lombok.Data; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 遗嘱消息 - **/ -@Builder -@Data -public class WillMeaasge { - - private String willTopic; - - private String willMessage; - - private boolean isRetain; - - private int qos; - -} +package com.myself.unclecatmyself.bootstrap.bean; + +import lombok.Builder; +import lombok.Data; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 遗嘱消息 + **/ +@Builder +@Data +public class WillMeaasge { + + private String willTopic; + + private String willMessage; + + private boolean isRetain; + + private int qos; + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/AbstractChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java similarity index 86% rename from src/main/java/com/myself/nettychat/bootstrap/channel/AbstractChannelService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java index c0e51f2..d948c92 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/AbstractChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java @@ -1,112 +1,112 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.BaseApi; -import com.myself.nettychat.bootstrap.ChannelService; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.myself.nettychat.bootstrap.bean.MqttChannel; -import com.myself.nettychat.bootstrap.bean.RetainMessage; -import com.myself.nettychat.bootstrap.channel.cache.CacheMap; -import com.myself.nettychat.bootstrap.scan.ScanRunnable; -import io.netty.channel.Channel; -import io.netty.util.AttributeKey; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.Collection; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象类 - **/ -@Slf4j -public abstract class AbstractChannelService extends PublishApiSevice implements ChannelService , BaseApi { - - protected AttributeKey _login = AttributeKey.valueOf("login"); - - protected AttributeKey _deviceId = AttributeKey.valueOf("deviceId"); - - protected static char SPLITOR = '/'; - - protected ExecutorService executorService =Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2); - - - protected static CacheMap cacheMap= new CacheMap<>(); - - - protected static ConcurrentHashMap mqttChannels = new ConcurrentHashMap<>(); // deviceId - mqChannel 登录 - - - protected static ConcurrentHashMap> retain = new ConcurrentHashMap<>(); // topic - 保留消息 - - - - protected static Cache> mqttChannelCache = CacheBuilder.newBuilder().maximumSize(100).build(); - - public AbstractChannelService(ScanRunnable scanRunnable) { - super(scanRunnable); - } - - - protected Collection getChannels(String topic,TopicFilter topicFilter){ - try { - return mqttChannelCache.get(topic, () -> topicFilter.filter(topic)); - } catch (Exception e) { - log.info(String.format("guava cache key topic【%s】 channel value== null ",topic)); - } - return null; - } - - - @FunctionalInterface - interface TopicFilter{ - Collection filter(String topic); - } - - protected boolean deleteChannel(String topic,MqttChannel mqttChannel){ - return Optional.ofNullable(topic).map(s -> { - mqttChannelCache.invalidate(s); - return cacheMap.delete(getTopic(s),mqttChannel); - }).orElse(false); - } - - protected boolean addChannel(String topic,MqttChannel mqttChannel) - { - return Optional.ofNullable(topic).map(s -> { - mqttChannelCache.invalidate(s); - return cacheMap.putData(getTopic(s),mqttChannel); - }).orElse(false); - } - - /** - * 获取channel - */ - public MqttChannel getMqttChannel(String deviceId){ - return Optional.ofNullable(deviceId).map(s -> mqttChannels.get(s)) - .orElse(null); - - } - - /** - * 获取channelId - */ - public String getDeviceId(Channel channel){ - return Optional.ofNullable(channel).map( channel1->channel1.attr(_deviceId).get()) - .orElse(null); - } - - - - protected String[] getTopic(String topic) { - return Optional.ofNullable(topic).map(s -> - StringUtils.split(topic,SPLITOR) - ).orElse(null); - } - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.BaseApi; +import com.myself.unclecatmyself.bootstrap.ChannelService; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; +import com.myself.unclecatmyself.bootstrap.bean.RetainMessage; +import com.myself.unclecatmyself.bootstrap.channel.cache.CacheMap; +import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; +import io.netty.channel.Channel; +import io.netty.util.AttributeKey; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.util.Collection; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 抽象类 + **/ +@Slf4j +public abstract class AbstractChannelService extends PublishApiSevice implements ChannelService , BaseApi { + + protected AttributeKey _login = AttributeKey.valueOf("login"); + + protected AttributeKey _deviceId = AttributeKey.valueOf("deviceId"); + + protected static char SPLITOR = '/'; + + protected ExecutorService executorService =Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2); + + + protected static CacheMap cacheMap= new CacheMap<>(); + + + protected static ConcurrentHashMap mqttChannels = new ConcurrentHashMap<>(); // deviceId - mqChannel 登录 + + + protected static ConcurrentHashMap> retain = new ConcurrentHashMap<>(); // topic - 保留消息 + + + + protected static Cache> mqttChannelCache = CacheBuilder.newBuilder().maximumSize(100).build(); + + public AbstractChannelService(ScanRunnable scanRunnable) { + super(scanRunnable); + } + + + protected Collection getChannels(String topic,TopicFilter topicFilter){ + try { + return mqttChannelCache.get(topic, () -> topicFilter.filter(topic)); + } catch (Exception e) { + log.info(String.format("guava cache key topic【%s】 channel value== null ",topic)); + } + return null; + } + + + @FunctionalInterface + interface TopicFilter{ + Collection filter(String topic); + } + + protected boolean deleteChannel(String topic,MqttChannel mqttChannel){ + return Optional.ofNullable(topic).map(s -> { + mqttChannelCache.invalidate(s); + return cacheMap.delete(getTopic(s),mqttChannel); + }).orElse(false); + } + + protected boolean addChannel(String topic,MqttChannel mqttChannel) + { + return Optional.ofNullable(topic).map(s -> { + mqttChannelCache.invalidate(s); + return cacheMap.putData(getTopic(s),mqttChannel); + }).orElse(false); + } + + /** + * 获取channel + */ + public MqttChannel getMqttChannel(String deviceId){ + return Optional.ofNullable(deviceId).map(s -> mqttChannels.get(s)) + .orElse(null); + + } + + /** + * 获取channelId + */ + public String getDeviceId(Channel channel){ + return Optional.ofNullable(channel).map( channel1->channel1.attr(_deviceId).get()) + .orElse(null); + } + + + + protected String[] getTopic(String topic) { + return Optional.ofNullable(topic).map(s -> + StringUtils.split(topic,SPLITOR) + ).orElse(null); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/ClientSessionService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java similarity index 88% rename from src/main/java/com/myself/nettychat/bootstrap/channel/ClientSessionService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java index 9a23c8b..daaaad7 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/ClientSessionService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java @@ -1,36 +1,36 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.bean.SessionMessage; -import org.springframework.stereotype.Service; - -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 会话保留处理 - **/ -@Service -public class ClientSessionService { - - private static ConcurrentHashMap> queueSession = new ConcurrentHashMap<>(); // 连接关闭后 保留此session 数据 deviceId - - - public void saveSessionMsg(String deviceId, SessionMessage sessionMessage) { - ConcurrentLinkedQueue sessionMessages = queueSession.getOrDefault(deviceId, new ConcurrentLinkedQueue<>()); - boolean flag; - do{ - flag = sessionMessages.add(sessionMessage); - } - while (!flag); - queueSession.put(deviceId,sessionMessages); - } - - public ConcurrentLinkedQueue getByteBuf(String deviceId){ - return Optional.ofNullable(deviceId).map(s -> queueSession.get(s)) - .orElse(null); - } - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.bean.SessionMessage; +import org.springframework.stereotype.Service; + +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 会话保留处理 + **/ +@Service +public class ClientSessionService { + + private static ConcurrentHashMap> queueSession = new ConcurrentHashMap<>(); // 连接关闭后 保留此session 数据 deviceId + + + public void saveSessionMsg(String deviceId, SessionMessage sessionMessage) { + ConcurrentLinkedQueue sessionMessages = queueSession.getOrDefault(deviceId, new ConcurrentLinkedQueue<>()); + boolean flag; + do{ + flag = sessionMessages.add(sessionMessage); + } + while (!flag); + queueSession.put(deviceId,sessionMessages); + } + + public ConcurrentLinkedQueue getByteBuf(String deviceId){ + return Optional.ofNullable(deviceId).map(s -> queueSession.get(s)) + .orElse(null); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java similarity index 95% rename from src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java index ef7b308..3a62caf 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java @@ -1,440 +1,439 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.bean.*; -import com.myself.nettychat.bootstrap.scan.ScanRunnable; -import com.myself.nettychat.common.enums.ConfirmStatus; -import com.myself.nettychat.common.enums.SessionStatus; -import com.myself.nettychat.common.enums.SubStatus; -import com.myself.nettychat.common.exception.ConnectionException; -import com.myself.nettychat.common.utils.ByteBufUtil; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CopyOnWriteArraySet; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Channel事件处理service - **/ -@Slf4j -//@Component -public class MqttChannelService extends AbstractChannelService { - - @Autowired - private ClientSessionService clientSessionService; - - @Autowired - private WillService willService; - - private final ScanRunnable scanRunnable; - - public MqttChannelService(ScanRunnable scanRunnable) { - super(scanRunnable); - this.scanRunnable = scanRunnable; - } - - - /** - * 取消订阅 - */ - @Override - public void unsubscribe(String deviceId, List topics1) { - Optional.ofNullable(mqttChannels.get(deviceId)).ifPresent(mqttChannel -> { - topics1.forEach(topic -> { - deleteChannel(topic,mqttChannel); - }); - }); - } - - /** - * 登录成功后 回复 - */ - private void replyLogin(Channel channel, MqttConnectMessage mqttConnectMessage) { - MqttFixedHeader mqttFixedHeader1 = mqttConnectMessage.fixedHeader(); - MqttConnectVariableHeader mqttConnectVariableHeader = mqttConnectMessage.variableHeader(); - final MqttConnectPayload payload = mqttConnectMessage.payload(); - String deviceId = getDeviceId(channel); - MqttChannel build = MqttChannel.builder().channel(channel).cleanSession(mqttConnectVariableHeader.isCleanSession()) - .deviceId(payload.clientIdentifier()) - .sessionStatus(SessionStatus.OPEN) - .isWill(mqttConnectVariableHeader.isWillFlag()) - .subStatus(SubStatus.NO) - .topic(new CopyOnWriteArraySet<>()) - .message(new ConcurrentHashMap<>()) - .receive(new CopyOnWriteArraySet<>()) - .build(); - if (connectSuccess(deviceId, build)) { // 初始化存储mqttchannel - if (mqttConnectVariableHeader.isWillFlag()) { // 遗嘱消息标志 - boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (payload.willMessage() != null) - , mqttConnectVariableHeader1 -> (payload.willTopic() != null)); - if (!b) { - throw new ConnectionException("will message and will topic is not null"); - } - // 处理遗嘱消息 - final WillMeaasge buildWill = WillMeaasge.builder(). - qos(mqttConnectVariableHeader.willQos()) - .willMessage(deviceId) - .willTopic(payload.willTopic()) - .isRetain(mqttConnectVariableHeader.isWillRetain()) - .build(); - willService.save(payload.clientIdentifier(), buildWill); - } else { - willService.del(payload.clientIdentifier()); - boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (!mqttConnectVariableHeader1.isWillRetain()), - mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.willQos() == 0)); - if (!b) { - throw new ConnectionException("will retain should be null and will QOS equal 0"); - } - } - doIfElse(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.isCleanSession()), mqttConnectVariableHeader1 -> { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, false); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck);// 清理会话 - }, mqttConnectVariableHeader1 -> { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck);// 非清理会话 - - }); //发送 session 数据 - ConcurrentLinkedQueue sessionMessages = clientSessionService.getByteBuf(payload.clientIdentifier()); - doIfElse(sessionMessages, messages -> messages != null && !messages.isEmpty(), byteBufs -> { - SessionMessage sessionMessage; - while ((sessionMessage = byteBufs.poll()) != null) { - switch (sessionMessage.getQoS()) { - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - case AT_MOST_ONCE: - sendQos0Msg(channel, sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - } - } - - }); - } - } - - - - /** - * qos2 第二步 - */ - @Override - public void doPubrel(Channel channel, int messageId) { - MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); - doIfElse(mqttChannel,mqttChannel1 ->mqttChannel1.isLogin(),mqttChannel1 -> { - mqttChannel1.removeRecevice(messageId); - sendToPubComp(channel,messageId); - }); - } - - - - /** - * qos2 第三步 - */ - @Override - public void doPubrec(Channel channel, int mqttMessage) { - sendPubRel(channel,false,mqttMessage); - } - - /** - * 连接成功后 - * @param deviceId - * @param build - */ - @Override - public boolean connectSuccess(String deviceId, MqttChannel build) { - return Optional.ofNullable(mqttChannels.get(deviceId)) - .map(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case OPEN: - return false; - case CLOSE: - switch (mqttChannel.getSubStatus()){ - case YES: // 清除订阅 topic - deleteSubTopic(mqttChannel).stream() - .forEach(s -> cacheMap.putData(getTopic(s),build)); - break; - } - } - mqttChannels.put(deviceId,build); - return true; - }).orElseGet(() -> { - mqttChannels.put(deviceId,build); - return true; - }); - } - - - /** - * 订阅成功后 (发送保留消息) - */ - public void suscribeSuccess(String deviceId, Set topics){ - doIfElse(topics,topics1->!CollectionUtils.isEmpty(topics1),strings -> { - MqttChannel mqttChannel = mqttChannels.get(deviceId); - mqttChannel.setSubStatus(SubStatus.YES); // 设置订阅主题标识 - mqttChannel.addTopic(strings); - executorService.execute(() -> { - Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { - if(mqttChannel1.isLogin()){ - strings.parallelStream().forEach(topic -> { - addChannel(topic,mqttChannel); - sendRetain(topic,mqttChannel); // 发送保留消息 - }); - } - }); - }); - }); - } - - - /** - *成功登陆 (发送会话消息) - * @param channel - * @param deviceId - * @param mqttConnectMessage - */ - @Override - public void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage) { - channel.attr(_login).set(true); - channel.attr(_deviceId).set(deviceId); - replyLogin(channel, mqttConnectMessage); - } - - - /** - * 发布消息成功 () - * @param channel - * @param mqttPublishMessage - */ - @Override - public void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage) { - MqttFixedHeader mqttFixedHeader = mqttPublishMessage.fixedHeader(); - MqttPublishVariableHeader mqttPublishVariableHeader = mqttPublishMessage.variableHeader(); - MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); - ByteBuf payload = mqttPublishMessage.payload(); - byte[] bytes = ByteBufUtil.copyByteBuf(payload); // - int messageId = mqttPublishVariableHeader.messageId(); - executorService.execute(() -> { - if (channel.hasAttr(_login) && mqttChannel != null) { - boolean isRetain; - switch (mqttFixedHeader.qosLevel()) { - case AT_MOST_ONCE: // 至多一次 - break; - case AT_LEAST_ONCE: - sendPubBack(channel, messageId); - break; - case EXACTLY_ONCE: - sendPubRec(mqttChannel, messageId); - break; - } - if ((isRetain=mqttFixedHeader.isRetain()) && mqttFixedHeader.qosLevel() != MqttQoS.AT_MOST_ONCE) { //是保留消息 qos >0 - saveRetain(mqttPublishVariableHeader.topicName(), - RetainMessage.builder() - .byteBuf(bytes) - .qoS(mqttFixedHeader.qosLevel()) - .build(), false); - } else if (mqttFixedHeader.isRetain() && mqttFixedHeader.qosLevel() == MqttQoS.AT_MOST_ONCE) { // 是保留消息 qos=0 清除之前保留消息 保留现在 - saveRetain(mqttPublishVariableHeader.topicName(), - RetainMessage.builder() - .byteBuf(bytes) - .qoS(mqttFixedHeader.qosLevel()) - .build(), true); - } - if (!mqttChannel.checkRecevice(messageId)) { - push(mqttPublishVariableHeader.topicName(), mqttFixedHeader.qosLevel(), bytes,isRetain); - mqttChannel.addRecevice(messageId); - } - } - }); - - } - /** - * 推送消息给订阅者 - */ - private void push(String topic, MqttQoS qos, byte[] bytes, boolean isRetain){ - Collection subChannels = getChannels(topic, topic1 -> cacheMap.getData(getTopic(topic1))); - if(!CollectionUtils.isEmpty(subChannels)){ - subChannels.parallelStream().forEach(subChannel -> { - switch (subChannel.getSessionStatus()){ - case OPEN: // 在线 - if(subChannel.isActive()){ // 防止channel失效 但是离线状态没更改 - switch (qos){ - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,subChannel,topic,bytes); - break; - case AT_MOST_ONCE: - sendQos0Msg(subChannel.getChannel(),topic,bytes); - break; - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,subChannel,topic,bytes); - break; - } - } - else{ - if(!subChannel.isCleanSession() & !isRetain){ - clientSessionService.saveSessionMsg(subChannel.getDeviceId(), - SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); - break; - } - } - break; - case CLOSE: // 连接 设置了 clean session =false - clientSessionService.saveSessionMsg(subChannel.getDeviceId(), - SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); - break; - } - }); - } - } - - /** - * 关闭channel 操作 - * @param deviceId - */ - @Override - public void closeSuccess(String deviceId,boolean isDisconnect) { - if(StringUtils.isNotBlank(deviceId)){ - executorService.execute(() -> { - MqttChannel mqttChannel = mqttChannels.get(deviceId); - Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { - mqttChannel1.setSessionStatus(SessionStatus.CLOSE); // 设置关闭 - mqttChannel1.close(); // 关闭channel - mqttChannel1.setChannel(null); - if(!mqttChannel1.isCleanSession()){ // 保持会话 - // 处理 qos1 未确认数据 - ConcurrentHashMap message = mqttChannel1.getMessage(); - Optional.ofNullable(message).ifPresent(integerConfirmMessageConcurrentHashMap -> { - integerConfirmMessageConcurrentHashMap.forEach((integer, confirmMessage) -> doIfElse(confirmMessage, sendMqttMessage ->sendMqttMessage.getConfirmStatus()== ConfirmStatus.PUB, sendMqttMessage ->{ - clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), SessionMessage.builder() - .byteBuf(sendMqttMessage.getByteBuf()) - .qoS(sendMqttMessage.getQos()) - .topic(sendMqttMessage.getTopic()) - .build()); // 把待确认数据转入session中 - } - )); - - }); - } - else{ // 删除sub topic-消息 - mqttChannels.remove(deviceId); // 移除channelId 不保持会话 直接删除 保持会话 旧的在重新connect时替换 - switch (mqttChannel1.getSubStatus()){ - case YES: - deleteSubTopic(mqttChannel1); - break; - } - } - if(mqttChannel1.isWill()){ // 发送遗言 - if(!isDisconnect){ // 不是disconnection操作 - willService.doSend(deviceId); - } - } - }); - }); - } - } - - /** - * 清除channel 订阅主题 - * @param mqttChannel - */ - public Set deleteSubTopic(MqttChannel mqttChannel){ - Set topics = mqttChannel.getTopic(); - topics.parallelStream().forEach(topic -> cacheMap.delete(getTopic(topic),mqttChannel)); - return topics; - } - - /** - * 发送 遗嘱消息(有的channel 已经关闭 但是保持了 session 此时加入session 数据中 ) - * @param willMeaasge 遗嘱消息 - */ - public void sendWillMsg(WillMeaasge willMeaasge){ - Collection mqttChannels = getChannels(willMeaasge.getWillTopic(), topic -> cacheMap.getData(getTopic(topic))); - if(!CollectionUtils.isEmpty(mqttChannels)){ - mqttChannels.forEach(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case CLOSE: - clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), - SessionMessage.builder() - .topic(willMeaasge.getWillTopic()) - .qoS(MqttQoS.valueOf(willMeaasge.getQos())) - .byteBuf(willMeaasge.getWillMessage().getBytes()).build()); - break; - case OPEN: - writeWillMsg(mqttChannel,willMeaasge); - break; - } - }); - } - } - - /** - * 保存保留消息 - * @param topic 主题 - * @param retainMessage 信息 - */ - private void saveRetain(String topic, RetainMessage retainMessage, boolean isClean){ - ConcurrentLinkedQueue retainMessages = retain.getOrDefault(topic, new ConcurrentLinkedQueue<>()); - if(!retainMessages.isEmpty() && isClean){ - retainMessages.clear(); - } - boolean flag; - do{ - flag = retainMessages.add(retainMessage); - } - while (!flag); - retain.put(topic, retainMessages); - } - - /** - * 发送保留消息 - */ - public void sendRetain(String topic,MqttChannel mqttChannel){ - retain.forEach((_topic, retainMessages) -> { - if(StringUtils.startsWith(_topic,topic)){ - Optional.ofNullable(retainMessages).ifPresent(pubMessages1 -> { - retainMessages.parallelStream().forEach(retainMessage -> { - log.info("【发送保留消息】"+mqttChannel.getChannel().remoteAddress()+":"+retainMessage.getString()+"【成功】"); - switch (retainMessage.getQoS()){ - case AT_MOST_ONCE: - sendQos0Msg(mqttChannel.getChannel(),_topic,retainMessage.getByteBuf()); - break; - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); - break; - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); - break; - } - }); - }); - } - }); - - } - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.bean.*; +import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; +import com.myself.unclecatmyself.common.enums.ConfirmStatus; +import com.myself.unclecatmyself.common.enums.SessionStatus; +import com.myself.unclecatmyself.common.enums.SubStatus; +import com.myself.unclecatmyself.common.exception.ConnectionException; +import com.myself.unclecatmyself.common.utils.ByteBufUtil; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArraySet; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc Channel事件处理service + **/ +@Slf4j +//@Component +public class MqttChannelService extends AbstractChannelService { + + @Autowired + private ClientSessionService clientSessionService; + + @Autowired + private WillService willService; + + private final ScanRunnable scanRunnable; + + public MqttChannelService(ScanRunnable scanRunnable) { + super(scanRunnable); + this.scanRunnable = scanRunnable; + } + + + /** + * 取消订阅 + */ + @Override + public void unsubscribe(String deviceId, List topics1) { + Optional.ofNullable(mqttChannels.get(deviceId)).ifPresent(mqttChannel -> { + topics1.forEach(topic -> { + deleteChannel(topic,mqttChannel); + }); + }); + } + + /** + * 登录成功后 回复 + */ + private void replyLogin(Channel channel, MqttConnectMessage mqttConnectMessage) { + MqttFixedHeader mqttFixedHeader1 = mqttConnectMessage.fixedHeader(); + MqttConnectVariableHeader mqttConnectVariableHeader = mqttConnectMessage.variableHeader(); + final MqttConnectPayload payload = mqttConnectMessage.payload(); + String deviceId = getDeviceId(channel); + MqttChannel build = MqttChannel.builder().channel(channel).cleanSession(mqttConnectVariableHeader.isCleanSession()) + .deviceId(payload.clientIdentifier()) + .sessionStatus(SessionStatus.OPEN) + .isWill(mqttConnectVariableHeader.isWillFlag()) + .subStatus(SubStatus.NO) + .topic(new CopyOnWriteArraySet<>()) + .message(new ConcurrentHashMap<>()) + .receive(new CopyOnWriteArraySet<>()) + .build(); + if (connectSuccess(deviceId, build)) { // 初始化存储mqttchannel + if (mqttConnectVariableHeader.isWillFlag()) { // 遗嘱消息标志 + boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (payload.willMessage() != null) + , mqttConnectVariableHeader1 -> (payload.willTopic() != null)); + if (!b) { + throw new ConnectionException("will message and will topic is not null"); + } + // 处理遗嘱消息 + final WillMeaasge buildWill = WillMeaasge.builder(). + qos(mqttConnectVariableHeader.willQos()) + .willMessage(deviceId) + .willTopic(payload.willTopic()) + .isRetain(mqttConnectVariableHeader.isWillRetain()) + .build(); + willService.save(payload.clientIdentifier(), buildWill); + } else { + willService.del(payload.clientIdentifier()); + boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (!mqttConnectVariableHeader1.isWillRetain()), + mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.willQos() == 0)); + if (!b) { + throw new ConnectionException("will retain should be null and will QOS equal 0"); + } + } + doIfElse(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.isCleanSession()), mqttConnectVariableHeader1 -> { + MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; + MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, false); + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( + MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); + MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); + channel.writeAndFlush(connAck);// 清理会话 + }, mqttConnectVariableHeader1 -> { + MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; + MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( + MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); + MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); + channel.writeAndFlush(connAck);// 非清理会话 + + }); //发送 session 数据 + ConcurrentLinkedQueue sessionMessages = clientSessionService.getByteBuf(payload.clientIdentifier()); + doIfElse(sessionMessages, messages -> messages != null && !messages.isEmpty(), byteBufs -> { + SessionMessage sessionMessage; + while ((sessionMessage = byteBufs.poll()) != null) { + switch (sessionMessage.getQoS()) { + case EXACTLY_ONCE: + sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); + break; + case AT_MOST_ONCE: + sendQos0Msg(channel, sessionMessage.getTopic(), sessionMessage.getByteBuf()); + break; + case AT_LEAST_ONCE: + sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); + break; + } + } + + }); + } + } + + + + /** + * qos2 第二步 + */ + @Override + public void doPubrel(Channel channel, int messageId) { + MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); + doIfElse(mqttChannel,mqttChannel1 ->mqttChannel1.isLogin(),mqttChannel1 -> { + mqttChannel1.removeRecevice(messageId); + sendToPubComp(channel,messageId); + }); + } + + + + /** + * qos2 第三步 + */ + @Override + public void doPubrec(Channel channel, int mqttMessage) { + sendPubRel(channel,false,mqttMessage); + } + + /** + * 连接成功后 + * @param deviceId + * @param build + */ + @Override + public boolean connectSuccess(String deviceId, MqttChannel build) { + return Optional.ofNullable(mqttChannels.get(deviceId)) + .map(mqttChannel -> { + switch (mqttChannel.getSessionStatus()){ + case OPEN: + return false; + case CLOSE: + switch (mqttChannel.getSubStatus()){ + case YES: // 清除订阅 topic + deleteSubTopic(mqttChannel).stream() + .forEach(s -> cacheMap.putData(getTopic(s),build)); + break; + } + } + mqttChannels.put(deviceId,build); + return true; + }).orElseGet(() -> { + mqttChannels.put(deviceId,build); + return true; + }); + } + + + /** + * 订阅成功后 (发送保留消息) + */ + public void suscribeSuccess(String deviceId, Set topics){ + doIfElse(topics,topics1->!CollectionUtils.isEmpty(topics1),strings -> { + MqttChannel mqttChannel = mqttChannels.get(deviceId); + mqttChannel.setSubStatus(SubStatus.YES); // 设置订阅主题标识 + mqttChannel.addTopic(strings); + executorService.execute(() -> { + Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { + if(mqttChannel1.isLogin()){ + strings.parallelStream().forEach(topic -> { + addChannel(topic,mqttChannel); + sendRetain(topic,mqttChannel); // 发送保留消息 + }); + } + }); + }); + }); + } + + + /** + *成功登陆 (发送会话消息) + * @param channel + * @param deviceId + * @param mqttConnectMessage + */ + @Override + public void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage) { + channel.attr(_login).set(true); + channel.attr(_deviceId).set(deviceId); + replyLogin(channel, mqttConnectMessage); + } + + + /** + * 发布消息成功 () + * @param channel + * @param mqttPublishMessage + */ + @Override + public void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage) { + MqttFixedHeader mqttFixedHeader = mqttPublishMessage.fixedHeader(); + MqttPublishVariableHeader mqttPublishVariableHeader = mqttPublishMessage.variableHeader(); + MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); + ByteBuf payload = mqttPublishMessage.payload(); + byte[] bytes = ByteBufUtil.copyByteBuf(payload); // + int messageId = mqttPublishVariableHeader.messageId(); + executorService.execute(() -> { + if (channel.hasAttr(_login) && mqttChannel != null) { + boolean isRetain; + switch (mqttFixedHeader.qosLevel()) { + case AT_MOST_ONCE: // 至多一次 + break; + case AT_LEAST_ONCE: + sendPubBack(channel, messageId); + break; + case EXACTLY_ONCE: + sendPubRec(mqttChannel, messageId); + break; + } + if ((isRetain=mqttFixedHeader.isRetain()) && mqttFixedHeader.qosLevel() != MqttQoS.AT_MOST_ONCE) { //是保留消息 qos >0 + saveRetain(mqttPublishVariableHeader.topicName(), + RetainMessage.builder() + .byteBuf(bytes) + .qoS(mqttFixedHeader.qosLevel()) + .build(), false); + } else if (mqttFixedHeader.isRetain() && mqttFixedHeader.qosLevel() == MqttQoS.AT_MOST_ONCE) { // 是保留消息 qos=0 清除之前保留消息 保留现在 + saveRetain(mqttPublishVariableHeader.topicName(), + RetainMessage.builder() + .byteBuf(bytes) + .qoS(mqttFixedHeader.qosLevel()) + .build(), true); + } + if (!mqttChannel.checkRecevice(messageId)) { + push(mqttPublishVariableHeader.topicName(), mqttFixedHeader.qosLevel(), bytes,isRetain); + mqttChannel.addRecevice(messageId); + } + } + }); + + } + /** + * 推送消息给订阅者 + */ + private void push(String topic, MqttQoS qos, byte[] bytes, boolean isRetain){ + Collection subChannels = getChannels(topic, topic1 -> cacheMap.getData(getTopic(topic1))); + if(!CollectionUtils.isEmpty(subChannels)){ + subChannels.parallelStream().forEach(subChannel -> { + switch (subChannel.getSessionStatus()){ + case OPEN: // 在线 + if(subChannel.isActive()){ // 防止channel失效 但是离线状态没更改 + switch (qos){ + case AT_LEAST_ONCE: + sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,subChannel,topic,bytes); + break; + case AT_MOST_ONCE: + sendQos0Msg(subChannel.getChannel(),topic,bytes); + break; + case EXACTLY_ONCE: + sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,subChannel,topic,bytes); + break; + } + } + else{ + if(!subChannel.isCleanSession() & !isRetain){ + clientSessionService.saveSessionMsg(subChannel.getDeviceId(), + SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); + break; + } + } + break; + case CLOSE: // 连接 设置了 clean session =false + clientSessionService.saveSessionMsg(subChannel.getDeviceId(), + SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); + break; + } + }); + } + } + + /** + * 关闭channel 操作 + * @param deviceId + */ + @Override + public void closeSuccess(String deviceId,boolean isDisconnect) { + if(StringUtils.isNotBlank(deviceId)){ + executorService.execute(() -> { + MqttChannel mqttChannel = mqttChannels.get(deviceId); + Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { + mqttChannel1.setSessionStatus(SessionStatus.CLOSE); // 设置关闭 + mqttChannel1.close(); // 关闭channel + mqttChannel1.setChannel(null); + if(!mqttChannel1.isCleanSession()){ // 保持会话 + // 处理 qos1 未确认数据 + ConcurrentHashMap message = mqttChannel1.getMessage(); + Optional.ofNullable(message).ifPresent(integerConfirmMessageConcurrentHashMap -> { + integerConfirmMessageConcurrentHashMap.forEach((integer, confirmMessage) -> doIfElse(confirmMessage, sendMqttMessage ->sendMqttMessage.getConfirmStatus()== ConfirmStatus.PUB, sendMqttMessage ->{ + clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), SessionMessage.builder() + .byteBuf(sendMqttMessage.getByteBuf()) + .qoS(sendMqttMessage.getQos()) + .topic(sendMqttMessage.getTopic()) + .build()); // 把待确认数据转入session中 + } + )); + + }); + } + else{ // 删除sub topic-消息 + mqttChannels.remove(deviceId); // 移除channelId 不保持会话 直接删除 保持会话 旧的在重新connect时替换 + switch (mqttChannel1.getSubStatus()){ + case YES: + deleteSubTopic(mqttChannel1); + break; + } + } + if(mqttChannel1.isWill()){ // 发送遗言 + if(!isDisconnect){ // 不是disconnection操作 + willService.doSend(deviceId); + } + } + }); + }); + } + } + + /** + * 清除channel 订阅主题 + * @param mqttChannel + */ + public Set deleteSubTopic(MqttChannel mqttChannel){ + Set topics = mqttChannel.getTopic(); + topics.parallelStream().forEach(topic -> cacheMap.delete(getTopic(topic),mqttChannel)); + return topics; + } + + /** + * 发送 遗嘱消息(有的channel 已经关闭 但是保持了 session 此时加入session 数据中 ) + * @param willMeaasge 遗嘱消息 + */ + public void sendWillMsg(WillMeaasge willMeaasge){ + Collection mqttChannels = getChannels(willMeaasge.getWillTopic(), topic -> cacheMap.getData(getTopic(topic))); + if(!CollectionUtils.isEmpty(mqttChannels)){ + mqttChannels.forEach(mqttChannel -> { + switch (mqttChannel.getSessionStatus()){ + case CLOSE: + clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), + SessionMessage.builder() + .topic(willMeaasge.getWillTopic()) + .qoS(MqttQoS.valueOf(willMeaasge.getQos())) + .byteBuf(willMeaasge.getWillMessage().getBytes()).build()); + break; + case OPEN: + writeWillMsg(mqttChannel,willMeaasge); + break; + } + }); + } + } + + /** + * 保存保留消息 + * @param topic 主题 + * @param retainMessage 信息 + */ + private void saveRetain(String topic, RetainMessage retainMessage, boolean isClean){ + ConcurrentLinkedQueue retainMessages = retain.getOrDefault(topic, new ConcurrentLinkedQueue<>()); + if(!retainMessages.isEmpty() && isClean){ + retainMessages.clear(); + } + boolean flag; + do{ + flag = retainMessages.add(retainMessage); + } + while (!flag); + retain.put(topic, retainMessages); + } + + /** + * 发送保留消息 + */ + public void sendRetain(String topic,MqttChannel mqttChannel){ + retain.forEach((_topic, retainMessages) -> { + if(StringUtils.startsWith(_topic,topic)){ + Optional.ofNullable(retainMessages).ifPresent(pubMessages1 -> { + retainMessages.parallelStream().forEach(retainMessage -> { + log.info("【发送保留消息】"+mqttChannel.getChannel().remoteAddress()+":"+retainMessage.getString()+"【成功】"); + switch (retainMessage.getQoS()){ + case AT_MOST_ONCE: + sendQos0Msg(mqttChannel.getChannel(),_topic,retainMessage.getByteBuf()); + break; + case AT_LEAST_ONCE: + sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); + break; + case EXACTLY_ONCE: + sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); + break; + } + }); + }); + } + }); + + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java similarity index 92% rename from src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java index f404aac..5e4e403 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/MqttHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java @@ -1,223 +1,222 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.BaseApi; -import com.myself.nettychat.bootstrap.BaseAuthService; -import com.myself.nettychat.bootstrap.ChannelService; -import com.myself.nettychat.bootstrap.bean.SendMqttMessage; -import com.myself.nettychat.common.enums.ConfirmStatus; -import com.myself.nettychat.common.mqtts.ServerMqttHandlerService; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -//@Component -public class MqttHandlerService extends ServerMqttHandlerService implements BaseApi { - - @Autowired - ChannelService mqttChannelService; - - private final BaseAuthService baseAuthService; - - public MqttHandlerService(BaseAuthService baseAuthService) { - this.baseAuthService = baseAuthService; - } - - /** - * 登录 - * - */ - @Override - public boolean login(Channel channel, MqttConnectMessage mqttConnectMessage) { -// 校验规则 自定义校验规则 - MqttConnectPayload payload = mqttConnectMessage.payload(); - String deviceId = payload.clientIdentifier(); - if (StringUtils.isBlank(deviceId)) { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; - connectBack(channel,connectReturnCode); - return false; - } - - if(mqttConnectMessage.variableHeader().hasPassword() && mqttConnectMessage.variableHeader().hasUserName() - && !baseAuthService.authorized(payload.userName(),payload.password())){ - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; - connectBack(channel,connectReturnCode); - return false; - } - return Optional.ofNullable(mqttChannelService.getMqttChannel(deviceId)) - .map(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case OPEN: - return false; - } - mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); - return true; - }).orElseGet(() -> { - mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); - return true; - }); - - } - - private void connectBack(Channel channel, MqttConnectReturnCode connectReturnCode){ - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK,false, MqttQoS.AT_MOST_ONCE, false, 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck); - } - - - /** - * 发布 - */ - @Override - public void publish(Channel channel, MqttPublishMessage mqttPublishMessage) { - mqttChannelService.publishSuccess(channel, mqttPublishMessage); - } - - /** - * 订阅 - */ - @Override - public void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage) { - Set topics = mqttSubscribeMessage.payload().topicSubscriptions().stream().map(mqttTopicSubscription -> - mqttTopicSubscription.topicName() - ).collect(Collectors.toSet()); - mqttChannelService.suscribeSuccess(mqttChannelService.getDeviceId(channel), topics); - subBack(channel, mqttSubscribeMessage, topics.size()); - } - - private void subBack(Channel channel, MqttSubscribeMessage mqttSubscribeMessage, int num) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); - MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(mqttSubscribeMessage.variableHeader().messageId()); - List grantedQoSLevels = new ArrayList<>(num); - for (int i = 0; i < num; i++) { - grantedQoSLevels.add(mqttSubscribeMessage.payload().topicSubscriptions().get(i).qualityOfService().value()); - } - MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); - MqttSubAckMessage mqttSubAckMessage = new MqttSubAckMessage(mqttFixedHeader, variableHeader, payload); - channel.writeAndFlush(mqttSubAckMessage); - } - - - /** - * 关闭通道 - */ - @Override - public void close(Channel channel) { - mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), false); - channel.close(); - } - - /** - * 回复pong消息 - */ - @Override - public void pong(Channel channel) { - if (channel.isOpen() && channel.isActive() && channel.isWritable()) { - log.info("收到来自:【" + channel.remoteAddress().toString() + "】心跳"); - MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0); - channel.writeAndFlush(new MqttMessage(fixedHeader)); - } - } - - /** - * 取消订阅 - */ - @Override - public void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage) { - List topics1 = mqttMessage.payload().topics(); - mqttChannelService.unsubscribe(mqttChannelService.getDeviceId(channel), topics1); - unSubBack(channel, mqttMessage.variableHeader().messageId()); - } - - /** - * 回复取消订阅 - */ - private void unSubBack(Channel channel, int messageId) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0x02); - MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); - MqttUnsubAckMessage mqttUnsubAckMessage = new MqttUnsubAckMessage(mqttFixedHeader, variableHeader); - channel.writeAndFlush(mqttUnsubAckMessage); - } - - - /** - * 消息回复确认(qos1 级别 保证收到消息 但是可能会重复) - */ - @Override - public void puback(Channel channel, MqttMessage mqttMessage) { - MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = messageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - } - - - /** - * disconnect 主动断线 - */ - @Override - public void disconnect(Channel channel) { - mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), true); - } - - - /** - * qos2 发布收到 - */ - @Override - public void pubrec(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = messageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.PUBREL); // 复制为空 - mqttChannelService.doPubrec(channel, messageId); - } - - /** - * qos2 发布释放 - */ - @Override - public void pubrel(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = mqttMessageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - mqttChannelService.doPubrel(channel, messageId); - - } - - /** - * qos2 发布完成 - */ - @Override - public void pubcomp(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = mqttMessageIdVariableHeader.messageId(); - SendMqttMessage sendMqttMessage = mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId); - sendMqttMessage.setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - } - - @Override - public void doTimeOut(Channel channel, IdleStateEvent evt) { - log.info("【PingPongService:doTimeOut 心跳超时】" + channel.remoteAddress() + "【channel 关闭】"); - switch (evt.state()) { - case READER_IDLE: - close(channel); - case WRITER_IDLE: - close(channel); - case ALL_IDLE: - close(channel); - } - } - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.BaseApi; +import com.myself.unclecatmyself.bootstrap.BaseAuthService; +import com.myself.unclecatmyself.bootstrap.ChannelService; +import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; +import com.myself.unclecatmyself.common.enums.ConfirmStatus; +import com.myself.unclecatmyself.common.mqtts.ServerMqttHandlerService; +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +@Slf4j +//@Component +public class MqttHandlerService extends ServerMqttHandlerService implements BaseApi { + + @Autowired + ChannelService mqttChannelService; + + private final BaseAuthService baseAuthService; + + public MqttHandlerService(BaseAuthService baseAuthService) { + this.baseAuthService = baseAuthService; + } + + /** + * 登录 + * + */ + @Override + public boolean login(Channel channel, MqttConnectMessage mqttConnectMessage) { +// 校验规则 自定义校验规则 + MqttConnectPayload payload = mqttConnectMessage.payload(); + String deviceId = payload.clientIdentifier(); + if (StringUtils.isBlank(deviceId)) { + MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; + connectBack(channel,connectReturnCode); + return false; + } + + if(mqttConnectMessage.variableHeader().hasPassword() && mqttConnectMessage.variableHeader().hasUserName() + && !baseAuthService.authorized(payload.userName(),payload.password())){ + MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; + connectBack(channel,connectReturnCode); + return false; + } + return Optional.ofNullable(mqttChannelService.getMqttChannel(deviceId)) + .map(mqttChannel -> { + switch (mqttChannel.getSessionStatus()){ + case OPEN: + return false; + } + mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); + return true; + }).orElseGet(() -> { + mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); + return true; + }); + + } + + private void connectBack(Channel channel, MqttConnectReturnCode connectReturnCode){ + MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( + MqttMessageType.CONNACK,false, MqttQoS.AT_MOST_ONCE, false, 0x02); + MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); + channel.writeAndFlush(connAck); + } + + + /** + * 发布 + */ + @Override + public void publish(Channel channel, MqttPublishMessage mqttPublishMessage) { + mqttChannelService.publishSuccess(channel, mqttPublishMessage); + } + + /** + * 订阅 + */ + @Override + public void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage) { + Set topics = mqttSubscribeMessage.payload().topicSubscriptions().stream().map(mqttTopicSubscription -> + mqttTopicSubscription.topicName() + ).collect(Collectors.toSet()); + mqttChannelService.suscribeSuccess(mqttChannelService.getDeviceId(channel), topics); + subBack(channel, mqttSubscribeMessage, topics.size()); + } + + private void subBack(Channel channel, MqttSubscribeMessage mqttSubscribeMessage, int num) { + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); + MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(mqttSubscribeMessage.variableHeader().messageId()); + List grantedQoSLevels = new ArrayList<>(num); + for (int i = 0; i < num; i++) { + grantedQoSLevels.add(mqttSubscribeMessage.payload().topicSubscriptions().get(i).qualityOfService().value()); + } + MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); + MqttSubAckMessage mqttSubAckMessage = new MqttSubAckMessage(mqttFixedHeader, variableHeader, payload); + channel.writeAndFlush(mqttSubAckMessage); + } + + + /** + * 关闭通道 + */ + @Override + public void close(Channel channel) { + mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), false); + channel.close(); + } + + /** + * 回复pong消息 + */ + @Override + public void pong(Channel channel) { + if (channel.isOpen() && channel.isActive() && channel.isWritable()) { + log.info("收到来自:【" + channel.remoteAddress().toString() + "】心跳"); + MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0); + channel.writeAndFlush(new MqttMessage(fixedHeader)); + } + } + + /** + * 取消订阅 + */ + @Override + public void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage) { + List topics1 = mqttMessage.payload().topics(); + mqttChannelService.unsubscribe(mqttChannelService.getDeviceId(channel), topics1); + unSubBack(channel, mqttMessage.variableHeader().messageId()); + } + + /** + * 回复取消订阅 + */ + private void unSubBack(Channel channel, int messageId) { + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0x02); + MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); + MqttUnsubAckMessage mqttUnsubAckMessage = new MqttUnsubAckMessage(mqttFixedHeader, variableHeader); + channel.writeAndFlush(mqttUnsubAckMessage); + } + + + /** + * 消息回复确认(qos1 级别 保证收到消息 但是可能会重复) + */ + @Override + public void puback(Channel channel, MqttMessage mqttMessage) { + MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = messageIdVariableHeader.messageId(); + mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 + } + + + /** + * disconnect 主动断线 + */ + @Override + public void disconnect(Channel channel) { + mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), true); + } + + + /** + * qos2 发布收到 + */ + @Override + public void pubrec(Channel channel, MqttMessage mqttMessage ) { + MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = messageIdVariableHeader.messageId(); + mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.PUBREL); // 复制为空 + mqttChannelService.doPubrec(channel, messageId); + } + + /** + * qos2 发布释放 + */ + @Override + public void pubrel(Channel channel, MqttMessage mqttMessage ) { + MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = mqttMessageIdVariableHeader.messageId(); + mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 + mqttChannelService.doPubrel(channel, messageId); + + } + + /** + * qos2 发布完成 + */ + @Override + public void pubcomp(Channel channel, MqttMessage mqttMessage ) { + MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); + int messageId = mqttMessageIdVariableHeader.messageId(); + SendMqttMessage sendMqttMessage = mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId); + sendMqttMessage.setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 + } + + @Override + public void doTimeOut(Channel channel, IdleStateEvent evt) { + log.info("【PingPongService:doTimeOut 心跳超时】" + channel.remoteAddress() + "【channel 关闭】"); + switch (evt.state()) { + case READER_IDLE: + close(channel); + case WRITER_IDLE: + close(channel); + case ALL_IDLE: + close(channel); + } + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/PublishApiSevice.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java similarity index 92% rename from src/main/java/com/myself/nettychat/bootstrap/channel/PublishApiSevice.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java index 4af733f..49e775c 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/PublishApiSevice.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java @@ -1,162 +1,162 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.bean.MqttChannel; -import com.myself.nettychat.bootstrap.bean.SendMqttMessage; -import com.myself.nettychat.bootstrap.bean.WillMeaasge; -import com.myself.nettychat.bootstrap.scan.ScanRunnable; -import com.myself.nettychat.common.utils.MessageId; -import com.myself.nettychat.common.enums.ConfirmStatus; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 发送消息以及确认 - **/ -@Slf4j -public class PublishApiSevice { - - private final ScanRunnable scanRunnable; - - public PublishApiSevice(ScanRunnable scanRunnable) { - this.scanRunnable = scanRunnable; - } - - - /** - * 写入遗嘱消息 - */ - protected void writeWillMsg(MqttChannel mqttChannel, WillMeaasge willMeaasge) { -// dup保证消息可靠传输,默认为0,只占用一个字节,表示第一次发送。不能用于检测消息重复发送等 - switch (willMeaasge.getQos()){ - case 0: // qos0 - sendQos0Msg(mqttChannel.getChannel(),willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - case 1: // qos1 - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - case 2: // qos2 - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - } - - - } - - protected void sendQosConfirmMsg(MqttQoS qos, MqttChannel mqttChannel, String topic, byte[] bytes) { - if(mqttChannel.isLogin()){ - int messageId = MessageId.messageId(); - switch (qos){ - case AT_LEAST_ONCE: - mqttChannel.addSendMqttMessage(messageId,sendQos1Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); - break; - case EXACTLY_ONCE: - mqttChannel.addSendMqttMessage(messageId,sendQos2Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); - break; - } - } - - } - - - /** - * 发送 qos1 类的消息 - */ - private SendMqttMessage sendQos1Msg(Channel channel, String topic, boolean isDup, byte[] byteBuf, int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.AT_LEAST_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - return addQueue(channel,messageId,topic,byteBuf,MqttQoS.AT_LEAST_ONCE, ConfirmStatus.PUB); - } - - - - /** - * 发送 qos0 类的消息 byte - */ - protected void sendQos0Msg(Channel channel, String topic, byte[] byteBuf){ - if(channel!=null){ - sendQos0Msg(channel,topic,byteBuf,0); - } - } - private void sendQos0Msg(Channel channel, String topic, byte[] byteBuf,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,false, MqttQoS.AT_MOST_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader,Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - } - - - - - private SendMqttMessage sendQos2Msg(Channel channel, String topic,boolean isDup, byte[] byteBuf, int messageId) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.EXACTLY_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - return addQueue(channel,messageId,topic,byteBuf,MqttQoS.EXACTLY_ONCE,ConfirmStatus.PUB); - } - - - /** - * 发送qos1 publish 确认消息 - */ - protected void sendPubBack(Channel channel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK,false, MqttQoS.AT_MOST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - - /** - * 发送qos2 publish 确认消息 第一步 - */ - protected void sendPubRec( MqttChannel mqttChannel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC,false, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - Channel channel = mqttChannel.getChannel(); - channel.writeAndFlush(mqttPubAckMessage); - SendMqttMessage sendMqttMessage = addQueue(channel, messageId, null, null, null, ConfirmStatus.PUBREC); - mqttChannel.addSendMqttMessage(messageId,sendMqttMessage); - } - - /** - * 发送qos2 publish 确认消息 第二步 - */ - protected void sendPubRel(Channel channel,boolean isDup,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL,isDup, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - /** - * 发送qos2 publish 确认消息 第三步 - */ - protected void sendToPubComp(Channel channel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP,false, MqttQoS.AT_MOST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - private SendMqttMessage addQueue(Channel channel,int messageId,String topic,byte[] datas,MqttQoS mqttQoS,ConfirmStatus confirmStatus){ - SendMqttMessage build = SendMqttMessage.builder(). - channel(channel). - confirmStatus(confirmStatus). - messageId(messageId) - .topic(topic) - .qos(mqttQoS) - .byteBuf(datas) - .time(System.currentTimeMillis()).build(); - scanRunnable.addQueue(build); - return build; - } - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; +import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; +import com.myself.unclecatmyself.bootstrap.bean.WillMeaasge; +import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; +import com.myself.unclecatmyself.common.utils.MessageId; +import com.myself.unclecatmyself.common.enums.ConfirmStatus; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import lombok.extern.slf4j.Slf4j; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 发送消息以及确认 + **/ +@Slf4j +public class PublishApiSevice { + + private final ScanRunnable scanRunnable; + + public PublishApiSevice(ScanRunnable scanRunnable) { + this.scanRunnable = scanRunnable; + } + + + /** + * 写入遗嘱消息 + */ + protected void writeWillMsg(MqttChannel mqttChannel, WillMeaasge willMeaasge) { +// dup保证消息可靠传输,默认为0,只占用一个字节,表示第一次发送。不能用于检测消息重复发送等 + switch (willMeaasge.getQos()){ + case 0: // qos0 + sendQos0Msg(mqttChannel.getChannel(),willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); + break; + case 1: // qos1 + sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); + break; + case 2: // qos2 + sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); + break; + } + + + } + + protected void sendQosConfirmMsg(MqttQoS qos, MqttChannel mqttChannel, String topic, byte[] bytes) { + if(mqttChannel.isLogin()){ + int messageId = MessageId.messageId(); + switch (qos){ + case AT_LEAST_ONCE: + mqttChannel.addSendMqttMessage(messageId,sendQos1Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); + break; + case EXACTLY_ONCE: + mqttChannel.addSendMqttMessage(messageId,sendQos2Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); + break; + } + } + + } + + + /** + * 发送 qos1 类的消息 + */ + private SendMqttMessage sendQos1Msg(Channel channel, String topic, boolean isDup, byte[] byteBuf, int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.AT_LEAST_ONCE,false,0); + MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); + MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); + channel.writeAndFlush(mqttPublishMessage); + return addQueue(channel,messageId,topic,byteBuf,MqttQoS.AT_LEAST_ONCE, ConfirmStatus.PUB); + } + + + + /** + * 发送 qos0 类的消息 byte + */ + protected void sendQos0Msg(Channel channel, String topic, byte[] byteBuf){ + if(channel!=null){ + sendQos0Msg(channel,topic,byteBuf,0); + } + } + private void sendQos0Msg(Channel channel, String topic, byte[] byteBuf,int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,false, MqttQoS.AT_MOST_ONCE,false,0); + MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); + MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader,Unpooled.wrappedBuffer(byteBuf)); + channel.writeAndFlush(mqttPublishMessage); + } + + + + + private SendMqttMessage sendQos2Msg(Channel channel, String topic,boolean isDup, byte[] byteBuf, int messageId) { + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.EXACTLY_ONCE,false,0); + MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); + MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); + channel.writeAndFlush(mqttPublishMessage); + return addQueue(channel,messageId,topic,byteBuf,MqttQoS.EXACTLY_ONCE,ConfirmStatus.PUB); + } + + + /** + * 发送qos1 publish 确认消息 + */ + protected void sendPubBack(Channel channel,int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK,false, MqttQoS.AT_MOST_ONCE,false,0x02); + MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); + MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); + channel.writeAndFlush(mqttPubAckMessage); + } + + + /** + * 发送qos2 publish 确认消息 第一步 + */ + protected void sendPubRec( MqttChannel mqttChannel,int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC,false, MqttQoS.AT_LEAST_ONCE,false,0x02); + MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); + MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); + Channel channel = mqttChannel.getChannel(); + channel.writeAndFlush(mqttPubAckMessage); + SendMqttMessage sendMqttMessage = addQueue(channel, messageId, null, null, null, ConfirmStatus.PUBREC); + mqttChannel.addSendMqttMessage(messageId,sendMqttMessage); + } + + /** + * 发送qos2 publish 确认消息 第二步 + */ + protected void sendPubRel(Channel channel,boolean isDup,int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL,isDup, MqttQoS.AT_LEAST_ONCE,false,0x02); + MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); + MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); + channel.writeAndFlush(mqttPubAckMessage); + } + + /** + * 发送qos2 publish 确认消息 第三步 + */ + protected void sendToPubComp(Channel channel,int messageId){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP,false, MqttQoS.AT_MOST_ONCE,false,0x02); + MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); + MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); + channel.writeAndFlush(mqttPubAckMessage); + } + + private SendMqttMessage addQueue(Channel channel,int messageId,String topic,byte[] datas,MqttQoS mqttQoS,ConfirmStatus confirmStatus){ + SendMqttMessage build = SendMqttMessage.builder(). + channel(channel). + confirmStatus(confirmStatus). + messageId(messageId) + .topic(topic) + .qos(mqttQoS) + .byteBuf(datas) + .time(System.currentTimeMillis()).build(); + scanRunnable.addQueue(build); + return build; + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java similarity index 90% rename from src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 60f4fef..1dcc8e7 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -1,8 +1,8 @@ -package com.myself.nettychat.bootstrap.channel; +package com.myself.unclecatmyself.bootstrap.channel; import com.google.gson.Gson; -import com.myself.nettychat.bootstrap.WsChannelService; -import com.myself.nettychat.bootstrap.channel.cache.WsCacheMap; +import com.myself.unclecatmyself.bootstrap.WsChannelService; +import com.myself.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java similarity index 88% rename from src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index ab53211..7f88269 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -1,11 +1,11 @@ -package com.myself.nettychat.bootstrap.channel; +package com.myself.unclecatmyself.bootstrap.channel; import com.google.gson.Gson; -import com.myself.nettychat.bootstrap.backmsg.InChatBackMapService; -import com.myself.nettychat.bootstrap.BaseAuthService; -import com.myself.nettychat.bootstrap.WsChannelService; -import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; -import com.myself.nettychat.bootstrap.verify.InChatVerifyService; +import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; +import com.myself.unclecatmyself.bootstrap.BaseAuthService; +import com.myself.unclecatmyself.bootstrap.WsChannelService; +import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; +import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java similarity index 81% rename from src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java index 8c16068..e82387b 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/WillService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java @@ -1,52 +1,51 @@ -package com.myself.nettychat.bootstrap.channel; - -import com.myself.nettychat.bootstrap.BaseApi; -import com.myself.nettychat.bootstrap.ChannelService; -import com.myself.nettychat.bootstrap.bean.WillMeaasge; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -//@Component -@Data -@NoArgsConstructor -public class WillService implements BaseApi { - - @Autowired - ChannelService channelService; - - private static ConcurrentHashMap willMeaasges = new ConcurrentHashMap<>(); // deviceid -WillMeaasge - - - - /** - * 保存遗嘱消息 - */ - public void save(String deviceid, WillMeaasge build) { - willMeaasges.put(deviceid,build); // 替换旧的 - } - - - public void doSend( String deviceId) { // 客户端断开连接后 开启遗嘱消息发送 - if(StringUtils.isNotBlank(deviceId)&&(willMeaasges.get(deviceId))!=null){ - WillMeaasge willMeaasge = willMeaasges.get(deviceId); - channelService.sendWillMsg(willMeaasge); // 发送遗嘱消息 - if(!willMeaasge.isRetain()){ // 移除 - willMeaasges.remove(deviceId); - log.info("deviceId will message["+willMeaasge.getWillMessage()+"] is removed"); - } - } - } - - /** - * 删除遗嘱消息 - */ - public void del(String deviceid ) {willMeaasges.remove(deviceid);} - -} +package com.myself.unclecatmyself.bootstrap.channel; + +import com.myself.unclecatmyself.bootstrap.BaseApi; +import com.myself.unclecatmyself.bootstrap.ChannelService; +import com.myself.unclecatmyself.bootstrap.bean.WillMeaasge; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.concurrent.ConcurrentHashMap; + +@Slf4j +//@Component +@Data +@NoArgsConstructor +public class WillService implements BaseApi { + + @Autowired + ChannelService channelService; + + private static ConcurrentHashMap willMeaasges = new ConcurrentHashMap<>(); // deviceid -WillMeaasge + + + + /** + * 保存遗嘱消息 + */ + public void save(String deviceid, WillMeaasge build) { + willMeaasges.put(deviceid,build); // 替换旧的 + } + + + public void doSend( String deviceId) { // 客户端断开连接后 开启遗嘱消息发送 + if(StringUtils.isNotBlank(deviceId)&&(willMeaasges.get(deviceId))!=null){ + WillMeaasge willMeaasge = willMeaasges.get(deviceId); + channelService.sendWillMsg(willMeaasge); // 发送遗嘱消息 + if(!willMeaasge.isRetain()){ // 移除 + willMeaasges.remove(deviceId); + log.info("deviceId will message["+willMeaasge.getWillMessage()+"] is removed"); + } + } + } + + /** + * 删除遗嘱消息 + */ + public void del(String deviceid ) {willMeaasges.remove(deviceid);} + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/CacheMap.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java similarity index 94% rename from src/main/java/com/myself/nettychat/bootstrap/channel/cache/CacheMap.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java index 68f805e..5486b84 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/CacheMap.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java @@ -1,137 +1,137 @@ -package com.myself.nettychat.bootstrap.channel.cache; - -import lombok.extern.slf4j.Slf4j; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -/** - * @author MySelf - * @create 2018/9/22 - * @desc 缓存操作 - **/ -@Slf4j -public class CacheMap { - - private ConcurrentHashMap> datas = new ConcurrentHashMap<>(); - - public boolean putData(K[] topic, V v){ - if(topic.length==1){ - Node kvNode = buildOne(topic[0], v); - if(kvNode!=null && kvNode.topic.equals(topic[0])){ - return true; - } - } - else{ - Node kvNode = buildOne(topic[0], null); - for(int i=1;i kvNode = datas.get(ks[0]); - for(int i=1;i getData(K[] ks){ - if(ks.length==1){ - return datas.get(ks[0]).get(); - } - else{ - Node node = datas.get(ks[0]); - if(node!=null){ - List all = new ArrayList<>(); - all.addAll(node.get()); - for(int i=1;i buildOne(K k,V v){ - - Node node = this.datas.computeIfAbsent(k, key -> { - Node kObjectNode = new Node<>(k); - return kObjectNode; - }); - if(v!=null){ - node.put(v); - } - return node; - } - - - - class Node{ - - private final K topic; - - - private volatile ConcurrentHashMap> map =new ConcurrentHashMap<>() ; - - - List vs = new CopyOnWriteArrayList<>(); - - - public K getTopic() {return topic;} - - Node(K topic) { - this.topic = topic; - } - - public boolean delValue(V v){ - return vs.remove(v); - } - - public Node putNextValue(K k,V v){ - Node kvNode = map.computeIfAbsent(k, key -> { - Node node = new Node<>(k); - return node; - }); - if(v!=null){ - kvNode.put(v); - } - return kvNode; - } - - - public Node getNext(K k){ - return map.get(k); - } - - - public boolean put(V v){ - return vs.add(v); - } - - - public List get(){ - return vs; - } - } - -} +package com.myself.unclecatmyself.bootstrap.channel.cache; + +import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +/** + * @author MySelf + * @create 2018/9/22 + * @desc 缓存操作 + **/ +@Slf4j +public class CacheMap { + + private ConcurrentHashMap> datas = new ConcurrentHashMap<>(); + + public boolean putData(K[] topic, V v){ + if(topic.length==1){ + Node kvNode = buildOne(topic[0], v); + if(kvNode!=null && kvNode.topic.equals(topic[0])){ + return true; + } + } + else{ + Node kvNode = buildOne(topic[0], null); + for(int i=1;i kvNode = datas.get(ks[0]); + for(int i=1;i getData(K[] ks){ + if(ks.length==1){ + return datas.get(ks[0]).get(); + } + else{ + Node node = datas.get(ks[0]); + if(node!=null){ + List all = new ArrayList<>(); + all.addAll(node.get()); + for(int i=1;i buildOne(K k,V v){ + + Node node = this.datas.computeIfAbsent(k, key -> { + Node kObjectNode = new Node<>(k); + return kObjectNode; + }); + if(v!=null){ + node.put(v); + } + return node; + } + + + + class Node{ + + private final K topic; + + + private volatile ConcurrentHashMap> map =new ConcurrentHashMap<>() ; + + + List vs = new CopyOnWriteArrayList<>(); + + + public K getTopic() {return topic;} + + Node(K topic) { + this.topic = topic; + } + + public boolean delValue(V v){ + return vs.remove(v); + } + + public Node putNextValue(K k,V v){ + Node kvNode = map.computeIfAbsent(k, key -> { + Node node = new Node<>(k); + return node; + }); + if(v!=null){ + kvNode.put(v); + } + return kvNode; + } + + + public Node getNext(K k){ + return map.get(k); + } + + + public boolean put(V v){ + return vs.add(v); + } + + + public List get(){ + return vs; + } + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java similarity index 97% rename from src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index c40cfdd..ba77197 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.bootstrap.channel.cache; +package com.myself.unclecatmyself.bootstrap.channel.cache; import io.netty.channel.Channel; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/myself/nettychat/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java similarity index 90% rename from src/main/java/com/myself/nettychat/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java index 6c34606..cf3829d 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java @@ -1,26 +1,26 @@ -package com.myself.nettychat.bootstrap.coder; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageEncoder; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; - -import java.util.List; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 转换 - **/ -public class ByteBufToWebSocketFrameEncoder extends MessageToMessageEncoder { - - @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf byteBuf, List out) throws Exception { - if (byteBuf == null) { - return; - } - BinaryWebSocketFrame result = new BinaryWebSocketFrame(); - result.content().writeBytes(byteBuf); - out.add(result); - } -} +package com.myself.unclecatmyself.bootstrap.coder; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageEncoder; +import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; + +import java.util.List; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 转换 + **/ +public class ByteBufToWebSocketFrameEncoder extends MessageToMessageEncoder { + + @Override + protected void encode(ChannelHandlerContext ctx, ByteBuf byteBuf, List out) throws Exception { + if (byteBuf == null) { + return; + } + BinaryWebSocketFrame result = new BinaryWebSocketFrame(); + result.content().writeBytes(byteBuf); + out.add(result); + } +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/coder/WebSocketFrameToByteBufDecoder.java b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java similarity index 90% rename from src/main/java/com/myself/nettychat/bootstrap/coder/WebSocketFrameToByteBufDecoder.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java index 032d657..856a8cb 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/coder/WebSocketFrameToByteBufDecoder.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java @@ -1,25 +1,25 @@ -package com.myself.nettychat.bootstrap.coder; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageDecoder; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; - -import java.util.List; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 转换 - **/ -public class WebSocketFrameToByteBufDecoder extends MessageToMessageDecoder { - - - @Override - protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame wsFrame, List out) throws Exception { - ByteBuf buf = wsFrame.content(); - //避免计数器为0,报错 - buf.retain(); - out.add(buf); - } -} +package com.myself.unclecatmyself.bootstrap.coder; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageDecoder; +import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; + +import java.util.List; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 转换 + **/ +public class WebSocketFrameToByteBufDecoder extends MessageToMessageDecoder { + + + @Override + protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame wsFrame, List out) throws Exception { + ByteBuf buf = wsFrame.content(); + //避免计数器为0,报错 + buf.retain(); + out.add(buf); + } +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java similarity index 85% rename from src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java index a3cb6f7..b516bd4 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultMqttHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java @@ -1,105 +1,104 @@ -package com.myself.nettychat.bootstrap.handler; - -import com.myself.nettychat.bootstrap.ChannelService; -import com.myself.nettychat.bootstrap.bean.MqttChannel; -import com.myself.nettychat.common.mqtts.MqttHandlerIntf; -import com.myself.nettychat.common.mqtts.MqttHander; -import com.myself.nettychat.common.mqtts.ServerMqttHandlerService; -import com.myself.nettychat.common.exception.NoFindHandlerException; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 默认MQTTHandler处理 - **/ -@Slf4j -//@Component -@ChannelHandler.Sharable -public class DefaultMqttHandler extends MqttHander { - - private final MqttHandlerIntf mqttHandlerApi; - - @Autowired - ChannelService channelService; - - - public DefaultMqttHandler(MqttHandlerIntf mqttHandlerApi) { - super(mqttHandlerApi); - this.mqttHandlerApi = mqttHandlerApi; - } - - @Override - public void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) { - Channel channel = channelHandlerContext.channel(); - ServerMqttHandlerService serverMqttHandlerService; - if(mqttHandlerApi instanceof ServerMqttHandlerService){ - serverMqttHandlerService =(ServerMqttHandlerService)mqttHandlerApi; - } - else{ - throw new NoFindHandlerException("server handler 不匹配"); - } - MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); - if(mqttFixedHeader.messageType().equals(MqttMessageType.CONNECT)){ - if(!serverMqttHandlerService.login(channel, (MqttConnectMessage) mqttMessage)){ - channel.close(); - } - return ; - } - MqttChannel mqttChannel = channelService.getMqttChannel(channelService.getDeviceId(channel)); - if(mqttChannel!=null && mqttChannel.isLogin()){ - switch (mqttFixedHeader.messageType()){ - case PUBLISH: - serverMqttHandlerService.publish(channel, (MqttPublishMessage) mqttMessage); - break; - case SUBSCRIBE: - serverMqttHandlerService.subscribe(channel, (MqttSubscribeMessage) mqttMessage); - break; - case PINGREQ: - serverMqttHandlerService.pong(channel); - break; - case DISCONNECT: - serverMqttHandlerService.disconnect(channel); - break; - case UNSUBSCRIBE: - serverMqttHandlerService.unsubscribe(channel,(MqttUnsubscribeMessage)mqttMessage); - break; - case PUBACK: - mqttHandlerApi.puback(channel,mqttMessage); - break; - case PUBREC: - mqttHandlerApi.pubrec(channel,mqttMessage); - break; - case PUBREL: - mqttHandlerApi.pubrel(channel,mqttMessage); - break; - case PUBCOMP: - mqttHandlerApi.pubcomp(channel,mqttMessage); - break; - default: - break; - } - } - } - - - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultMqttHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - log.error("exception",cause); - mqttHandlerApi.close(ctx.channel()); - } - -} +package com.myself.unclecatmyself.bootstrap.handler; + +import com.myself.unclecatmyself.bootstrap.ChannelService; +import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; +import com.myself.unclecatmyself.common.mqtts.MqttHandlerIntf; +import com.myself.unclecatmyself.common.mqtts.MqttHander; +import com.myself.unclecatmyself.common.mqtts.ServerMqttHandlerService; +import com.myself.unclecatmyself.common.exception.NoFindHandlerException; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.mqtt.*; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 默认MQTTHandler处理 + **/ +@Slf4j +//@Component +@ChannelHandler.Sharable +public class DefaultMqttHandler extends MqttHander { + + private final MqttHandlerIntf mqttHandlerApi; + + @Autowired + ChannelService channelService; + + + public DefaultMqttHandler(MqttHandlerIntf mqttHandlerApi) { + super(mqttHandlerApi); + this.mqttHandlerApi = mqttHandlerApi; + } + + @Override + public void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) { + Channel channel = channelHandlerContext.channel(); + ServerMqttHandlerService serverMqttHandlerService; + if(mqttHandlerApi instanceof ServerMqttHandlerService){ + serverMqttHandlerService =(ServerMqttHandlerService)mqttHandlerApi; + } + else{ + throw new NoFindHandlerException("server handler 不匹配"); + } + MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); + if(mqttFixedHeader.messageType().equals(MqttMessageType.CONNECT)){ + if(!serverMqttHandlerService.login(channel, (MqttConnectMessage) mqttMessage)){ + channel.close(); + } + return ; + } + MqttChannel mqttChannel = channelService.getMqttChannel(channelService.getDeviceId(channel)); + if(mqttChannel!=null && mqttChannel.isLogin()){ + switch (mqttFixedHeader.messageType()){ + case PUBLISH: + serverMqttHandlerService.publish(channel, (MqttPublishMessage) mqttMessage); + break; + case SUBSCRIBE: + serverMqttHandlerService.subscribe(channel, (MqttSubscribeMessage) mqttMessage); + break; + case PINGREQ: + serverMqttHandlerService.pong(channel); + break; + case DISCONNECT: + serverMqttHandlerService.disconnect(channel); + break; + case UNSUBSCRIBE: + serverMqttHandlerService.unsubscribe(channel,(MqttUnsubscribeMessage)mqttMessage); + break; + case PUBACK: + mqttHandlerApi.puback(channel,mqttMessage); + break; + case PUBREC: + mqttHandlerApi.pubrec(channel,mqttMessage); + break; + case PUBREL: + mqttHandlerApi.pubrel(channel,mqttMessage); + break; + case PUBCOMP: + mqttHandlerApi.pubcomp(channel,mqttMessage); + break; + default: + break; + } + } + } + + + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultMqttHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + log.error("exception",cause); + mqttHandlerApi.close(ctx.channel()); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java similarity index 87% rename from src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index c78409e..84cae39 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -1,85 +1,85 @@ -package com.myself.nettychat.bootstrap.handler; - -import com.alibaba.fastjson.JSON; -import com.myself.nettychat.common.exception.NoFindHandlerException; -import com.myself.nettychat.common.websockets.ServerWebSocketHandlerService; -import com.myself.nettychat.common.websockets.WebSocketHandler; -import com.myself.nettychat.common.websockets.WebSocketHandlerApi; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; - -import java.util.Map; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:15 2018\11\16 0016 - */ -@Slf4j -@Component -@ChannelHandler.Sharable -public class DefaultWebSocketHandler extends WebSocketHandler { - - private final WebSocketHandlerApi webSocketHandlerApi; - - public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { - super(webSocketHandlerApi); - this.webSocketHandlerApi = webSocketHandlerApi; - } - - @Override - protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { - - } - - @Override - protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { - Channel channel = ctx.channel(); - ServerWebSocketHandlerService serverWebSocketHandlerService; - if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ - serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; - }else{ - throw new NoFindHandlerException("Server Handler 不匹配"); - } - Map maps = (Map) JSON.parse(msg.text()); - switch (maps.get("type")){ - case "login": - log.info("【用户链接登录操作】"); - serverWebSocketHandlerService.login(channel,maps); - break; - //针对个人,发送给自己 - case "sendMe": - log.info("【用户链接发送给自己】"); - serverWebSocketHandlerService.sendMeText(channel,maps); - break; - //针对个人,发送给某人 - case "sendTo": - log.info("【用户链接发送给某人】"); - serverWebSocketHandlerService.sendToText(channel,maps); - break; - case "sendGroup": - log.info("【用户链接发送给群聊】"); - serverWebSocketHandlerService.sendGroupText(channel,maps); - break; - default: - break; - } - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ - log.error("exception",cause); - webSocketHandlerApi.close(ctx.channel()); - } -} +package com.myself.unclecatmyself.bootstrap.handler; + +import com.alibaba.fastjson.JSON; +import com.myself.unclecatmyself.common.exception.NoFindHandlerException; +import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; +import com.myself.unclecatmyself.common.websockets.WebSocketHandler; +import com.myself.unclecatmyself.common.websockets.WebSocketHandlerApi; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:15 2018\11\16 0016 + */ +@Slf4j +@Component +@ChannelHandler.Sharable +public class DefaultWebSocketHandler extends WebSocketHandler { + + private final WebSocketHandlerApi webSocketHandlerApi; + + public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { + super(webSocketHandlerApi); + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { + + } + + @Override + protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { + Channel channel = ctx.channel(); + ServerWebSocketHandlerService serverWebSocketHandlerService; + if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ + serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; + }else{ + throw new NoFindHandlerException("Server Handler 不匹配"); + } + Map maps = (Map) JSON.parse(msg.text()); + switch (maps.get("type")){ + case "login": + log.info("【用户链接登录操作】"); + serverWebSocketHandlerService.login(channel,maps); + break; + //针对个人,发送给自己 + case "sendMe": + log.info("【用户链接发送给自己】"); + serverWebSocketHandlerService.sendMeText(channel,maps); + break; + //针对个人,发送给某人 + case "sendTo": + log.info("【用户链接发送给某人】"); + serverWebSocketHandlerService.sendToText(channel,maps); + break; + case "sendGroup": + log.info("【用户链接发送给群聊】"); + serverWebSocketHandlerService.sendGroupText(channel,maps); + break; + default: + break; + } + } + + @Override + public void channelActive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ + log.error("exception",cause); + webSocketHandlerApi.close(ctx.channel()); + } +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/scan/SacnScheduled.java b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java similarity index 92% rename from src/main/java/com/myself/nettychat/bootstrap/scan/SacnScheduled.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java index 15cc0ce..b278c5a 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/scan/SacnScheduled.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java @@ -1,59 +1,59 @@ -package com.myself.nettychat.bootstrap.scan; - -import com.myself.nettychat.bootstrap.bean.SendMqttMessage; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 扫描消息确认 - **/ -@Slf4j -public class SacnScheduled extends ScanRunnable { - - private final long time; - - public SacnScheduled(long time) { - this.time = time; - } - - private boolean checkTime(long time) { - return System.currentTimeMillis()-time>=10*1000; - } - - @Override - public void doInfo(SendMqttMessage poll) { - if(checkTime(poll.getTime()) && poll.getChannel().isActive()){ - poll.setTime(System.currentTimeMillis()); - switch (poll.getConfirmStatus()){ - case PUB: - pubMessage(poll.getChannel(),poll); - break; - case PUBREL: - sendAck(MqttMessageType.PUBREL,poll); - break; - case PUBREC: - sendAck(MqttMessageType.PUBREC,poll); - break; - } - } - } - - private void pubMessage(Channel channel, SendMqttMessage mqttMessage){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,true, mqttMessage.getQos(),mqttMessage.isRetain(),0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(mqttMessage.getTopic(),mqttMessage.getMessageId()); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(mqttMessage.getByteBuf())); - channel.writeAndFlush(mqttPublishMessage); - } - - protected void sendAck(MqttMessageType type,SendMqttMessage mqttMessage){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(type,true, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(mqttMessage.getMessageId()); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - mqttMessage.getChannel().writeAndFlush(mqttPubAckMessage); - } - -} +package com.myself.unclecatmyself.bootstrap.scan; + +import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import lombok.extern.slf4j.Slf4j; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 扫描消息确认 + **/ +@Slf4j +public class SacnScheduled extends ScanRunnable { + + private final long time; + + public SacnScheduled(long time) { + this.time = time; + } + + private boolean checkTime(long time) { + return System.currentTimeMillis()-time>=10*1000; + } + + @Override + public void doInfo(SendMqttMessage poll) { + if(checkTime(poll.getTime()) && poll.getChannel().isActive()){ + poll.setTime(System.currentTimeMillis()); + switch (poll.getConfirmStatus()){ + case PUB: + pubMessage(poll.getChannel(),poll); + break; + case PUBREL: + sendAck(MqttMessageType.PUBREL,poll); + break; + case PUBREC: + sendAck(MqttMessageType.PUBREC,poll); + break; + } + } + } + + private void pubMessage(Channel channel, SendMqttMessage mqttMessage){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,true, mqttMessage.getQos(),mqttMessage.isRetain(),0); + MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(mqttMessage.getTopic(),mqttMessage.getMessageId()); + MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(mqttMessage.getByteBuf())); + channel.writeAndFlush(mqttPublishMessage); + } + + protected void sendAck(MqttMessageType type,SendMqttMessage mqttMessage){ + MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(type,true, MqttQoS.AT_LEAST_ONCE,false,0x02); + MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(mqttMessage.getMessageId()); + MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); + mqttMessage.getChannel().writeAndFlush(mqttPubAckMessage); + } + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java similarity index 83% rename from src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java index fdd6dbe..9726fc6 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/scan/ScanRunnable.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java @@ -1,43 +1,43 @@ -package com.myself.nettychat.bootstrap.scan; - -import com.myself.nettychat.bootstrap.bean.SendMqttMessage; -import lombok.extern.slf4j.Slf4j; -import com.myself.nettychat.common.enums.ConfirmStatus; -import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 扫描未确认的消息 - **/ -@Slf4j -public abstract class ScanRunnable implements Runnable{ - - LinkedBlockingQueue queue =new LinkedBlockingQueue(); - - public boolean addQueue(SendMqttMessage t){ - return queue.add(t); - } - - public boolean addQueues(List ts){ - return queue.addAll(ts); - } - - @Override - public void run() { - for(;;){ - try { - SendMqttMessage poll= queue.take(); - if(poll.getConfirmStatus()!= ConfirmStatus.COMPLETE){ - doInfo(poll); - queue.offer(poll); - } - } catch (InterruptedException e) { - log.error("scan InterruptedException",e); - } - } - } - public abstract void doInfo( SendMqttMessage poll); - -} +package com.myself.unclecatmyself.bootstrap.scan; + +import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; +import lombok.extern.slf4j.Slf4j; +import com.myself.unclecatmyself.common.enums.ConfirmStatus; +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 扫描未确认的消息 + **/ +@Slf4j +public abstract class ScanRunnable implements Runnable{ + + LinkedBlockingQueue queue =new LinkedBlockingQueue(); + + public boolean addQueue(SendMqttMessage t){ + return queue.add(t); + } + + public boolean addQueues(List ts){ + return queue.addAll(ts); + } + + @Override + public void run() { + for(;;){ + try { + SendMqttMessage poll= queue.take(); + if(poll.getConfirmStatus()!= ConfirmStatus.COMPLETE){ + doInfo(poll); + queue.offer(poll); + } + } catch (InterruptedException e) { + log.error("scan InterruptedException",e); + } + } + } + public abstract void doInfo( SendMqttMessage poll); + +} diff --git a/src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java similarity index 76% rename from src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java index 87c6ad6..9438c0c 100644 --- a/src/main/java/com/myself/nettychat/bootstrap/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java @@ -1,4 +1,4 @@ -package com.myself.nettychat.bootstrap.verify; +package com.myself.unclecatmyself.bootstrap.verify; /** * 用户校验层 diff --git a/src/main/java/com/myself/nettychat/common/enums/ConfirmStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java similarity index 72% rename from src/main/java/com/myself/nettychat/common/enums/ConfirmStatus.java rename to src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java index 968b807..255adf9 100644 --- a/src/main/java/com/myself/nettychat/common/enums/ConfirmStatus.java +++ b/src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java @@ -1,13 +1,13 @@ -package com.myself.nettychat.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 确认状态 - **/ -public enum ConfirmStatus { - PUB, - PUBREC, - PUBREL, - COMPLETE, -} +package com.myself.unclecatmyself.common.enums; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 确认状态 + **/ +public enum ConfirmStatus { + PUB, + PUBREC, + PUBREL, + COMPLETE, +} diff --git a/src/main/java/com/myself/nettychat/common/enums/ProtocolEnum.java b/src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java similarity index 71% rename from src/main/java/com/myself/nettychat/common/enums/ProtocolEnum.java rename to src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java index 19855ea..6b29d02 100644 --- a/src/main/java/com/myself/nettychat/common/enums/ProtocolEnum.java +++ b/src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java @@ -1,14 +1,14 @@ -package com.myself.nettychat.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 协议 - **/ -public enum ProtocolEnum { - MQTT, - - MQTT_WS_MQTT, - - MQTT_WS_PAHO, -} +package com.myself.unclecatmyself.common.enums; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 协议 + **/ +public enum ProtocolEnum { + MQTT, + + MQTT_WS_MQTT, + + MQTT_WS_PAHO, +} diff --git a/src/main/java/com/myself/nettychat/common/enums/QosStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java similarity index 78% rename from src/main/java/com/myself/nettychat/common/enums/QosStatus.java rename to src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java index 0a3643a..d5e31b2 100644 --- a/src/main/java/com/myself/nettychat/common/enums/QosStatus.java +++ b/src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java @@ -1,14 +1,14 @@ -package com.myself.nettychat.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Qos确认状态 - **/ -public enum QosStatus { - - PUBD, // 已发送 没收到RECD (发送) - - RECD, //publish 推送回复过(发送) - -} +package com.myself.unclecatmyself.common.enums; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc Qos确认状态 + **/ +public enum QosStatus { + + PUBD, // 已发送 没收到RECD (发送) + + RECD, //publish 推送回复过(发送) + +} diff --git a/src/main/java/com/myself/nettychat/common/enums/SessionStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java similarity index 70% rename from src/main/java/com/myself/nettychat/common/enums/SessionStatus.java rename to src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java index 593d63f..a9ee354 100644 --- a/src/main/java/com/myself/nettychat/common/enums/SessionStatus.java +++ b/src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java @@ -1,13 +1,13 @@ -package com.myself.nettychat.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Channel 会话状态 - **/ -public enum SessionStatus { - - OPEN, - CLOSE - -} +package com.myself.unclecatmyself.common.enums; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc Channel 会话状态 + **/ +public enum SessionStatus { + + OPEN, + CLOSE + +} diff --git a/src/main/java/com/myself/nettychat/common/enums/SubStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java similarity index 69% rename from src/main/java/com/myself/nettychat/common/enums/SubStatus.java rename to src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java index 2ab833c..8b7929e 100644 --- a/src/main/java/com/myself/nettychat/common/enums/SubStatus.java +++ b/src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java @@ -1,11 +1,11 @@ -package com.myself.nettychat.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 是否订阅过主题 - **/ -public enum SubStatus { - YES, - NO -} +package com.myself.unclecatmyself.common.enums; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 是否订阅过主题 + **/ +public enum SubStatus { + YES, + NO +} diff --git a/src/main/java/com/myself/nettychat/common/exception/ConnectionException.java b/src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java similarity index 77% rename from src/main/java/com/myself/nettychat/common/exception/ConnectionException.java rename to src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java index 76d1cb2..cfedebd 100644 --- a/src/main/java/com/myself/nettychat/common/exception/ConnectionException.java +++ b/src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java @@ -1,14 +1,14 @@ -package com.myself.nettychat.common.exception; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 连接异常 - **/ -public class ConnectionException extends RuntimeException { - - public ConnectionException(String message) { - super(message); - } - -} +package com.myself.unclecatmyself.common.exception; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 连接异常 + **/ +public class ConnectionException extends RuntimeException { + + public ConnectionException(String message) { + super(message); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/exception/NoFindHandlerException.java b/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java similarity index 79% rename from src/main/java/com/myself/nettychat/common/exception/NoFindHandlerException.java rename to src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java index 1b1ed2a..e05464a 100644 --- a/src/main/java/com/myself/nettychat/common/exception/NoFindHandlerException.java +++ b/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java @@ -1,14 +1,14 @@ -package com.myself.nettychat.common.exception; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 找不到Handler异常 - **/ -public class NoFindHandlerException extends RuntimeException { - - public NoFindHandlerException(String message) { - super(message); - } - -} +package com.myself.unclecatmyself.common.exception; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 找不到Handler异常 + **/ +public class NoFindHandlerException extends RuntimeException { + + public NoFindHandlerException(String message) { + super(message); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/ip/IpUtils.java b/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java similarity index 94% rename from src/main/java/com/myself/nettychat/common/ip/IpUtils.java rename to src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java index 4ccfc3d..8068203 100644 --- a/src/main/java/com/myself/nettychat/common/ip/IpUtils.java +++ b/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java @@ -1,68 +1,68 @@ -package com.myself.nettychat.common.ip; - -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.util.Enumeration; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc ip操作 - **/ -public class IpUtils { - - /*** - * 获取外网IP - * @return - */ - public static String internetIp() { - try { - - Enumeration networks = NetworkInterface.getNetworkInterfaces(); - InetAddress inetAddress = null; - Enumeration inetAddresses = null; - while (networks.hasMoreElements()) { - inetAddresses = networks.nextElement().getInetAddresses(); - while (inetAddresses.hasMoreElements()) { - inetAddress = inetAddresses.nextElement(); - if (inetAddress != null - && inetAddress instanceof Inet4Address - && !inetAddress.isSiteLocalAddress() - && !inetAddress.isLoopbackAddress() - && inetAddress.getHostAddress().indexOf(":") == -1) { - return inetAddress.getHostAddress(); - } - } - } - - return null; - - } catch (Exception e) { - - throw new RuntimeException(e); - } - } - - /** - * 获取内网IP - * - * @return - */ - public static String intranetIp() { - try { - return InetAddress.getLocalHost().getHostAddress(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * 获取服务启动host - * @return - */ - public static String getHost(){ - return internetIp()==null?intranetIp():internetIp(); - } - -} +package com.myself.unclecatmyself.common.ip; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc ip操作 + **/ +public class IpUtils { + + /*** + * 获取外网IP + * @return + */ + public static String internetIp() { + try { + + Enumeration networks = NetworkInterface.getNetworkInterfaces(); + InetAddress inetAddress = null; + Enumeration inetAddresses = null; + while (networks.hasMoreElements()) { + inetAddresses = networks.nextElement().getInetAddresses(); + while (inetAddresses.hasMoreElements()) { + inetAddress = inetAddresses.nextElement(); + if (inetAddress != null + && inetAddress instanceof Inet4Address + && !inetAddress.isSiteLocalAddress() + && !inetAddress.isLoopbackAddress() + && inetAddress.getHostAddress().indexOf(":") == -1) { + return inetAddress.getHostAddress(); + } + } + } + + return null; + + } catch (Exception e) { + + throw new RuntimeException(e); + } + } + + /** + * 获取内网IP + * + * @return + */ + public static String intranetIp() { + try { + return InetAddress.getLocalHost().getHostAddress(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * 获取服务启动host + * @return + */ + public static String getHost(){ + return internetIp()==null?intranetIp():internetIp(); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/mqtts/ClientMqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java similarity index 90% rename from src/main/java/com/myself/nettychat/common/mqtts/ClientMqttHandlerService.java rename to src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java index 56f9fda..d60c3a2 100644 --- a/src/main/java/com/myself/nettychat/common/mqtts/ClientMqttHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java @@ -1,27 +1,27 @@ -package com.myself.nettychat.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象出客户端的事件 - **/ -public abstract class ClientMqttHandlerService implements MqttHandlerIntf { - - @Override - public void doTimeOut(Channel channel, IdleStateEvent evt) { - heart(channel,evt); - } - - public abstract void heart(Channel channel, IdleStateEvent evt); - - public abstract void suback(Channel channel,MqttSubAckMessage mqttMessage) ; - - public abstract void pubBackMessage(Channel channel, int i); - - public abstract void unsubBack(Channel channel, MqttMessage mqttMessage); -} +package com.myself.unclecatmyself.common.mqtts; + +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import io.netty.handler.timeout.IdleStateEvent; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 抽象出客户端的事件 + **/ +public abstract class ClientMqttHandlerService implements MqttHandlerIntf { + + @Override + public void doTimeOut(Channel channel, IdleStateEvent evt) { + heart(channel,evt); + } + + public abstract void heart(Channel channel, IdleStateEvent evt); + + public abstract void suback(Channel channel,MqttSubAckMessage mqttMessage) ; + + public abstract void pubBackMessage(Channel channel, int i); + + public abstract void unsubBack(Channel channel, MqttMessage mqttMessage); +} diff --git a/src/main/java/com/myself/nettychat/common/mqtts/MqttHander.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java similarity index 94% rename from src/main/java/com/myself/nettychat/common/mqtts/MqttHander.java rename to src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java index 061dd77..6512483 100644 --- a/src/main/java/com/myself/nettychat/common/mqtts/MqttHander.java +++ b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java @@ -1,50 +1,50 @@ -package com.myself.nettychat.common.mqtts; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.mqtt.MqttFixedHeader; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; - -import java.util.Optional; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc mtqq协议处理器 - **/ -@Slf4j -public abstract class MqttHander extends SimpleChannelInboundHandler { - - MqttHandlerIntf mqttHandlerApi; - - public MqttHander(MqttHandlerIntf mqttHandlerIntf){ - this.mqttHandlerApi=mqttHandlerIntf; - } - - @Override - protected void channelRead0(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) throws Exception { - MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); - Optional.ofNullable(mqttFixedHeader) - .ifPresent(mqttFixedHeader1 -> doMessage(channelHandlerContext,mqttMessage)); - } - - - public abstract void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage); - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultMqttHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - mqttHandlerApi.close(ctx.channel()); - } - - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if(evt instanceof IdleStateEvent){ - mqttHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); - } - super.userEventTriggered(ctx, evt); - } - -} +package com.myself.unclecatmyself.common.mqtts; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.mqtt.MqttFixedHeader; +import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; + +import java.util.Optional; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc mtqq协议处理器 + **/ +@Slf4j +public abstract class MqttHander extends SimpleChannelInboundHandler { + + MqttHandlerIntf mqttHandlerApi; + + public MqttHander(MqttHandlerIntf mqttHandlerIntf){ + this.mqttHandlerApi=mqttHandlerIntf; + } + + @Override + protected void channelRead0(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) throws Exception { + MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); + Optional.ofNullable(mqttFixedHeader) + .ifPresent(mqttFixedHeader1 -> doMessage(channelHandlerContext,mqttMessage)); + } + + + public abstract void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage); + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultMqttHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + mqttHandlerApi.close(ctx.channel()); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent){ + mqttHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); + } + super.userEventTriggered(ctx, evt); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/mqtts/MqttHandlerIntf.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java similarity index 89% rename from src/main/java/com/myself/nettychat/common/mqtts/MqttHandlerIntf.java rename to src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java index 4f274ee..1c8f883 100644 --- a/src/main/java/com/myself/nettychat/common/mqtts/MqttHandlerIntf.java +++ b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java @@ -1,26 +1,26 @@ -package com.myself.nettychat.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.timeout.IdleStateEvent; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 自定义 对外暴露,消息处理API - **/ -public interface MqttHandlerIntf { - - void close(Channel channel); - - void puback(Channel channel, MqttMessage mqttMessage); - - void pubrec(Channel channel, MqttMessage mqttMessage); - - void pubrel(Channel channel, MqttMessage mqttMessage); - - void pubcomp(Channel channel, MqttMessage mqttMessage); - - void doTimeOut(Channel channel, IdleStateEvent evt); - -} +package com.myself.unclecatmyself.common.mqtts; + +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.MqttMessage; +import io.netty.handler.timeout.IdleStateEvent; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 自定义 对外暴露,消息处理API + **/ +public interface MqttHandlerIntf { + + void close(Channel channel); + + void puback(Channel channel, MqttMessage mqttMessage); + + void pubrec(Channel channel, MqttMessage mqttMessage); + + void pubrel(Channel channel, MqttMessage mqttMessage); + + void pubcomp(Channel channel, MqttMessage mqttMessage); + + void doTimeOut(Channel channel, IdleStateEvent evt); + +} diff --git a/src/main/java/com/myself/nettychat/common/mqtts/ServerMqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java similarity index 92% rename from src/main/java/com/myself/nettychat/common/mqtts/ServerMqttHandlerService.java rename to src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java index fd62ee5..31cc216 100644 --- a/src/main/java/com/myself/nettychat/common/mqtts/ServerMqttHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java @@ -1,28 +1,28 @@ -package com.myself.nettychat.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象出服务端的事件 - **/ -public abstract class ServerMqttHandlerService implements MqttHandlerIntf { - - public abstract boolean login(Channel channel, MqttConnectMessage mqttConnectMessage); - - public abstract void publish(Channel channel, MqttPublishMessage mqttPublishMessage); - - public abstract void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage); - - public abstract void pong(Channel channel); - - public abstract void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage); - - public abstract void disconnect(Channel channel); - - public abstract void doTimeOut(Channel channel, IdleStateEvent evt); - -} +package com.myself.unclecatmyself.common.mqtts; + +import io.netty.channel.Channel; +import io.netty.handler.codec.mqtt.*; +import io.netty.handler.timeout.IdleStateEvent; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 抽象出服务端的事件 + **/ +public abstract class ServerMqttHandlerService implements MqttHandlerIntf { + + public abstract boolean login(Channel channel, MqttConnectMessage mqttConnectMessage); + + public abstract void publish(Channel channel, MqttPublishMessage mqttPublishMessage); + + public abstract void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage); + + public abstract void pong(Channel channel); + + public abstract void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage); + + public abstract void disconnect(Channel channel); + + public abstract void doTimeOut(Channel channel, IdleStateEvent evt); + +} diff --git a/src/main/java/com/myself/nettychat/common/pool/DefaultThreadFactory.java b/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java similarity index 94% rename from src/main/java/com/myself/nettychat/common/pool/DefaultThreadFactory.java rename to src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java index b6c776f..1396e08 100644 --- a/src/main/java/com/myself/nettychat/common/pool/DefaultThreadFactory.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java @@ -1,43 +1,43 @@ -package com.myself.nettychat.common.pool; - -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 线程池 - **/ -public class DefaultThreadFactory implements ThreadFactory { - - private static final AtomicInteger poolNumber = new AtomicInteger(1); - private final ThreadGroup threadGroup; - private final AtomicInteger currentThreadNumber = new AtomicInteger(1); - private final String namePrefix; - private int priority = Thread.NORM_PRIORITY; - private boolean isDaemon = false; - - public DefaultThreadFactory(String prefix) { - this(prefix, false); - } - - public DefaultThreadFactory(String prefix, boolean isDaemon) { - this(prefix, isDaemon, Thread.NORM_PRIORITY); - } - - public DefaultThreadFactory(String prefix, boolean isDaemon, int priority) { - SecurityManager s = System.getSecurityManager(); - this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); - this.namePrefix = prefix + "-" + poolNumber.getAndIncrement() + "-thread-"; - this.isDaemon = isDaemon; - this.priority = priority; - } - - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(threadGroup, r, namePrefix + currentThreadNumber.getAndIncrement(), 0); - thread.setDaemon(isDaemon); - thread.setPriority(priority); - return thread; - } -} +package com.myself.unclecatmyself.common.pool; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 线程池 + **/ +public class DefaultThreadFactory implements ThreadFactory { + + private static final AtomicInteger poolNumber = new AtomicInteger(1); + private final ThreadGroup threadGroup; + private final AtomicInteger currentThreadNumber = new AtomicInteger(1); + private final String namePrefix; + private int priority = Thread.NORM_PRIORITY; + private boolean isDaemon = false; + + public DefaultThreadFactory(String prefix) { + this(prefix, false); + } + + public DefaultThreadFactory(String prefix, boolean isDaemon) { + this(prefix, isDaemon, Thread.NORM_PRIORITY); + } + + public DefaultThreadFactory(String prefix, boolean isDaemon, int priority) { + SecurityManager s = System.getSecurityManager(); + this.threadGroup = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup(); + this.namePrefix = prefix + "-" + poolNumber.getAndIncrement() + "-thread-"; + this.isDaemon = isDaemon; + this.priority = priority; + } + + @Override + public Thread newThread(Runnable r) { + Thread thread = new Thread(threadGroup, r, namePrefix + currentThreadNumber.getAndIncrement(), 0); + thread.setDaemon(isDaemon); + thread.setPriority(priority); + return thread; + } +} diff --git a/src/main/java/com/myself/nettychat/common/pool/ExecutorQueue.java b/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java similarity index 95% rename from src/main/java/com/myself/nettychat/common/pool/ExecutorQueue.java rename to src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java index 0217bc1..4dd8ba3 100644 --- a/src/main/java/com/myself/nettychat/common/pool/ExecutorQueue.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java @@ -1,57 +1,57 @@ -package com.myself.nettychat.common.pool; - -import java.util.concurrent.LinkedTransferQueue; -import java.util.concurrent.RejectedExecutionException; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc LinkedTransferQueue 能保证更高性能,相比与LinkedBlockingQueue有明显提升 - * 不过LinkedTransferQueue的缺点是没有队列长度控制,需要在外层协助控制 - **/ -public class ExecutorQueue extends LinkedTransferQueue { - - private static final long serialVersionUID = -265236426751004839L; - - private StandardThreadExecutor threadPoolExecutor; - - public ExecutorQueue() { - super(); - } - - public void setStandardThreadExecutor(StandardThreadExecutor threadPoolExecutor) { - this.threadPoolExecutor = threadPoolExecutor; - } - - // 注:代码来源于 tomcat - public boolean force(Runnable o) { - if (threadPoolExecutor.isShutdown()) { - throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); - } - // forces the item onto the queue, to be used if the task is rejected - return super.offer(o); - } - - // 注:tomcat的代码进行一些小变更 - public boolean offer(Runnable o) { - int poolSize = threadPoolExecutor.getPoolSize(); - - // we are maxed out on threads, simply queue the object - if (poolSize == threadPoolExecutor.getMaximumPoolSize()) { - return super.offer(o); - } - // we have idle threads, just add it to the queue - // note that we don't use getActiveCount(), see BZ 49730 - if (poolSize >= threadPoolExecutor.getSubmittedTasksCount()) { - return super.offer(o); - } - // if we have less threads than maximum force creation of a new - // thread - if (poolSize < threadPoolExecutor.getMaximumPoolSize()) { - return false; - } - // if we reached here, we need to add it to the queue - return super.offer(o); - } - -} +package com.myself.unclecatmyself.common.pool; + +import java.util.concurrent.LinkedTransferQueue; +import java.util.concurrent.RejectedExecutionException; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc LinkedTransferQueue 能保证更高性能,相比与LinkedBlockingQueue有明显提升 + * 不过LinkedTransferQueue的缺点是没有队列长度控制,需要在外层协助控制 + **/ +public class ExecutorQueue extends LinkedTransferQueue { + + private static final long serialVersionUID = -265236426751004839L; + + private StandardThreadExecutor threadPoolExecutor; + + public ExecutorQueue() { + super(); + } + + public void setStandardThreadExecutor(StandardThreadExecutor threadPoolExecutor) { + this.threadPoolExecutor = threadPoolExecutor; + } + + // 注:代码来源于 tomcat + public boolean force(Runnable o) { + if (threadPoolExecutor.isShutdown()) { + throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); + } + // forces the item onto the queue, to be used if the task is rejected + return super.offer(o); + } + + // 注:tomcat的代码进行一些小变更 + public boolean offer(Runnable o) { + int poolSize = threadPoolExecutor.getPoolSize(); + + // we are maxed out on threads, simply queue the object + if (poolSize == threadPoolExecutor.getMaximumPoolSize()) { + return super.offer(o); + } + // we have idle threads, just add it to the queue + // note that we don't use getActiveCount(), see BZ 49730 + if (poolSize >= threadPoolExecutor.getSubmittedTasksCount()) { + return super.offer(o); + } + // if we have less threads than maximum force creation of a new + // thread + if (poolSize < threadPoolExecutor.getMaximumPoolSize()) { + return false; + } + // if we reached here, we need to add it to the queue + return super.offer(o); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/pool/Scheduled.java b/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java similarity index 79% rename from src/main/java/com/myself/nettychat/common/pool/Scheduled.java rename to src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java index f3711ca..7b9e1f6 100644 --- a/src/main/java/com/myself/nettychat/common/pool/Scheduled.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java @@ -1,15 +1,15 @@ -package com.myself.nettychat.common.pool; - -import java.util.concurrent.ScheduledFuture; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 接口 - **/ -@FunctionalInterface -public interface Scheduled { - - ScheduledFuture submit(Runnable runnable); - -} +package com.myself.unclecatmyself.common.pool; + +import java.util.concurrent.ScheduledFuture; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 接口 + **/ +@FunctionalInterface +public interface Scheduled { + + ScheduledFuture submit(Runnable runnable); + +} diff --git a/src/main/java/com/myself/nettychat/common/pool/StandardThreadExecutor.java b/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java similarity index 96% rename from src/main/java/com/myself/nettychat/common/pool/StandardThreadExecutor.java rename to src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java index 8172d49..75d1129 100644 --- a/src/main/java/com/myself/nettychat/common/pool/StandardThreadExecutor.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java @@ -1,100 +1,100 @@ -package com.myself.nettychat.common.pool; - -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 代码和思路主要来自于: - * tomcat: org.apache.catalina.core.StandardThreadExecutor - * - * java.util.concurrent.threadPoolExecutor execute执行策略: - * 优先offer到queue,queue满后再扩充线程到maxThread,如果已经到了maxThread就reject - * 比较适合于CPU密集型应用(比如runnable内部执行的操作都在JVM内部,memory copy, or compute等等) - * - * StandardThreadExecutor execute执行策略: - * 优先扩充线程到maxThread,再offer到queue,如果满了就reject - * 比较适合于业务处理需要远程资源的场景 - **/ -public class StandardThreadExecutor extends ThreadPoolExecutor { - - public static final int DEFAULT_MIN_THREADS = 20; - public static final int DEFAULT_MAX_THREADS = 200; - public static final int DEFAULT_MAX_IDLE_TIME = 60000; // 1 minutes - - protected AtomicInteger submittedTasksCount; // 正在处理的任务数 - private int maxSubmittedTaskCount; // 最大允许同时处理的任务数 - - public StandardThreadExecutor() { - this(DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS); - } - - public StandardThreadExecutor(int coreThread, int maxThreads) { - this(coreThread, maxThreads, maxThreads); - } - - public StandardThreadExecutor(int coreThread, int maxThreads, long keepAliveTime, TimeUnit unit) { - this(coreThread, maxThreads, keepAliveTime, unit, maxThreads); - } - - public StandardThreadExecutor(int coreThreads, int maxThreads, int queueCapacity) { - this(coreThreads, maxThreads, queueCapacity, Executors.defaultThreadFactory()); - } - - public StandardThreadExecutor(int coreThreads, int maxThreads, int queueCapacity, ThreadFactory threadFactory) { - this(coreThreads, maxThreads, DEFAULT_MAX_IDLE_TIME, TimeUnit.MILLISECONDS, queueCapacity, threadFactory); - } - - public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, int queueCapacity) { - this(coreThreads, maxThreads, keepAliveTime, unit, queueCapacity, Executors.defaultThreadFactory()); - } - - public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, - int queueCapacity, ThreadFactory threadFactory) { - this(coreThreads, maxThreads, keepAliveTime, unit, queueCapacity, threadFactory, new AbortPolicy()); - } - - public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, - int queueCapacity, ThreadFactory threadFactory, RejectedExecutionHandler handler) { - super(coreThreads, maxThreads, keepAliveTime, unit, new ExecutorQueue(), threadFactory, handler); - ((ExecutorQueue) getQueue()).setStandardThreadExecutor(this); - - submittedTasksCount = new AtomicInteger(0); - - // 最大并发任务限制: 队列buffer数 + 最大线程数 - maxSubmittedTaskCount = queueCapacity + maxThreads; - } - - @Override - public void execute(Runnable command) { - int count = submittedTasksCount.incrementAndGet(); - - // 超过最大的并发任务限制,进行 reject - // 依赖的LinkedTransferQueue没有长度限制,因此这里进行控制 - if (count > maxSubmittedTaskCount) { - submittedTasksCount.decrementAndGet(); - getRejectedExecutionHandler().rejectedExecution(command, this); - } - - try { - super.execute(command); - } catch (RejectedExecutionException rx) { - // there could have been contention around the queue - if (!((ExecutorQueue) getQueue()).force(command)) { - submittedTasksCount.decrementAndGet(); - getRejectedExecutionHandler().rejectedExecution(command, this); - } - rx.printStackTrace(); - } - } - - public int getSubmittedTasksCount() { - return this.submittedTasksCount.get(); - } - - - protected void afterExecute(Runnable r, Throwable t) { - submittedTasksCount.decrementAndGet(); - } -} +package com.myself.unclecatmyself.common.pool; + +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 代码和思路主要来自于: + * tomcat: org.apache.catalina.core.StandardThreadExecutor + * + * java.util.concurrent.threadPoolExecutor execute执行策略: + * 优先offer到queue,queue满后再扩充线程到maxThread,如果已经到了maxThread就reject + * 比较适合于CPU密集型应用(比如runnable内部执行的操作都在JVM内部,memory copy, or compute等等) + * + * StandardThreadExecutor execute执行策略: + * 优先扩充线程到maxThread,再offer到queue,如果满了就reject + * 比较适合于业务处理需要远程资源的场景 + **/ +public class StandardThreadExecutor extends ThreadPoolExecutor { + + public static final int DEFAULT_MIN_THREADS = 20; + public static final int DEFAULT_MAX_THREADS = 200; + public static final int DEFAULT_MAX_IDLE_TIME = 60000; // 1 minutes + + protected AtomicInteger submittedTasksCount; // 正在处理的任务数 + private int maxSubmittedTaskCount; // 最大允许同时处理的任务数 + + public StandardThreadExecutor() { + this(DEFAULT_MIN_THREADS, DEFAULT_MAX_THREADS); + } + + public StandardThreadExecutor(int coreThread, int maxThreads) { + this(coreThread, maxThreads, maxThreads); + } + + public StandardThreadExecutor(int coreThread, int maxThreads, long keepAliveTime, TimeUnit unit) { + this(coreThread, maxThreads, keepAliveTime, unit, maxThreads); + } + + public StandardThreadExecutor(int coreThreads, int maxThreads, int queueCapacity) { + this(coreThreads, maxThreads, queueCapacity, Executors.defaultThreadFactory()); + } + + public StandardThreadExecutor(int coreThreads, int maxThreads, int queueCapacity, ThreadFactory threadFactory) { + this(coreThreads, maxThreads, DEFAULT_MAX_IDLE_TIME, TimeUnit.MILLISECONDS, queueCapacity, threadFactory); + } + + public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, int queueCapacity) { + this(coreThreads, maxThreads, keepAliveTime, unit, queueCapacity, Executors.defaultThreadFactory()); + } + + public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, + int queueCapacity, ThreadFactory threadFactory) { + this(coreThreads, maxThreads, keepAliveTime, unit, queueCapacity, threadFactory, new AbortPolicy()); + } + + public StandardThreadExecutor(int coreThreads, int maxThreads, long keepAliveTime, TimeUnit unit, + int queueCapacity, ThreadFactory threadFactory, RejectedExecutionHandler handler) { + super(coreThreads, maxThreads, keepAliveTime, unit, new ExecutorQueue(), threadFactory, handler); + ((ExecutorQueue) getQueue()).setStandardThreadExecutor(this); + + submittedTasksCount = new AtomicInteger(0); + + // 最大并发任务限制: 队列buffer数 + 最大线程数 + maxSubmittedTaskCount = queueCapacity + maxThreads; + } + + @Override + public void execute(Runnable command) { + int count = submittedTasksCount.incrementAndGet(); + + // 超过最大的并发任务限制,进行 reject + // 依赖的LinkedTransferQueue没有长度限制,因此这里进行控制 + if (count > maxSubmittedTaskCount) { + submittedTasksCount.decrementAndGet(); + getRejectedExecutionHandler().rejectedExecution(command, this); + } + + try { + super.execute(command); + } catch (RejectedExecutionException rx) { + // there could have been contention around the queue + if (!((ExecutorQueue) getQueue()).force(command)) { + submittedTasksCount.decrementAndGet(); + getRejectedExecutionHandler().rejectedExecution(command, this); + } + rx.printStackTrace(); + } + } + + public int getSubmittedTasksCount() { + return this.submittedTasksCount.get(); + } + + + protected void afterExecute(Runnable r, Throwable t) { + submittedTasksCount.decrementAndGet(); + } +} diff --git a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java similarity index 77% rename from src/main/java/com/myself/nettychat/common/properties/InitNetty.java rename to src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java index ff57529..7fd3b02 100644 --- a/src/main/java/com/myself/nettychat/common/properties/InitNetty.java +++ b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java @@ -1,51 +1,49 @@ -package com.myself.nettychat.common.properties; - -import com.myself.nettychat.common.websockets.WebSocketHandler; -import lombok.Builder; -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 10:54 2018\8\14 0014 - */ -@Data -@ConfigurationProperties(prefix = "inchat") -public class InitNetty { - - private int webport; - - private int bossThread; - - private int workerThread; - - private boolean keepalive; - - private int backlog; - - private boolean nodelay; - - private boolean reuseaddr; - - private int sndbuf; - - private int revbuf; - - private int heart; - - private int period; - - private String serverName; - - private int initalDelay; - - private int maxContext; - - private String webSocketPath; - - private Class webSocketHandler; - -} +package com.myself.unclecatmyself.common.properties; + +import com.myself.unclecatmyself.common.websockets.WebSocketHandler; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 10:54 2018\8\14 0014 + */ +@Data +@ConfigurationProperties(prefix = "inchat") +public class InitNetty { + + private int webport; + + private int bossThread; + + private int workerThread; + + private boolean keepalive; + + private int backlog; + + private boolean nodelay; + + private boolean reuseaddr; + + private int sndbuf; + + private int revbuf; + + private int heart; + + private int period; + + private String serverName; + + private int initalDelay; + + private int maxContext; + + private String webSocketPath; + + private Class webSocketHandler; + +} diff --git a/src/main/java/com/myself/nettychat/common/ssl/SecureSocketKeyStore.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java similarity index 98% rename from src/main/java/com/myself/nettychat/common/ssl/SecureSocketKeyStore.java rename to src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java index 3bae691..bdded08 100644 --- a/src/main/java/com/myself/nettychat/common/ssl/SecureSocketKeyStore.java +++ b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java @@ -1,456 +1,456 @@ -package com.myself.nettychat.common.ssl; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.security.KeyStore; - -/** - * A bogus key store which provides all the required information to create an - * example SSL connection. - * - * To generate a bogus key store: - * - *
- * keytool -genkey -alias securesocket \ -keysize 2048 -validity 36500 \  -keyalg RSA -dname "CN=securesocket" \   -keypass inc0rrect -storepass mu$tch8ng3 \  -keystore cert.jks
- *
- *
- *
- *
- * 
- */ -public class SecureSocketKeyStore { - - private static final byte[] CERT_BYTES = { (byte) 254, (byte) 237, - (byte) 254, (byte) 237, (byte) 0, (byte) 0, (byte) 0, (byte) 2, - (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, (byte) 0, - (byte) 0, (byte) 1, (byte) 0, (byte) 12, (byte) 115, (byte) 101, - (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, - (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, - (byte) 0, (byte) 0, (byte) 1, (byte) 69, (byte) 231, (byte) 201, - (byte) 156, (byte) 140, (byte) 0, (byte) 0, (byte) 5, (byte) 0, - (byte) 48, (byte) 130, (byte) 4, (byte) 252, (byte) 48, (byte) 14, - (byte) 6, (byte) 10, (byte) 43, (byte) 6, (byte) 1, (byte) 4, - (byte) 1, (byte) 42, (byte) 2, (byte) 17, (byte) 1, (byte) 1, - (byte) 5, (byte) 0, (byte) 4, (byte) 130, (byte) 4, (byte) 232, - (byte) 221, (byte) 18, (byte) 203, (byte) 171, (byte) 175, - (byte) 82, (byte) 132, (byte) 227, (byte) 115, (byte) 143, - (byte) 38, (byte) 191, (byte) 42, (byte) 202, (byte) 130, - (byte) 171, (byte) 75, (byte) 6, (byte) 161, (byte) 120, - (byte) 204, (byte) 61, (byte) 106, (byte) 160, (byte) 81, (byte) 9, - (byte) 204, (byte) 153, (byte) 166, (byte) 38, (byte) 246, - (byte) 13, (byte) 43, (byte) 19, (byte) 100, (byte) 132, (byte) 45, - (byte) 90, (byte) 143, (byte) 1, (byte) 231, (byte) 182, (byte) 89, - (byte) 228, (byte) 183, (byte) 17, (byte) 95, (byte) 129, - (byte) 229, (byte) 42, (byte) 182, (byte) 126, (byte) 114, - (byte) 76, (byte) 124, (byte) 123, (byte) 246, (byte) 152, - (byte) 0, (byte) 141, (byte) 212, (byte) 111, (byte) 52, - (byte) 243, (byte) 112, (byte) 31, (byte) 117, (byte) 124, - (byte) 142, (byte) 24, (byte) 59, (byte) 198, (byte) 164, - (byte) 253, (byte) 21, (byte) 177, (byte) 189, (byte) 74, - (byte) 218, (byte) 110, (byte) 83, (byte) 154, (byte) 49, - (byte) 186, (byte) 159, (byte) 173, (byte) 202, (byte) 94, - (byte) 174, (byte) 183, (byte) 223, (byte) 119, (byte) 109, - (byte) 110, (byte) 72, (byte) 93, (byte) 208, (byte) 195, - (byte) 19, (byte) 89, (byte) 33, (byte) 34, (byte) 186, (byte) 12, - (byte) 86, (byte) 156, (byte) 156, (byte) 210, (byte) 111, - (byte) 110, (byte) 44, (byte) 106, (byte) 36, (byte) 67, - (byte) 168, (byte) 7, (byte) 179, (byte) 244, (byte) 53, - (byte) 134, (byte) 10, (byte) 86, (byte) 179, (byte) 34, (byte) 60, - (byte) 184, (byte) 179, (byte) 162, (byte) 69, (byte) 24, - (byte) 168, (byte) 100, (byte) 183, (byte) 206, (byte) 64, - (byte) 4, (byte) 32, (byte) 66, (byte) 237, (byte) 228, (byte) 92, - (byte) 6, (byte) 213, (byte) 141, (byte) 147, (byte) 198, - (byte) 141, (byte) 216, (byte) 41, (byte) 0, (byte) 101, (byte) 65, - (byte) 41, (byte) 185, (byte) 128, (byte) 229, (byte) 107, - (byte) 25, (byte) 89, (byte) 148, (byte) 16, (byte) 194, - (byte) 101, (byte) 100, (byte) 243, (byte) 147, (byte) 77, - (byte) 230, (byte) 11, (byte) 151, (byte) 99, (byte) 124, - (byte) 55, (byte) 195, (byte) 185, (byte) 30, (byte) 234, - (byte) 83, (byte) 61, (byte) 109, (byte) 131, (byte) 156, - (byte) 244, (byte) 133, (byte) 66, (byte) 39, (byte) 153, (byte) 9, - (byte) 34, (byte) 218, (byte) 201, (byte) 143, (byte) 190, - (byte) 127, (byte) 119, (byte) 102, (byte) 6, (byte) 83, - (byte) 134, (byte) 96, (byte) 170, (byte) 79, (byte) 196, - (byte) 214, (byte) 47, (byte) 215, (byte) 37, (byte) 250, - (byte) 64, (byte) 8, (byte) 165, (byte) 203, (byte) 44, (byte) 53, - (byte) 113, (byte) 147, (byte) 251, (byte) 29, (byte) 26, - (byte) 38, (byte) 193, (byte) 11, (byte) 223, (byte) 212, - (byte) 114, (byte) 96, (byte) 162, (byte) 39, (byte) 48, - (byte) 200, (byte) 172, (byte) 182, (byte) 254, (byte) 180, - (byte) 198, (byte) 11, (byte) 128, (byte) 75, (byte) 74, (byte) 93, - (byte) 226, (byte) 157, (byte) 80, (byte) 14, (byte) 9, (byte) 217, - (byte) 236, (byte) 205, (byte) 153, (byte) 35, (byte) 242, - (byte) 130, (byte) 140, (byte) 25, (byte) 16, (byte) 156, - (byte) 247, (byte) 230, (byte) 5, (byte) 247, (byte) 0, (byte) 34, - (byte) 196, (byte) 15, (byte) 118, (byte) 255, (byte) 185, - (byte) 199, (byte) 59, (byte) 99, (byte) 27, (byte) 187, (byte) 83, - (byte) 81, (byte) 12, (byte) 71, (byte) 69, (byte) 127, (byte) 130, - (byte) 164, (byte) 97, (byte) 195, (byte) 216, (byte) 215, - (byte) 61, (byte) 29, (byte) 196, (byte) 62, (byte) 160, - (byte) 188, (byte) 209, (byte) 173, (byte) 230, (byte) 0, - (byte) 204, (byte) 225, (byte) 1, (byte) 5, (byte) 42, (byte) 223, - (byte) 232, (byte) 187, (byte) 190, (byte) 67, (byte) 126, - (byte) 235, (byte) 178, (byte) 218, (byte) 179, (byte) 46, - (byte) 186, (byte) 156, (byte) 186, (byte) 6, (byte) 191, - (byte) 68, (byte) 239, (byte) 31, (byte) 16, (byte) 204, (byte) 24, - (byte) 68, (byte) 164, (byte) 88, (byte) 10, (byte) 174, (byte) 26, - (byte) 54, (byte) 187, (byte) 149, (byte) 132, (byte) 128, - (byte) 173, (byte) 165, (byte) 8, (byte) 69, (byte) 96, (byte) 49, - (byte) 57, (byte) 223, (byte) 110, (byte) 29, (byte) 215, - (byte) 98, (byte) 42, (byte) 15, (byte) 153, (byte) 228, - (byte) 216, (byte) 61, (byte) 160, (byte) 230, (byte) 34, - (byte) 40, (byte) 232, (byte) 136, (byte) 139, (byte) 140, - (byte) 236, (byte) 251, (byte) 119, (byte) 242, (byte) 199, - (byte) 167, (byte) 61, (byte) 141, (byte) 89, (byte) 29, (byte) 82, - (byte) 114, (byte) 229, (byte) 198, (byte) 27, (byte) 133, - (byte) 87, (byte) 0, (byte) 53, (byte) 69, (byte) 42, (byte) 91, - (byte) 174, (byte) 82, (byte) 244, (byte) 160, (byte) 82, - (byte) 142, (byte) 221, (byte) 106, (byte) 151, (byte) 241, - (byte) 214, (byte) 64, (byte) 14, (byte) 28, (byte) 2, (byte) 3, - (byte) 145, (byte) 143, (byte) 18, (byte) 165, (byte) 247, - (byte) 178, (byte) 211, (byte) 16, (byte) 222, (byte) 76, - (byte) 60, (byte) 119, (byte) 130, (byte) 199, (byte) 230, - (byte) 229, (byte) 3, (byte) 22, (byte) 100, (byte) 135, - (byte) 103, (byte) 60, (byte) 181, (byte) 191, (byte) 56, - (byte) 249, (byte) 181, (byte) 169, (byte) 210, (byte) 25, - (byte) 152, (byte) 201, (byte) 226, (byte) 119, (byte) 71, - (byte) 204, (byte) 70, (byte) 220, (byte) 103, (byte) 46, - (byte) 166, (byte) 125, (byte) 40, (byte) 86, (byte) 208, - (byte) 114, (byte) 138, (byte) 24, (byte) 27, (byte) 219, - (byte) 123, (byte) 161, (byte) 52, (byte) 14, (byte) 38, - (byte) 244, (byte) 112, (byte) 238, (byte) 121, (byte) 90, - (byte) 34, (byte) 157, (byte) 131, (byte) 53, (byte) 245, - (byte) 162, (byte) 89, (byte) 188, (byte) 6, (byte) 202, - (byte) 164, (byte) 130, (byte) 34, (byte) 232, (byte) 74, - (byte) 45, (byte) 137, (byte) 164, (byte) 200, (byte) 197, - (byte) 247, (byte) 64, (byte) 110, (byte) 122, (byte) 49, - (byte) 116, (byte) 137, (byte) 253, (byte) 170, (byte) 232, - (byte) 120, (byte) 26, (byte) 171, (byte) 228, (byte) 229, - (byte) 49, (byte) 56, (byte) 56, (byte) 106, (byte) 110, (byte) 12, - (byte) 109, (byte) 93, (byte) 105, (byte) 241, (byte) 196, - (byte) 11, (byte) 18, (byte) 89, (byte) 108, (byte) 146, - (byte) 224, (byte) 161, (byte) 181, (byte) 236, (byte) 74, - (byte) 128, (byte) 24, (byte) 239, (byte) 22, (byte) 146, (byte) 0, - (byte) 69, (byte) 182, (byte) 246, (byte) 43, (byte) 59, - (byte) 208, (byte) 33, (byte) 48, (byte) 81, (byte) 0, (byte) 70, - (byte) 225, (byte) 222, (byte) 122, (byte) 178, (byte) 138, - (byte) 12, (byte) 207, (byte) 233, (byte) 164, (byte) 13, - (byte) 176, (byte) 123, (byte) 95, (byte) 68, (byte) 238, - (byte) 134, (byte) 66, (byte) 95, (byte) 194, (byte) 192, - (byte) 225, (byte) 244, (byte) 14, (byte) 78, (byte) 53, - (byte) 189, (byte) 217, (byte) 229, (byte) 203, (byte) 192, - (byte) 34, (byte) 38, (byte) 169, (byte) 63, (byte) 239, - (byte) 128, (byte) 172, (byte) 143, (byte) 75, (byte) 7, - (byte) 237, (byte) 125, (byte) 179, (byte) 235, (byte) 229, - (byte) 98, (byte) 8, (byte) 211, (byte) 237, (byte) 116, (byte) 75, - (byte) 27, (byte) 211, (byte) 131, (byte) 245, (byte) 89, - (byte) 150, (byte) 35, (byte) 49, (byte) 207, (byte) 113, - (byte) 237, (byte) 114, (byte) 125, (byte) 134, (byte) 191, - (byte) 110, (byte) 30, (byte) 119, (byte) 131, (byte) 175, - (byte) 166, (byte) 201, (byte) 255, (byte) 200, (byte) 1, - (byte) 126, (byte) 163, (byte) 172, (byte) 52, (byte) 118, - (byte) 184, (byte) 221, (byte) 165, (byte) 167, (byte) 165, - (byte) 20, (byte) 135, (byte) 32, (byte) 222, (byte) 188, - (byte) 250, (byte) 64, (byte) 161, (byte) 67, (byte) 236, - (byte) 212, (byte) 131, (byte) 44, (byte) 32, (byte) 70, (byte) 0, - (byte) 24, (byte) 178, (byte) 83, (byte) 155, (byte) 145, - (byte) 136, (byte) 131, (byte) 120, (byte) 181, (byte) 164, - (byte) 155, (byte) 172, (byte) 41, (byte) 213, (byte) 164, - (byte) 98, (byte) 169, (byte) 152, (byte) 184, (byte) 170, - (byte) 107, (byte) 7, (byte) 21, (byte) 228, (byte) 175, - (byte) 192, (byte) 238, (byte) 68, (byte) 197, (byte) 119, - (byte) 228, (byte) 225, (byte) 156, (byte) 235, (byte) 241, - (byte) 172, (byte) 171, (byte) 236, (byte) 128, (byte) 78, - (byte) 117, (byte) 152, (byte) 123, (byte) 93, (byte) 156, - (byte) 57, (byte) 238, (byte) 211, (byte) 188, (byte) 47, - (byte) 62, (byte) 45, (byte) 127, (byte) 58, (byte) 38, (byte) 29, - (byte) 131, (byte) 95, (byte) 85, (byte) 149, (byte) 112, - (byte) 215, (byte) 207, (byte) 41, (byte) 201, (byte) 30, - (byte) 149, (byte) 73, (byte) 245, (byte) 179, (byte) 176, - (byte) 246, (byte) 203, (byte) 204, (byte) 252, (byte) 13, - (byte) 98, (byte) 151, (byte) 93, (byte) 87, (byte) 241, - (byte) 166, (byte) 46, (byte) 249, (byte) 148, (byte) 49, - (byte) 141, (byte) 136, (byte) 49, (byte) 77, (byte) 250, - (byte) 191, (byte) 157, (byte) 90, (byte) 84, (byte) 51, - (byte) 129, (byte) 133, (byte) 66, (byte) 253, (byte) 99, - (byte) 243, (byte) 34, (byte) 142, (byte) 197, (byte) 4, - (byte) 126, (byte) 7, (byte) 217, (byte) 126, (byte) 205, - (byte) 250, (byte) 141, (byte) 231, (byte) 225, (byte) 203, - (byte) 171, (byte) 246, (byte) 201, (byte) 48, (byte) 96, - (byte) 207, (byte) 74, (byte) 253, (byte) 120, (byte) 114, - (byte) 163, (byte) 192, (byte) 24, (byte) 12, (byte) 10, - (byte) 210, (byte) 94, (byte) 136, (byte) 152, (byte) 185, - (byte) 109, (byte) 87, (byte) 35, (byte) 159, (byte) 238, - (byte) 122, (byte) 200, (byte) 107, (byte) 103, (byte) 243, - (byte) 250, (byte) 152, (byte) 68, (byte) 66, (byte) 170, (byte) 0, - (byte) 134, (byte) 229, (byte) 168, (byte) 182, (byte) 30, - (byte) 89, (byte) 240, (byte) 121, (byte) 106, (byte) 148, - (byte) 142, (byte) 49, (byte) 242, (byte) 215, (byte) 233, - (byte) 57, (byte) 120, (byte) 204, (byte) 180, (byte) 239, - (byte) 199, (byte) 133, (byte) 255, (byte) 71, (byte) 3, - (byte) 132, (byte) 228, (byte) 110, (byte) 66, (byte) 227, - (byte) 122, (byte) 82, (byte) 118, (byte) 173, (byte) 218, - (byte) 54, (byte) 99, (byte) 167, (byte) 154, (byte) 3, (byte) 189, - (byte) 25, (byte) 123, (byte) 169, (byte) 42, (byte) 184, - (byte) 59, (byte) 36, (byte) 131, (byte) 206, (byte) 248, - (byte) 90, (byte) 32, (byte) 183, (byte) 86, (byte) 62, (byte) 149, - (byte) 107, (byte) 243, (byte) 71, (byte) 197, (byte) 124, - (byte) 155, (byte) 214, (byte) 91, (byte) 29, (byte) 81, (byte) 28, - (byte) 115, (byte) 98, (byte) 130, (byte) 184, (byte) 135, - (byte) 13, (byte) 191, (byte) 147, (byte) 43, (byte) 10, - (byte) 178, (byte) 99, (byte) 165, (byte) 210, (byte) 87, - (byte) 87, (byte) 148, (byte) 31, (byte) 198, (byte) 129, - (byte) 32, (byte) 181, (byte) 3, (byte) 144, (byte) 61, (byte) 5, - (byte) 166, (byte) 252, (byte) 73, (byte) 205, (byte) 230, - (byte) 178, (byte) 162, (byte) 46, (byte) 56, (byte) 99, (byte) 77, - (byte) 97, (byte) 236, (byte) 121, (byte) 157, (byte) 139, - (byte) 153, (byte) 217, (byte) 171, (byte) 19, (byte) 68, - (byte) 36, (byte) 14, (byte) 123, (byte) 249, (byte) 101, - (byte) 127, (byte) 184, (byte) 123, (byte) 7, (byte) 124, - (byte) 68, (byte) 98, (byte) 34, (byte) 139, (byte) 224, - (byte) 173, (byte) 246, (byte) 196, (byte) 180, (byte) 70, - (byte) 207, (byte) 168, (byte) 211, (byte) 255, (byte) 84, - (byte) 0, (byte) 174, (byte) 11, (byte) 160, (byte) 155, - (byte) 127, (byte) 228, (byte) 81, (byte) 226, (byte) 115, - (byte) 142, (byte) 200, (byte) 107, (byte) 4, (byte) 204, - (byte) 219, (byte) 192, (byte) 189, (byte) 56, (byte) 127, - (byte) 184, (byte) 187, (byte) 161, (byte) 106, (byte) 62, - (byte) 225, (byte) 211, (byte) 115, (byte) 30, (byte) 172, - (byte) 191, (byte) 66, (byte) 25, (byte) 66, (byte) 235, - (byte) 107, (byte) 41, (byte) 186, (byte) 40, (byte) 239, - (byte) 173, (byte) 11, (byte) 247, (byte) 89, (byte) 79, - (byte) 135, (byte) 86, (byte) 73, (byte) 77, (byte) 164, (byte) 34, - (byte) 109, (byte) 236, (byte) 56, (byte) 198, (byte) 141, - (byte) 87, (byte) 74, (byte) 172, (byte) 56, (byte) 24, (byte) 150, - (byte) 233, (byte) 233, (byte) 165, (byte) 122, (byte) 201, - (byte) 112, (byte) 232, (byte) 23, (byte) 12, (byte) 166, - (byte) 128, (byte) 114, (byte) 139, (byte) 207, (byte) 233, - (byte) 47, (byte) 220, (byte) 172, (byte) 175, (byte) 40, - (byte) 109, (byte) 82, (byte) 142, (byte) 130, (byte) 177, - (byte) 50, (byte) 127, (byte) 196, (byte) 106, (byte) 172, - (byte) 178, (byte) 71, (byte) 178, (byte) 204, (byte) 99, - (byte) 113, (byte) 33, (byte) 189, (byte) 188, (byte) 168, - (byte) 76, (byte) 92, (byte) 230, (byte) 211, (byte) 239, - (byte) 75, (byte) 71, (byte) 64, (byte) 197, (byte) 26, (byte) 222, - (byte) 19, (byte) 213, (byte) 161, (byte) 144, (byte) 20, - (byte) 126, (byte) 192, (byte) 156, (byte) 15, (byte) 113, - (byte) 64, (byte) 73, (byte) 7, (byte) 241, (byte) 217, (byte) 127, - (byte) 171, (byte) 199, (byte) 66, (byte) 32, (byte) 179, (byte) 4, - (byte) 181, (byte) 93, (byte) 121, (byte) 193, (byte) 10, - (byte) 169, (byte) 255, (byte) 152, (byte) 199, (byte) 95, - (byte) 177, (byte) 227, (byte) 135, (byte) 21, (byte) 64, - (byte) 203, (byte) 9, (byte) 79, (byte) 243, (byte) 114, (byte) 2, - (byte) 201, (byte) 157, (byte) 180, (byte) 52, (byte) 193, - (byte) 66, (byte) 34, (byte) 155, (byte) 52, (byte) 35, (byte) 93, - (byte) 31, (byte) 96, (byte) 77, (byte) 12, (byte) 80, (byte) 195, - (byte) 96, (byte) 247, (byte) 251, (byte) 237, (byte) 36, - (byte) 170, (byte) 7, (byte) 3, (byte) 251, (byte) 243, (byte) 47, - (byte) 180, (byte) 98, (byte) 207, (byte) 176, (byte) 106, - (byte) 237, (byte) 114, (byte) 91, (byte) 229, (byte) 56, - (byte) 94, (byte) 154, (byte) 32, (byte) 62, (byte) 240, - (byte) 132, (byte) 4, (byte) 144, (byte) 227, (byte) 140, - (byte) 137, (byte) 76, (byte) 15, (byte) 117, (byte) 82, - (byte) 223, (byte) 168, (byte) 135, (byte) 33, (byte) 91, - (byte) 173, (byte) 4, (byte) 245, (byte) 192, (byte) 95, - (byte) 135, (byte) 22, (byte) 138, (byte) 89, (byte) 1, (byte) 14, - (byte) 230, (byte) 143, (byte) 195, (byte) 93, (byte) 133, - (byte) 194, (byte) 252, (byte) 188, (byte) 31, (byte) 39, - (byte) 162, (byte) 59, (byte) 148, (byte) 219, (byte) 213, - (byte) 179, (byte) 195, (byte) 165, (byte) 67, (byte) 68, - (byte) 39, (byte) 178, (byte) 143, (byte) 192, (byte) 177, - (byte) 221, (byte) 236, (byte) 63, (byte) 40, (byte) 205, - (byte) 26, (byte) 81, (byte) 127, (byte) 5, (byte) 213, (byte) 192, - (byte) 22, (byte) 147, (byte) 98, (byte) 207, (byte) 153, (byte) 8, - (byte) 108, (byte) 75, (byte) 182, (byte) 148, (byte) 0, - (byte) 151, (byte) 15, (byte) 178, (byte) 98, (byte) 145, - (byte) 255, (byte) 213, (byte) 142, (byte) 63, (byte) 247, - (byte) 42, (byte) 161, (byte) 246, (byte) 21, (byte) 128, - (byte) 47, (byte) 248, (byte) 217, (byte) 70, (byte) 195, - (byte) 151, (byte) 236, (byte) 73, (byte) 153, (byte) 230, - (byte) 152, (byte) 217, (byte) 12, (byte) 189, (byte) 65, - (byte) 85, (byte) 189, (byte) 204, (byte) 212, (byte) 161, - (byte) 210, (byte) 217, (byte) 74, (byte) 75, (byte) 186, - (byte) 122, (byte) 167, (byte) 149, (byte) 178, (byte) 202, - (byte) 205, (byte) 246, (byte) 225, (byte) 225, (byte) 190, - (byte) 56, (byte) 42, (byte) 162, (byte) 215, (byte) 107, - (byte) 45, (byte) 121, (byte) 235, (byte) 195, (byte) 219, - (byte) 22, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, - (byte) 5, (byte) 88, (byte) 46, (byte) 53, (byte) 48, (byte) 57, - (byte) 0, (byte) 0, (byte) 2, (byte) 211, (byte) 48, (byte) 130, - (byte) 2, (byte) 207, (byte) 48, (byte) 130, (byte) 1, (byte) 183, - (byte) 160, (byte) 3, (byte) 2, (byte) 1, (byte) 2, (byte) 2, - (byte) 4, (byte) 58, (byte) 247, (byte) 71, (byte) 185, (byte) 48, - (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, - (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, - (byte) 5, (byte) 0, (byte) 48, (byte) 23, (byte) 49, (byte) 21, - (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, (byte) 4, - (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, (byte) 99, - (byte) 117, (byte) 114, (byte) 101, (byte) 115, (byte) 111, - (byte) 99, (byte) 107, (byte) 101, (byte) 116, (byte) 48, - (byte) 32, (byte) 23, (byte) 13, (byte) 49, (byte) 52, (byte) 48, - (byte) 53, (byte) 49, (byte) 48, (byte) 50, (byte) 48, (byte) 49, - (byte) 56, (byte) 52, (byte) 48, (byte) 90, (byte) 24, (byte) 15, - (byte) 50, (byte) 49, (byte) 49, (byte) 52, (byte) 48, (byte) 52, - (byte) 49, (byte) 54, (byte) 50, (byte) 48, (byte) 49, (byte) 56, - (byte) 52, (byte) 48, (byte) 90, (byte) 48, (byte) 23, (byte) 49, - (byte) 21, (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, - (byte) 4, (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, - (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, - (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, - (byte) 48, (byte) 130, (byte) 1, (byte) 34, (byte) 48, (byte) 13, - (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, (byte) 134, - (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 1, (byte) 5, - (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 15, (byte) 0, - (byte) 48, (byte) 130, (byte) 1, (byte) 10, (byte) 2, (byte) 130, - (byte) 1, (byte) 1, (byte) 0, (byte) 153, (byte) 113, (byte) 7, - (byte) 44, (byte) 219, (byte) 76, (byte) 101, (byte) 226, - (byte) 138, (byte) 96, (byte) 219, (byte) 60, (byte) 167, - (byte) 138, (byte) 222, (byte) 6, (byte) 78, (byte) 169, (byte) 64, - (byte) 188, (byte) 156, (byte) 190, (byte) 119, (byte) 16, - (byte) 34, (byte) 228, (byte) 250, (byte) 253, (byte) 119, - (byte) 75, (byte) 240, (byte) 60, (byte) 242, (byte) 52, - (byte) 137, (byte) 146, (byte) 20, (byte) 130, (byte) 202, - (byte) 226, (byte) 125, (byte) 19, (byte) 7, (byte) 34, (byte) 8, - (byte) 61, (byte) 243, (byte) 202, (byte) 225, (byte) 206, - (byte) 223, (byte) 53, (byte) 74, (byte) 56, (byte) 222, (byte) 47, - (byte) 99, (byte) 235, (byte) 57, (byte) 73, (byte) 90, (byte) 198, - (byte) 109, (byte) 104, (byte) 36, (byte) 255, (byte) 124, - (byte) 57, (byte) 155, (byte) 248, (byte) 120, (byte) 56, - (byte) 56, (byte) 38, (byte) 41, (byte) 216, (byte) 1, (byte) 216, - (byte) 216, (byte) 100, (byte) 239, (byte) 79, (byte) 222, - (byte) 34, (byte) 21, (byte) 182, (byte) 112, (byte) 136, - (byte) 137, (byte) 16, (byte) 141, (byte) 15, (byte) 83, (byte) 94, - (byte) 245, (byte) 36, (byte) 203, (byte) 178, (byte) 137, - (byte) 159, (byte) 86, (byte) 220, (byte) 253, (byte) 112, - (byte) 200, (byte) 50, (byte) 135, (byte) 215, (byte) 190, - (byte) 21, (byte) 186, (byte) 84, (byte) 21, (byte) 96, (byte) 126, - (byte) 253, (byte) 115, (byte) 209, (byte) 241, (byte) 94, - (byte) 115, (byte) 219, (byte) 0, (byte) 25, (byte) 253, - (byte) 209, (byte) 182, (byte) 118, (byte) 230, (byte) 10, - (byte) 50, (byte) 131, (byte) 39, (byte) 249, (byte) 136, - (byte) 11, (byte) 101, (byte) 192, (byte) 12, (byte) 210, - (byte) 179, (byte) 237, (byte) 213, (byte) 68, (byte) 101, - (byte) 58, (byte) 187, (byte) 255, (byte) 240, (byte) 164, - (byte) 147, (byte) 72, (byte) 148, (byte) 227, (byte) 155, - (byte) 88, (byte) 250, (byte) 101, (byte) 253, (byte) 87, - (byte) 140, (byte) 168, (byte) 39, (byte) 163, (byte) 133, - (byte) 150, (byte) 252, (byte) 226, (byte) 234, (byte) 52, - (byte) 88, (byte) 40, (byte) 56, (byte) 23, (byte) 105, (byte) 236, - (byte) 4, (byte) 113, (byte) 98, (byte) 4, (byte) 0, (byte) 117, - (byte) 59, (byte) 77, (byte) 236, (byte) 135, (byte) 93, (byte) 54, - (byte) 30, (byte) 6, (byte) 126, (byte) 90, (byte) 15, (byte) 105, - (byte) 89, (byte) 216, (byte) 154, (byte) 72, (byte) 134, - (byte) 209, (byte) 74, (byte) 197, (byte) 237, (byte) 51, - (byte) 37, (byte) 33, (byte) 106, (byte) 50, (byte) 71, (byte) 134, - (byte) 169, (byte) 173, (byte) 88, (byte) 111, (byte) 217, - (byte) 117, (byte) 184, (byte) 97, (byte) 1, (byte) 38, (byte) 76, - (byte) 112, (byte) 170, (byte) 190, (byte) 250, (byte) 96, - (byte) 17, (byte) 45, (byte) 117, (byte) 183, (byte) 82, - (byte) 155, (byte) 10, (byte) 53, (byte) 15, (byte) 214, (byte) 36, - (byte) 134, (byte) 249, (byte) 146, (byte) 98, (byte) 99, - (byte) 64, (byte) 158, (byte) 99, (byte) 227, (byte) 21, (byte) 92, - (byte) 98, (byte) 90, (byte) 202, (byte) 214, (byte) 134, - (byte) 233, (byte) 212, (byte) 149, (byte) 2, (byte) 3, (byte) 1, - (byte) 0, (byte) 1, (byte) 163, (byte) 33, (byte) 48, (byte) 31, - (byte) 48, (byte) 29, (byte) 6, (byte) 3, (byte) 85, (byte) 29, - (byte) 14, (byte) 4, (byte) 22, (byte) 4, (byte) 20, (byte) 115, - (byte) 110, (byte) 177, (byte) 165, (byte) 41, (byte) 26, - (byte) 142, (byte) 198, (byte) 221, (byte) 63, (byte) 79, - (byte) 252, (byte) 219, (byte) 159, (byte) 68, (byte) 102, - (byte) 76, (byte) 153, (byte) 128, (byte) 164, (byte) 48, - (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, - (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, - (byte) 5, (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 1, - (byte) 0, (byte) 118, (byte) 55, (byte) 245, (byte) 122, - (byte) 159, (byte) 155, (byte) 98, (byte) 122, (byte) 229, - (byte) 186, (byte) 23, (byte) 207, (byte) 109, (byte) 225, - (byte) 220, (byte) 74, (byte) 51, (byte) 218, (byte) 10, - (byte) 115, (byte) 137, (byte) 103, (byte) 127, (byte) 28, - (byte) 30, (byte) 184, (byte) 149, (byte) 249, (byte) 193, - (byte) 206, (byte) 208, (byte) 181, (byte) 191, (byte) 128, - (byte) 18, (byte) 208, (byte) 24, (byte) 132, (byte) 147, - (byte) 184, (byte) 198, (byte) 82, (byte) 204, (byte) 183, - (byte) 127, (byte) 87, (byte) 234, (byte) 136, (byte) 197, - (byte) 34, (byte) 232, (byte) 124, (byte) 210, (byte) 2, - (byte) 192, (byte) 69, (byte) 246, (byte) 25, (byte) 232, - (byte) 162, (byte) 0, (byte) 157, (byte) 216, (byte) 194, - (byte) 26, (byte) 207, (byte) 225, (byte) 169, (byte) 59, - (byte) 246, (byte) 52, (byte) 51, (byte) 150, (byte) 210, - (byte) 50, (byte) 118, (byte) 58, (byte) 154, (byte) 45, - (byte) 128, (byte) 138, (byte) 47, (byte) 174, (byte) 83, - (byte) 117, (byte) 18, (byte) 224, (byte) 9, (byte) 146, - (byte) 180, (byte) 178, (byte) 22, (byte) 76, (byte) 82, - (byte) 229, (byte) 16, (byte) 150, (byte) 127, (byte) 13, - (byte) 122, (byte) 218, (byte) 159, (byte) 195, (byte) 232, - (byte) 168, (byte) 206, (byte) 105, (byte) 82, (byte) 37, - (byte) 252, (byte) 186, (byte) 223, (byte) 222, (byte) 7, - (byte) 106, (byte) 87, (byte) 218, (byte) 89, (byte) 22, - (byte) 252, (byte) 7, (byte) 177, (byte) 52, (byte) 180, (byte) 9, - (byte) 16, (byte) 29, (byte) 57, (byte) 192, (byte) 209, - (byte) 225, (byte) 155, (byte) 16, (byte) 219, (byte) 38, - (byte) 90, (byte) 174, (byte) 152, (byte) 140, (byte) 252, - (byte) 114, (byte) 133, (byte) 106, (byte) 24, (byte) 107, - (byte) 227, (byte) 80, (byte) 166, (byte) 63, (byte) 47, (byte) 16, - (byte) 15, (byte) 89, (byte) 242, (byte) 19, (byte) 87, (byte) 193, - (byte) 250, (byte) 222, (byte) 223, (byte) 183, (byte) 61, - (byte) 91, (byte) 17, (byte) 92, (byte) 35, (byte) 142, (byte) 44, - (byte) 153, (byte) 135, (byte) 86, (byte) 97, (byte) 70, - (byte) 205, (byte) 38, (byte) 192, (byte) 18, (byte) 244, - (byte) 61, (byte) 46, (byte) 21, (byte) 145, (byte) 99, (byte) 72, - (byte) 142, (byte) 37, (byte) 19, (byte) 219, (byte) 167, - (byte) 62, (byte) 71, (byte) 197, (byte) 86, (byte) 152, - (byte) 139, (byte) 122, (byte) 231, (byte) 122, (byte) 206, - (byte) 42, (byte) 142, (byte) 164, (byte) 237, (byte) 19, - (byte) 60, (byte) 95, (byte) 239, (byte) 191, (byte) 64, - (byte) 188, (byte) 94, (byte) 154, (byte) 199, (byte) 252, - (byte) 62, (byte) 26, (byte) 181, (byte) 194, (byte) 141, - (byte) 13, (byte) 1, (byte) 112, (byte) 161, (byte) 195, - (byte) 149, (byte) 116, (byte) 57, (byte) 118, (byte) 114, - (byte) 248, (byte) 235, (byte) 54, (byte) 229, (byte) 48, - (byte) 53, (byte) 30, (byte) 145, (byte) 199, (byte) 207, - (byte) 49, (byte) 175, (byte) 44, (byte) 172, (byte) 120, - (byte) 254, (byte) 181, (byte) 100, (byte) 113, (byte) 191, - (byte) 64, (byte) 131, (byte) 125, (byte) 80, (byte) 180, - (byte) 229, (byte) 109, (byte) 97, (byte) 8, (byte) 166, - (byte) 155, (byte) 72, (byte) 252, (byte) 84, (byte) 62, (byte) 97, - (byte) 80, (byte) 26, (byte) 17, (byte) 143, (byte) 96, (byte) 16, - (byte) 204, (byte) 86, (byte) 61, (byte) 226, (byte) 149 }; - - - public static KeyStore getKeyStore() - { - KeyStore ks = null; - try{ - ks = KeyStore.getInstance("JKS"); - ks.load(asInputStream(), getKeyStorePassword()); - }catch(Exception ex){ - throw new RuntimeException("Failed to load SSL key store.", ex); - } - return ks; - } - - public static InputStream asInputStream() { - return new ByteArrayInputStream(CERT_BYTES); - } - - public static char[] getCertificatePassword() { - return "inc0rrect".toCharArray(); - } - - public static char[] getKeyStorePassword() { - return "mu$tch8ng3".toCharArray(); - } - - public static String getCertificatePasswordString() { - return "inc0rrect"; - } - - public static String getKeyStorePasswordString() { - return "mu$tch8ng3"; - } - - private SecureSocketKeyStore() { - - } - -} +package com.myself.unclecatmyself.common.ssl; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.security.KeyStore; + +/** + * A bogus key store which provides all the required information to create an + * example SSL connection. + * + * To generate a bogus key store: + * + *
+ * keytool -genkey -alias securesocket \ -keysize 2048 -validity 36500 \  -keyalg RSA -dname "CN=securesocket" \   -keypass inc0rrect -storepass mu$tch8ng3 \  -keystore cert.jks
+ *
+ *
+ *
+ *
+ * 
+ */ +public class SecureSocketKeyStore { + + private static final byte[] CERT_BYTES = { (byte) 254, (byte) 237, + (byte) 254, (byte) 237, (byte) 0, (byte) 0, (byte) 0, (byte) 2, + (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, (byte) 0, + (byte) 0, (byte) 1, (byte) 0, (byte) 12, (byte) 115, (byte) 101, + (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, + (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, + (byte) 0, (byte) 0, (byte) 1, (byte) 69, (byte) 231, (byte) 201, + (byte) 156, (byte) 140, (byte) 0, (byte) 0, (byte) 5, (byte) 0, + (byte) 48, (byte) 130, (byte) 4, (byte) 252, (byte) 48, (byte) 14, + (byte) 6, (byte) 10, (byte) 43, (byte) 6, (byte) 1, (byte) 4, + (byte) 1, (byte) 42, (byte) 2, (byte) 17, (byte) 1, (byte) 1, + (byte) 5, (byte) 0, (byte) 4, (byte) 130, (byte) 4, (byte) 232, + (byte) 221, (byte) 18, (byte) 203, (byte) 171, (byte) 175, + (byte) 82, (byte) 132, (byte) 227, (byte) 115, (byte) 143, + (byte) 38, (byte) 191, (byte) 42, (byte) 202, (byte) 130, + (byte) 171, (byte) 75, (byte) 6, (byte) 161, (byte) 120, + (byte) 204, (byte) 61, (byte) 106, (byte) 160, (byte) 81, (byte) 9, + (byte) 204, (byte) 153, (byte) 166, (byte) 38, (byte) 246, + (byte) 13, (byte) 43, (byte) 19, (byte) 100, (byte) 132, (byte) 45, + (byte) 90, (byte) 143, (byte) 1, (byte) 231, (byte) 182, (byte) 89, + (byte) 228, (byte) 183, (byte) 17, (byte) 95, (byte) 129, + (byte) 229, (byte) 42, (byte) 182, (byte) 126, (byte) 114, + (byte) 76, (byte) 124, (byte) 123, (byte) 246, (byte) 152, + (byte) 0, (byte) 141, (byte) 212, (byte) 111, (byte) 52, + (byte) 243, (byte) 112, (byte) 31, (byte) 117, (byte) 124, + (byte) 142, (byte) 24, (byte) 59, (byte) 198, (byte) 164, + (byte) 253, (byte) 21, (byte) 177, (byte) 189, (byte) 74, + (byte) 218, (byte) 110, (byte) 83, (byte) 154, (byte) 49, + (byte) 186, (byte) 159, (byte) 173, (byte) 202, (byte) 94, + (byte) 174, (byte) 183, (byte) 223, (byte) 119, (byte) 109, + (byte) 110, (byte) 72, (byte) 93, (byte) 208, (byte) 195, + (byte) 19, (byte) 89, (byte) 33, (byte) 34, (byte) 186, (byte) 12, + (byte) 86, (byte) 156, (byte) 156, (byte) 210, (byte) 111, + (byte) 110, (byte) 44, (byte) 106, (byte) 36, (byte) 67, + (byte) 168, (byte) 7, (byte) 179, (byte) 244, (byte) 53, + (byte) 134, (byte) 10, (byte) 86, (byte) 179, (byte) 34, (byte) 60, + (byte) 184, (byte) 179, (byte) 162, (byte) 69, (byte) 24, + (byte) 168, (byte) 100, (byte) 183, (byte) 206, (byte) 64, + (byte) 4, (byte) 32, (byte) 66, (byte) 237, (byte) 228, (byte) 92, + (byte) 6, (byte) 213, (byte) 141, (byte) 147, (byte) 198, + (byte) 141, (byte) 216, (byte) 41, (byte) 0, (byte) 101, (byte) 65, + (byte) 41, (byte) 185, (byte) 128, (byte) 229, (byte) 107, + (byte) 25, (byte) 89, (byte) 148, (byte) 16, (byte) 194, + (byte) 101, (byte) 100, (byte) 243, (byte) 147, (byte) 77, + (byte) 230, (byte) 11, (byte) 151, (byte) 99, (byte) 124, + (byte) 55, (byte) 195, (byte) 185, (byte) 30, (byte) 234, + (byte) 83, (byte) 61, (byte) 109, (byte) 131, (byte) 156, + (byte) 244, (byte) 133, (byte) 66, (byte) 39, (byte) 153, (byte) 9, + (byte) 34, (byte) 218, (byte) 201, (byte) 143, (byte) 190, + (byte) 127, (byte) 119, (byte) 102, (byte) 6, (byte) 83, + (byte) 134, (byte) 96, (byte) 170, (byte) 79, (byte) 196, + (byte) 214, (byte) 47, (byte) 215, (byte) 37, (byte) 250, + (byte) 64, (byte) 8, (byte) 165, (byte) 203, (byte) 44, (byte) 53, + (byte) 113, (byte) 147, (byte) 251, (byte) 29, (byte) 26, + (byte) 38, (byte) 193, (byte) 11, (byte) 223, (byte) 212, + (byte) 114, (byte) 96, (byte) 162, (byte) 39, (byte) 48, + (byte) 200, (byte) 172, (byte) 182, (byte) 254, (byte) 180, + (byte) 198, (byte) 11, (byte) 128, (byte) 75, (byte) 74, (byte) 93, + (byte) 226, (byte) 157, (byte) 80, (byte) 14, (byte) 9, (byte) 217, + (byte) 236, (byte) 205, (byte) 153, (byte) 35, (byte) 242, + (byte) 130, (byte) 140, (byte) 25, (byte) 16, (byte) 156, + (byte) 247, (byte) 230, (byte) 5, (byte) 247, (byte) 0, (byte) 34, + (byte) 196, (byte) 15, (byte) 118, (byte) 255, (byte) 185, + (byte) 199, (byte) 59, (byte) 99, (byte) 27, (byte) 187, (byte) 83, + (byte) 81, (byte) 12, (byte) 71, (byte) 69, (byte) 127, (byte) 130, + (byte) 164, (byte) 97, (byte) 195, (byte) 216, (byte) 215, + (byte) 61, (byte) 29, (byte) 196, (byte) 62, (byte) 160, + (byte) 188, (byte) 209, (byte) 173, (byte) 230, (byte) 0, + (byte) 204, (byte) 225, (byte) 1, (byte) 5, (byte) 42, (byte) 223, + (byte) 232, (byte) 187, (byte) 190, (byte) 67, (byte) 126, + (byte) 235, (byte) 178, (byte) 218, (byte) 179, (byte) 46, + (byte) 186, (byte) 156, (byte) 186, (byte) 6, (byte) 191, + (byte) 68, (byte) 239, (byte) 31, (byte) 16, (byte) 204, (byte) 24, + (byte) 68, (byte) 164, (byte) 88, (byte) 10, (byte) 174, (byte) 26, + (byte) 54, (byte) 187, (byte) 149, (byte) 132, (byte) 128, + (byte) 173, (byte) 165, (byte) 8, (byte) 69, (byte) 96, (byte) 49, + (byte) 57, (byte) 223, (byte) 110, (byte) 29, (byte) 215, + (byte) 98, (byte) 42, (byte) 15, (byte) 153, (byte) 228, + (byte) 216, (byte) 61, (byte) 160, (byte) 230, (byte) 34, + (byte) 40, (byte) 232, (byte) 136, (byte) 139, (byte) 140, + (byte) 236, (byte) 251, (byte) 119, (byte) 242, (byte) 199, + (byte) 167, (byte) 61, (byte) 141, (byte) 89, (byte) 29, (byte) 82, + (byte) 114, (byte) 229, (byte) 198, (byte) 27, (byte) 133, + (byte) 87, (byte) 0, (byte) 53, (byte) 69, (byte) 42, (byte) 91, + (byte) 174, (byte) 82, (byte) 244, (byte) 160, (byte) 82, + (byte) 142, (byte) 221, (byte) 106, (byte) 151, (byte) 241, + (byte) 214, (byte) 64, (byte) 14, (byte) 28, (byte) 2, (byte) 3, + (byte) 145, (byte) 143, (byte) 18, (byte) 165, (byte) 247, + (byte) 178, (byte) 211, (byte) 16, (byte) 222, (byte) 76, + (byte) 60, (byte) 119, (byte) 130, (byte) 199, (byte) 230, + (byte) 229, (byte) 3, (byte) 22, (byte) 100, (byte) 135, + (byte) 103, (byte) 60, (byte) 181, (byte) 191, (byte) 56, + (byte) 249, (byte) 181, (byte) 169, (byte) 210, (byte) 25, + (byte) 152, (byte) 201, (byte) 226, (byte) 119, (byte) 71, + (byte) 204, (byte) 70, (byte) 220, (byte) 103, (byte) 46, + (byte) 166, (byte) 125, (byte) 40, (byte) 86, (byte) 208, + (byte) 114, (byte) 138, (byte) 24, (byte) 27, (byte) 219, + (byte) 123, (byte) 161, (byte) 52, (byte) 14, (byte) 38, + (byte) 244, (byte) 112, (byte) 238, (byte) 121, (byte) 90, + (byte) 34, (byte) 157, (byte) 131, (byte) 53, (byte) 245, + (byte) 162, (byte) 89, (byte) 188, (byte) 6, (byte) 202, + (byte) 164, (byte) 130, (byte) 34, (byte) 232, (byte) 74, + (byte) 45, (byte) 137, (byte) 164, (byte) 200, (byte) 197, + (byte) 247, (byte) 64, (byte) 110, (byte) 122, (byte) 49, + (byte) 116, (byte) 137, (byte) 253, (byte) 170, (byte) 232, + (byte) 120, (byte) 26, (byte) 171, (byte) 228, (byte) 229, + (byte) 49, (byte) 56, (byte) 56, (byte) 106, (byte) 110, (byte) 12, + (byte) 109, (byte) 93, (byte) 105, (byte) 241, (byte) 196, + (byte) 11, (byte) 18, (byte) 89, (byte) 108, (byte) 146, + (byte) 224, (byte) 161, (byte) 181, (byte) 236, (byte) 74, + (byte) 128, (byte) 24, (byte) 239, (byte) 22, (byte) 146, (byte) 0, + (byte) 69, (byte) 182, (byte) 246, (byte) 43, (byte) 59, + (byte) 208, (byte) 33, (byte) 48, (byte) 81, (byte) 0, (byte) 70, + (byte) 225, (byte) 222, (byte) 122, (byte) 178, (byte) 138, + (byte) 12, (byte) 207, (byte) 233, (byte) 164, (byte) 13, + (byte) 176, (byte) 123, (byte) 95, (byte) 68, (byte) 238, + (byte) 134, (byte) 66, (byte) 95, (byte) 194, (byte) 192, + (byte) 225, (byte) 244, (byte) 14, (byte) 78, (byte) 53, + (byte) 189, (byte) 217, (byte) 229, (byte) 203, (byte) 192, + (byte) 34, (byte) 38, (byte) 169, (byte) 63, (byte) 239, + (byte) 128, (byte) 172, (byte) 143, (byte) 75, (byte) 7, + (byte) 237, (byte) 125, (byte) 179, (byte) 235, (byte) 229, + (byte) 98, (byte) 8, (byte) 211, (byte) 237, (byte) 116, (byte) 75, + (byte) 27, (byte) 211, (byte) 131, (byte) 245, (byte) 89, + (byte) 150, (byte) 35, (byte) 49, (byte) 207, (byte) 113, + (byte) 237, (byte) 114, (byte) 125, (byte) 134, (byte) 191, + (byte) 110, (byte) 30, (byte) 119, (byte) 131, (byte) 175, + (byte) 166, (byte) 201, (byte) 255, (byte) 200, (byte) 1, + (byte) 126, (byte) 163, (byte) 172, (byte) 52, (byte) 118, + (byte) 184, (byte) 221, (byte) 165, (byte) 167, (byte) 165, + (byte) 20, (byte) 135, (byte) 32, (byte) 222, (byte) 188, + (byte) 250, (byte) 64, (byte) 161, (byte) 67, (byte) 236, + (byte) 212, (byte) 131, (byte) 44, (byte) 32, (byte) 70, (byte) 0, + (byte) 24, (byte) 178, (byte) 83, (byte) 155, (byte) 145, + (byte) 136, (byte) 131, (byte) 120, (byte) 181, (byte) 164, + (byte) 155, (byte) 172, (byte) 41, (byte) 213, (byte) 164, + (byte) 98, (byte) 169, (byte) 152, (byte) 184, (byte) 170, + (byte) 107, (byte) 7, (byte) 21, (byte) 228, (byte) 175, + (byte) 192, (byte) 238, (byte) 68, (byte) 197, (byte) 119, + (byte) 228, (byte) 225, (byte) 156, (byte) 235, (byte) 241, + (byte) 172, (byte) 171, (byte) 236, (byte) 128, (byte) 78, + (byte) 117, (byte) 152, (byte) 123, (byte) 93, (byte) 156, + (byte) 57, (byte) 238, (byte) 211, (byte) 188, (byte) 47, + (byte) 62, (byte) 45, (byte) 127, (byte) 58, (byte) 38, (byte) 29, + (byte) 131, (byte) 95, (byte) 85, (byte) 149, (byte) 112, + (byte) 215, (byte) 207, (byte) 41, (byte) 201, (byte) 30, + (byte) 149, (byte) 73, (byte) 245, (byte) 179, (byte) 176, + (byte) 246, (byte) 203, (byte) 204, (byte) 252, (byte) 13, + (byte) 98, (byte) 151, (byte) 93, (byte) 87, (byte) 241, + (byte) 166, (byte) 46, (byte) 249, (byte) 148, (byte) 49, + (byte) 141, (byte) 136, (byte) 49, (byte) 77, (byte) 250, + (byte) 191, (byte) 157, (byte) 90, (byte) 84, (byte) 51, + (byte) 129, (byte) 133, (byte) 66, (byte) 253, (byte) 99, + (byte) 243, (byte) 34, (byte) 142, (byte) 197, (byte) 4, + (byte) 126, (byte) 7, (byte) 217, (byte) 126, (byte) 205, + (byte) 250, (byte) 141, (byte) 231, (byte) 225, (byte) 203, + (byte) 171, (byte) 246, (byte) 201, (byte) 48, (byte) 96, + (byte) 207, (byte) 74, (byte) 253, (byte) 120, (byte) 114, + (byte) 163, (byte) 192, (byte) 24, (byte) 12, (byte) 10, + (byte) 210, (byte) 94, (byte) 136, (byte) 152, (byte) 185, + (byte) 109, (byte) 87, (byte) 35, (byte) 159, (byte) 238, + (byte) 122, (byte) 200, (byte) 107, (byte) 103, (byte) 243, + (byte) 250, (byte) 152, (byte) 68, (byte) 66, (byte) 170, (byte) 0, + (byte) 134, (byte) 229, (byte) 168, (byte) 182, (byte) 30, + (byte) 89, (byte) 240, (byte) 121, (byte) 106, (byte) 148, + (byte) 142, (byte) 49, (byte) 242, (byte) 215, (byte) 233, + (byte) 57, (byte) 120, (byte) 204, (byte) 180, (byte) 239, + (byte) 199, (byte) 133, (byte) 255, (byte) 71, (byte) 3, + (byte) 132, (byte) 228, (byte) 110, (byte) 66, (byte) 227, + (byte) 122, (byte) 82, (byte) 118, (byte) 173, (byte) 218, + (byte) 54, (byte) 99, (byte) 167, (byte) 154, (byte) 3, (byte) 189, + (byte) 25, (byte) 123, (byte) 169, (byte) 42, (byte) 184, + (byte) 59, (byte) 36, (byte) 131, (byte) 206, (byte) 248, + (byte) 90, (byte) 32, (byte) 183, (byte) 86, (byte) 62, (byte) 149, + (byte) 107, (byte) 243, (byte) 71, (byte) 197, (byte) 124, + (byte) 155, (byte) 214, (byte) 91, (byte) 29, (byte) 81, (byte) 28, + (byte) 115, (byte) 98, (byte) 130, (byte) 184, (byte) 135, + (byte) 13, (byte) 191, (byte) 147, (byte) 43, (byte) 10, + (byte) 178, (byte) 99, (byte) 165, (byte) 210, (byte) 87, + (byte) 87, (byte) 148, (byte) 31, (byte) 198, (byte) 129, + (byte) 32, (byte) 181, (byte) 3, (byte) 144, (byte) 61, (byte) 5, + (byte) 166, (byte) 252, (byte) 73, (byte) 205, (byte) 230, + (byte) 178, (byte) 162, (byte) 46, (byte) 56, (byte) 99, (byte) 77, + (byte) 97, (byte) 236, (byte) 121, (byte) 157, (byte) 139, + (byte) 153, (byte) 217, (byte) 171, (byte) 19, (byte) 68, + (byte) 36, (byte) 14, (byte) 123, (byte) 249, (byte) 101, + (byte) 127, (byte) 184, (byte) 123, (byte) 7, (byte) 124, + (byte) 68, (byte) 98, (byte) 34, (byte) 139, (byte) 224, + (byte) 173, (byte) 246, (byte) 196, (byte) 180, (byte) 70, + (byte) 207, (byte) 168, (byte) 211, (byte) 255, (byte) 84, + (byte) 0, (byte) 174, (byte) 11, (byte) 160, (byte) 155, + (byte) 127, (byte) 228, (byte) 81, (byte) 226, (byte) 115, + (byte) 142, (byte) 200, (byte) 107, (byte) 4, (byte) 204, + (byte) 219, (byte) 192, (byte) 189, (byte) 56, (byte) 127, + (byte) 184, (byte) 187, (byte) 161, (byte) 106, (byte) 62, + (byte) 225, (byte) 211, (byte) 115, (byte) 30, (byte) 172, + (byte) 191, (byte) 66, (byte) 25, (byte) 66, (byte) 235, + (byte) 107, (byte) 41, (byte) 186, (byte) 40, (byte) 239, + (byte) 173, (byte) 11, (byte) 247, (byte) 89, (byte) 79, + (byte) 135, (byte) 86, (byte) 73, (byte) 77, (byte) 164, (byte) 34, + (byte) 109, (byte) 236, (byte) 56, (byte) 198, (byte) 141, + (byte) 87, (byte) 74, (byte) 172, (byte) 56, (byte) 24, (byte) 150, + (byte) 233, (byte) 233, (byte) 165, (byte) 122, (byte) 201, + (byte) 112, (byte) 232, (byte) 23, (byte) 12, (byte) 166, + (byte) 128, (byte) 114, (byte) 139, (byte) 207, (byte) 233, + (byte) 47, (byte) 220, (byte) 172, (byte) 175, (byte) 40, + (byte) 109, (byte) 82, (byte) 142, (byte) 130, (byte) 177, + (byte) 50, (byte) 127, (byte) 196, (byte) 106, (byte) 172, + (byte) 178, (byte) 71, (byte) 178, (byte) 204, (byte) 99, + (byte) 113, (byte) 33, (byte) 189, (byte) 188, (byte) 168, + (byte) 76, (byte) 92, (byte) 230, (byte) 211, (byte) 239, + (byte) 75, (byte) 71, (byte) 64, (byte) 197, (byte) 26, (byte) 222, + (byte) 19, (byte) 213, (byte) 161, (byte) 144, (byte) 20, + (byte) 126, (byte) 192, (byte) 156, (byte) 15, (byte) 113, + (byte) 64, (byte) 73, (byte) 7, (byte) 241, (byte) 217, (byte) 127, + (byte) 171, (byte) 199, (byte) 66, (byte) 32, (byte) 179, (byte) 4, + (byte) 181, (byte) 93, (byte) 121, (byte) 193, (byte) 10, + (byte) 169, (byte) 255, (byte) 152, (byte) 199, (byte) 95, + (byte) 177, (byte) 227, (byte) 135, (byte) 21, (byte) 64, + (byte) 203, (byte) 9, (byte) 79, (byte) 243, (byte) 114, (byte) 2, + (byte) 201, (byte) 157, (byte) 180, (byte) 52, (byte) 193, + (byte) 66, (byte) 34, (byte) 155, (byte) 52, (byte) 35, (byte) 93, + (byte) 31, (byte) 96, (byte) 77, (byte) 12, (byte) 80, (byte) 195, + (byte) 96, (byte) 247, (byte) 251, (byte) 237, (byte) 36, + (byte) 170, (byte) 7, (byte) 3, (byte) 251, (byte) 243, (byte) 47, + (byte) 180, (byte) 98, (byte) 207, (byte) 176, (byte) 106, + (byte) 237, (byte) 114, (byte) 91, (byte) 229, (byte) 56, + (byte) 94, (byte) 154, (byte) 32, (byte) 62, (byte) 240, + (byte) 132, (byte) 4, (byte) 144, (byte) 227, (byte) 140, + (byte) 137, (byte) 76, (byte) 15, (byte) 117, (byte) 82, + (byte) 223, (byte) 168, (byte) 135, (byte) 33, (byte) 91, + (byte) 173, (byte) 4, (byte) 245, (byte) 192, (byte) 95, + (byte) 135, (byte) 22, (byte) 138, (byte) 89, (byte) 1, (byte) 14, + (byte) 230, (byte) 143, (byte) 195, (byte) 93, (byte) 133, + (byte) 194, (byte) 252, (byte) 188, (byte) 31, (byte) 39, + (byte) 162, (byte) 59, (byte) 148, (byte) 219, (byte) 213, + (byte) 179, (byte) 195, (byte) 165, (byte) 67, (byte) 68, + (byte) 39, (byte) 178, (byte) 143, (byte) 192, (byte) 177, + (byte) 221, (byte) 236, (byte) 63, (byte) 40, (byte) 205, + (byte) 26, (byte) 81, (byte) 127, (byte) 5, (byte) 213, (byte) 192, + (byte) 22, (byte) 147, (byte) 98, (byte) 207, (byte) 153, (byte) 8, + (byte) 108, (byte) 75, (byte) 182, (byte) 148, (byte) 0, + (byte) 151, (byte) 15, (byte) 178, (byte) 98, (byte) 145, + (byte) 255, (byte) 213, (byte) 142, (byte) 63, (byte) 247, + (byte) 42, (byte) 161, (byte) 246, (byte) 21, (byte) 128, + (byte) 47, (byte) 248, (byte) 217, (byte) 70, (byte) 195, + (byte) 151, (byte) 236, (byte) 73, (byte) 153, (byte) 230, + (byte) 152, (byte) 217, (byte) 12, (byte) 189, (byte) 65, + (byte) 85, (byte) 189, (byte) 204, (byte) 212, (byte) 161, + (byte) 210, (byte) 217, (byte) 74, (byte) 75, (byte) 186, + (byte) 122, (byte) 167, (byte) 149, (byte) 178, (byte) 202, + (byte) 205, (byte) 246, (byte) 225, (byte) 225, (byte) 190, + (byte) 56, (byte) 42, (byte) 162, (byte) 215, (byte) 107, + (byte) 45, (byte) 121, (byte) 235, (byte) 195, (byte) 219, + (byte) 22, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, + (byte) 5, (byte) 88, (byte) 46, (byte) 53, (byte) 48, (byte) 57, + (byte) 0, (byte) 0, (byte) 2, (byte) 211, (byte) 48, (byte) 130, + (byte) 2, (byte) 207, (byte) 48, (byte) 130, (byte) 1, (byte) 183, + (byte) 160, (byte) 3, (byte) 2, (byte) 1, (byte) 2, (byte) 2, + (byte) 4, (byte) 58, (byte) 247, (byte) 71, (byte) 185, (byte) 48, + (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, + (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, + (byte) 5, (byte) 0, (byte) 48, (byte) 23, (byte) 49, (byte) 21, + (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, (byte) 4, + (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, (byte) 99, + (byte) 117, (byte) 114, (byte) 101, (byte) 115, (byte) 111, + (byte) 99, (byte) 107, (byte) 101, (byte) 116, (byte) 48, + (byte) 32, (byte) 23, (byte) 13, (byte) 49, (byte) 52, (byte) 48, + (byte) 53, (byte) 49, (byte) 48, (byte) 50, (byte) 48, (byte) 49, + (byte) 56, (byte) 52, (byte) 48, (byte) 90, (byte) 24, (byte) 15, + (byte) 50, (byte) 49, (byte) 49, (byte) 52, (byte) 48, (byte) 52, + (byte) 49, (byte) 54, (byte) 50, (byte) 48, (byte) 49, (byte) 56, + (byte) 52, (byte) 48, (byte) 90, (byte) 48, (byte) 23, (byte) 49, + (byte) 21, (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, + (byte) 4, (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, + (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, + (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, + (byte) 48, (byte) 130, (byte) 1, (byte) 34, (byte) 48, (byte) 13, + (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, (byte) 134, + (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 1, (byte) 5, + (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 15, (byte) 0, + (byte) 48, (byte) 130, (byte) 1, (byte) 10, (byte) 2, (byte) 130, + (byte) 1, (byte) 1, (byte) 0, (byte) 153, (byte) 113, (byte) 7, + (byte) 44, (byte) 219, (byte) 76, (byte) 101, (byte) 226, + (byte) 138, (byte) 96, (byte) 219, (byte) 60, (byte) 167, + (byte) 138, (byte) 222, (byte) 6, (byte) 78, (byte) 169, (byte) 64, + (byte) 188, (byte) 156, (byte) 190, (byte) 119, (byte) 16, + (byte) 34, (byte) 228, (byte) 250, (byte) 253, (byte) 119, + (byte) 75, (byte) 240, (byte) 60, (byte) 242, (byte) 52, + (byte) 137, (byte) 146, (byte) 20, (byte) 130, (byte) 202, + (byte) 226, (byte) 125, (byte) 19, (byte) 7, (byte) 34, (byte) 8, + (byte) 61, (byte) 243, (byte) 202, (byte) 225, (byte) 206, + (byte) 223, (byte) 53, (byte) 74, (byte) 56, (byte) 222, (byte) 47, + (byte) 99, (byte) 235, (byte) 57, (byte) 73, (byte) 90, (byte) 198, + (byte) 109, (byte) 104, (byte) 36, (byte) 255, (byte) 124, + (byte) 57, (byte) 155, (byte) 248, (byte) 120, (byte) 56, + (byte) 56, (byte) 38, (byte) 41, (byte) 216, (byte) 1, (byte) 216, + (byte) 216, (byte) 100, (byte) 239, (byte) 79, (byte) 222, + (byte) 34, (byte) 21, (byte) 182, (byte) 112, (byte) 136, + (byte) 137, (byte) 16, (byte) 141, (byte) 15, (byte) 83, (byte) 94, + (byte) 245, (byte) 36, (byte) 203, (byte) 178, (byte) 137, + (byte) 159, (byte) 86, (byte) 220, (byte) 253, (byte) 112, + (byte) 200, (byte) 50, (byte) 135, (byte) 215, (byte) 190, + (byte) 21, (byte) 186, (byte) 84, (byte) 21, (byte) 96, (byte) 126, + (byte) 253, (byte) 115, (byte) 209, (byte) 241, (byte) 94, + (byte) 115, (byte) 219, (byte) 0, (byte) 25, (byte) 253, + (byte) 209, (byte) 182, (byte) 118, (byte) 230, (byte) 10, + (byte) 50, (byte) 131, (byte) 39, (byte) 249, (byte) 136, + (byte) 11, (byte) 101, (byte) 192, (byte) 12, (byte) 210, + (byte) 179, (byte) 237, (byte) 213, (byte) 68, (byte) 101, + (byte) 58, (byte) 187, (byte) 255, (byte) 240, (byte) 164, + (byte) 147, (byte) 72, (byte) 148, (byte) 227, (byte) 155, + (byte) 88, (byte) 250, (byte) 101, (byte) 253, (byte) 87, + (byte) 140, (byte) 168, (byte) 39, (byte) 163, (byte) 133, + (byte) 150, (byte) 252, (byte) 226, (byte) 234, (byte) 52, + (byte) 88, (byte) 40, (byte) 56, (byte) 23, (byte) 105, (byte) 236, + (byte) 4, (byte) 113, (byte) 98, (byte) 4, (byte) 0, (byte) 117, + (byte) 59, (byte) 77, (byte) 236, (byte) 135, (byte) 93, (byte) 54, + (byte) 30, (byte) 6, (byte) 126, (byte) 90, (byte) 15, (byte) 105, + (byte) 89, (byte) 216, (byte) 154, (byte) 72, (byte) 134, + (byte) 209, (byte) 74, (byte) 197, (byte) 237, (byte) 51, + (byte) 37, (byte) 33, (byte) 106, (byte) 50, (byte) 71, (byte) 134, + (byte) 169, (byte) 173, (byte) 88, (byte) 111, (byte) 217, + (byte) 117, (byte) 184, (byte) 97, (byte) 1, (byte) 38, (byte) 76, + (byte) 112, (byte) 170, (byte) 190, (byte) 250, (byte) 96, + (byte) 17, (byte) 45, (byte) 117, (byte) 183, (byte) 82, + (byte) 155, (byte) 10, (byte) 53, (byte) 15, (byte) 214, (byte) 36, + (byte) 134, (byte) 249, (byte) 146, (byte) 98, (byte) 99, + (byte) 64, (byte) 158, (byte) 99, (byte) 227, (byte) 21, (byte) 92, + (byte) 98, (byte) 90, (byte) 202, (byte) 214, (byte) 134, + (byte) 233, (byte) 212, (byte) 149, (byte) 2, (byte) 3, (byte) 1, + (byte) 0, (byte) 1, (byte) 163, (byte) 33, (byte) 48, (byte) 31, + (byte) 48, (byte) 29, (byte) 6, (byte) 3, (byte) 85, (byte) 29, + (byte) 14, (byte) 4, (byte) 22, (byte) 4, (byte) 20, (byte) 115, + (byte) 110, (byte) 177, (byte) 165, (byte) 41, (byte) 26, + (byte) 142, (byte) 198, (byte) 221, (byte) 63, (byte) 79, + (byte) 252, (byte) 219, (byte) 159, (byte) 68, (byte) 102, + (byte) 76, (byte) 153, (byte) 128, (byte) 164, (byte) 48, + (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, + (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, + (byte) 5, (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 1, + (byte) 0, (byte) 118, (byte) 55, (byte) 245, (byte) 122, + (byte) 159, (byte) 155, (byte) 98, (byte) 122, (byte) 229, + (byte) 186, (byte) 23, (byte) 207, (byte) 109, (byte) 225, + (byte) 220, (byte) 74, (byte) 51, (byte) 218, (byte) 10, + (byte) 115, (byte) 137, (byte) 103, (byte) 127, (byte) 28, + (byte) 30, (byte) 184, (byte) 149, (byte) 249, (byte) 193, + (byte) 206, (byte) 208, (byte) 181, (byte) 191, (byte) 128, + (byte) 18, (byte) 208, (byte) 24, (byte) 132, (byte) 147, + (byte) 184, (byte) 198, (byte) 82, (byte) 204, (byte) 183, + (byte) 127, (byte) 87, (byte) 234, (byte) 136, (byte) 197, + (byte) 34, (byte) 232, (byte) 124, (byte) 210, (byte) 2, + (byte) 192, (byte) 69, (byte) 246, (byte) 25, (byte) 232, + (byte) 162, (byte) 0, (byte) 157, (byte) 216, (byte) 194, + (byte) 26, (byte) 207, (byte) 225, (byte) 169, (byte) 59, + (byte) 246, (byte) 52, (byte) 51, (byte) 150, (byte) 210, + (byte) 50, (byte) 118, (byte) 58, (byte) 154, (byte) 45, + (byte) 128, (byte) 138, (byte) 47, (byte) 174, (byte) 83, + (byte) 117, (byte) 18, (byte) 224, (byte) 9, (byte) 146, + (byte) 180, (byte) 178, (byte) 22, (byte) 76, (byte) 82, + (byte) 229, (byte) 16, (byte) 150, (byte) 127, (byte) 13, + (byte) 122, (byte) 218, (byte) 159, (byte) 195, (byte) 232, + (byte) 168, (byte) 206, (byte) 105, (byte) 82, (byte) 37, + (byte) 252, (byte) 186, (byte) 223, (byte) 222, (byte) 7, + (byte) 106, (byte) 87, (byte) 218, (byte) 89, (byte) 22, + (byte) 252, (byte) 7, (byte) 177, (byte) 52, (byte) 180, (byte) 9, + (byte) 16, (byte) 29, (byte) 57, (byte) 192, (byte) 209, + (byte) 225, (byte) 155, (byte) 16, (byte) 219, (byte) 38, + (byte) 90, (byte) 174, (byte) 152, (byte) 140, (byte) 252, + (byte) 114, (byte) 133, (byte) 106, (byte) 24, (byte) 107, + (byte) 227, (byte) 80, (byte) 166, (byte) 63, (byte) 47, (byte) 16, + (byte) 15, (byte) 89, (byte) 242, (byte) 19, (byte) 87, (byte) 193, + (byte) 250, (byte) 222, (byte) 223, (byte) 183, (byte) 61, + (byte) 91, (byte) 17, (byte) 92, (byte) 35, (byte) 142, (byte) 44, + (byte) 153, (byte) 135, (byte) 86, (byte) 97, (byte) 70, + (byte) 205, (byte) 38, (byte) 192, (byte) 18, (byte) 244, + (byte) 61, (byte) 46, (byte) 21, (byte) 145, (byte) 99, (byte) 72, + (byte) 142, (byte) 37, (byte) 19, (byte) 219, (byte) 167, + (byte) 62, (byte) 71, (byte) 197, (byte) 86, (byte) 152, + (byte) 139, (byte) 122, (byte) 231, (byte) 122, (byte) 206, + (byte) 42, (byte) 142, (byte) 164, (byte) 237, (byte) 19, + (byte) 60, (byte) 95, (byte) 239, (byte) 191, (byte) 64, + (byte) 188, (byte) 94, (byte) 154, (byte) 199, (byte) 252, + (byte) 62, (byte) 26, (byte) 181, (byte) 194, (byte) 141, + (byte) 13, (byte) 1, (byte) 112, (byte) 161, (byte) 195, + (byte) 149, (byte) 116, (byte) 57, (byte) 118, (byte) 114, + (byte) 248, (byte) 235, (byte) 54, (byte) 229, (byte) 48, + (byte) 53, (byte) 30, (byte) 145, (byte) 199, (byte) 207, + (byte) 49, (byte) 175, (byte) 44, (byte) 172, (byte) 120, + (byte) 254, (byte) 181, (byte) 100, (byte) 113, (byte) 191, + (byte) 64, (byte) 131, (byte) 125, (byte) 80, (byte) 180, + (byte) 229, (byte) 109, (byte) 97, (byte) 8, (byte) 166, + (byte) 155, (byte) 72, (byte) 252, (byte) 84, (byte) 62, (byte) 97, + (byte) 80, (byte) 26, (byte) 17, (byte) 143, (byte) 96, (byte) 16, + (byte) 204, (byte) 86, (byte) 61, (byte) 226, (byte) 149 }; + + + public static KeyStore getKeyStore() + { + KeyStore ks = null; + try{ + ks = KeyStore.getInstance("JKS"); + ks.load(asInputStream(), getKeyStorePassword()); + }catch(Exception ex){ + throw new RuntimeException("Failed to load SSL key store.", ex); + } + return ks; + } + + public static InputStream asInputStream() { + return new ByteArrayInputStream(CERT_BYTES); + } + + public static char[] getCertificatePassword() { + return "inc0rrect".toCharArray(); + } + + public static char[] getKeyStorePassword() { + return "mu$tch8ng3".toCharArray(); + } + + public static String getCertificatePasswordString() { + return "inc0rrect"; + } + + public static String getKeyStorePasswordString() { + return "mu$tch8ng3"; + } + + private SecureSocketKeyStore() { + + } + +} diff --git a/src/main/java/com/myself/nettychat/common/ssl/SecureSocketSslContextFactory.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java similarity index 96% rename from src/main/java/com/myself/nettychat/common/ssl/SecureSocketSslContextFactory.java rename to src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java index d4a0bf7..06d0edd 100644 --- a/src/main/java/com/myself/nettychat/common/ssl/SecureSocketSslContextFactory.java +++ b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java @@ -1,89 +1,89 @@ -package com.myself.nettychat.common.ssl; - -import io.netty.util.internal.SystemPropertyUtil; - -import javax.net.ssl.*; -import java.security.KeyStore; -import java.security.SecureRandom; - -/** - * Creates a bogus {@link SSLContext}. A client-side context created by this - * factory accepts any certificate even if it is invalid. A server-side context - * created by this factory sends a bogus certificate defined in {@link }. - *

- * You will have to create your context differently in a real world application. - * - *

Client Certificate Authentication

- * - * To enable client certificate authentication: - *
    - *
  • Enable client authentication on the server side by calling - * {@link SSLEngine#setNeedClientAuth(boolean)} before creating - * {@link }.
  • - *
  • When initializing an {@link SSLContext} on the client side, - * specify the {@link KeyManager} that contains the client certificate as - * the first argument of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
  • - *
  • When initializing an {@link SSLContext} on the server side, - * specify the proper {@link TrustManager} as the second argument of - * {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} - * to validate the client certificate.
  • - *
- */ -public final class SecureSocketSslContextFactory { - - private static final String PROTOCOL = "TLS"; - private static final SSLContext SERVER_CONTEXT; - private static final SSLContext CLIENT_CONTEXT; - - static { - String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm"); - if (algorithm == null) { - algorithm = "SunX509"; - } - - SSLContext serverContext; - SSLContext clientContext; - try { - // - //SecureSocketSslContextFactory.class.getResourceAsStream("/securesocket.jks") - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(SecureSocketKeyStore.asInputStream(), - SecureSocketKeyStore.getKeyStorePassword()); - - // Set up key manager factory to use our key store - KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); - kmf.init(ks, SecureSocketKeyStore.getCertificatePassword()); - - // Initialize the SSLContext to work with our key managers. - serverContext = SSLContext.getInstance(PROTOCOL); - serverContext.init(kmf.getKeyManagers(), null, null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the server-side SSLContext", e); - } - - try { - clientContext = SSLContext.getInstance(PROTOCOL); - clientContext.init(null, SecureSokcetTrustManagerFactory.getTrustManagers(), null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the client-side SSLContext", e); - } - - SERVER_CONTEXT = serverContext; - CLIENT_CONTEXT = clientContext; - } - - public static SSLContext getServerContext() { - return SERVER_CONTEXT; - } - - public static SSLContext getClientContext() { - return CLIENT_CONTEXT; - } - - private SecureSocketSslContextFactory() { - // Unused - } - -} +package com.myself.unclecatmyself.common.ssl; + +import io.netty.util.internal.SystemPropertyUtil; + +import javax.net.ssl.*; +import java.security.KeyStore; +import java.security.SecureRandom; + +/** + * Creates a bogus {@link SSLContext}. A client-side context created by this + * factory accepts any certificate even if it is invalid. A server-side context + * created by this factory sends a bogus certificate defined in {@link }. + *

+ * You will have to create your context differently in a real world application. + * + *

Client Certificate Authentication

+ * + * To enable client certificate authentication: + *
    + *
  • Enable client authentication on the server side by calling + * {@link SSLEngine#setNeedClientAuth(boolean)} before creating + * {@link }.
  • + *
  • When initializing an {@link SSLContext} on the client side, + * specify the {@link KeyManager} that contains the client certificate as + * the first argument of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
  • + *
  • When initializing an {@link SSLContext} on the server side, + * specify the proper {@link TrustManager} as the second argument of + * {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} + * to validate the client certificate.
  • + *
+ */ +public final class SecureSocketSslContextFactory { + + private static final String PROTOCOL = "TLS"; + private static final SSLContext SERVER_CONTEXT; + private static final SSLContext CLIENT_CONTEXT; + + static { + String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm"); + if (algorithm == null) { + algorithm = "SunX509"; + } + + SSLContext serverContext; + SSLContext clientContext; + try { + // + //SecureSocketSslContextFactory.class.getResourceAsStream("/securesocket.jks") + KeyStore ks = KeyStore.getInstance("JKS"); + ks.load(SecureSocketKeyStore.asInputStream(), + SecureSocketKeyStore.getKeyStorePassword()); + + // Set up key manager factory to use our key store + KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); + kmf.init(ks, SecureSocketKeyStore.getCertificatePassword()); + + // Initialize the SSLContext to work with our key managers. + serverContext = SSLContext.getInstance(PROTOCOL); + serverContext.init(kmf.getKeyManagers(), null, null); + } catch (Exception e) { + throw new Error( + "Failed to initialize the server-side SSLContext", e); + } + + try { + clientContext = SSLContext.getInstance(PROTOCOL); + clientContext.init(null, SecureSokcetTrustManagerFactory.getTrustManagers(), null); + } catch (Exception e) { + throw new Error( + "Failed to initialize the client-side SSLContext", e); + } + + SERVER_CONTEXT = serverContext; + CLIENT_CONTEXT = clientContext; + } + + public static SSLContext getServerContext() { + return SERVER_CONTEXT; + } + + public static SSLContext getClientContext() { + return CLIENT_CONTEXT; + } + + private SecureSocketSslContextFactory() { + // Unused + } + +} diff --git a/src/main/java/com/myself/nettychat/common/ssl/SecureSokcetTrustManagerFactory.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java similarity index 95% rename from src/main/java/com/myself/nettychat/common/ssl/SecureSokcetTrustManagerFactory.java rename to src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java index fdc57a1..5cd5e23 100644 --- a/src/main/java/com/myself/nettychat/common/ssl/SecureSokcetTrustManagerFactory.java +++ b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java @@ -1,63 +1,63 @@ -package com.myself.nettychat.common.ssl; - -import javax.net.ssl.ManagerFactoryParameters; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactorySpi; -import javax.net.ssl.X509TrustManager; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.cert.X509Certificate; - -/** - * Bogus {@link TrustManagerFactorySpi} which accepts any certificate - * even if it is invalid. - */ -public class SecureSokcetTrustManagerFactory extends TrustManagerFactorySpi { - - private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) { - // Always trust - it is an example. - // You should do something in the real world. - // You will reach here only if you enabled client certificate auth, - // as described in SecureChatSslContextFactory. - System.err.println( - "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN()); - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - // Always trust - it is an example. - // You should do something in the real world. - System.err.println( - "UNKNOWN SERVER CERTIFICATE: 222 " + chain[0].getSubjectDN()); - } - }; - - public static TrustManager[] getTrustManagers() { - return new TrustManager[] { DUMMY_TRUST_MANAGER }; - } - - @Override - protected TrustManager[] engineGetTrustManagers() { - return getTrustManagers(); - } - - @Override - protected void engineInit(KeyStore keystore) throws KeyStoreException { - // Unused - } - - @Override - protected void engineInit(ManagerFactoryParameters managerFactoryParameters) - throws InvalidAlgorithmParameterException { - // Unused - } - -} +package com.myself.unclecatmyself.common.ssl; + +import javax.net.ssl.ManagerFactoryParameters; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactorySpi; +import javax.net.ssl.X509TrustManager; +import java.security.InvalidAlgorithmParameterException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.cert.X509Certificate; + +/** + * Bogus {@link TrustManagerFactorySpi} which accepts any certificate + * even if it is invalid. + */ +public class SecureSokcetTrustManagerFactory extends TrustManagerFactorySpi { + + private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { + @Override + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) { + // Always trust - it is an example. + // You should do something in the real world. + // You will reach here only if you enabled client certificate auth, + // as described in SecureChatSslContextFactory. + System.err.println( + "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN()); + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) { + // Always trust - it is an example. + // You should do something in the real world. + System.err.println( + "UNKNOWN SERVER CERTIFICATE: 222 " + chain[0].getSubjectDN()); + } + }; + + public static TrustManager[] getTrustManagers() { + return new TrustManager[] { DUMMY_TRUST_MANAGER }; + } + + @Override + protected TrustManager[] engineGetTrustManagers() { + return getTrustManagers(); + } + + @Override + protected void engineInit(KeyStore keystore) throws KeyStoreException { + // Unused + } + + @Override + protected void engineInit(ManagerFactoryParameters managerFactoryParameters) + throws InvalidAlgorithmParameterException { + // Unused + } + +} diff --git a/src/main/java/com/myself/nettychat/common/ssl/StreamReader.java b/src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java similarity index 87% rename from src/main/java/com/myself/nettychat/common/ssl/StreamReader.java rename to src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java index 25cf5b7..b503615 100644 --- a/src/main/java/com/myself/nettychat/common/ssl/StreamReader.java +++ b/src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java @@ -1,25 +1,25 @@ -package com.myself.nettychat.common.ssl; - -import java.io.InputStream; - -public class StreamReader { - - public String toByteArray(InputStream fin) - { - int i = -1; - StringBuilder buf = new StringBuilder(); - try{ - while((i=fin.read())!=-1){ - if(buf.length()>0) buf.append(","); - buf.append("(byte)"); - buf.append(i); - } - - }catch(Throwable e){ - ; - } - - return buf.toString(); - } - -} +package com.myself.unclecatmyself.common.ssl; + +import java.io.InputStream; + +public class StreamReader { + + public String toByteArray(InputStream fin) + { + int i = -1; + StringBuilder buf = new StringBuilder(); + try{ + while((i=fin.read())!=-1){ + if(buf.length()>0) buf.append(","); + buf.append("(byte)"); + buf.append(i); + } + + }catch(Throwable e){ + ; + } + + return buf.toString(); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/ssl/X509CertTool.java b/src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java similarity index 95% rename from src/main/java/com/myself/nettychat/common/ssl/X509CertTool.java rename to src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java index be36d26..f5996ea 100644 --- a/src/main/java/com/myself/nettychat/common/ssl/X509CertTool.java +++ b/src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java @@ -1,69 +1,69 @@ -package com.myself.nettychat.common.ssl; - - - - -import sun.security.x509.*; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.PrivateKey; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Date; - - -/** - * This class would require rt.jar in the class path in order to - * generated it alternative is using keytool. - */ -public class X509CertTool { - - /** - * Create a self-signed X.509 Certificate - * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB" - * @param pair the KeyPair - * @param days how many days from now the Certificate is valid for - * @param algorithm the signing algorithm, eg "SHA1withRSA" - */ - @SuppressWarnings("restriction") - X509Certificate generateCertificate(String dn, KeyPair pair, int days, - String algorithm) throws GeneralSecurityException, IOException { - PrivateKey privkey = pair.getPrivate(); - X509CertInfo info = new X509CertInfo(); - Date from = new Date(); - Date to = new Date(from.getTime() + days * 86400000l); - CertificateValidity interval = new CertificateValidity(from, to); - BigInteger sn = new BigInteger(64, new SecureRandom()); - X500Name owner = new X500Name(dn); - - info.set(X509CertInfo.VALIDITY, interval); - info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn)); - info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); - info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); - info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic())); - info.set(X509CertInfo.VERSION, new CertificateVersion( - CertificateVersion.V3)); - AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); - info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo)); - - // Sign the cert to identify the algorithm that's used. - X509CertImpl cert = new X509CertImpl(info); - cert.sign(privkey, algorithm); - - // Update the algorith, and resign. - algo = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG); - info.set(CertificateAlgorithmId.NAME + "." - + CertificateAlgorithmId.ALGORITHM, algo); - cert = new X509CertImpl(info); - cert.sign(privkey, algorithm); - return cert; - } - - public static void main(String[] args) { - - } - -} +package com.myself.unclecatmyself.common.ssl; + + + + +import sun.security.x509.*; + +import java.io.IOException; +import java.math.BigInteger; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.PrivateKey; +import java.security.SecureRandom; +import java.security.cert.X509Certificate; +import java.util.Date; + + +/** + * This class would require rt.jar in the class path in order to + * generated it alternative is using keytool. + */ +public class X509CertTool { + + /** + * Create a self-signed X.509 Certificate + * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB" + * @param pair the KeyPair + * @param days how many days from now the Certificate is valid for + * @param algorithm the signing algorithm, eg "SHA1withRSA" + */ + @SuppressWarnings("restriction") + X509Certificate generateCertificate(String dn, KeyPair pair, int days, + String algorithm) throws GeneralSecurityException, IOException { + PrivateKey privkey = pair.getPrivate(); + X509CertInfo info = new X509CertInfo(); + Date from = new Date(); + Date to = new Date(from.getTime() + days * 86400000l); + CertificateValidity interval = new CertificateValidity(from, to); + BigInteger sn = new BigInteger(64, new SecureRandom()); + X500Name owner = new X500Name(dn); + + info.set(X509CertInfo.VALIDITY, interval); + info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn)); + info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); + info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); + info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic())); + info.set(X509CertInfo.VERSION, new CertificateVersion( + CertificateVersion.V3)); + AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); + info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo)); + + // Sign the cert to identify the algorithm that's used. + X509CertImpl cert = new X509CertImpl(info); + cert.sign(privkey, algorithm); + + // Update the algorith, and resign. + algo = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG); + info.set(CertificateAlgorithmId.NAME + "." + + CertificateAlgorithmId.ALGORITHM, algo); + cert = new X509CertImpl(info); + cert.sign(privkey, algorithm); + return cert; + } + + public static void main(String[] args) { + + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/ByteBufUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java similarity index 84% rename from src/main/java/com/myself/nettychat/common/utils/ByteBufUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java index ae5cc58..b1f8fae 100644 --- a/src/main/java/com/myself/nettychat/common/utils/ByteBufUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java @@ -1,19 +1,19 @@ -package com.myself.nettychat.common.utils; - - -import io.netty.buffer.ByteBuf; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 跨线程情况下 byteBuf 需要转换成byte[] - **/ -public class ByteBufUtil { - - public static byte[] copyByteBuf(ByteBuf byteBuf){ - byte[] bytes = new byte[byteBuf.readableBytes()]; - byteBuf.readBytes(bytes); - return bytes; - } - -} +package com.myself.unclecatmyself.common.utils; + + +import io.netty.buffer.ByteBuf; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 跨线程情况下 byteBuf 需要转换成byte[] + **/ +public class ByteBufUtil { + + public static byte[] copyByteBuf(ByteBuf byteBuf){ + byte[] bytes = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(bytes); + return bytes; + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/CRC16MySelf.java b/src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java similarity index 93% rename from src/main/java/com/myself/nettychat/common/utils/CRC16MySelf.java rename to src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java index f9f9eaa..7f2bf92 100644 --- a/src/main/java/com/myself/nettychat/common/utils/CRC16MySelf.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java @@ -1,73 +1,73 @@ -package com.myself.nettychat.common.utils; - -import java.math.BigInteger; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:31 2018\9\20 0020 - */ -public class CRC16MySelf { - - /** - * 生成指定格式的传输数据 - * @param ChannelId - * @param type - * @param data - * @return - */ - public static String getAllString(String ChannelId,String type,String data){ - String test = ChannelId + type + data; - String crcString = getCRC(test.getBytes()); - String result = Const.HEAD + test + crcString + Const.TAIL; - return result; - } - - /** - * 计算CRC16校验码 - * - * @param bytes 字节数组 - * @return {@link String} 校验码 - * @since 1.0 - */ - public static String getCRC(byte[] bytes) { - int CRC = 0x0000ffff; - int POLYNOMIAL = 0x0000a001; - int i, j; - for (i = 0; i < bytes.length; i++) { - CRC ^= ((int) bytes[i] & 0x000000ff); - for (j = 0; j < 8; j++) { - if ((CRC & 0x00000001) != 0) { - CRC >>= 1; - CRC ^= POLYNOMIAL; - } else { - CRC >>= 1; - } - } - } - return Integer.toHexString(CRC); - } - - /** - * 将16进制单精度浮点型转换为10进制浮点型 - * - * @return float - * @since 1.0 - */ - private float parseHex2Float(String hexStr) { - BigInteger bigInteger = new BigInteger(hexStr, 16); - return Float.intBitsToFloat(bigInteger.intValue()); - } - - /** - * 将十进制浮点型转换为十六进制浮点型 - * - * @return String - * @since 1.0 - */ - private String parseFloat2Hex(float data) { - return Integer.toHexString(Float.floatToIntBits(data)); - } - -} +package com.myself.unclecatmyself.common.utils; + +import java.math.BigInteger; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 19:31 2018\9\20 0020 + */ +public class CRC16MySelf { + + /** + * 生成指定格式的传输数据 + * @param ChannelId + * @param type + * @param data + * @return + */ + public static String getAllString(String ChannelId,String type,String data){ + String test = ChannelId + type + data; + String crcString = getCRC(test.getBytes()); + String result = Const.HEAD + test + crcString + Const.TAIL; + return result; + } + + /** + * 计算CRC16校验码 + * + * @param bytes 字节数组 + * @return {@link String} 校验码 + * @since 1.0 + */ + public static String getCRC(byte[] bytes) { + int CRC = 0x0000ffff; + int POLYNOMIAL = 0x0000a001; + int i, j; + for (i = 0; i < bytes.length; i++) { + CRC ^= ((int) bytes[i] & 0x000000ff); + for (j = 0; j < 8; j++) { + if ((CRC & 0x00000001) != 0) { + CRC >>= 1; + CRC ^= POLYNOMIAL; + } else { + CRC >>= 1; + } + } + } + return Integer.toHexString(CRC); + } + + /** + * 将16进制单精度浮点型转换为10进制浮点型 + * + * @return float + * @since 1.0 + */ + private float parseHex2Float(String hexStr) { + BigInteger bigInteger = new BigInteger(hexStr, 16); + return Float.intBitsToFloat(bigInteger.intValue()); + } + + /** + * 将十进制浮点型转换为十六进制浮点型 + * + * @return String + * @since 1.0 + */ + private String parseFloat2Hex(float data) { + return Integer.toHexString(Float.floatToIntBits(data)); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/CallBackMessage.java b/src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java similarity index 92% rename from src/main/java/com/myself/nettychat/common/utils/CallBackMessage.java rename to src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java index b3a773c..d2d6a04 100644 --- a/src/main/java/com/myself/nettychat/common/utils/CallBackMessage.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java @@ -1,35 +1,35 @@ -package com.myself.nettychat.common.utils; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -import java.nio.charset.Charset; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:30 2018\9\20 0020 - */ -public class CallBackMessage { - - public static final ByteBuf SUCCESS = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("success", Charset.forName("UTF-8"))); - - public static final ByteBuf ERROR = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("error", Charset.forName("UTF-8"))); - - public static final ByteBuf Check1_test = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("Check1\r", Charset.forName("UTF-8"))); - - public static final ByteBuf Check2 = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("Check2", Charset.forName("UTF-8"))); - - - public static ByteBuf sendString(String send){ - return Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(send, Charset.forName("UTF-8"))); - } - - -} +package com.myself.unclecatmyself.common.utils; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + +import java.nio.charset.Charset; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 19:30 2018\9\20 0020 + */ +public class CallBackMessage { + + public static final ByteBuf SUCCESS = Unpooled.unreleasableBuffer( + Unpooled.copiedBuffer("success", Charset.forName("UTF-8"))); + + public static final ByteBuf ERROR = Unpooled.unreleasableBuffer( + Unpooled.copiedBuffer("error", Charset.forName("UTF-8"))); + + public static final ByteBuf Check1_test = Unpooled.unreleasableBuffer( + Unpooled.copiedBuffer("Check1\r", Charset.forName("UTF-8"))); + + public static final ByteBuf Check2 = Unpooled.unreleasableBuffer( + Unpooled.copiedBuffer("Check2", Charset.forName("UTF-8"))); + + + public static ByteBuf sendString(String send){ + return Unpooled.unreleasableBuffer( + Unpooled.copiedBuffer(send, Charset.forName("UTF-8"))); + } + + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/Const.java b/src/main/java/com/myself/unclecatmyself/common/utils/Const.java similarity index 95% rename from src/main/java/com/myself/nettychat/common/utils/Const.java rename to src/main/java/com/myself/unclecatmyself/common/utils/Const.java index 63189b7..d6af216 100644 --- a/src/main/java/com/myself/nettychat/common/utils/Const.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/Const.java @@ -1,181 +1,181 @@ -package com.myself.nettychat.common.utils; - -import io.netty.channel.Channel; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:30 2018\9\20 0020 - */ -public class Const { - - //帧头 - public static final String HEAD = "gz"; - //帧尾 - public static final String TAIL = "xr"; - //控制锁状态 - public static final String CONTROL_TYPE = "s"; - //24锁 全部关闭状态 - public static final String LOCKS = "nnnnnnnnnnnnnnnnnnnnnnnn"; - //开锁标识 - public static final char OPEN = 'y'; - //客户端执行结果 - public static final String RESULT_TYPE = "j"; - //客户端执行测试结果 - public static final String RESULT_TEXT = "t"; - //服务器执行结果 - public static final String SUCCESS = "yyyyyyyyyyyyyyyyyyyyyyyy"; - public static final String ERROR = "nnnnnnnnnnnnnnnnnnnnnnnn"; - - private static Map map = new ConcurrentHashMap(); - - /** - * Netty连接池添加连接 - * @param clientId 连接ID - * @param channel 连接实例 - */ - public static void add(String clientId,Channel channel){ - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - System.out.println("add ChannelId: " + clientId + " " + formatter.format(new Date())); - map.put(clientId,channel); - } - - /** - * 判断是否存在该连接ID实例 - * @param channelID 连接Id - * @return - */ - public static boolean hasChannelID(String channelID){ - boolean state = map.containsKey(channelID); - return state; - } - - /** - * 根据连接ID 获取连接实例 - * @param clientId 链接Id - * @return - */ - public static Channel get(String clientId){ - return map.get(clientId); - } - - /** - * 根据链接实例移除链接实例 - * @param channel 链接实例 - */ - public static void remove(Channel channel){ - for (Map.Entry entry:map.entrySet()){ - if (entry.getValue()==channel){ - map.remove(entry.getKey()); - } - } - } - - /** - * 获取链接数组个数 - * @return - */ - public static int getSzie(){ - return map.size(); - } - - /** - * 获取链接数组Id - * @return - */ - public static Set getIdList(){ - return map.keySet(); - } - - /** - * 获取连接池数据信息 - */ - public static void mapInfo(){ - System.out.println("channel size : " + map.size()); - for (Map.Entry entry:map.entrySet()){ - System.out.println("clientId: " + entry.getKey()); - } - } - - /** - * 链接实例是否存在链接池中 - * @param channel 链接实例 - * @return 链接Id - */ - public static String isChannel(Channel channel){ - String clientId = null; - for (Map.Entry entry:map.entrySet()){ - if (entry.getValue() == channel){ - clientId = (String) entry.getKey(); - } - } - return clientId; - } - - /** - * 更新链接实例Id - * @param clientId 原始ID - * @param newID 新的连接ID - */ - public static void ChangeClientId(String clientId,String newID){ - for (Map.Entry entry:map.entrySet()){ - if (entry.getKey()==clientId){ - Channel channel = (Channel) entry.getValue(); - map.remove(entry.getKey()); - map.put(newID,channel); - } - } - } - - public static void changeChannel(String channelID, Channel channel) { - map.remove(channelID); - map.put(channelID,channel); - } - - public enum StateEnum{ - SUCCESS(1,"ok"), - FALID(2,"no"); - private int state; - - private String stateInfo; - - StateEnum(int state, String stateInfo) { - this.state = state; - this.stateInfo = stateInfo; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public String getStateInfo() { - return stateInfo; - } - - public void setStateInfo(String stateInfo) { - this.stateInfo = stateInfo; - } - - public static StateEnum stateOf(int index){ - for (StateEnum item:values()){ - if (item.getState() == index){ - return item; - } - } - return null; - } - } - - -} +package com.myself.unclecatmyself.common.utils; + +import io.netty.channel.Channel; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 19:30 2018\9\20 0020 + */ +public class Const { + + //帧头 + public static final String HEAD = "gz"; + //帧尾 + public static final String TAIL = "xr"; + //控制锁状态 + public static final String CONTROL_TYPE = "s"; + //24锁 全部关闭状态 + public static final String LOCKS = "nnnnnnnnnnnnnnnnnnnnnnnn"; + //开锁标识 + public static final char OPEN = 'y'; + //客户端执行结果 + public static final String RESULT_TYPE = "j"; + //客户端执行测试结果 + public static final String RESULT_TEXT = "t"; + //服务器执行结果 + public static final String SUCCESS = "yyyyyyyyyyyyyyyyyyyyyyyy"; + public static final String ERROR = "nnnnnnnnnnnnnnnnnnnnnnnn"; + + private static Map map = new ConcurrentHashMap(); + + /** + * Netty连接池添加连接 + * @param clientId 连接ID + * @param channel 连接实例 + */ + public static void add(String clientId,Channel channel){ + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + System.out.println("add ChannelId: " + clientId + " " + formatter.format(new Date())); + map.put(clientId,channel); + } + + /** + * 判断是否存在该连接ID实例 + * @param channelID 连接Id + * @return + */ + public static boolean hasChannelID(String channelID){ + boolean state = map.containsKey(channelID); + return state; + } + + /** + * 根据连接ID 获取连接实例 + * @param clientId 链接Id + * @return + */ + public static Channel get(String clientId){ + return map.get(clientId); + } + + /** + * 根据链接实例移除链接实例 + * @param channel 链接实例 + */ + public static void remove(Channel channel){ + for (Map.Entry entry:map.entrySet()){ + if (entry.getValue()==channel){ + map.remove(entry.getKey()); + } + } + } + + /** + * 获取链接数组个数 + * @return + */ + public static int getSzie(){ + return map.size(); + } + + /** + * 获取链接数组Id + * @return + */ + public static Set getIdList(){ + return map.keySet(); + } + + /** + * 获取连接池数据信息 + */ + public static void mapInfo(){ + System.out.println("channel size : " + map.size()); + for (Map.Entry entry:map.entrySet()){ + System.out.println("clientId: " + entry.getKey()); + } + } + + /** + * 链接实例是否存在链接池中 + * @param channel 链接实例 + * @return 链接Id + */ + public static String isChannel(Channel channel){ + String clientId = null; + for (Map.Entry entry:map.entrySet()){ + if (entry.getValue() == channel){ + clientId = (String) entry.getKey(); + } + } + return clientId; + } + + /** + * 更新链接实例Id + * @param clientId 原始ID + * @param newID 新的连接ID + */ + public static void ChangeClientId(String clientId,String newID){ + for (Map.Entry entry:map.entrySet()){ + if (entry.getKey()==clientId){ + Channel channel = (Channel) entry.getValue(); + map.remove(entry.getKey()); + map.put(newID,channel); + } + } + } + + public static void changeChannel(String channelID, Channel channel) { + map.remove(channelID); + map.put(channelID,channel); + } + + public enum StateEnum{ + SUCCESS(1,"ok"), + FALID(2,"no"); + private int state; + + private String stateInfo; + + StateEnum(int state, String stateInfo) { + this.state = state; + this.stateInfo = stateInfo; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public String getStateInfo() { + return stateInfo; + } + + public void setStateInfo(String stateInfo) { + this.stateInfo = stateInfo; + } + + public static StateEnum stateOf(int index){ + for (StateEnum item:values()){ + if (item.getState() == index){ + return item; + } + } + return null; + } + } + + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/CookieUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java similarity index 93% rename from src/main/java/com/myself/nettychat/common/utils/CookieUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java index 8bf761a..033312c 100644 --- a/src/main/java/com/myself/nettychat/common/utils/CookieUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java @@ -1,65 +1,65 @@ -package com.myself.nettychat.common.utils; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * cookie工具类 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 12:06 2018\6\13 0013 - */ -public class CookieUtil { - /** - * 设置cookie - * @param response - * @param name - * @param value - * @param maxAge - */ - public static void set(HttpServletResponse response, - String name, - String value, - int maxAge){ - Cookie cookie = new Cookie(name,value); - cookie.setPath("/"); - cookie.setMaxAge(maxAge); - response.addCookie(cookie); - } - - /** - * 获取cookie - * @param request - * @param name - * @return - */ - public static Cookie get(HttpServletRequest request, - String name){ - Map cookieMap = readCookieMap(request); - if (cookieMap.containsKey(name)){ - return cookieMap.get(name); - }else{ - return null; - } - } - - /** - * 将cookie封装成Map - * @param request - * @return - */ - private static Map readCookieMap(HttpServletRequest request){ - Map cookieMap = new HashMap<>(); - Cookie[] cookies = request.getCookies(); - if (cookies != null){ - for (Cookie cookie:cookies){ - cookieMap.put(cookie.getName(),cookie); - } - } - return cookieMap; - } -} +package com.myself.unclecatmyself.common.utils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; + +/** + * cookie工具类 + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 12:06 2018\6\13 0013 + */ +public class CookieUtil { + /** + * 设置cookie + * @param response + * @param name + * @param value + * @param maxAge + */ + public static void set(HttpServletResponse response, + String name, + String value, + int maxAge){ + Cookie cookie = new Cookie(name,value); + cookie.setPath("/"); + cookie.setMaxAge(maxAge); + response.addCookie(cookie); + } + + /** + * 获取cookie + * @param request + * @param name + * @return + */ + public static Cookie get(HttpServletRequest request, + String name){ + Map cookieMap = readCookieMap(request); + if (cookieMap.containsKey(name)){ + return cookieMap.get(name); + }else{ + return null; + } + } + + /** + * 将cookie封装成Map + * @param request + * @return + */ + private static Map readCookieMap(HttpServletRequest request){ + Map cookieMap = new HashMap<>(); + Cookie[] cookies = request.getCookies(); + if (cookies != null){ + for (Cookie cookie:cookies){ + cookieMap.put(cookie.getName(),cookie); + } + } + return cookieMap; + } +} diff --git a/src/main/java/com/myself/nettychat/common/utils/DataResction.java b/src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java similarity index 93% rename from src/main/java/com/myself/nettychat/common/utils/DataResction.java rename to src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java index 8d6a30f..2976d33 100644 --- a/src/main/java/com/myself/nettychat/common/utils/DataResction.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java @@ -1,106 +1,106 @@ -package com.myself.nettychat.common.utils; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class DataResction { - - /** - * 切除符合协议的帧头帧尾 - * @param data 原始通信数据 - * @return - */ - public static String ResctionHeadAndFeet(String data){ - return data.substring(2,data.length()-2); - } - - /** - * 切除符合协议的帧头帧尾————本地测试方法 - * @param data - * @return - */ - public static String ResctionHeadAndFeet_test(String data){ - return data.substring(2,data.length()-4); - } - - /** - * 返回通信CRC校验码 - * @param data - * @return - */ - public static String ResctionCRCCode(String data){ - return data.substring(39,data.length()); - } - - /** - * 返回通信内容,除去CRC校验码 - * @param data - * @return - */ - public static String ResctionData(String data){ - return data.substring(0,39); - } - - public static String ResctionDataNoID(String data){ - return data.substring(14); - } - - /** - * 返回设备唯一ID - * @param data - * @return - */ - public static String ResctionID(String data){ - return data.substring(0,14); - } - - /** - * 返回数据类型 - * @param data - * @return - */ - public static String ResctionType(String data){ - return data.substring(0,1); - } - - /** - * 返回实际内容值 - * @param data - * @return - */ - public static String ResctionRealData(String data){ - return data.substring(1); - } - - /** - * 截取电量信息,并返回 - * @param data - * @return - */ - public static String ResctionPower(String data){ - return data.substring(0,4); - } - - /** - * 截取纬度信息,并返回 - * @param data - * @return - */ - public static String ResctionLatitude(String data){ - return data.substring(3,11); - } - - /** - * 截取经度信息,并返回 - * @param data - * @return - */ - public static String ResctionLongitude(String data){ - return data.substring(14,data.length()); - } - - -} +package com.myself.unclecatmyself.common.utils; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 19:32 2018\9\20 0020 + */ +public class DataResction { + + /** + * 切除符合协议的帧头帧尾 + * @param data 原始通信数据 + * @return + */ + public static String ResctionHeadAndFeet(String data){ + return data.substring(2,data.length()-2); + } + + /** + * 切除符合协议的帧头帧尾————本地测试方法 + * @param data + * @return + */ + public static String ResctionHeadAndFeet_test(String data){ + return data.substring(2,data.length()-4); + } + + /** + * 返回通信CRC校验码 + * @param data + * @return + */ + public static String ResctionCRCCode(String data){ + return data.substring(39,data.length()); + } + + /** + * 返回通信内容,除去CRC校验码 + * @param data + * @return + */ + public static String ResctionData(String data){ + return data.substring(0,39); + } + + public static String ResctionDataNoID(String data){ + return data.substring(14); + } + + /** + * 返回设备唯一ID + * @param data + * @return + */ + public static String ResctionID(String data){ + return data.substring(0,14); + } + + /** + * 返回数据类型 + * @param data + * @return + */ + public static String ResctionType(String data){ + return data.substring(0,1); + } + + /** + * 返回实际内容值 + * @param data + * @return + */ + public static String ResctionRealData(String data){ + return data.substring(1); + } + + /** + * 截取电量信息,并返回 + * @param data + * @return + */ + public static String ResctionPower(String data){ + return data.substring(0,4); + } + + /** + * 截取纬度信息,并返回 + * @param data + * @return + */ + public static String ResctionLatitude(String data){ + return data.substring(3,11); + } + + /** + * 截取经度信息,并返回 + * @param data + * @return + */ + public static String ResctionLongitude(String data){ + return data.substring(14,data.length()); + } + + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/DataValida.java b/src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java similarity index 93% rename from src/main/java/com/myself/nettychat/common/utils/DataValida.java rename to src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java index 5d0c882..b66ed2c 100644 --- a/src/main/java/com/myself/nettychat/common/utils/DataValida.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java @@ -1,51 +1,51 @@ -package com.myself.nettychat.common.utils; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class DataValida { - - /** - * 校验数据帧头帧尾是否符合协议规范 - * @param data 通信原始数据 - * @return - */ - public static boolean ValidateHeadAndFeet(String data){ - boolean state = false; - if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-2,data.length()))){ - return true; - } - return state; - } - - /** - * 校验数据帧头是否符合协议数据规范————本地测试 - * @param data - * @return - */ - public static boolean ValidateHeadAndFeet_test(String data){ - boolean state = false; - if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-4,data.length()-2))){ - return true; - } - return state; - } - - /** - * CRC16校验 - * @param data 内容数据 - * @param crcCode 附带CRC校验码 - * @return - */ - public static boolean ValidateCRCCode(String data,String crcCode){ - boolean state = false; - if (crcCode.equals(CRC16MySelf.getCRC(data.getBytes()))){ - return true; - } - return state; - } - -} +package com.myself.unclecatmyself.common.utils; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 19:32 2018\9\20 0020 + */ +public class DataValida { + + /** + * 校验数据帧头帧尾是否符合协议规范 + * @param data 通信原始数据 + * @return + */ + public static boolean ValidateHeadAndFeet(String data){ + boolean state = false; + if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-2,data.length()))){ + return true; + } + return state; + } + + /** + * 校验数据帧头是否符合协议数据规范————本地测试 + * @param data + * @return + */ + public static boolean ValidateHeadAndFeet_test(String data){ + boolean state = false; + if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-4,data.length()-2))){ + return true; + } + return state; + } + + /** + * CRC16校验 + * @param data 内容数据 + * @param crcCode 附带CRC校验码 + * @return + */ + public static boolean ValidateCRCCode(String data,String crcCode){ + boolean state = false; + if (crcCode.equals(CRC16MySelf.getCRC(data.getBytes()))){ + return true; + } + return state; + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/IdWorker.java b/src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java similarity index 96% rename from src/main/java/com/myself/nettychat/common/utils/IdWorker.java rename to src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java index 8e45b4f..64fb401 100644 --- a/src/main/java/com/myself/nettychat/common/utils/IdWorker.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java @@ -1,150 +1,150 @@ -package com.myself.nettychat.common.utils; - -import java.lang.management.ManagementFactory; -import java.net.InetAddress; -import java.net.NetworkInterface; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 全局id生成器 - **/ -public class IdWorker { - - // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) - private final static long twepoch = 1288834974657L; - // 机器标识位数 - private final static long workerIdBits = 5L; - // 数据中心标识位数 - private final static long datacenterIdBits = 5L; - // 机器ID最大值 - private final static long maxWorkerId = -1L ^ (-1L << workerIdBits); - // 数据中心ID最大值 - private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); - // 毫秒内自增位 - private final static long sequenceBits = 12L; - // 机器ID偏左移12位 - private final static long workerIdShift = sequenceBits; - // 数据中心ID左移17位 - private final static long datacenterIdShift = sequenceBits + workerIdBits; - // 时间毫秒左移22位 - private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; - - private final static long sequenceMask = -1L ^ (-1L << sequenceBits); - /* 上次生产id时间戳 */ - private static long lastTimestamp = -1L; - // 0,并发控制 - private long sequence = 0L; - - private final long workerId; - // 数据标识id部分 - private final long datacenterId; - - public IdWorker(){ - this.datacenterId = getDatacenterId(maxDatacenterId); - this.workerId = getMaxWorkerId(datacenterId, maxWorkerId); - } - /** - * @param workerId - * 工作机器ID - * @param datacenterId - * 序列号 - */ - public IdWorker(long workerId, long datacenterId) { - if (workerId > maxWorkerId || workerId < 0) { - throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); - } - if (datacenterId > maxDatacenterId || datacenterId < 0) { - throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); - } - this.workerId = workerId; - this.datacenterId = datacenterId; - } - /** - * 获取下一个ID - * - * @return - */ - public synchronized long nextId() { - long timestamp = timeGen(); - if (timestamp < lastTimestamp) { - throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); - } - - if (lastTimestamp == timestamp) { - // 当前毫秒内,则+1 - sequence = (sequence + 1) & sequenceMask; - if (sequence == 0) { - // 当前毫秒内计数满了,则等待下一秒 - timestamp = tilNextMillis(lastTimestamp); - } - } else { - sequence = 0L; - } - lastTimestamp = timestamp; - // ID偏移组合生成最终的ID,并返回ID - long nextId = ((timestamp - twepoch) << timestampLeftShift) - | (datacenterId << datacenterIdShift) - | (workerId << workerIdShift) | sequence; - - return nextId; - } - - private long tilNextMillis(final long lastTimestamp) { - long timestamp = this.timeGen(); - while (timestamp <= lastTimestamp) { - timestamp = this.timeGen(); - } - return timestamp; - } - - private long timeGen() { - return System.currentTimeMillis(); - } - - /** - *

- * 获取 maxWorkerId - *

- */ - protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) { - StringBuffer mpid = new StringBuffer(); - mpid.append(datacenterId); - String name = ManagementFactory.getRuntimeMXBean().getName(); - if (!name.isEmpty()) { - /* - * GET jvmPid - */ - mpid.append(name.split("@")[0]); - } - /* - * MAC + PID 的 hashcode 获取16个低位 - */ - return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1); - } - - /** - *

- * 数据标识id部分 - *

- */ - protected static long getDatacenterId(long maxDatacenterId) { - long id = 0L; - try { - InetAddress ip = InetAddress.getLocalHost(); - NetworkInterface network = NetworkInterface.getByInetAddress(ip); - if (network == null) { - id = 1L; - } else { - byte[] mac = network.getHardwareAddress(); - id = ((0x000000FF & (long) mac[mac.length - 1]) - | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; - id = id % (maxDatacenterId + 1); - } - } catch (Exception e) { - System.out.println(" getDatacenterId: " + e.getMessage()); - } - return id; - } - -} +package com.myself.unclecatmyself.common.utils; + +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.NetworkInterface; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 全局id生成器 + **/ +public class IdWorker { + + // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) + private final static long twepoch = 1288834974657L; + // 机器标识位数 + private final static long workerIdBits = 5L; + // 数据中心标识位数 + private final static long datacenterIdBits = 5L; + // 机器ID最大值 + private final static long maxWorkerId = -1L ^ (-1L << workerIdBits); + // 数据中心ID最大值 + private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); + // 毫秒内自增位 + private final static long sequenceBits = 12L; + // 机器ID偏左移12位 + private final static long workerIdShift = sequenceBits; + // 数据中心ID左移17位 + private final static long datacenterIdShift = sequenceBits + workerIdBits; + // 时间毫秒左移22位 + private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; + + private final static long sequenceMask = -1L ^ (-1L << sequenceBits); + /* 上次生产id时间戳 */ + private static long lastTimestamp = -1L; + // 0,并发控制 + private long sequence = 0L; + + private final long workerId; + // 数据标识id部分 + private final long datacenterId; + + public IdWorker(){ + this.datacenterId = getDatacenterId(maxDatacenterId); + this.workerId = getMaxWorkerId(datacenterId, maxWorkerId); + } + /** + * @param workerId + * 工作机器ID + * @param datacenterId + * 序列号 + */ + public IdWorker(long workerId, long datacenterId) { + if (workerId > maxWorkerId || workerId < 0) { + throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); + } + if (datacenterId > maxDatacenterId || datacenterId < 0) { + throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + /** + * 获取下一个ID + * + * @return + */ + public synchronized long nextId() { + long timestamp = timeGen(); + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + if (lastTimestamp == timestamp) { + // 当前毫秒内,则+1 + sequence = (sequence + 1) & sequenceMask; + if (sequence == 0) { + // 当前毫秒内计数满了,则等待下一秒 + timestamp = tilNextMillis(lastTimestamp); + } + } else { + sequence = 0L; + } + lastTimestamp = timestamp; + // ID偏移组合生成最终的ID,并返回ID + long nextId = ((timestamp - twepoch) << timestampLeftShift) + | (datacenterId << datacenterIdShift) + | (workerId << workerIdShift) | sequence; + + return nextId; + } + + private long tilNextMillis(final long lastTimestamp) { + long timestamp = this.timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = this.timeGen(); + } + return timestamp; + } + + private long timeGen() { + return System.currentTimeMillis(); + } + + /** + *

+ * 获取 maxWorkerId + *

+ */ + protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) { + StringBuffer mpid = new StringBuffer(); + mpid.append(datacenterId); + String name = ManagementFactory.getRuntimeMXBean().getName(); + if (!name.isEmpty()) { + /* + * GET jvmPid + */ + mpid.append(name.split("@")[0]); + } + /* + * MAC + PID 的 hashcode 获取16个低位 + */ + return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1); + } + + /** + *

+ * 数据标识id部分 + *

+ */ + protected static long getDatacenterId(long maxDatacenterId) { + long id = 0L; + try { + InetAddress ip = InetAddress.getLocalHost(); + NetworkInterface network = NetworkInterface.getByInetAddress(ip); + if (network == null) { + id = 1L; + } else { + byte[] mac = network.getHardwareAddress(); + id = ((0x000000FF & (long) mac[mac.length - 1]) + | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; + id = id % (maxDatacenterId + 1); + } + } catch (Exception e) { + System.out.println(" getDatacenterId: " + e.getMessage()); + } + return id; + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/MessageId.java b/src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java similarity index 88% rename from src/main/java/com/myself/nettychat/common/utils/MessageId.java rename to src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java index a6b21f8..0405d0c 100644 --- a/src/main/java/com/myself/nettychat/common/utils/MessageId.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java @@ -1,27 +1,27 @@ -package com.myself.nettychat.common.utils; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 生成messageId - **/ -public class MessageId { - - private static AtomicInteger index = new AtomicInteger(1); - /** - * 获取messageId - * @return id - */ - public static int messageId(){ - for (;;) { - int current = index.get(); - int next = (current >= Integer.MAX_VALUE ? 0: current + 1); - if (index.compareAndSet(current, next)) { - return current; - } - } - } - -} +package com.myself.unclecatmyself.common.utils; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 生成messageId + **/ +public class MessageId { + + private static AtomicInteger index = new AtomicInteger(1); + /** + * 获取messageId + * @return id + */ + public static int messageId(){ + for (;;) { + int current = index.get(); + int next = (current >= Integer.MAX_VALUE ? 0: current + 1); + if (index.compareAndSet(current, next)) { + return current; + } + } + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/RandomNameUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java similarity index 85% rename from src/main/java/com/myself/nettychat/common/utils/RandomNameUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java index f9e2b19..f182055 100644 --- a/src/main/java/com/myself/nettychat/common/utils/RandomNameUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java @@ -1,20 +1,20 @@ -package com.myself.nettychat.common.utils; - -import java.util.Random; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:48 2018\8\14 0014 - */ -public class RandomNameUtil { - - private static Random ran = new Random(); - private final static int delta = 0x9fa5 - 0x4e00 + 1; - - public static char getName(){ - return (char)(0x4e00 + ran.nextInt(delta)); - } - -} +package com.myself.unclecatmyself.common.utils; + +import java.util.Random; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 11:48 2018\8\14 0014 + */ +public class RandomNameUtil { + + private static Random ran = new Random(); + private final static int delta = 0x9fa5 - 0x4e00 + 1; + + public static char getName(){ + return (char)(0x4e00 + ran.nextInt(delta)); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/RemotingUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java similarity index 96% rename from src/main/java/com/myself/nettychat/common/utils/RemotingUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java index 27ca76c..1604a9f 100644 --- a/src/main/java/com/myself/nettychat/common/utils/RemotingUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java @@ -1,187 +1,187 @@ -package com.myself.nettychat.common.utils; - -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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. - */ - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.lang.reflect.Method; -import java.net.*; -import java.nio.channels.Selector; -import java.nio.channels.SocketChannel; -import java.nio.channels.spi.SelectorProvider; -import java.util.ArrayList; -import java.util.Enumeration; - -public class RemotingUtil { - - public static final String OS_NAME = System.getProperty("os.name"); - - private static final Logger log = LoggerFactory.getLogger(RemotingUtil.class); - private static boolean isLinuxPlatform = false; - private static boolean isWindowsPlatform = false; - - static { - if (OS_NAME != null && OS_NAME.toLowerCase().contains("linux")) { - isLinuxPlatform = true; - } - - if (OS_NAME != null && OS_NAME.toLowerCase().contains("windows")) { - isWindowsPlatform = true; - } - } - - public static boolean isWindowsPlatform() { - return isWindowsPlatform; - } - - public static Selector openSelector() throws IOException { - Selector result = null; - - if (isLinuxPlatform()) { - try { - final Class providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider"); - if (providerClazz != null) { - try { - final Method method = providerClazz.getMethod("provider"); - if (method != null) { - final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); - if (selectorProvider != null) { - result = selectorProvider.openSelector(); - } - } - } catch (final Exception e) { - log.warn("Open ePoll Selector for linux platform exception", e); - } - } - } catch (final Exception e) { - // ignore - } - } - - if (result == null) { - result = Selector.open(); - } - - return result; - } - - public static boolean isLinuxPlatform() { - return isLinuxPlatform; - } - - public static String getLocalAddress() { - try { - // Traversal Network interface to get the first non-loopback and non-private address - Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); - ArrayList ipv4Result = new ArrayList(); - ArrayList ipv6Result = new ArrayList(); - while (enumeration.hasMoreElements()) { - final NetworkInterface networkInterface = enumeration.nextElement(); - final Enumeration en = networkInterface.getInetAddresses(); - while (en.hasMoreElements()) { - final InetAddress address = en.nextElement(); - if (!address.isLoopbackAddress()) { - if (address instanceof Inet6Address) { - ipv6Result.add(normalizeHostAddress(address)); - } else { - ipv4Result.add(normalizeHostAddress(address)); - } - } - } - } - - // prefer ipv4 - if (!ipv4Result.isEmpty()) { - for (String ip : ipv4Result) { - if (ip.startsWith("127.0") || ip.startsWith("192.168")) { - continue; - } - - return ip; - } - - return ipv4Result.get(ipv4Result.size() - 1); - } else if (!ipv6Result.isEmpty()) { - return ipv6Result.get(0); - } - //If failed to find,fall back to localhost - final InetAddress localHost = InetAddress.getLocalHost(); - return normalizeHostAddress(localHost); - } catch (Exception e) { - log.error("Failed to obtain local address", e); - } - - return null; - } - - public static String normalizeHostAddress(final InetAddress localHost) { - if (localHost instanceof Inet6Address) { - return "[" + localHost.getHostAddress() + "]"; - } else { - return localHost.getHostAddress(); - } - } - - public static SocketAddress string2SocketAddress(final String addr) { - String[] s = addr.split(":"); - InetSocketAddress isa = new InetSocketAddress(s[0], Integer.parseInt(s[1])); - return isa; - } - - public static String socketAddress2String(final SocketAddress addr) { - StringBuilder sb = new StringBuilder(); - InetSocketAddress inetSocketAddress = (InetSocketAddress) addr; - sb.append(inetSocketAddress.getAddress().getHostAddress()); - sb.append(":"); - sb.append(inetSocketAddress.getPort()); - return sb.toString(); - } - - public static SocketChannel connect(SocketAddress remote) { - return connect(remote, 1000 * 5); - } - - public static SocketChannel connect(SocketAddress remote, final int timeoutMillis) { - SocketChannel sc = null; - try { - sc = SocketChannel.open(); - sc.configureBlocking(true); - sc.socket().setSoLinger(false, -1); - sc.socket().setTcpNoDelay(true); - sc.socket().setReceiveBufferSize(1024 * 64); - sc.socket().setSendBufferSize(1024 * 64); - sc.socket().connect(remote, timeoutMillis); - sc.configureBlocking(false); - return sc; - } catch (Exception e) { - if (sc != null) { - try { - sc.close(); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - - return null; - } - - -} +package com.myself.unclecatmyself.common.utils; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.net.*; +import java.nio.channels.Selector; +import java.nio.channels.SocketChannel; +import java.nio.channels.spi.SelectorProvider; +import java.util.ArrayList; +import java.util.Enumeration; + +public class RemotingUtil { + + public static final String OS_NAME = System.getProperty("os.name"); + + private static final Logger log = LoggerFactory.getLogger(RemotingUtil.class); + private static boolean isLinuxPlatform = false; + private static boolean isWindowsPlatform = false; + + static { + if (OS_NAME != null && OS_NAME.toLowerCase().contains("linux")) { + isLinuxPlatform = true; + } + + if (OS_NAME != null && OS_NAME.toLowerCase().contains("windows")) { + isWindowsPlatform = true; + } + } + + public static boolean isWindowsPlatform() { + return isWindowsPlatform; + } + + public static Selector openSelector() throws IOException { + Selector result = null; + + if (isLinuxPlatform()) { + try { + final Class providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider"); + if (providerClazz != null) { + try { + final Method method = providerClazz.getMethod("provider"); + if (method != null) { + final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); + if (selectorProvider != null) { + result = selectorProvider.openSelector(); + } + } + } catch (final Exception e) { + log.warn("Open ePoll Selector for linux platform exception", e); + } + } + } catch (final Exception e) { + // ignore + } + } + + if (result == null) { + result = Selector.open(); + } + + return result; + } + + public static boolean isLinuxPlatform() { + return isLinuxPlatform; + } + + public static String getLocalAddress() { + try { + // Traversal Network interface to get the first non-loopback and non-private address + Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); + ArrayList ipv4Result = new ArrayList(); + ArrayList ipv6Result = new ArrayList(); + while (enumeration.hasMoreElements()) { + final NetworkInterface networkInterface = enumeration.nextElement(); + final Enumeration en = networkInterface.getInetAddresses(); + while (en.hasMoreElements()) { + final InetAddress address = en.nextElement(); + if (!address.isLoopbackAddress()) { + if (address instanceof Inet6Address) { + ipv6Result.add(normalizeHostAddress(address)); + } else { + ipv4Result.add(normalizeHostAddress(address)); + } + } + } + } + + // prefer ipv4 + if (!ipv4Result.isEmpty()) { + for (String ip : ipv4Result) { + if (ip.startsWith("127.0") || ip.startsWith("192.168")) { + continue; + } + + return ip; + } + + return ipv4Result.get(ipv4Result.size() - 1); + } else if (!ipv6Result.isEmpty()) { + return ipv6Result.get(0); + } + //If failed to find,fall back to localhost + final InetAddress localHost = InetAddress.getLocalHost(); + return normalizeHostAddress(localHost); + } catch (Exception e) { + log.error("Failed to obtain local address", e); + } + + return null; + } + + public static String normalizeHostAddress(final InetAddress localHost) { + if (localHost instanceof Inet6Address) { + return "[" + localHost.getHostAddress() + "]"; + } else { + return localHost.getHostAddress(); + } + } + + public static SocketAddress string2SocketAddress(final String addr) { + String[] s = addr.split(":"); + InetSocketAddress isa = new InetSocketAddress(s[0], Integer.parseInt(s[1])); + return isa; + } + + public static String socketAddress2String(final SocketAddress addr) { + StringBuilder sb = new StringBuilder(); + InetSocketAddress inetSocketAddress = (InetSocketAddress) addr; + sb.append(inetSocketAddress.getAddress().getHostAddress()); + sb.append(":"); + sb.append(inetSocketAddress.getPort()); + return sb.toString(); + } + + public static SocketChannel connect(SocketAddress remote) { + return connect(remote, 1000 * 5); + } + + public static SocketChannel connect(SocketAddress remote, final int timeoutMillis) { + SocketChannel sc = null; + try { + sc = SocketChannel.open(); + sc.configureBlocking(true); + sc.socket().setSoLinger(false, -1); + sc.socket().setTcpNoDelay(true); + sc.socket().setReceiveBufferSize(1024 * 64); + sc.socket().setSendBufferSize(1024 * 64); + sc.socket().connect(remote, timeoutMillis); + sc.configureBlocking(false); + return sc; + } catch (Exception e) { + if (sc != null) { + try { + sc.close(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + } + + return null; + } + + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/SendUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java similarity index 95% rename from src/main/java/com/myself/nettychat/common/utils/SendUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java index c902996..7b2c0f0 100644 --- a/src/main/java/com/myself/nettychat/common/utils/SendUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java @@ -1,84 +1,84 @@ -package com.myself.nettychat.common.utils; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; - -import java.nio.charset.Charset; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class SendUtil { - - public boolean send(Integer item, Channel channel, String channelID, String type){ - try { - if (item != null && channel != null){ - String items = IntegerToString(item); - String result = CRC16MySelf.getAllString(channelID,type,items); - System.out.println("send:" + result); - ByteBuf msg = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(result, Charset.forName("UTF-8"))); - channel.writeAndFlush(msg.duplicate()); - return true; - } - }catch (Exception e){ - System.out.println(e.getMessage()); - return false; - } - return false; - } - - /** - * 广播发送事件 - * @param items - * @param channel - * @param channelID - * @param type - * @return - */ - public void sendAll(String items, Channel channel, String channelID, String type){ - try { - if (items != null && channel != null){ - String result = CRC16MySelf.getAllString(channelID,type,items); - ByteBuf msg = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(result, Charset.forName("UTF-8"))); - channel.writeAndFlush(msg.duplicate()); - } - }catch (Exception e){ - e.printStackTrace(); - System.out.println(e.getMessage()); - } - } - - public String IntegerToString(Integer item){ - char[] locks_char = Const.LOCKS.toCharArray(); - for (int i=0;i T getBean(Class clazz){ - return getApplicationContext().getBean(clazz); - } - - //通过name,以及Clazz返回指定的Bean - public static T getBean(String name,Class clazz){ - return getApplicationContext().getBean(name, clazz); - } - -} +package com.myself.unclecatmyself.common.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 获取spring当前Bean + **/ +@Component +public class SpringBeanUtils implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + if (SpringBeanUtils.applicationContext == null){ + SpringBeanUtils.applicationContext = applicationContext; + } + } + + //获取applicationContext + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + //通过name获取 Bean. + public static Object getBean(String name){ + return getApplicationContext().getBean(name); + } + + //通过class获取Bean. + public static T getBean(Class clazz){ + return getApplicationContext().getBean(clazz); + } + + //通过name,以及Clazz返回指定的Bean + public static T getBean(String name,Class clazz){ + return getApplicationContext().getBean(name, clazz); + } + +} diff --git a/src/main/java/com/myself/nettychat/common/utils/StringUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/StringUtil.java similarity index 87% rename from src/main/java/com/myself/nettychat/common/utils/StringUtil.java rename to src/main/java/com/myself/unclecatmyself/common/utils/StringUtil.java index bd4741d..9ec9281 100644 --- a/src/main/java/com/myself/nettychat/common/utils/StringUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/StringUtil.java @@ -1,21 +1,21 @@ -package com.myself.nettychat.common.utils; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 15:55 2018\8\20 0020 - */ -public class StringUtil { - - public static String getName(String str){ - int nameIndex = str.indexOf("-"); - return str.substring(0,nameIndex); - } - - - public static String getMsg(String str){ - int nameIndex = str.indexOf("-"); - return str.substring(nameIndex + 1,str.length()); - } -} +package com.myself.unclecatmyself.common.utils; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 15:55 2018\8\20 0020 + */ +public class StringUtil { + + public static String getName(String str){ + int nameIndex = str.indexOf("-"); + return str.substring(0,nameIndex); + } + + + public static String getMsg(String str){ + int nameIndex = str.indexOf("-"); + return str.substring(nameIndex + 1,str.length()); + } +} diff --git a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java similarity index 92% rename from src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java rename to src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index adb7f56..e9d81ea 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -1,7 +1,6 @@ -package com.myself.nettychat.common.websockets; +package com.myself.unclecatmyself.common.websockets; import io.netty.channel.Channel; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; import java.util.Map; diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java similarity index 94% rename from src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java rename to src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java index c4cd4aa..de64e80 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java @@ -1,51 +1,51 @@ -package com.myself.nettychat.common.websockets; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:19 2018\11\16 0016 - */ -@Slf4j -public abstract class WebSocketHandler extends SimpleChannelInboundHandler { - - WebSocketHandlerApi webSocketHandlerApi; - - public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ - this.webSocketHandlerApi = webSocketHandlerApi; - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof TextWebSocketFrame){ - textdoMessage(ctx,(TextWebSocketFrame)msg); - }else if (msg instanceof WebSocketFrame){ - webdoMessage(ctx,(WebSocketFrame)msg); - } - } - - protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); - - protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - webSocketHandlerApi.close(ctx.channel()); - } - - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if(evt instanceof IdleStateEvent){ - webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); - } - super.userEventTriggered(ctx, evt); - } -} +package com.myself.unclecatmyself.common.websockets; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.handler.timeout.IdleStateEvent; +import lombok.extern.slf4j.Slf4j; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:19 2018\11\16 0016 + */ +@Slf4j +public abstract class WebSocketHandler extends SimpleChannelInboundHandler { + + WebSocketHandlerApi webSocketHandlerApi; + + public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ + this.webSocketHandlerApi = webSocketHandlerApi; + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof TextWebSocketFrame){ + textdoMessage(ctx,(TextWebSocketFrame)msg); + }else if (msg instanceof WebSocketFrame){ + webdoMessage(ctx,(WebSocketFrame)msg); + } + } + + protected abstract void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg); + + protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); + + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + webSocketHandlerApi.close(ctx.channel()); + } + + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent){ + webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); + } + super.userEventTriggered(ctx, evt); + } +} diff --git a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java similarity index 78% rename from src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java rename to src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java index b19d381..94ecc0c 100644 --- a/src/main/java/com/myself/nettychat/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -1,25 +1,24 @@ -package com.myself.nettychat.common.websockets; - -import io.netty.channel.Channel; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.timeout.IdleStateEvent; - -import java.util.Map; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:22 2018\11\16 0016 - */ -public interface WebSocketHandlerApi { - - void close(Channel channel); - - void sendMeText(Channel channel, Map maps); - - void sendToText(Channel channel, Map maps); - - void doTimeOut(Channel channel, IdleStateEvent evt); - -} +package com.myself.unclecatmyself.common.websockets; + +import io.netty.channel.Channel; +import io.netty.handler.timeout.IdleStateEvent; + +import java.util.Map; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 20:22 2018\11\16 0016 + */ +public interface WebSocketHandlerApi { + + void close(Channel channel); + + void sendMeText(Channel channel, Map maps); + + void sendToText(Channel channel, Map maps); + + void doTimeOut(Channel channel, IdleStateEvent evt); + +} diff --git a/src/main/java/com/myself/nettychat/task/ScheduledPool.java b/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java similarity index 80% rename from src/main/java/com/myself/nettychat/task/ScheduledPool.java rename to src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java index ebff4f8..a7ce31c 100644 --- a/src/main/java/com/myself/nettychat/task/ScheduledPool.java +++ b/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java @@ -1,33 +1,33 @@ -package com.myself.nettychat.task; - -import com.myself.nettychat.common.properties.InitNetty; -import com.myself.nettychat.common.pool.Scheduled; -import org.springframework.stereotype.Service; - -import java.util.concurrent.*; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 定时任务 - **/ -@Service -public class ScheduledPool implements Scheduled { - - private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(20); - - private final InitNetty serverBean; - - public ScheduledPool(InitNetty serverBean) { - this.serverBean = serverBean; - } - - @Override - public ScheduledFuture submit(Runnable runnable) { - int initalDelay = serverBean.getInitalDelay(); - int period = serverBean.getPeriod(); - return scheduledExecutorService.scheduleAtFixedRate(runnable, initalDelay, period, TimeUnit.SECONDS); - } - -} +package com.myself.unclecatmyself.task; + +import com.myself.unclecatmyself.common.properties.InitNetty; +import com.myself.unclecatmyself.common.pool.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.concurrent.*; + + +/** + * @author MySelf + * @create 2018/9/22 + * @desc 定时任务 + **/ +@Service +public class ScheduledPool implements Scheduled { + + private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(20); + + private final InitNetty serverBean; + + public ScheduledPool(InitNetty serverBean) { + this.serverBean = serverBean; + } + + @Override + public ScheduledFuture submit(Runnable runnable) { + int initalDelay = serverBean.getInitalDelay(); + int period = serverBean.getPeriod(); + return scheduledExecutorService.scheduleAtFixedRate(runnable, initalDelay, period, TimeUnit.SECONDS); + } + +} diff --git a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java similarity index 92% rename from src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java rename to src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java index ac3e15c..0e31a95 100644 --- a/src/main/java/com/myself/nettychat/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java @@ -1,6 +1,6 @@ -package com.myself.nettychat.user; +package com.myself.unclecatmyself.user; -import com.myself.nettychat.bootstrap.backmsg.InChatBackMapService; +import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import org.springframework.stereotype.Service; import java.util.HashMap; diff --git a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java similarity index 87% rename from src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java rename to src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java index a257109..f69a09d 100644 --- a/src/main/java/com/myself/nettychat/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java @@ -1,6 +1,6 @@ -package com.myself.nettychat.user; +package com.myself.unclecatmyself.user; -import com.myself.nettychat.bootstrap.verify.InChatVerifyService; +import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e3f6e8f..361e201 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,4 +14,4 @@ inchat: initalDelay: 10 # 重置延迟 maxContext: 65536 webSocketPath: "/ws" - webSocketHandler: com.myself.nettychat.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 + webSocketHandler: com.myself.unclecatmyselfyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 diff --git a/src/test/java/com/myself/nettychat/NettychatApplicationTests.java b/src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java similarity index 89% rename from src/test/java/com/myself/nettychat/NettychatApplicationTests.java rename to src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java index 9c04bf0..7ec68ed 100644 --- a/src/test/java/com/myself/nettychat/NettychatApplicationTests.java +++ b/src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java @@ -1,4 +1,4 @@ -package com.myself.nettychat; +package com.myself.unclecatmyself; import org.junit.Test; import org.junit.runner.RunWith; From a7a753ed9e94ad9225e32824bf00794c97586395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Fri, 30 Nov 2018 17:28:55 +0800 Subject: [PATCH 043/151] some --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 361e201..d670f9b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,4 +14,4 @@ inchat: initalDelay: 10 # 重置延迟 maxContext: 65536 webSocketPath: "/ws" - webSocketHandler: com.myself.unclecatmyselfyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 + webSocketHandler: com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 From 5b71d4791af9bdbbb9ebcb16d04c4317260e3189 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 2 Dec 2018 23:07:09 +0800 Subject: [PATCH 044/151] update --- doc/design_cn.md | 4 ++++ .../myself/unclecatmyself/user/InChatBackMapServiceImpl.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/design_cn.md b/doc/design_cn.md index e15ca8d..69e88be 100644 --- a/doc/design_cn.md +++ b/doc/design_cn.md @@ -1,5 +1,9 @@ # 项目设计思路 +## 设计原则 + +AOP、DI为主,基于Spring Boot快速搭建,尽量减少用户的二次搭配开发 + ## 关于登录 关于InChat统一登录的接口设计,设计针对小程序、APP、Web端的登录作用,所以将作为token的形式登录InChat的WebSocket长连接,用户服务器做sso的认证登录后得到token后直接发送login信息到InChat,用户服务器需要重写InChat中的verifyToken方法校验自己的的Token信息是否有效,正常则启动长连接。考虑到token失效问题,WebSocket长连接的登录仅做初次登录,接下来考虑以心跳形式保持链接状态(pingpong),使用token认证是为保护InChat链接的常规化(目前暂时这样设计后面根据使用情况更改设计) diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java index 0e31a95..5b53528 100644 --- a/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java @@ -7,7 +7,7 @@ import java.util.Map; /** - * 不属于项目代码 + * 列入项目中 * Created by MySelf on 2018/11/23. */ @Service From 5f6975e70fa185cc5f5319443478c1fd63e837fe Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 2 Dec 2018 23:09:01 +0800 Subject: [PATCH 045/151] update --- doc/Project-Log-cn.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 227ac85..2d75d5f 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -6,4 +6,5 @@ * 【2018-11-26】 登录存储用户token与链接实例,发送给自己功能API,部分功能代码重构 * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 * 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 -* 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 \ No newline at end of file +* 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 +* 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 \ No newline at end of file From 7e60273304ec356003d63639662742f23b7ed759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 11:45:04 +0800 Subject: [PATCH 046/151] update-map --- Front-End-Testing/chat.html | 16 ++++++++++++ doc/design_cn.md | 6 ++++- .../backmsg}/InChatBackMapServiceImpl.java | 2 +- .../channel/WebSocketHandlerService.java | 26 ++++++++++++------- .../handler/DefaultWebSocketHandler.java | 10 +++++-- .../ServerWebSocketHandlerService.java | 16 +++++++++--- .../websockets/WebSocketHandlerApi.java | 5 ++-- 7 files changed, 62 insertions(+), 19 deletions(-) rename src/main/java/com/myself/unclecatmyself/{user => bootstrap/backmsg}/InChatBackMapServiceImpl.java (96%) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 18d1223..bd42199 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -118,6 +118,21 @@ } } + function addGroup(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "addGroup", + value: ["1111","2222","3333"] + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } + } + window.onbeforeunload = function(event) { event.returnValue = "刷新提醒"; }; @@ -130,6 +145,7 @@

SpringBoot netty 聊天室

+

diff --git a/doc/design_cn.md b/doc/design_cn.md index 69e88be..fff6164 100644 --- a/doc/design_cn.md +++ b/doc/design_cn.md @@ -10,4 +10,8 @@ AOP、DI为主,基于Spring Boot快速搭建,尽量减少用户的二次搭 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/design/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(12).png) -* 【2018-11-22】 编码实现和[详细实现文档](detail/Login-cn.md) \ No newline at end of file +* 【2018-11-22】 编码实现和[详细实现文档](detail/Login-cn.md) + +## 离线消息模板 + +一版采用RabbitMQ \ No newline at end of file diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java rename to src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 5b53528..abb437e 100644 --- a/src/main/java/com/myself/unclecatmyself/user/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.user; +package com.myself.unclecatmyself.bootstrap.backmsg; import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 7f88269..5f40928 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -1,5 +1,6 @@ package com.myself.unclecatmyself.bootstrap.channel; +import com.alibaba.fastjson.JSONArray; import com.google.gson.Gson; import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.myself.unclecatmyself.bootstrap.BaseAuthService; @@ -41,9 +42,9 @@ public WebSocketHandlerService(BaseAuthService baseAuthService,Gson gson){ } @Override - public boolean login(Channel channel, Map maps) { + public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 - String token = maps.get(inChatVerifyService.getVerifyLogin()); + String token = (String) maps.get(inChatVerifyService.getVerifyLogin()); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); websocketChannelService.loginWsSuccess(channel,token); @@ -55,16 +56,16 @@ public boolean login(Channel channel, Map maps) { } @Override - public void sendMeText(Channel channel, Map maps) { + public void sendMeText(Channel channel, Map maps) { channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendMe(maps.get("value"))))); + gson.toJson(inChatBackMapService.sendMe((String) maps.get("value"))))); } @Override - public void sendToText(Channel channel, Map maps) { - String otherOne = maps.get("one"); - String value = maps.get("value"); - String me = maps.get("me"); + public void sendToText(Channel channel, Map maps) { + String otherOne = (String) maps.get("one"); + String value = (String) maps.get("value"); + String me = (String) maps.get("me"); if (websocketChannelService.hasOther(otherOne)){ //发送给对方 Channel other = websocketChannelService.getChannel(otherOne); @@ -96,7 +97,14 @@ public void doTimeOut(Channel channel, IdleStateEvent evt) { } @Override - public void sendGroupText(Channel channel, Map maps) { + public void sendGroupText(Channel channel, Map maps) { + + } + + @Override + public void addGroup(Channel channel, Map maps) { + JSONArray value = (JSONArray) maps.get("value"); + log.info(value.getString(0)); } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 84cae39..8aac960 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -47,8 +47,8 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) }else{ throw new NoFindHandlerException("Server Handler 不匹配"); } - Map maps = (Map) JSON.parse(msg.text()); - switch (maps.get("type")){ + Map maps = (Map) JSON.parse(msg.text()); + switch ((String)maps.get("type")){ case "login": log.info("【用户链接登录操作】"); serverWebSocketHandlerService.login(channel,maps); @@ -63,10 +63,16 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) log.info("【用户链接发送给某人】"); serverWebSocketHandlerService.sendToText(channel,maps); break; + //发送给群组 case "sendGroup": log.info("【用户链接发送给群聊】"); serverWebSocketHandlerService.sendGroupText(channel,maps); break; + //组件群组 + case "addGroup": + log.info("【组件群组】"); + serverWebSocketHandlerService.addGroup(channel,maps); + break; default: break; } diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index e9d81ea..3e81a28 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -16,21 +16,21 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA * @param map {@link Map} 数据信息 * @return {@link Boolean} 成功失败 */ - public abstract boolean login(Channel channel, Map map); + public abstract boolean login(Channel channel, Map map); /** * 发送给自己 * @param channel {@link Channel} 链接实例 * @param maps {@link Map} 数据信息 */ - public abstract void sendMeText(Channel channel,Map maps); + public abstract void sendMeText(Channel channel,Map maps); /** * 发送给某人 * @param channel {@link Channel} 链接实例 * @param maps {@link Map} 数据信息 */ - public abstract void sendToText(Channel channel, Map maps); + public abstract void sendToText(Channel channel, Map maps); public abstract void pong(Channel channel); @@ -47,5 +47,13 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA * @param channel {@link Channel} 链接实例 * @param maps {@link Map} 数据信息 */ - public abstract void sendGroupText(Channel channel, Map maps); + public abstract void sendGroupText(Channel channel, Map maps); + + + /** + * 组件群聊 + * @param channel {@link Channel} 链接实例 + * @param maps {@link Map} 数据信息 + */ + public abstract void addGroup(Channel channel, Map maps); } diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java index 94ecc0c..5619d8a 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -15,10 +15,11 @@ public interface WebSocketHandlerApi { void close(Channel channel); - void sendMeText(Channel channel, Map maps); + void sendMeText(Channel channel, Map maps); - void sendToText(Channel channel, Map maps); + void sendToText(Channel channel, Map maps); void doTimeOut(Channel channel, IdleStateEvent evt); + void addGroup(Channel channel, Map maps); } From d2e1a1fdb50a71e953338aac5a476d73f2a50a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 11:46:18 +0800 Subject: [PATCH 047/151] log --- doc/Project-Log-cn.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 2d75d5f..c1db6fc 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -7,4 +7,5 @@ * 【2018-11-27】 发送消息给在线其他用户,代码部分模块加注释,[撰写设计文档](detail/login_rect.md),但是中途思路有所转变 * 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 * 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 -* 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 \ No newline at end of file +* 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 +* 【2018-12-03】 构建【组件群聊】模块功能,整改数据接收Map转为Map。 \ No newline at end of file From 2380ce1bdf85e7264f0bfa023f142899bc798eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 13:47:12 +0800 Subject: [PATCH 048/151] update --- .../bootstrap/channel/WebSocketHandlerService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 5f40928..06e5072 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -104,8 +104,7 @@ public void sendGroupText(Channel channel, Map maps) { @Override public void addGroup(Channel channel, Map maps) { JSONArray value = (JSONArray) maps.get("value"); - log.info(value.getString(0)); - + //TODO 群聊数据业务 } @Override From 880e356f2111d6200ab512fac56f069ab7d60f75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 14:35:39 +0800 Subject: [PATCH 049/151] update --- Front-End-Testing/chat.html | 10 ++++++---- doc/Project-Log-cn.md | 2 +- .../backmsg/InChatBackMapService.java | 9 +++++++++ .../channel/WebSocketHandlerService.java | 20 +++++++++++-------- .../handler/DefaultWebSocketHandler.java | 5 ----- .../bootstrap/verify/InChatVerifyService.java | 4 +++- .../ServerWebSocketHandlerService.java | 7 ------- .../websockets/WebSocketHandlerApi.java | 2 -- .../user/InChatVerifyServiceImpl.java | 14 ++++--------- 9 files changed, 35 insertions(+), 38 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index bd42199..4cb8e6a 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -118,14 +118,16 @@ } } - function addGroup(value) { + function sendGroup(value) { if (!window.WebSocket) { return; } if (socket.readyState == WebSocket.OPEN) { var message = { - type: "addGroup", - value: ["1111","2222","3333"] + type: "sendGroup", + groupId: "2", + me: "3333", + value: value } socket.send(JSON.stringify(message)); } else { @@ -145,7 +147,7 @@

SpringBoot netty 聊天室

- +

diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index c1db6fc..2322d4f 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -8,4 +8,4 @@ * 【2018-11-29】 修复登录下线关闭channel异常BUG,移除原始未重构代码,更新下线模块,与本地在线存储功能。 * 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 * 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 -* 【2018-12-03】 构建【组件群聊】模块功能,整改数据接收Map转为Map。 \ No newline at end of file +* 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java index e150031..ed16e4d 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java @@ -42,4 +42,13 @@ public interface InChatBackMapService { * @return */ Map getMsg(String me, String value); + + /** + * 发送消息到群里 + * @param me {@link String} 发送人的标签 + * @param value {@link String} 通讯消息 + * @param groupId {@link String} 群聊Id + * @return + */ + Map sendGroup(String me,String value,String groupId); } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 06e5072..8ceb19f 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -44,7 +44,7 @@ public WebSocketHandlerService(BaseAuthService baseAuthService,Gson gson){ @Override public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 - String token = (String) maps.get(inChatVerifyService.getVerifyLogin()); + String token = (String) maps.get("token"); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); websocketChannelService.loginWsSuccess(channel,token); @@ -98,13 +98,17 @@ public void doTimeOut(Channel channel, IdleStateEvent evt) { @Override public void sendGroupText(Channel channel, Map maps) { - - } - - @Override - public void addGroup(Channel channel, Map maps) { - JSONArray value = (JSONArray) maps.get("value"); - //TODO 群聊数据业务 + String groupId = (String) maps.get("groupId"); + String me = (String) maps.get("me"); + String value = (String) maps.get("value"); + JSONArray array = inChatVerifyService.getArrayByGroupId(groupId); + for (Object item:array) { + if (websocketChannelService.hasOther((String) item)){ + Channel other = websocketChannelService.getChannel((String) item); + other.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); + } + } } @Override diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 8aac960..b40475c 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -68,11 +68,6 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) log.info("【用户链接发送给群聊】"); serverWebSocketHandlerService.sendGroupText(channel,maps); break; - //组件群组 - case "addGroup": - log.info("【组件群组】"); - serverWebSocketHandlerService.addGroup(channel,maps); - break; default: break; } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java index 9438c0c..d7da9a8 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java @@ -1,5 +1,7 @@ package com.myself.unclecatmyself.bootstrap.verify; +import com.alibaba.fastjson.JSONArray; + /** * 用户校验层 * Created by MySelf on 2018/11/22. @@ -8,5 +10,5 @@ public interface InChatVerifyService { boolean verifyToken(String token); - String getVerifyLogin(); + JSONArray getArrayByGroupId(String groupId); } \ No newline at end of file diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index 3e81a28..87c99e0 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -49,11 +49,4 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA */ public abstract void sendGroupText(Channel channel, Map maps); - - /** - * 组件群聊 - * @param channel {@link Channel} 链接实例 - * @param maps {@link Map} 数据信息 - */ - public abstract void addGroup(Channel channel, Map maps); } diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java index 5619d8a..5937678 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -20,6 +20,4 @@ public interface WebSocketHandlerApi { void sendToText(Channel channel, Map maps); void doTimeOut(Channel channel, IdleStateEvent evt); - - void addGroup(Channel channel, Map maps); } diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java index f69a09d..7e580f0 100644 --- a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java @@ -1,5 +1,6 @@ package com.myself.unclecatmyself.user; +import com.alibaba.fastjson.JSONArray; import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -16,19 +17,12 @@ public class InChatVerifyServiceImpl implements InChatVerifyService { public boolean verifyToken(String token) { //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 log.info("verify---"+token); - //为了方便多人登录,暂不校验 -// if ("3333".equals(token)){ -// return true; -// } return true; } - /** - * 用户期望校验的自定义名称、openid、token、cookie、或者公司自定义的名称等 - * @return - */ @Override - public String getVerifyLogin() { - return "token"; + public JSONArray getArrayByGroupId(String groupId) { + return JSONArray.parseArray("['1111','2222','3333']"); } + } From 15d705f948c55a9c8636969027a3502cfee08afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 15:04:10 +0800 Subject: [PATCH 050/151] update-task-to-db --- .../backmsg/InChatBackMapServiceImpl.java | 12 +++++++- .../channel/WebSocketHandlerService.java | 19 ++++++++++++ .../data/InChatToDataBaseService.java | 12 ++++++++ .../task/DataAsynchronousTask.java | 29 +++++++++++++++++++ .../user/InChatToDataBaseServiceImpl.java | 19 ++++++++++++ 5 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java create mode 100644 src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java create mode 100644 src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index abb437e..2aa1575 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -32,7 +32,7 @@ public Map loginError() { @Override public Map sendMe(String value) { Map backMap = new HashMap<>(); - backMap.put("type","send"); + backMap.put("type","sendMe"); backMap.put("value",value); return backMap; } @@ -55,4 +55,14 @@ public Map getMsg(String me, String value) { return backMap; } + @Override + public Map sendGroup(String me, String value, String groupId) { + Map backMap = new HashMap<>(); + backMap.put("type","sendGroup"); + backMap.put("from",me); + backMap.put("value",value); + backMap.put("groupId",groupId); + return backMap; + } + } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 8ceb19f..9bfd383 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -7,6 +7,7 @@ import com.myself.unclecatmyself.bootstrap.WsChannelService; import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; +import com.myself.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.timeout.IdleStateEvent; @@ -32,6 +33,9 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService{ @Autowired WsChannelService websocketChannelService; + @Autowired + DataAsynchronousTask dataAsynchronousTask; + private final Gson gson; private final BaseAuthService baseAuthService; @@ -59,6 +63,11 @@ public boolean login(Channel channel, Map maps) { public void sendMeText(Channel channel, Map maps) { channel.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.sendMe((String) maps.get("value"))))); + try { + dataAsynchronousTask.writeData(maps); + } catch (Exception e) { + e.printStackTrace(); + } } @Override @@ -75,6 +84,11 @@ public void sendToText(Channel channel, Map maps) { channel.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); } + try { + dataAsynchronousTask.writeData(maps); + } catch (Exception e) { + e.printStackTrace(); + } } @@ -109,6 +123,11 @@ public void sendGroupText(Channel channel, Map maps) { gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); } } + try { + dataAsynchronousTask.writeData(maps); + } catch (Exception e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java new file mode 100644 index 0000000..f8737a0 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java @@ -0,0 +1,12 @@ +package com.myself.unclecatmyself.bootstrap.data; + +import java.util.Map; + +/** + * Created by MySelf on 2018/12/3. + */ +public interface InChatToDataBaseService { + + Boolean writeMapToDB(Map maps); + +} diff --git a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java new file mode 100644 index 0000000..d8bc407 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java @@ -0,0 +1,29 @@ +package com.myself.unclecatmyself.task; + +import com.myself.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.AsyncResult; +import org.springframework.stereotype.Component; + +import java.util.Map; +import java.util.concurrent.Future; + +/** + * Created by MySelf on 2018/12/3. + */ +@Slf4j +@Component +public class DataAsynchronousTask { + + @Autowired + InChatToDataBaseService inChatToDataBaseService; + + @Async + public Future writeData(Map maps) throws Exception { + log.info("异步写入数据:"+maps.toString()); + return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); + } + +} diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java new file mode 100644 index 0000000..a34d6bd --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java @@ -0,0 +1,19 @@ +package com.myself.unclecatmyself.user; + +import com.myself.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * 不属于项目文件 + * Created by MySelf on 2018/12/3. + */ +@Service +public class InChatToDataBaseServiceImpl implements InChatToDataBaseService { + @Override + public Boolean writeMapToDB(Map maps) { + //TODO 写入数据库 + return true; + } +} From df43976901c236be4c090335810f116a3621ed76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Mon, 3 Dec 2018 17:55:18 +0800 Subject: [PATCH 051/151] update --- pom.xml | 6 +- .../unclecatmyself/auto/RabbitMQConfig.java | 57 +++++++++++++++++++ .../myself/unclecatmyself/auto/Receiver.java | 20 +++++++ .../myself/unclecatmyself/auto/Sender.java | 26 +++++++++ src/main/resources/application.yml | 3 + 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java create mode 100644 src/main/java/com/myself/unclecatmyself/auto/Receiver.java create mode 100644 src/main/java/com/myself/unclecatmyself/auto/Sender.java diff --git a/pom.xml b/pom.xml index 52cc944..96fe9c2 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ jar inchat - Demo project for Spring Boot + 一个轻量级、高效率的支持聊天与物联网的通讯框架 org.springframework.boot @@ -96,6 +96,10 @@ curator-framework 2.9.1 + + org.springframework.boot + spring-boot-starter-amqp + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java b/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java new file mode 100644 index 0000000..bf27ef6 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java @@ -0,0 +1,57 @@ +package com.myself.unclecatmyself.auto; + +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.TopicExchange; +import org.springframework.amqp.rabbit.annotation.EnableRabbit; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Created by MySelf on 2018/12/3. + */ +@Configuration +@EnableRabbit +public class RabbitMQConfig { + + static final String topicExchangeName = "inchat-exchange"; + + static final String queueName = "inchatQueue"; + + @Bean + Queue queue(){ + return new Queue(queueName,false); + } + + @Bean + TopicExchange exchange(){ + return new TopicExchange(topicExchangeName); + } + + @Bean + Binding binding(Queue queue,TopicExchange exchange){ + return BindingBuilder.bind(queue).to(exchange).with("inchat.#"); + } + + @Bean + SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, + MessageListenerAdapter listenerAdapter){ + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); + container.setConnectionFactory(connectionFactory); + container.setQueueNames(queueName); + container.setMessageListener(listenerAdapter); + return container; + } + + @Bean + MessageListenerAdapter listenerAdapter(Receiver receiver){ + return new MessageListenerAdapter(receiver,"receiveMessage"); + } + +} diff --git a/src/main/java/com/myself/unclecatmyself/auto/Receiver.java b/src/main/java/com/myself/unclecatmyself/auto/Receiver.java new file mode 100644 index 0000000..a202c61 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/auto/Receiver.java @@ -0,0 +1,20 @@ +package com.myself.unclecatmyself.auto; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +/** + * Created by MySelf on 2018/12/3. + */ +@Slf4j +@Component +public class Receiver{ + + + @RabbitListener(queues = RabbitMQConfig.queueName) + public void receiveMessage(String message){ + log.info("Received < " + message + " >"); + } + +} diff --git a/src/main/java/com/myself/unclecatmyself/auto/Sender.java b/src/main/java/com/myself/unclecatmyself/auto/Sender.java new file mode 100644 index 0000000..d036420 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/auto/Sender.java @@ -0,0 +1,26 @@ +package com.myself.unclecatmyself.auto; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * Created by MySelf on 2018/12/3. + */ +@Slf4j +@Component +public class Sender { + + private final RabbitTemplate rabbitTemplate; + + public Sender(RabbitTemplate rabbitTemplate){ + this.rabbitTemplate = rabbitTemplate; + } + + public void send(Map maps){ + rabbitTemplate.convertAndSend(RabbitMQConfig.topicExchangeName,"inchat.",maps); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d670f9b..3e21f63 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,3 +15,6 @@ inchat: maxContext: 65536 webSocketPath: "/ws" webSocketHandler: com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 +spring: + rabbitmq: + host: 192.168.192.132 \ No newline at end of file From 5e69748a19b6b3a62ad9efe10c443ccacc092e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 4 Dec 2018 11:49:51 +0800 Subject: [PATCH 052/151] =?UTF-8?q?=E6=95=B4=E4=BD=93=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/design_cn.md | 14 +++++++++++++- .../myself/unclecatmyself/auto/RabbitMQConfig.java | 2 -- .../common/properties/InitNetty.java | 2 ++ src/main/resources/application.yml | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/design_cn.md b/doc/design_cn.md index fff6164..1a9ef66 100644 --- a/doc/design_cn.md +++ b/doc/design_cn.md @@ -14,4 +14,16 @@ AOP、DI为主,基于Spring Boot快速搭建,尽量减少用户的二次搭 ## 离线消息模板 -一版采用RabbitMQ \ No newline at end of file +一版采用RabbitMQ----移除 + +## 整体设计 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E6%9C%AA%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6(19).png) + +1、移除原本Token概念,用户均以唯一标识登录并存储在线键值对于系统本地Cache。(登录存储、退出移除) +2、DefaultWebSocketHandler,是框架默认的处理,数据均已json格式,拆分业务点 +3、由InChat内部的服务(WebSocketHandlerService )进行具体的业务实现并回写 +4、对于数据的存储与写入,默认是异步写入数据,用户可以重写InChatToDataBaseService,获取实时数据 +5、在高并发情况下,我们不推荐异步处理数据,可以通过配置化启动mq(目前支持RabbitMq),框架自动注入对应Bean,并由MQ来执行数据写入 +6、关于数据库连接池,我们不会绑定用户使用,而是支持用户自定义。 + diff --git a/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java b/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java index bf27ef6..bd4e685 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java +++ b/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java @@ -8,8 +8,6 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; -import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; -import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java index 7fd3b02..d6afa32 100644 --- a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java @@ -44,6 +44,8 @@ public class InitNetty { private String webSocketPath; + private Boolean rabbitmq; + private Class webSocketHandler; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3e21f63..5160057 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,6 +15,7 @@ inchat: maxContext: 65536 webSocketPath: "/ws" webSocketHandler: com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 + rabbitmq: true spring: rabbitmq: host: 192.168.192.132 \ No newline at end of file From 9f925f885021ed611849860b82b4fc09830542c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 4 Dec 2018 14:07:56 +0800 Subject: [PATCH 053/151] qq --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2116aa4..f21aa96 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # InChat +[![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) + #### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) -#### QQ群:628793702(欢迎参与交流与提供建议、业务场景、需求功能等) +#### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** From d016cacec7b80781dccaca62b851d80a344824eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 4 Dec 2018 14:10:08 +0800 Subject: [PATCH 054/151] update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f21aa96..4a2feb1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # InChat [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) +[![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) #### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) From 08694c34cbe0ae68a3a4fb08bab680143bba973e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Tue, 4 Dec 2018 15:16:35 +0800 Subject: [PATCH 055/151] ready-to-maven --- pom.xml | 8 +-- .../unclecatmyself/auto/RabbitMQConfig.java | 55 ------------------- .../myself/unclecatmyself/auto/Receiver.java | 20 ------- .../myself/unclecatmyself/auto/Sender.java | 26 --------- .../common/properties/InitNetty.java | 35 ++++++------ src/main/resources/application.yml | 21 ------- 6 files changed, 21 insertions(+), 144 deletions(-) delete mode 100644 src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java delete mode 100644 src/main/java/com/myself/unclecatmyself/auto/Receiver.java delete mode 100644 src/main/java/com/myself/unclecatmyself/auto/Sender.java diff --git a/pom.xml b/pom.xml index 96fe9c2..4ad1e32 100644 --- a/pom.xml +++ b/pom.xml @@ -96,10 +96,10 @@ curator-framework 2.9.1 - - org.springframework.boot - spring-boot-starter-amqp - + + + + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java b/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java deleted file mode 100644 index bd4e685..0000000 --- a/src/main/java/com/myself/unclecatmyself/auto/RabbitMQConfig.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.myself.unclecatmyself.auto; - -import org.springframework.amqp.core.Binding; -import org.springframework.amqp.core.BindingBuilder; -import org.springframework.amqp.core.Queue; -import org.springframework.amqp.core.TopicExchange; -import org.springframework.amqp.rabbit.annotation.EnableRabbit; -import org.springframework.amqp.rabbit.connection.ConnectionFactory; -import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; -import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Created by MySelf on 2018/12/3. - */ -@Configuration -@EnableRabbit -public class RabbitMQConfig { - - static final String topicExchangeName = "inchat-exchange"; - - static final String queueName = "inchatQueue"; - - @Bean - Queue queue(){ - return new Queue(queueName,false); - } - - @Bean - TopicExchange exchange(){ - return new TopicExchange(topicExchangeName); - } - - @Bean - Binding binding(Queue queue,TopicExchange exchange){ - return BindingBuilder.bind(queue).to(exchange).with("inchat.#"); - } - - @Bean - SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, - MessageListenerAdapter listenerAdapter){ - SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); - container.setConnectionFactory(connectionFactory); - container.setQueueNames(queueName); - container.setMessageListener(listenerAdapter); - return container; - } - - @Bean - MessageListenerAdapter listenerAdapter(Receiver receiver){ - return new MessageListenerAdapter(receiver,"receiveMessage"); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/auto/Receiver.java b/src/main/java/com/myself/unclecatmyself/auto/Receiver.java deleted file mode 100644 index a202c61..0000000 --- a/src/main/java/com/myself/unclecatmyself/auto/Receiver.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.myself.unclecatmyself.auto; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.stereotype.Component; - -/** - * Created by MySelf on 2018/12/3. - */ -@Slf4j -@Component -public class Receiver{ - - - @RabbitListener(queues = RabbitMQConfig.queueName) - public void receiveMessage(String message){ - log.info("Received < " + message + " >"); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/auto/Sender.java b/src/main/java/com/myself/unclecatmyself/auto/Sender.java deleted file mode 100644 index d036420..0000000 --- a/src/main/java/com/myself/unclecatmyself/auto/Sender.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.myself.unclecatmyself.auto; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.stereotype.Component; - -import java.util.Map; - -/** - * Created by MySelf on 2018/12/3. - */ -@Slf4j -@Component -public class Sender { - - private final RabbitTemplate rabbitTemplate; - - public Sender(RabbitTemplate rabbitTemplate){ - this.rabbitTemplate = rabbitTemplate; - } - - public void send(Map maps){ - rabbitTemplate.convertAndSend(RabbitMQConfig.topicExchangeName,"inchat.",maps); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java index d6afa32..62c1b91 100644 --- a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java @@ -1,5 +1,6 @@ package com.myself.unclecatmyself.common.properties; +import com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; import com.myself.unclecatmyself.common.websockets.WebSocketHandler; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -14,38 +15,36 @@ @ConfigurationProperties(prefix = "inchat") public class InitNetty { - private int webport; + private int webport = 8090; - private int bossThread; + private int bossThread = 1; - private int workerThread; + private int workerThread = 2; - private boolean keepalive; + private boolean keepalive = true; - private int backlog; + private int backlog = 1024; - private boolean nodelay; + private boolean nodelay = true; - private boolean reuseaddr; + private boolean reuseaddr = true; - private int sndbuf; + private int sndbuf = 10485760; - private int revbuf; + private int revbuf = 10485760; - private int heart; + private int heart = 180; - private int period; + private int period = 10; - private String serverName; + private String serverName = "iot-netty-chat"; - private int initalDelay; + private int initalDelay = 10; - private int maxContext; + private int maxContext = 65536; - private String webSocketPath; + private String webSocketPath = "/ws"; - private Boolean rabbitmq; - - private Class webSocketHandler; + private Class webSocketHandler = DefaultWebSocketHandler.class; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5160057..e69de29 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,21 +0,0 @@ -inchat: - webport: 8090 # Websocket 监听端口 - bossThread: 1 - workerThread: 2 - keepalive: true # 套接字参数, 连接保修, 默认值为 false。启用此功能后, tcp 会主动检测空闲连接的有效性。您可以将此功能视为 tcp 的检测信号机制, 请务必注意, 默认检测信号间隔为 7200s, 即2小时。netty 默认关闭此功能 - backlog: 1024 # 套接字参数, 服务器接受连接的队列长度, 如果队列已满, 则客户端连接将被拒绝 - nodelay: true #TCP参数,立即发送数据,默认值为Ture(Netty默认为True而操作系统默认为False)。该值设置Nagle算法的启用,改算法将小的碎片数据连接成更大的报文来最小化所发送的报文的数量,如果需要发送一些较小的报文,则需要禁用该算法。Netty默认禁用该算法,从而最小化报文传输延时。 - reuseaddr: true #地址复用,默认值False。有四种情况可以使用:(1).当有一个有相同本地地址和端口的socket1处于TIME_WAIT状态时,而你希望启动的程序的socket2要占用该地址和端口,比如重启服务且保持先前端口。(2).有多块网卡或用IP Alias技术的机器在同一端口启动多个进程,但每个进程绑定的本地IP地址不能相同。(3).单个进程绑定相同的端口到多个socket上,但每个socket绑定的ip地址不同。(4).完全相同的地址和端口的重复绑定。但这只用于UDP的多播,不用于TCP。 - sndbuf: 10485760 # tcp 数据发送缓冲区大小。 - revbuf: 10485760 # tcp 数据接收缓冲区大小。 - heart: 180 # 读取超时 - period: 10 # 重新发送周期 - serverName: iot-netty-chat - initalDelay: 10 # 重置延迟 - maxContext: 65536 - webSocketPath: "/ws" - webSocketHandler: com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler # WebSocket 默认处理 - rabbitmq: true -spring: - rabbitmq: - host: 192.168.192.132 \ No newline at end of file From 5539405394975118455dcbfa423cb2a076d5d7ac Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Tue, 4 Dec 2018 21:56:03 +0800 Subject: [PATCH 056/151] stu-1 --- README.md | 2 +- doc/advice/advice.md | 5 +++++ doc/document.md | 46 -------------------------------------------- doc/study/1-st.md | 34 ++++++++++++++++++++++++++++++++ doc/study/mulu.md | 3 +++ doc/work.md | 4 ---- 6 files changed, 43 insertions(+), 51 deletions(-) delete mode 100644 doc/document.md create mode 100644 doc/study/1-st.md create mode 100644 doc/study/mulu.md delete mode 100644 doc/work.md diff --git a/README.md b/README.md index 4a2feb1..523922f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ ## 教程 -* [业务场景技术实现分析](doc/work.md) +* [netty源码讲解](doc/study/mulu.md) * [项目设计思路](doc/design_cn.md) > * [登录模块详细设计](doc/detail/Login-cn.md) diff --git a/doc/advice/advice.md b/doc/advice/advice.md index 1d33b23..3b6ff2b 100644 --- a/doc/advice/advice.md +++ b/doc/advice/advice.md @@ -15,4 +15,9 @@ * 对上方项目的修改 * https://github.com/JaryZhen/rulegin +> 贡献者:[ELLIOT](https://github.com/chanjjaeseo) + +* RabbitMQ 基本操作 +* https://github.com/chanjjaeseo/rabbitMQ-sample + diff --git a/doc/document.md b/doc/document.md deleted file mode 100644 index e3c0dfd..0000000 --- a/doc/document.md +++ /dev/null @@ -1,46 +0,0 @@ -# InChat 中文文档说明 - -> 目前正在撰写中。 - -## 简介 - -***(InChat)Iot Netty Chat*** - -> master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目 - -一个轻量级、高效的通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 - -## 学习资料 - -* [netty4通信原理](netty-study.md) - -## 关于demo分支 - -原始项目核心演示, 您可以先运行了解, 模仿微聊天聊天应用程序, 逐步更新, 基于 springbot-web 套接字的一般框架, 结合 netty 聊天社交, 并记录聊天日志, 异步存储, 前端临时 sui mobile, 添加实现 tcp/后端通信端口 (mqtt 协议、实时和单片机等 tcp 硬件通信), 添加图片处理流、聊天实现文本和图片发送功能,api 调用 netty 长链接执行发送消息 (联机、用户列表的数量) - -## demo分支演示效果图 - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(5).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(3).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(4).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(2).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(1).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/9.png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) - -## 关于im-api分支 - -腾讯 im (云通信) 后端仿真项目, 以 api 的形式对接, 如果有前端想要停靠可以运行此分支, 预计该分支最终将为一个单一的服务并发 300, 000个用户的 im 后台项目 - -## 关于paho-mqtt分支 - -基于 paho. js 和 java mqtt 客户端消息订阅和通信的小型程序端或移动 web 端, 小程序物联网演示目前支持 ws 格式 - -## 关于tcp-wechat分支 - -基于小程序端与单片机等硬件 tcp/ip 的主要通信, 将物联网中心作为中转, 本演示将充分实现具体功能 - -## 联系 - -QQ群:628793702 \ No newline at end of file diff --git a/doc/study/1-st.md b/doc/study/1-st.md new file mode 100644 index 0000000..d93848c --- /dev/null +++ b/doc/study/1-st.md @@ -0,0 +1,34 @@ +# 第一章 Netty的大致介绍 + +netty被广泛应用于世面上的许多框架,如Dubbo、RocketMQ、Spark、ElasticSearch、Cassandra、Flink、Netty-SocketIO、Spring5、Play、Grpc..... + +以上均是将Netty作为底层网络通讯。 + +## Netty是什么? + +* 异步事件驱动框架,用于快速开发高性能服务端和客户端 +* 封装了JDK底层BIO和NIO模型,提供高度可用的API +* 自带编解码器解决拆包粘包问题,用户只用关心业务逻辑 +* 精心设计的reactor线程模型支持高并发海量连接 +* 自带各种协议栈让你处理任何一种通用协议都几乎不用亲自动手 + +## 学习Netty有必要吗? + +* 各大开源项目选择Netty作为底层通信框架 +* 更好的使用,少走弯路 +* 遇到BUG?单机连接数上不去?性能遇到瓶颈?如何调优? +* 详解reactor线程模型,实践中举一反三 +* 庞大的项目是如何组织的,设计模式,体验优秀的设计 +* 阅读源码其实没有那么困难 + +## 怎么学习Netty? + +* 自己摸索不如前人指路 +* 对应socket编程,逐个切入 +* 填坑路程 + +## 适合人群 + +* 系统掌握Netty底层核心原理 +* 加速掌握基于Netty的各类中间件框架 +* 对技术有追求。对优秀代码由执念的开发者 diff --git a/doc/study/mulu.md b/doc/study/mulu.md new file mode 100644 index 0000000..68a45d3 --- /dev/null +++ b/doc/study/mulu.md @@ -0,0 +1,3 @@ +# Netty 入门与源码讲解 + +* [Netty介绍与详情](1-st.md) \ No newline at end of file diff --git a/doc/work.md b/doc/work.md deleted file mode 100644 index 9ffd579..0000000 --- a/doc/work.md +++ /dev/null @@ -1,4 +0,0 @@ -## 业务场景技术实现分析 - -> 欢迎加入QQ群628793702,贡献想法 - From ef27762951d65448ab150dca027b125d8bdda0ea Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Tue, 4 Dec 2018 21:58:53 +0800 Subject: [PATCH 057/151] update --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 523922f..3a4b82b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) +[![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) #### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) @@ -21,7 +22,7 @@ ## 教程 -* [netty源码讲解](doc/study/mulu.md) +### [Netty入门与源码讲解](doc/study/mulu.md) * [项目设计思路](doc/design_cn.md) > * [登录模块详细设计](doc/detail/Login-cn.md) From 6d068d3766b8ade3eb31ca8b85ec3a0cdc901657 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Tue, 4 Dec 2018 22:12:18 +0800 Subject: [PATCH 058/151] update --- README.md | 1 - doc/advice/advice.md | 4 ++++ doc/study/2-st.md | 0 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 doc/study/2-st.md diff --git a/README.md b/README.md index 3a4b82b..abb484b 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ ## 相关资料(欢迎贡献) -* [netty4通信原理](doc/netty-study.md) * [QQ群建议贡献](doc/advice/advice.md) ## demo分支介绍 diff --git a/doc/advice/advice.md b/doc/advice/advice.md index 3b6ff2b..76b35e9 100644 --- a/doc/advice/advice.md +++ b/doc/advice/advice.md @@ -20,4 +20,8 @@ * RabbitMQ 基本操作 * https://github.com/chanjjaeseo/rabbitMQ-sample +> 贡献者:[noseparte](https://github.com/noseparte) +* [netty4通信原理](../netty-study.md) +* MongoDB的基本操作 +* https://github.com/noseparte/mongoTeam diff --git a/doc/study/2-st.md b/doc/study/2-st.md new file mode 100644 index 0000000..e69de29 From be85333474c82ce5b707cb4ac197727226df3ad1 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Tue, 4 Dec 2018 23:22:15 +0800 Subject: [PATCH 059/151] 2-st --- doc/study/2-st.md | 195 ++++++++++++++++++++++++++++++++++++++++++++++ doc/study/mulu.md | 3 +- 2 files changed, 197 insertions(+), 1 deletion(-) diff --git a/doc/study/2-st.md b/doc/study/2-st.md index e69de29..4ff3c2b 100644 --- a/doc/study/2-st.md +++ b/doc/study/2-st.md @@ -0,0 +1,195 @@ +# 第二章 Netty基本组件 + +## 一个简单的socket例子 + +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/stduy/100.png) + +### ServerBoot启动类 + +```java +package com.example.demo; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 23:00 2018\12\4 0004 + */ +public class ServerBoot { + + private static final int PORT = 8000; + + public static void main(String[] args){ + Server server = new Server(PORT); + server.start(); + } + +} +``` + +### Server监听端口服务类 + +```java +package com.example.demo; + +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 22:46 2018\12\4 0004 + */ +@Slf4j +public class Server { + + private ServerSocket serverSocket; + + public Server(int port){ + try { + this.serverSocket = new ServerSocket(port); + log.info("服务端启动成功,端口:" + port); + }catch (IOException e){ + log.error("服务端启动失败"); + } + } + + public void start(){ + new Thread(new Runnable() { + @Override + public void run() { + doStart(); + } + }).start(); + } + + private void doStart(){ + while (true){ + try { + //阻塞方法 + Socket client = serverSocket.accept(); + new ClientHandler(client).start(); + }catch (IOException e){ + log.error("服务端异常"); + } + } + } +} +``` + +### ClientHandler客户端接入监听类 + +```java +package com.example.demo; + +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 22:50 2018\12\4 0004 + */ +@Slf4j +public class ClientHandler { + + public static final int MAX_DATA_LEN = 1024; + private final Socket socket; + + public ClientHandler(Socket socket){ + this.socket = socket; + } + + public void start(){ + log.info("新客户端接入"); + new Thread(new Runnable() { + @Override + public void run() { + doStart(); + } + }).start(); + } + + private void doStart(){ + try { + InputStream inputStream = socket.getInputStream(); + while (true){ + byte[] data = new byte[MAX_DATA_LEN]; + int len; + while((len = inputStream.read(data)) != -1){ + String message = new String(data,0,len); + log.info("客户端传来消息:" + message); + socket.getOutputStream().write(data); + } + } + }catch (IOException e){ + e.printStackTrace(); + } + } + +} +``` + + +### Client客户端启动类 + +```java +package com.example.demo; + +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.net.Socket; + +/** + * @Author:UncleCatMySelf + * @Email:zhupeijie_java@126.com + * @QQ:1341933031 + * @Date:Created in 23:01 2018\12\4 0004 + */ +@Slf4j +public class Client { + + private static final String HOST = "127.0.0.1"; + private static final int PORT = 8000; + private static final int SLEEP_TIME = 5000; + + public static void main(String[] args) throws IOException{ + final Socket socket = new Socket(HOST,PORT); + + new Thread(new Runnable() { + @Override + public void run() { + log.info("客户端启动成功!"); + while (true){ + try { + String message = "hello myself"; + log.info("客户端发送数据:" + message); + socket.getOutputStream().write(message.getBytes()); + }catch (Exception e){ + log.info("写数据出错!"); + } + sleep(); + } + } + }).start(); + } + + private static void sleep(){ + try { + Thread.sleep(SLEEP_TIME); + }catch (InterruptedException e){ + e.printStackTrace(); + } + } + +} +``` \ No newline at end of file diff --git a/doc/study/mulu.md b/doc/study/mulu.md index 68a45d3..ddd649c 100644 --- a/doc/study/mulu.md +++ b/doc/study/mulu.md @@ -1,3 +1,4 @@ # Netty 入门与源码讲解 -* [Netty介绍与详情](1-st.md) \ No newline at end of file +* [Netty介绍与详情](1-st.md) +* [Netty基本组件](2-st.md) \ No newline at end of file From b882772f87910eb8a6131eae9f1dce067672707c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 14:36:44 +0800 Subject: [PATCH 060/151] maven-update --- .../unclecatmyself/DefaultAutoService.java | 19 - .../auto/ServerAutoConfigure.java | 23 +- .../unclecatmyself/bootstrap/BaseApi.java | 74 --- .../bootstrap/BaseAuthService.java | 13 - .../bootstrap/ChannelService.java | 40 -- .../bootstrap/bean/MqttChannel.java | 115 ----- .../bootstrap/bean/RetainMessage.java | 19 - .../bootstrap/bean/SendMqttMessage.java | 35 -- .../bootstrap/bean/SendWebMessage.java | 28 -- .../bootstrap/bean/SessionMessage.java | 29 -- .../bootstrap/bean/WebChannel.java | 61 --- .../bootstrap/bean/WillMeaasge.java | 23 - .../channel/AbstractChannelService.java | 112 ----- .../channel/ClientSessionService.java | 36 -- .../bootstrap/channel/MqttChannelService.java | 439 ----------------- .../bootstrap/channel/MqttHandlerService.java | 222 --------- .../bootstrap/channel/PublishApiSevice.java | 162 ------- .../channel/WebSocketHandlerService.java | 12 +- .../bootstrap/channel/WillService.java | 51 -- .../coder/ByteBufToWebSocketFrameEncoder.java | 26 - .../coder/WebSocketFrameToByteBufDecoder.java | 25 - .../bootstrap/handler/DefaultMqttHandler.java | 104 ---- .../bootstrap/scan/SacnScheduled.java | 59 --- .../bootstrap/scan/ScanRunnable.java | 43 -- .../common/enums/ConfirmStatus.java | 13 - .../common/enums/ProtocolEnum.java | 14 - .../common/enums/QosStatus.java | 14 - .../common/enums/SessionStatus.java | 13 - .../common/enums/SubStatus.java | 11 - .../mqtts/ClientMqttHandlerService.java | 27 -- .../common/mqtts/MqttHander.java | 50 -- .../common/mqtts/MqttHandlerIntf.java | 26 - .../mqtts/ServerMqttHandlerService.java | 28 -- .../common/ssl/SecureSocketKeyStore.java | 456 ------------------ .../ssl/SecureSocketSslContextFactory.java | 89 ---- .../ssl/SecureSokcetTrustManagerFactory.java | 63 --- .../common/ssl/StreamReader.java | 25 - .../common/ssl/X509CertTool.java | 69 --- .../common/utils/ByteBufUtil.java | 19 - .../common/utils/CRC16MySelf.java | 73 --- .../common/utils/CallBackMessage.java | 35 -- .../unclecatmyself/common/utils/Const.java | 181 ------- .../common/utils/CookieUtil.java | 65 --- .../common/utils/DataResction.java | 106 ---- .../common/utils/DataValida.java | 51 -- .../unclecatmyself/common/utils/IdWorker.java | 150 ------ .../common/utils/MessageId.java | 27 -- .../common/utils/RandomNameUtil.java | 20 - .../unclecatmyself/common/utils/SendUtil.java | 84 ---- .../common/utils/StringUtil.java | 21 - .../user/InChatToDataBaseServiceImpl.java | 2 + 51 files changed, 16 insertions(+), 3486 deletions(-) delete mode 100644 src/main/java/com/myself/unclecatmyself/DefaultAutoService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/BaseAuthService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/ChannelService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java delete mode 100644 src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/Const.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java delete mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/StringUtil.java diff --git a/src/main/java/com/myself/unclecatmyself/DefaultAutoService.java b/src/main/java/com/myself/unclecatmyself/DefaultAutoService.java deleted file mode 100644 index 46dbb63..0000000 --- a/src/main/java/com/myself/unclecatmyself/DefaultAutoService.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.myself.unclecatmyself; - -import com.myself.unclecatmyself.bootstrap.BaseAuthService; -import org.springframework.stereotype.Service; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 默认权限 - **/ -@Service -public class DefaultAutoService implements BaseAuthService { - - @Override - public boolean authorized(String username, String password) { - return true; - } -} diff --git a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java index 4e896b0..e1ab79b 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java @@ -1,10 +1,7 @@ package com.myself.unclecatmyself.auto; -import com.myself.unclecatmyself.bootstrap.scan.SacnScheduled; -import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; import com.myself.unclecatmyself.common.properties.InitNetty; import org.apache.commons.lang3.ObjectUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -37,16 +34,16 @@ public ServerAutoConfigure(){ } - @Bean - @ConditionalOnMissingBean(name = "sacnScheduled") - public ScanRunnable initRunable(@Autowired InitNetty serverBean){ - long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); - ScanRunnable sacnScheduled = new SacnScheduled(time); - Thread scanRunnable = new Thread(sacnScheduled); - scanRunnable.setDaemon(true); - scanRunnable.start(); - return sacnScheduled; - } +// @Bean +// @ConditionalOnMissingBean(name = "sacnScheduled") +// public ScanRunnable initRunable(@Autowired InitNetty serverBean){ +// long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); +// ScanRunnable sacnScheduled = new SacnScheduled(time); +// Thread scanRunnable = new Thread(sacnScheduled); +// scanRunnable.setDaemon(true); +// scanRunnable.start(); +// return sacnScheduled; +// } @Bean(initMethod = "open", destroyMethod = "close") diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java b/src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java deleted file mode 100644 index 49984ec..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/BaseApi.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.myself.unclecatmyself.bootstrap; - -import javax.validation.constraints.NotNull; -import java.util.function.Consumer; -import java.util.function.Predicate; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 逻辑操作封装 - **/ -public interface BaseApi { - - default void doIfElse(T t, Predicate predicate, Consumer consumer){ - if(t!=null){ - if(predicate.test(t)){ - consumer.accept(t); - } - } - } - - - default void doIfElse(T t, Predicate predicate, Consumer consumer, Consumer consumer2){ - if(t!=null){ - if(predicate.test(t)){ - consumer.accept(t); - } - else{ - consumer2.accept(t); - } - } - } - default boolean doIf(T t, Predicate... predicates){ - if(t!=null){ - for(Predicate p:predicates){ - if(!p.test(t)){ - return false; - } - } - return true; - } - return false; - } - - default void doIfAnd(T t, Consumer consumer2, Predicate... predicates){ - boolean flag =true; - if(t!=null){ - for(Predicate p:predicates){ - if(!p.test(t)){ - flag= false; - break; - } - } - } - if(flag){ - consumer2.accept(t); - } - } - - default void doIfAnd1(@NotNull T t, @NotNull Consumer consumer2, @NotNull Predicate... predicates){ - Predicate one = predicates[0]; - int l; - if((l=predicates.length)>1){ - for(int i=1;i topics); - - void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage); - - void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage); - - void closeSuccess(String deviceId,boolean isDisconnect); - - void sendWillMsg(WillMeaasge willMeaasge); - - String getDeviceId(Channel channel); - - void unsubscribe(String deviceId, List topics1); - - void doPubrel(Channel channel, int mqttMessage); - - void doPubrec(Channel channel, int mqttMessage); - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java deleted file mode 100644 index 1d794c2..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/MqttChannel.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import io.netty.channel.Channel; -import io.netty.util.AttributeKey; -import lombok.Builder; -import lombok.Data; - -import com.myself.unclecatmyself.common.enums.SubStatus; -import com.myself.unclecatmyself.common.enums.SessionStatus; - -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc channel 封装类 - **/ -@Builder -@Data -public class MqttChannel { - - private transient volatile Channel channel; - - - private String deviceId; - - - private boolean isWill; - - - private volatile SubStatus subStatus; // 是否订阅过主题 - - - private Set topic ; - - - - private volatile SessionStatus sessionStatus; // 在线 - 离线 - - - - private volatile boolean cleanSession; // 当为 true 时 channel close 时 从缓存中删除 此channel - - - - - private ConcurrentHashMap message ; // messageId - message(qos1) // 待确认消息 - - - private Set receive; - - public void addRecevice(int messageId){ - receive.add(messageId); - } - - public boolean checkRecevice(int messageId){ - return receive.contains(messageId); - } - - public boolean removeRecevice(int messageId){ - return receive.remove(messageId); - } - - - public void addSendMqttMessage(int messageId,SendMqttMessage msg){ - message.put(messageId,msg); - } - - - public SendMqttMessage getSendMqttMessage(int messageId){ - return message.get(messageId); - } - - - public void removeSendMqttMessage(int messageId){ - message.remove(messageId); - } - - - /** - * 判断当前channel 是否登录过 - * @return - */ - public boolean isLogin(){ - return Optional.ofNullable(this.channel).map(channel1 -> { - AttributeKey _login = AttributeKey.valueOf("login"); - return channel1.isActive() && channel1.hasAttr(_login); - }).orElse(false); - } - - /** - * 非正常关闭 - */ - public void close(){ - Optional.ofNullable(this.channel).ifPresent(channel1 -> channel1.close()); - } - - /** - * 通道是否活跃 - * @return - */ - public boolean isActive(){ - return channel!=null&&this.channel.isActive(); - } - - - - public boolean addTopic(Set topics){ - return topic.addAll(topics); - } - - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java deleted file mode 100644 index e094abf..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/RetainMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - -@Builder -@Data -public class RetainMessage { - - private byte[] byteBuf; - - private MqttQoS qoS; - - public String getString(){ - return new String(byteBuf); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java deleted file mode 100644 index dbc6738..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendMqttMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - -import com.myself.unclecatmyself.common.enums.ConfirmStatus; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc mqtts 消息 - **/ -@Builder -@Data -public class SendMqttMessage { - - private int messageId; - - private Channel channel; - - private volatile ConfirmStatus confirmStatus; - - private long time; - - private byte[] byteBuf; - - private boolean isRetain; - - private MqttQoS qos; - - private String topic; - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java deleted file mode 100644 index bc1fe4e..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SendWebMessage.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import com.myself.unclecatmyself.common.enums.ConfirmStatus; -import io.netty.channel.Channel; -import lombok.Builder; -import lombok.Data; - -/** - * WebSocket 消息 - * Created by MySelf on 2018/11/21. - */ -@Data -@Builder -public class SendWebMessage { - - private int messageId; - - private Channel channel; - - private volatile ConfirmStatus confirmStatus; - - private long time; - - private byte[] byteBuf; - - private boolean isRetain; - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java deleted file mode 100644 index 36a1460..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/SessionMessage.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - - -import io.netty.handler.codec.mqtt.MqttQoS; -import lombok.Builder; -import lombok.Data; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Session会话数据保存 - **/ -@Builder -@Data -public class SessionMessage { - - private byte[] byteBuf; - - private MqttQoS qoS; - - private String topic; - - - public String getString(){ - return new String(byteBuf); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java deleted file mode 100644 index 164b0f9..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WebChannel.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import com.myself.unclecatmyself.common.enums.SessionStatus; -import io.netty.channel.Channel; -import io.netty.util.AttributeKey; -import lombok.Builder; -import lombok.Data; - -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 聊天消息channel 封装类 - * Created by MySelf on 2018/11/21. - */ -@Data -@Builder -public class WebChannel { - - private transient volatile Channel channel; - - private String msgId; - - private boolean isWill; - - private volatile SessionStatus sessionStatus; //在线 - 离线 - - private volatile boolean cleanSession; //当为 true 时channel close 时 从缓存中删除 此channel - - private ConcurrentHashMap message;// messageId - message(toid) //待确认消息 - - private Set receive; - - /** - * 判断当前channel是否登录过 - * @return - */ - public boolean isLogin(){ - return Optional.ofNullable(this.channel).map(channel1 -> { - AttributeKey _login = AttributeKey.valueOf("login"); - return channel1.isActive() && channel1.hasAttr(_login); - }).orElse(false); - } - - /** - * 非正常关闭 - */ - public void close(){ - Optional.ofNullable(this.channel).ifPresent(channel1 -> channel1.close()); - } - - /** - * 通过是否活跃 - * @return - */ - public boolean isActive(){ - return channel!=null&&this.channel.isActive(); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java b/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java deleted file mode 100644 index d72fa5e..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/bean/WillMeaasge.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.bean; - -import lombok.Builder; -import lombok.Data; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 遗嘱消息 - **/ -@Builder -@Data -public class WillMeaasge { - - private String willTopic; - - private String willMessage; - - private boolean isRetain; - - private int qos; - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java deleted file mode 100644 index d948c92..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/AbstractChannelService.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.BaseApi; -import com.myself.unclecatmyself.bootstrap.ChannelService; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; -import com.myself.unclecatmyself.bootstrap.bean.RetainMessage; -import com.myself.unclecatmyself.bootstrap.channel.cache.CacheMap; -import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; -import io.netty.channel.Channel; -import io.netty.util.AttributeKey; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.util.Collection; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象类 - **/ -@Slf4j -public abstract class AbstractChannelService extends PublishApiSevice implements ChannelService , BaseApi { - - protected AttributeKey _login = AttributeKey.valueOf("login"); - - protected AttributeKey _deviceId = AttributeKey.valueOf("deviceId"); - - protected static char SPLITOR = '/'; - - protected ExecutorService executorService =Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2); - - - protected static CacheMap cacheMap= new CacheMap<>(); - - - protected static ConcurrentHashMap mqttChannels = new ConcurrentHashMap<>(); // deviceId - mqChannel 登录 - - - protected static ConcurrentHashMap> retain = new ConcurrentHashMap<>(); // topic - 保留消息 - - - - protected static Cache> mqttChannelCache = CacheBuilder.newBuilder().maximumSize(100).build(); - - public AbstractChannelService(ScanRunnable scanRunnable) { - super(scanRunnable); - } - - - protected Collection getChannels(String topic,TopicFilter topicFilter){ - try { - return mqttChannelCache.get(topic, () -> topicFilter.filter(topic)); - } catch (Exception e) { - log.info(String.format("guava cache key topic【%s】 channel value== null ",topic)); - } - return null; - } - - - @FunctionalInterface - interface TopicFilter{ - Collection filter(String topic); - } - - protected boolean deleteChannel(String topic,MqttChannel mqttChannel){ - return Optional.ofNullable(topic).map(s -> { - mqttChannelCache.invalidate(s); - return cacheMap.delete(getTopic(s),mqttChannel); - }).orElse(false); - } - - protected boolean addChannel(String topic,MqttChannel mqttChannel) - { - return Optional.ofNullable(topic).map(s -> { - mqttChannelCache.invalidate(s); - return cacheMap.putData(getTopic(s),mqttChannel); - }).orElse(false); - } - - /** - * 获取channel - */ - public MqttChannel getMqttChannel(String deviceId){ - return Optional.ofNullable(deviceId).map(s -> mqttChannels.get(s)) - .orElse(null); - - } - - /** - * 获取channelId - */ - public String getDeviceId(Channel channel){ - return Optional.ofNullable(channel).map( channel1->channel1.attr(_deviceId).get()) - .orElse(null); - } - - - - protected String[] getTopic(String topic) { - return Optional.ofNullable(topic).map(s -> - StringUtils.split(topic,SPLITOR) - ).orElse(null); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java deleted file mode 100644 index daaaad7..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/ClientSessionService.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.bean.SessionMessage; -import org.springframework.stereotype.Service; - -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 会话保留处理 - **/ -@Service -public class ClientSessionService { - - private static ConcurrentHashMap> queueSession = new ConcurrentHashMap<>(); // 连接关闭后 保留此session 数据 deviceId - - - public void saveSessionMsg(String deviceId, SessionMessage sessionMessage) { - ConcurrentLinkedQueue sessionMessages = queueSession.getOrDefault(deviceId, new ConcurrentLinkedQueue<>()); - boolean flag; - do{ - flag = sessionMessages.add(sessionMessage); - } - while (!flag); - queueSession.put(deviceId,sessionMessages); - } - - public ConcurrentLinkedQueue getByteBuf(String deviceId){ - return Optional.ofNullable(deviceId).map(s -> queueSession.get(s)) - .orElse(null); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java deleted file mode 100644 index 3a62caf..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttChannelService.java +++ /dev/null @@ -1,439 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.bean.*; -import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; -import com.myself.unclecatmyself.common.enums.ConfirmStatus; -import com.myself.unclecatmyself.common.enums.SessionStatus; -import com.myself.unclecatmyself.common.enums.SubStatus; -import com.myself.unclecatmyself.common.exception.ConnectionException; -import com.myself.unclecatmyself.common.utils.ByteBufUtil; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.util.CollectionUtils; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CopyOnWriteArraySet; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Channel事件处理service - **/ -@Slf4j -//@Component -public class MqttChannelService extends AbstractChannelService { - - @Autowired - private ClientSessionService clientSessionService; - - @Autowired - private WillService willService; - - private final ScanRunnable scanRunnable; - - public MqttChannelService(ScanRunnable scanRunnable) { - super(scanRunnable); - this.scanRunnable = scanRunnable; - } - - - /** - * 取消订阅 - */ - @Override - public void unsubscribe(String deviceId, List topics1) { - Optional.ofNullable(mqttChannels.get(deviceId)).ifPresent(mqttChannel -> { - topics1.forEach(topic -> { - deleteChannel(topic,mqttChannel); - }); - }); - } - - /** - * 登录成功后 回复 - */ - private void replyLogin(Channel channel, MqttConnectMessage mqttConnectMessage) { - MqttFixedHeader mqttFixedHeader1 = mqttConnectMessage.fixedHeader(); - MqttConnectVariableHeader mqttConnectVariableHeader = mqttConnectMessage.variableHeader(); - final MqttConnectPayload payload = mqttConnectMessage.payload(); - String deviceId = getDeviceId(channel); - MqttChannel build = MqttChannel.builder().channel(channel).cleanSession(mqttConnectVariableHeader.isCleanSession()) - .deviceId(payload.clientIdentifier()) - .sessionStatus(SessionStatus.OPEN) - .isWill(mqttConnectVariableHeader.isWillFlag()) - .subStatus(SubStatus.NO) - .topic(new CopyOnWriteArraySet<>()) - .message(new ConcurrentHashMap<>()) - .receive(new CopyOnWriteArraySet<>()) - .build(); - if (connectSuccess(deviceId, build)) { // 初始化存储mqttchannel - if (mqttConnectVariableHeader.isWillFlag()) { // 遗嘱消息标志 - boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (payload.willMessage() != null) - , mqttConnectVariableHeader1 -> (payload.willTopic() != null)); - if (!b) { - throw new ConnectionException("will message and will topic is not null"); - } - // 处理遗嘱消息 - final WillMeaasge buildWill = WillMeaasge.builder(). - qos(mqttConnectVariableHeader.willQos()) - .willMessage(deviceId) - .willTopic(payload.willTopic()) - .isRetain(mqttConnectVariableHeader.isWillRetain()) - .build(); - willService.save(payload.clientIdentifier(), buildWill); - } else { - willService.del(payload.clientIdentifier()); - boolean b = doIf(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (!mqttConnectVariableHeader1.isWillRetain()), - mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.willQos() == 0)); - if (!b) { - throw new ConnectionException("will retain should be null and will QOS equal 0"); - } - } - doIfElse(mqttConnectVariableHeader, mqttConnectVariableHeader1 -> (mqttConnectVariableHeader1.isCleanSession()), mqttConnectVariableHeader1 -> { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, false); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck);// 清理会话 - }, mqttConnectVariableHeader1 -> { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_ACCEPTED; - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK, mqttFixedHeader1.isDup(), MqttQoS.AT_MOST_ONCE, mqttFixedHeader1.isRetain(), 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck);// 非清理会话 - - }); //发送 session 数据 - ConcurrentLinkedQueue sessionMessages = clientSessionService.getByteBuf(payload.clientIdentifier()); - doIfElse(sessionMessages, messages -> messages != null && !messages.isEmpty(), byteBufs -> { - SessionMessage sessionMessage; - while ((sessionMessage = byteBufs.poll()) != null) { - switch (sessionMessage.getQoS()) { - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - case AT_MOST_ONCE: - sendQos0Msg(channel, sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,getMqttChannel(deviceId), sessionMessage.getTopic(), sessionMessage.getByteBuf()); - break; - } - } - - }); - } - } - - - - /** - * qos2 第二步 - */ - @Override - public void doPubrel(Channel channel, int messageId) { - MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); - doIfElse(mqttChannel,mqttChannel1 ->mqttChannel1.isLogin(),mqttChannel1 -> { - mqttChannel1.removeRecevice(messageId); - sendToPubComp(channel,messageId); - }); - } - - - - /** - * qos2 第三步 - */ - @Override - public void doPubrec(Channel channel, int mqttMessage) { - sendPubRel(channel,false,mqttMessage); - } - - /** - * 连接成功后 - * @param deviceId - * @param build - */ - @Override - public boolean connectSuccess(String deviceId, MqttChannel build) { - return Optional.ofNullable(mqttChannels.get(deviceId)) - .map(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case OPEN: - return false; - case CLOSE: - switch (mqttChannel.getSubStatus()){ - case YES: // 清除订阅 topic - deleteSubTopic(mqttChannel).stream() - .forEach(s -> cacheMap.putData(getTopic(s),build)); - break; - } - } - mqttChannels.put(deviceId,build); - return true; - }).orElseGet(() -> { - mqttChannels.put(deviceId,build); - return true; - }); - } - - - /** - * 订阅成功后 (发送保留消息) - */ - public void suscribeSuccess(String deviceId, Set topics){ - doIfElse(topics,topics1->!CollectionUtils.isEmpty(topics1),strings -> { - MqttChannel mqttChannel = mqttChannels.get(deviceId); - mqttChannel.setSubStatus(SubStatus.YES); // 设置订阅主题标识 - mqttChannel.addTopic(strings); - executorService.execute(() -> { - Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { - if(mqttChannel1.isLogin()){ - strings.parallelStream().forEach(topic -> { - addChannel(topic,mqttChannel); - sendRetain(topic,mqttChannel); // 发送保留消息 - }); - } - }); - }); - }); - } - - - /** - *成功登陆 (发送会话消息) - * @param channel - * @param deviceId - * @param mqttConnectMessage - */ - @Override - public void loginSuccess(Channel channel, String deviceId, MqttConnectMessage mqttConnectMessage) { - channel.attr(_login).set(true); - channel.attr(_deviceId).set(deviceId); - replyLogin(channel, mqttConnectMessage); - } - - - /** - * 发布消息成功 () - * @param channel - * @param mqttPublishMessage - */ - @Override - public void publishSuccess(Channel channel, MqttPublishMessage mqttPublishMessage) { - MqttFixedHeader mqttFixedHeader = mqttPublishMessage.fixedHeader(); - MqttPublishVariableHeader mqttPublishVariableHeader = mqttPublishMessage.variableHeader(); - MqttChannel mqttChannel = getMqttChannel(getDeviceId(channel)); - ByteBuf payload = mqttPublishMessage.payload(); - byte[] bytes = ByteBufUtil.copyByteBuf(payload); // - int messageId = mqttPublishVariableHeader.messageId(); - executorService.execute(() -> { - if (channel.hasAttr(_login) && mqttChannel != null) { - boolean isRetain; - switch (mqttFixedHeader.qosLevel()) { - case AT_MOST_ONCE: // 至多一次 - break; - case AT_LEAST_ONCE: - sendPubBack(channel, messageId); - break; - case EXACTLY_ONCE: - sendPubRec(mqttChannel, messageId); - break; - } - if ((isRetain=mqttFixedHeader.isRetain()) && mqttFixedHeader.qosLevel() != MqttQoS.AT_MOST_ONCE) { //是保留消息 qos >0 - saveRetain(mqttPublishVariableHeader.topicName(), - RetainMessage.builder() - .byteBuf(bytes) - .qoS(mqttFixedHeader.qosLevel()) - .build(), false); - } else if (mqttFixedHeader.isRetain() && mqttFixedHeader.qosLevel() == MqttQoS.AT_MOST_ONCE) { // 是保留消息 qos=0 清除之前保留消息 保留现在 - saveRetain(mqttPublishVariableHeader.topicName(), - RetainMessage.builder() - .byteBuf(bytes) - .qoS(mqttFixedHeader.qosLevel()) - .build(), true); - } - if (!mqttChannel.checkRecevice(messageId)) { - push(mqttPublishVariableHeader.topicName(), mqttFixedHeader.qosLevel(), bytes,isRetain); - mqttChannel.addRecevice(messageId); - } - } - }); - - } - /** - * 推送消息给订阅者 - */ - private void push(String topic, MqttQoS qos, byte[] bytes, boolean isRetain){ - Collection subChannels = getChannels(topic, topic1 -> cacheMap.getData(getTopic(topic1))); - if(!CollectionUtils.isEmpty(subChannels)){ - subChannels.parallelStream().forEach(subChannel -> { - switch (subChannel.getSessionStatus()){ - case OPEN: // 在线 - if(subChannel.isActive()){ // 防止channel失效 但是离线状态没更改 - switch (qos){ - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,subChannel,topic,bytes); - break; - case AT_MOST_ONCE: - sendQos0Msg(subChannel.getChannel(),topic,bytes); - break; - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,subChannel,topic,bytes); - break; - } - } - else{ - if(!subChannel.isCleanSession() & !isRetain){ - clientSessionService.saveSessionMsg(subChannel.getDeviceId(), - SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); - break; - } - } - break; - case CLOSE: // 连接 设置了 clean session =false - clientSessionService.saveSessionMsg(subChannel.getDeviceId(), - SessionMessage.builder().byteBuf(bytes).qoS(qos).topic(topic).build() ); - break; - } - }); - } - } - - /** - * 关闭channel 操作 - * @param deviceId - */ - @Override - public void closeSuccess(String deviceId,boolean isDisconnect) { - if(StringUtils.isNotBlank(deviceId)){ - executorService.execute(() -> { - MqttChannel mqttChannel = mqttChannels.get(deviceId); - Optional.ofNullable(mqttChannel).ifPresent(mqttChannel1 -> { - mqttChannel1.setSessionStatus(SessionStatus.CLOSE); // 设置关闭 - mqttChannel1.close(); // 关闭channel - mqttChannel1.setChannel(null); - if(!mqttChannel1.isCleanSession()){ // 保持会话 - // 处理 qos1 未确认数据 - ConcurrentHashMap message = mqttChannel1.getMessage(); - Optional.ofNullable(message).ifPresent(integerConfirmMessageConcurrentHashMap -> { - integerConfirmMessageConcurrentHashMap.forEach((integer, confirmMessage) -> doIfElse(confirmMessage, sendMqttMessage ->sendMqttMessage.getConfirmStatus()== ConfirmStatus.PUB, sendMqttMessage ->{ - clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), SessionMessage.builder() - .byteBuf(sendMqttMessage.getByteBuf()) - .qoS(sendMqttMessage.getQos()) - .topic(sendMqttMessage.getTopic()) - .build()); // 把待确认数据转入session中 - } - )); - - }); - } - else{ // 删除sub topic-消息 - mqttChannels.remove(deviceId); // 移除channelId 不保持会话 直接删除 保持会话 旧的在重新connect时替换 - switch (mqttChannel1.getSubStatus()){ - case YES: - deleteSubTopic(mqttChannel1); - break; - } - } - if(mqttChannel1.isWill()){ // 发送遗言 - if(!isDisconnect){ // 不是disconnection操作 - willService.doSend(deviceId); - } - } - }); - }); - } - } - - /** - * 清除channel 订阅主题 - * @param mqttChannel - */ - public Set deleteSubTopic(MqttChannel mqttChannel){ - Set topics = mqttChannel.getTopic(); - topics.parallelStream().forEach(topic -> cacheMap.delete(getTopic(topic),mqttChannel)); - return topics; - } - - /** - * 发送 遗嘱消息(有的channel 已经关闭 但是保持了 session 此时加入session 数据中 ) - * @param willMeaasge 遗嘱消息 - */ - public void sendWillMsg(WillMeaasge willMeaasge){ - Collection mqttChannels = getChannels(willMeaasge.getWillTopic(), topic -> cacheMap.getData(getTopic(topic))); - if(!CollectionUtils.isEmpty(mqttChannels)){ - mqttChannels.forEach(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case CLOSE: - clientSessionService.saveSessionMsg(mqttChannel.getDeviceId(), - SessionMessage.builder() - .topic(willMeaasge.getWillTopic()) - .qoS(MqttQoS.valueOf(willMeaasge.getQos())) - .byteBuf(willMeaasge.getWillMessage().getBytes()).build()); - break; - case OPEN: - writeWillMsg(mqttChannel,willMeaasge); - break; - } - }); - } - } - - /** - * 保存保留消息 - * @param topic 主题 - * @param retainMessage 信息 - */ - private void saveRetain(String topic, RetainMessage retainMessage, boolean isClean){ - ConcurrentLinkedQueue retainMessages = retain.getOrDefault(topic, new ConcurrentLinkedQueue<>()); - if(!retainMessages.isEmpty() && isClean){ - retainMessages.clear(); - } - boolean flag; - do{ - flag = retainMessages.add(retainMessage); - } - while (!flag); - retain.put(topic, retainMessages); - } - - /** - * 发送保留消息 - */ - public void sendRetain(String topic,MqttChannel mqttChannel){ - retain.forEach((_topic, retainMessages) -> { - if(StringUtils.startsWith(_topic,topic)){ - Optional.ofNullable(retainMessages).ifPresent(pubMessages1 -> { - retainMessages.parallelStream().forEach(retainMessage -> { - log.info("【发送保留消息】"+mqttChannel.getChannel().remoteAddress()+":"+retainMessage.getString()+"【成功】"); - switch (retainMessage.getQoS()){ - case AT_MOST_ONCE: - sendQos0Msg(mqttChannel.getChannel(),_topic,retainMessage.getByteBuf()); - break; - case AT_LEAST_ONCE: - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); - break; - case EXACTLY_ONCE: - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,_topic,retainMessage.getByteBuf()); - break; - } - }); - }); - } - }); - - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java deleted file mode 100644 index 5e4e403..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/MqttHandlerService.java +++ /dev/null @@ -1,222 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.BaseApi; -import com.myself.unclecatmyself.bootstrap.BaseAuthService; -import com.myself.unclecatmyself.bootstrap.ChannelService; -import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; -import com.myself.unclecatmyself.common.enums.ConfirmStatus; -import com.myself.unclecatmyself.common.mqtts.ServerMqttHandlerService; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -//@Component -public class MqttHandlerService extends ServerMqttHandlerService implements BaseApi { - - @Autowired - ChannelService mqttChannelService; - - private final BaseAuthService baseAuthService; - - public MqttHandlerService(BaseAuthService baseAuthService) { - this.baseAuthService = baseAuthService; - } - - /** - * 登录 - * - */ - @Override - public boolean login(Channel channel, MqttConnectMessage mqttConnectMessage) { -// 校验规则 自定义校验规则 - MqttConnectPayload payload = mqttConnectMessage.payload(); - String deviceId = payload.clientIdentifier(); - if (StringUtils.isBlank(deviceId)) { - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_IDENTIFIER_REJECTED; - connectBack(channel,connectReturnCode); - return false; - } - - if(mqttConnectMessage.variableHeader().hasPassword() && mqttConnectMessage.variableHeader().hasUserName() - && !baseAuthService.authorized(payload.userName(),payload.password())){ - MqttConnectReturnCode connectReturnCode = MqttConnectReturnCode.CONNECTION_REFUSED_BAD_USER_NAME_OR_PASSWORD; - connectBack(channel,connectReturnCode); - return false; - } - return Optional.ofNullable(mqttChannelService.getMqttChannel(deviceId)) - .map(mqttChannel -> { - switch (mqttChannel.getSessionStatus()){ - case OPEN: - return false; - } - mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); - return true; - }).orElseGet(() -> { - mqttChannelService.loginSuccess(channel, deviceId, mqttConnectMessage); - return true; - }); - - } - - private void connectBack(Channel channel, MqttConnectReturnCode connectReturnCode){ - MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(connectReturnCode, true); - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader( - MqttMessageType.CONNACK,false, MqttQoS.AT_MOST_ONCE, false, 0x02); - MqttConnAckMessage connAck = new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader); - channel.writeAndFlush(connAck); - } - - - /** - * 发布 - */ - @Override - public void publish(Channel channel, MqttPublishMessage mqttPublishMessage) { - mqttChannelService.publishSuccess(channel, mqttPublishMessage); - } - - /** - * 订阅 - */ - @Override - public void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage) { - Set topics = mqttSubscribeMessage.payload().topicSubscriptions().stream().map(mqttTopicSubscription -> - mqttTopicSubscription.topicName() - ).collect(Collectors.toSet()); - mqttChannelService.suscribeSuccess(mqttChannelService.getDeviceId(channel), topics); - subBack(channel, mqttSubscribeMessage, topics.size()); - } - - private void subBack(Channel channel, MqttSubscribeMessage mqttSubscribeMessage, int num) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); - MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(mqttSubscribeMessage.variableHeader().messageId()); - List grantedQoSLevels = new ArrayList<>(num); - for (int i = 0; i < num; i++) { - grantedQoSLevels.add(mqttSubscribeMessage.payload().topicSubscriptions().get(i).qualityOfService().value()); - } - MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); - MqttSubAckMessage mqttSubAckMessage = new MqttSubAckMessage(mqttFixedHeader, variableHeader, payload); - channel.writeAndFlush(mqttSubAckMessage); - } - - - /** - * 关闭通道 - */ - @Override - public void close(Channel channel) { - mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), false); - channel.close(); - } - - /** - * 回复pong消息 - */ - @Override - public void pong(Channel channel) { - if (channel.isOpen() && channel.isActive() && channel.isWritable()) { - log.info("收到来自:【" + channel.remoteAddress().toString() + "】心跳"); - MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0); - channel.writeAndFlush(new MqttMessage(fixedHeader)); - } - } - - /** - * 取消订阅 - */ - @Override - public void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage) { - List topics1 = mqttMessage.payload().topics(); - mqttChannelService.unsubscribe(mqttChannelService.getDeviceId(channel), topics1); - unSubBack(channel, mqttMessage.variableHeader().messageId()); - } - - /** - * 回复取消订阅 - */ - private void unSubBack(Channel channel, int messageId) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0x02); - MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); - MqttUnsubAckMessage mqttUnsubAckMessage = new MqttUnsubAckMessage(mqttFixedHeader, variableHeader); - channel.writeAndFlush(mqttUnsubAckMessage); - } - - - /** - * 消息回复确认(qos1 级别 保证收到消息 但是可能会重复) - */ - @Override - public void puback(Channel channel, MqttMessage mqttMessage) { - MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = messageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - } - - - /** - * disconnect 主动断线 - */ - @Override - public void disconnect(Channel channel) { - mqttChannelService.closeSuccess(mqttChannelService.getDeviceId(channel), true); - } - - - /** - * qos2 发布收到 - */ - @Override - public void pubrec(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader messageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = messageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.PUBREL); // 复制为空 - mqttChannelService.doPubrec(channel, messageId); - } - - /** - * qos2 发布释放 - */ - @Override - public void pubrel(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = mqttMessageIdVariableHeader.messageId(); - mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId).setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - mqttChannelService.doPubrel(channel, messageId); - - } - - /** - * qos2 发布完成 - */ - @Override - public void pubcomp(Channel channel, MqttMessage mqttMessage ) { - MqttMessageIdVariableHeader mqttMessageIdVariableHeader = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); - int messageId = mqttMessageIdVariableHeader.messageId(); - SendMqttMessage sendMqttMessage = mqttChannelService.getMqttChannel(mqttChannelService.getDeviceId(channel)).getSendMqttMessage(messageId); - sendMqttMessage.setConfirmStatus(ConfirmStatus.COMPLETE); // 复制为空 - } - - @Override - public void doTimeOut(Channel channel, IdleStateEvent evt) { - log.info("【PingPongService:doTimeOut 心跳超时】" + channel.remoteAddress() + "【channel 关闭】"); - switch (evt.state()) { - case READER_IDLE: - close(channel); - case WRITER_IDLE: - close(channel); - case ALL_IDLE: - close(channel); - } - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java deleted file mode 100644 index 49e775c..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/PublishApiSevice.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; -import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; -import com.myself.unclecatmyself.bootstrap.bean.WillMeaasge; -import com.myself.unclecatmyself.bootstrap.scan.ScanRunnable; -import com.myself.unclecatmyself.common.utils.MessageId; -import com.myself.unclecatmyself.common.enums.ConfirmStatus; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 发送消息以及确认 - **/ -@Slf4j -public class PublishApiSevice { - - private final ScanRunnable scanRunnable; - - public PublishApiSevice(ScanRunnable scanRunnable) { - this.scanRunnable = scanRunnable; - } - - - /** - * 写入遗嘱消息 - */ - protected void writeWillMsg(MqttChannel mqttChannel, WillMeaasge willMeaasge) { -// dup保证消息可靠传输,默认为0,只占用一个字节,表示第一次发送。不能用于检测消息重复发送等 - switch (willMeaasge.getQos()){ - case 0: // qos0 - sendQos0Msg(mqttChannel.getChannel(),willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - case 1: // qos1 - sendQosConfirmMsg(MqttQoS.AT_LEAST_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - case 2: // qos2 - sendQosConfirmMsg(MqttQoS.EXACTLY_ONCE,mqttChannel,willMeaasge.getWillTopic(),willMeaasge.getWillMessage().getBytes()); - break; - } - - - } - - protected void sendQosConfirmMsg(MqttQoS qos, MqttChannel mqttChannel, String topic, byte[] bytes) { - if(mqttChannel.isLogin()){ - int messageId = MessageId.messageId(); - switch (qos){ - case AT_LEAST_ONCE: - mqttChannel.addSendMqttMessage(messageId,sendQos1Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); - break; - case EXACTLY_ONCE: - mqttChannel.addSendMqttMessage(messageId,sendQos2Msg(mqttChannel.getChannel(),topic,false,bytes,messageId)); - break; - } - } - - } - - - /** - * 发送 qos1 类的消息 - */ - private SendMqttMessage sendQos1Msg(Channel channel, String topic, boolean isDup, byte[] byteBuf, int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.AT_LEAST_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - return addQueue(channel,messageId,topic,byteBuf,MqttQoS.AT_LEAST_ONCE, ConfirmStatus.PUB); - } - - - - /** - * 发送 qos0 类的消息 byte - */ - protected void sendQos0Msg(Channel channel, String topic, byte[] byteBuf){ - if(channel!=null){ - sendQos0Msg(channel,topic,byteBuf,0); - } - } - private void sendQos0Msg(Channel channel, String topic, byte[] byteBuf,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,false, MqttQoS.AT_MOST_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader,Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - } - - - - - private SendMqttMessage sendQos2Msg(Channel channel, String topic,boolean isDup, byte[] byteBuf, int messageId) { - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,isDup, MqttQoS.EXACTLY_ONCE,false,0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(topic,messageId ); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(byteBuf)); - channel.writeAndFlush(mqttPublishMessage); - return addQueue(channel,messageId,topic,byteBuf,MqttQoS.EXACTLY_ONCE,ConfirmStatus.PUB); - } - - - /** - * 发送qos1 publish 确认消息 - */ - protected void sendPubBack(Channel channel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBACK,false, MqttQoS.AT_MOST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - - /** - * 发送qos2 publish 确认消息 第一步 - */ - protected void sendPubRec( MqttChannel mqttChannel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREC,false, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - Channel channel = mqttChannel.getChannel(); - channel.writeAndFlush(mqttPubAckMessage); - SendMqttMessage sendMqttMessage = addQueue(channel, messageId, null, null, null, ConfirmStatus.PUBREC); - mqttChannel.addSendMqttMessage(messageId,sendMqttMessage); - } - - /** - * 发送qos2 publish 确认消息 第二步 - */ - protected void sendPubRel(Channel channel,boolean isDup,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBREL,isDup, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - /** - * 发送qos2 publish 确认消息 第三步 - */ - protected void sendToPubComp(Channel channel,int messageId){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBCOMP,false, MqttQoS.AT_MOST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(messageId); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - channel.writeAndFlush(mqttPubAckMessage); - } - - private SendMqttMessage addQueue(Channel channel,int messageId,String topic,byte[] datas,MqttQoS mqttQoS,ConfirmStatus confirmStatus){ - SendMqttMessage build = SendMqttMessage.builder(). - channel(channel). - confirmStatus(confirmStatus). - messageId(messageId) - .topic(topic) - .qos(mqttQoS) - .byteBuf(datas) - .time(System.currentTimeMillis()).build(); - scanRunnable.addQueue(build); - return build; - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 9bfd383..9a0908e 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -3,7 +3,6 @@ import com.alibaba.fastjson.JSONArray; import com.google.gson.Gson; import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; -import com.myself.unclecatmyself.bootstrap.BaseAuthService; import com.myself.unclecatmyself.bootstrap.WsChannelService; import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; @@ -38,10 +37,7 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService{ private final Gson gson; - private final BaseAuthService baseAuthService; - - public WebSocketHandlerService(BaseAuthService baseAuthService,Gson gson){ - this.baseAuthService = baseAuthService; + public WebSocketHandlerService(Gson gson){ this.gson = gson; } @@ -76,13 +72,13 @@ public void sendToText(Channel channel, Map maps) { String value = (String) maps.get("value"); String me = (String) maps.get("me"); if (websocketChannelService.hasOther(otherOne)){ + //返回给自己 + channel.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); //发送给对方 Channel other = websocketChannelService.getChannel(otherOne); other.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.getMsg(me,value)))); - //返回给自己 - channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); } try { dataAsynchronousTask.writeData(maps); diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java deleted file mode 100644 index e82387b..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WillService.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.channel; - -import com.myself.unclecatmyself.bootstrap.BaseApi; -import com.myself.unclecatmyself.bootstrap.ChannelService; -import com.myself.unclecatmyself.bootstrap.bean.WillMeaasge; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.concurrent.ConcurrentHashMap; - -@Slf4j -//@Component -@Data -@NoArgsConstructor -public class WillService implements BaseApi { - - @Autowired - ChannelService channelService; - - private static ConcurrentHashMap willMeaasges = new ConcurrentHashMap<>(); // deviceid -WillMeaasge - - - - /** - * 保存遗嘱消息 - */ - public void save(String deviceid, WillMeaasge build) { - willMeaasges.put(deviceid,build); // 替换旧的 - } - - - public void doSend( String deviceId) { // 客户端断开连接后 开启遗嘱消息发送 - if(StringUtils.isNotBlank(deviceId)&&(willMeaasges.get(deviceId))!=null){ - WillMeaasge willMeaasge = willMeaasges.get(deviceId); - channelService.sendWillMsg(willMeaasge); // 发送遗嘱消息 - if(!willMeaasge.isRetain()){ // 移除 - willMeaasges.remove(deviceId); - log.info("deviceId will message["+willMeaasge.getWillMessage()+"] is removed"); - } - } - } - - /** - * 删除遗嘱消息 - */ - public void del(String deviceid ) {willMeaasges.remove(deviceid);} - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java deleted file mode 100644 index cf3829d..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/coder/ByteBufToWebSocketFrameEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.coder; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageEncoder; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; - -import java.util.List; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 转换 - **/ -public class ByteBufToWebSocketFrameEncoder extends MessageToMessageEncoder { - - @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf byteBuf, List out) throws Exception { - if (byteBuf == null) { - return; - } - BinaryWebSocketFrame result = new BinaryWebSocketFrame(); - result.content().writeBytes(byteBuf); - out.add(result); - } -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java b/src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java deleted file mode 100644 index 856a8cb..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/coder/WebSocketFrameToByteBufDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.coder; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageDecoder; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; - -import java.util.List; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 转换 - **/ -public class WebSocketFrameToByteBufDecoder extends MessageToMessageDecoder { - - - @Override - protected void decode(ChannelHandlerContext ctx, BinaryWebSocketFrame wsFrame, List out) throws Exception { - ByteBuf buf = wsFrame.content(); - //避免计数器为0,报错 - buf.retain(); - out.add(buf); - } -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java deleted file mode 100644 index b516bd4..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultMqttHandler.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.handler; - -import com.myself.unclecatmyself.bootstrap.ChannelService; -import com.myself.unclecatmyself.bootstrap.bean.MqttChannel; -import com.myself.unclecatmyself.common.mqtts.MqttHandlerIntf; -import com.myself.unclecatmyself.common.mqtts.MqttHander; -import com.myself.unclecatmyself.common.mqtts.ServerMqttHandlerService; -import com.myself.unclecatmyself.common.exception.NoFindHandlerException; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 默认MQTTHandler处理 - **/ -@Slf4j -//@Component -@ChannelHandler.Sharable -public class DefaultMqttHandler extends MqttHander { - - private final MqttHandlerIntf mqttHandlerApi; - - @Autowired - ChannelService channelService; - - - public DefaultMqttHandler(MqttHandlerIntf mqttHandlerApi) { - super(mqttHandlerApi); - this.mqttHandlerApi = mqttHandlerApi; - } - - @Override - public void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) { - Channel channel = channelHandlerContext.channel(); - ServerMqttHandlerService serverMqttHandlerService; - if(mqttHandlerApi instanceof ServerMqttHandlerService){ - serverMqttHandlerService =(ServerMqttHandlerService)mqttHandlerApi; - } - else{ - throw new NoFindHandlerException("server handler 不匹配"); - } - MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); - if(mqttFixedHeader.messageType().equals(MqttMessageType.CONNECT)){ - if(!serverMqttHandlerService.login(channel, (MqttConnectMessage) mqttMessage)){ - channel.close(); - } - return ; - } - MqttChannel mqttChannel = channelService.getMqttChannel(channelService.getDeviceId(channel)); - if(mqttChannel!=null && mqttChannel.isLogin()){ - switch (mqttFixedHeader.messageType()){ - case PUBLISH: - serverMqttHandlerService.publish(channel, (MqttPublishMessage) mqttMessage); - break; - case SUBSCRIBE: - serverMqttHandlerService.subscribe(channel, (MqttSubscribeMessage) mqttMessage); - break; - case PINGREQ: - serverMqttHandlerService.pong(channel); - break; - case DISCONNECT: - serverMqttHandlerService.disconnect(channel); - break; - case UNSUBSCRIBE: - serverMqttHandlerService.unsubscribe(channel,(MqttUnsubscribeMessage)mqttMessage); - break; - case PUBACK: - mqttHandlerApi.puback(channel,mqttMessage); - break; - case PUBREC: - mqttHandlerApi.pubrec(channel,mqttMessage); - break; - case PUBREL: - mqttHandlerApi.pubrel(channel,mqttMessage); - break; - case PUBCOMP: - mqttHandlerApi.pubcomp(channel,mqttMessage); - break; - default: - break; - } - } - } - - - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultMqttHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - log.error("exception",cause); - mqttHandlerApi.close(ctx.channel()); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java deleted file mode 100644 index b278c5a..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/scan/SacnScheduled.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.scan; - -import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import lombok.extern.slf4j.Slf4j; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 扫描消息确认 - **/ -@Slf4j -public class SacnScheduled extends ScanRunnable { - - private final long time; - - public SacnScheduled(long time) { - this.time = time; - } - - private boolean checkTime(long time) { - return System.currentTimeMillis()-time>=10*1000; - } - - @Override - public void doInfo(SendMqttMessage poll) { - if(checkTime(poll.getTime()) && poll.getChannel().isActive()){ - poll.setTime(System.currentTimeMillis()); - switch (poll.getConfirmStatus()){ - case PUB: - pubMessage(poll.getChannel(),poll); - break; - case PUBREL: - sendAck(MqttMessageType.PUBREL,poll); - break; - case PUBREC: - sendAck(MqttMessageType.PUBREC,poll); - break; - } - } - } - - private void pubMessage(Channel channel, SendMqttMessage mqttMessage){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH,true, mqttMessage.getQos(),mqttMessage.isRetain(),0); - MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(mqttMessage.getTopic(),mqttMessage.getMessageId()); - MqttPublishMessage mqttPublishMessage = new MqttPublishMessage(mqttFixedHeader,mqttPublishVariableHeader, Unpooled.wrappedBuffer(mqttMessage.getByteBuf())); - channel.writeAndFlush(mqttPublishMessage); - } - - protected void sendAck(MqttMessageType type,SendMqttMessage mqttMessage){ - MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(type,true, MqttQoS.AT_LEAST_ONCE,false,0x02); - MqttMessageIdVariableHeader from = MqttMessageIdVariableHeader.from(mqttMessage.getMessageId()); - MqttPubAckMessage mqttPubAckMessage = new MqttPubAckMessage(mqttFixedHeader,from); - mqttMessage.getChannel().writeAndFlush(mqttPubAckMessage); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java b/src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java deleted file mode 100644 index 9726fc6..0000000 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/scan/ScanRunnable.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.myself.unclecatmyself.bootstrap.scan; - -import com.myself.unclecatmyself.bootstrap.bean.SendMqttMessage; -import lombok.extern.slf4j.Slf4j; -import com.myself.unclecatmyself.common.enums.ConfirmStatus; -import java.util.List; -import java.util.concurrent.LinkedBlockingQueue; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 扫描未确认的消息 - **/ -@Slf4j -public abstract class ScanRunnable implements Runnable{ - - LinkedBlockingQueue queue =new LinkedBlockingQueue(); - - public boolean addQueue(SendMqttMessage t){ - return queue.add(t); - } - - public boolean addQueues(List ts){ - return queue.addAll(ts); - } - - @Override - public void run() { - for(;;){ - try { - SendMqttMessage poll= queue.take(); - if(poll.getConfirmStatus()!= ConfirmStatus.COMPLETE){ - doInfo(poll); - queue.offer(poll); - } - } catch (InterruptedException e) { - log.error("scan InterruptedException",e); - } - } - } - public abstract void doInfo( SendMqttMessage poll); - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java deleted file mode 100644 index 255adf9..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/enums/ConfirmStatus.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.myself.unclecatmyself.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 确认状态 - **/ -public enum ConfirmStatus { - PUB, - PUBREC, - PUBREL, - COMPLETE, -} diff --git a/src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java b/src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java deleted file mode 100644 index 6b29d02..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/enums/ProtocolEnum.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.myself.unclecatmyself.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 协议 - **/ -public enum ProtocolEnum { - MQTT, - - MQTT_WS_MQTT, - - MQTT_WS_PAHO, -} diff --git a/src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java deleted file mode 100644 index d5e31b2..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/enums/QosStatus.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.myself.unclecatmyself.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Qos确认状态 - **/ -public enum QosStatus { - - PUBD, // 已发送 没收到RECD (发送) - - RECD, //publish 推送回复过(发送) - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java deleted file mode 100644 index a9ee354..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/enums/SessionStatus.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.myself.unclecatmyself.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc Channel 会话状态 - **/ -public enum SessionStatus { - - OPEN, - CLOSE - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java b/src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java deleted file mode 100644 index 8b7929e..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/enums/SubStatus.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.myself.unclecatmyself.common.enums; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 是否订阅过主题 - **/ -public enum SubStatus { - YES, - NO -} diff --git a/src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java deleted file mode 100644 index d60c3a2..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/mqtts/ClientMqttHandlerService.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.myself.unclecatmyself.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; - - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象出客户端的事件 - **/ -public abstract class ClientMqttHandlerService implements MqttHandlerIntf { - - @Override - public void doTimeOut(Channel channel, IdleStateEvent evt) { - heart(channel,evt); - } - - public abstract void heart(Channel channel, IdleStateEvent evt); - - public abstract void suback(Channel channel,MqttSubAckMessage mqttMessage) ; - - public abstract void pubBackMessage(Channel channel, int i); - - public abstract void unsubBack(Channel channel, MqttMessage mqttMessage); -} diff --git a/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java deleted file mode 100644 index 6512483..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHander.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.myself.unclecatmyself.common.mqtts; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.mqtt.MqttFixedHeader; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; - -import java.util.Optional; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc mtqq协议处理器 - **/ -@Slf4j -public abstract class MqttHander extends SimpleChannelInboundHandler { - - MqttHandlerIntf mqttHandlerApi; - - public MqttHander(MqttHandlerIntf mqttHandlerIntf){ - this.mqttHandlerApi=mqttHandlerIntf; - } - - @Override - protected void channelRead0(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage) throws Exception { - MqttFixedHeader mqttFixedHeader = mqttMessage.fixedHeader(); - Optional.ofNullable(mqttFixedHeader) - .ifPresent(mqttFixedHeader1 -> doMessage(channelHandlerContext,mqttMessage)); - } - - - public abstract void doMessage(ChannelHandlerContext channelHandlerContext, MqttMessage mqttMessage); - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultMqttHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - mqttHandlerApi.close(ctx.channel()); - } - - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if(evt instanceof IdleStateEvent){ - mqttHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); - } - super.userEventTriggered(ctx, evt); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java deleted file mode 100644 index 1c8f883..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/mqtts/MqttHandlerIntf.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.myself.unclecatmyself.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.MqttMessage; -import io.netty.handler.timeout.IdleStateEvent; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 自定义 对外暴露,消息处理API - **/ -public interface MqttHandlerIntf { - - void close(Channel channel); - - void puback(Channel channel, MqttMessage mqttMessage); - - void pubrec(Channel channel, MqttMessage mqttMessage); - - void pubrel(Channel channel, MqttMessage mqttMessage); - - void pubcomp(Channel channel, MqttMessage mqttMessage); - - void doTimeOut(Channel channel, IdleStateEvent evt); - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java deleted file mode 100644 index 31cc216..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/mqtts/ServerMqttHandlerService.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.myself.unclecatmyself.common.mqtts; - -import io.netty.channel.Channel; -import io.netty.handler.codec.mqtt.*; -import io.netty.handler.timeout.IdleStateEvent; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象出服务端的事件 - **/ -public abstract class ServerMqttHandlerService implements MqttHandlerIntf { - - public abstract boolean login(Channel channel, MqttConnectMessage mqttConnectMessage); - - public abstract void publish(Channel channel, MqttPublishMessage mqttPublishMessage); - - public abstract void subscribe(Channel channel, MqttSubscribeMessage mqttSubscribeMessage); - - public abstract void pong(Channel channel); - - public abstract void unsubscribe(Channel channel, MqttUnsubscribeMessage mqttMessage); - - public abstract void disconnect(Channel channel); - - public abstract void doTimeOut(Channel channel, IdleStateEvent evt); - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java deleted file mode 100644 index bdded08..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketKeyStore.java +++ /dev/null @@ -1,456 +0,0 @@ -package com.myself.unclecatmyself.common.ssl; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.security.KeyStore; - -/** - * A bogus key store which provides all the required information to create an - * example SSL connection. - * - * To generate a bogus key store: - * - *
- * keytool -genkey -alias securesocket \ -keysize 2048 -validity 36500 \  -keyalg RSA -dname "CN=securesocket" \   -keypass inc0rrect -storepass mu$tch8ng3 \  -keystore cert.jks
- *
- *
- *
- *
- * 
- */ -public class SecureSocketKeyStore { - - private static final byte[] CERT_BYTES = { (byte) 254, (byte) 237, - (byte) 254, (byte) 237, (byte) 0, (byte) 0, (byte) 0, (byte) 2, - (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, (byte) 0, - (byte) 0, (byte) 1, (byte) 0, (byte) 12, (byte) 115, (byte) 101, - (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, - (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, - (byte) 0, (byte) 0, (byte) 1, (byte) 69, (byte) 231, (byte) 201, - (byte) 156, (byte) 140, (byte) 0, (byte) 0, (byte) 5, (byte) 0, - (byte) 48, (byte) 130, (byte) 4, (byte) 252, (byte) 48, (byte) 14, - (byte) 6, (byte) 10, (byte) 43, (byte) 6, (byte) 1, (byte) 4, - (byte) 1, (byte) 42, (byte) 2, (byte) 17, (byte) 1, (byte) 1, - (byte) 5, (byte) 0, (byte) 4, (byte) 130, (byte) 4, (byte) 232, - (byte) 221, (byte) 18, (byte) 203, (byte) 171, (byte) 175, - (byte) 82, (byte) 132, (byte) 227, (byte) 115, (byte) 143, - (byte) 38, (byte) 191, (byte) 42, (byte) 202, (byte) 130, - (byte) 171, (byte) 75, (byte) 6, (byte) 161, (byte) 120, - (byte) 204, (byte) 61, (byte) 106, (byte) 160, (byte) 81, (byte) 9, - (byte) 204, (byte) 153, (byte) 166, (byte) 38, (byte) 246, - (byte) 13, (byte) 43, (byte) 19, (byte) 100, (byte) 132, (byte) 45, - (byte) 90, (byte) 143, (byte) 1, (byte) 231, (byte) 182, (byte) 89, - (byte) 228, (byte) 183, (byte) 17, (byte) 95, (byte) 129, - (byte) 229, (byte) 42, (byte) 182, (byte) 126, (byte) 114, - (byte) 76, (byte) 124, (byte) 123, (byte) 246, (byte) 152, - (byte) 0, (byte) 141, (byte) 212, (byte) 111, (byte) 52, - (byte) 243, (byte) 112, (byte) 31, (byte) 117, (byte) 124, - (byte) 142, (byte) 24, (byte) 59, (byte) 198, (byte) 164, - (byte) 253, (byte) 21, (byte) 177, (byte) 189, (byte) 74, - (byte) 218, (byte) 110, (byte) 83, (byte) 154, (byte) 49, - (byte) 186, (byte) 159, (byte) 173, (byte) 202, (byte) 94, - (byte) 174, (byte) 183, (byte) 223, (byte) 119, (byte) 109, - (byte) 110, (byte) 72, (byte) 93, (byte) 208, (byte) 195, - (byte) 19, (byte) 89, (byte) 33, (byte) 34, (byte) 186, (byte) 12, - (byte) 86, (byte) 156, (byte) 156, (byte) 210, (byte) 111, - (byte) 110, (byte) 44, (byte) 106, (byte) 36, (byte) 67, - (byte) 168, (byte) 7, (byte) 179, (byte) 244, (byte) 53, - (byte) 134, (byte) 10, (byte) 86, (byte) 179, (byte) 34, (byte) 60, - (byte) 184, (byte) 179, (byte) 162, (byte) 69, (byte) 24, - (byte) 168, (byte) 100, (byte) 183, (byte) 206, (byte) 64, - (byte) 4, (byte) 32, (byte) 66, (byte) 237, (byte) 228, (byte) 92, - (byte) 6, (byte) 213, (byte) 141, (byte) 147, (byte) 198, - (byte) 141, (byte) 216, (byte) 41, (byte) 0, (byte) 101, (byte) 65, - (byte) 41, (byte) 185, (byte) 128, (byte) 229, (byte) 107, - (byte) 25, (byte) 89, (byte) 148, (byte) 16, (byte) 194, - (byte) 101, (byte) 100, (byte) 243, (byte) 147, (byte) 77, - (byte) 230, (byte) 11, (byte) 151, (byte) 99, (byte) 124, - (byte) 55, (byte) 195, (byte) 185, (byte) 30, (byte) 234, - (byte) 83, (byte) 61, (byte) 109, (byte) 131, (byte) 156, - (byte) 244, (byte) 133, (byte) 66, (byte) 39, (byte) 153, (byte) 9, - (byte) 34, (byte) 218, (byte) 201, (byte) 143, (byte) 190, - (byte) 127, (byte) 119, (byte) 102, (byte) 6, (byte) 83, - (byte) 134, (byte) 96, (byte) 170, (byte) 79, (byte) 196, - (byte) 214, (byte) 47, (byte) 215, (byte) 37, (byte) 250, - (byte) 64, (byte) 8, (byte) 165, (byte) 203, (byte) 44, (byte) 53, - (byte) 113, (byte) 147, (byte) 251, (byte) 29, (byte) 26, - (byte) 38, (byte) 193, (byte) 11, (byte) 223, (byte) 212, - (byte) 114, (byte) 96, (byte) 162, (byte) 39, (byte) 48, - (byte) 200, (byte) 172, (byte) 182, (byte) 254, (byte) 180, - (byte) 198, (byte) 11, (byte) 128, (byte) 75, (byte) 74, (byte) 93, - (byte) 226, (byte) 157, (byte) 80, (byte) 14, (byte) 9, (byte) 217, - (byte) 236, (byte) 205, (byte) 153, (byte) 35, (byte) 242, - (byte) 130, (byte) 140, (byte) 25, (byte) 16, (byte) 156, - (byte) 247, (byte) 230, (byte) 5, (byte) 247, (byte) 0, (byte) 34, - (byte) 196, (byte) 15, (byte) 118, (byte) 255, (byte) 185, - (byte) 199, (byte) 59, (byte) 99, (byte) 27, (byte) 187, (byte) 83, - (byte) 81, (byte) 12, (byte) 71, (byte) 69, (byte) 127, (byte) 130, - (byte) 164, (byte) 97, (byte) 195, (byte) 216, (byte) 215, - (byte) 61, (byte) 29, (byte) 196, (byte) 62, (byte) 160, - (byte) 188, (byte) 209, (byte) 173, (byte) 230, (byte) 0, - (byte) 204, (byte) 225, (byte) 1, (byte) 5, (byte) 42, (byte) 223, - (byte) 232, (byte) 187, (byte) 190, (byte) 67, (byte) 126, - (byte) 235, (byte) 178, (byte) 218, (byte) 179, (byte) 46, - (byte) 186, (byte) 156, (byte) 186, (byte) 6, (byte) 191, - (byte) 68, (byte) 239, (byte) 31, (byte) 16, (byte) 204, (byte) 24, - (byte) 68, (byte) 164, (byte) 88, (byte) 10, (byte) 174, (byte) 26, - (byte) 54, (byte) 187, (byte) 149, (byte) 132, (byte) 128, - (byte) 173, (byte) 165, (byte) 8, (byte) 69, (byte) 96, (byte) 49, - (byte) 57, (byte) 223, (byte) 110, (byte) 29, (byte) 215, - (byte) 98, (byte) 42, (byte) 15, (byte) 153, (byte) 228, - (byte) 216, (byte) 61, (byte) 160, (byte) 230, (byte) 34, - (byte) 40, (byte) 232, (byte) 136, (byte) 139, (byte) 140, - (byte) 236, (byte) 251, (byte) 119, (byte) 242, (byte) 199, - (byte) 167, (byte) 61, (byte) 141, (byte) 89, (byte) 29, (byte) 82, - (byte) 114, (byte) 229, (byte) 198, (byte) 27, (byte) 133, - (byte) 87, (byte) 0, (byte) 53, (byte) 69, (byte) 42, (byte) 91, - (byte) 174, (byte) 82, (byte) 244, (byte) 160, (byte) 82, - (byte) 142, (byte) 221, (byte) 106, (byte) 151, (byte) 241, - (byte) 214, (byte) 64, (byte) 14, (byte) 28, (byte) 2, (byte) 3, - (byte) 145, (byte) 143, (byte) 18, (byte) 165, (byte) 247, - (byte) 178, (byte) 211, (byte) 16, (byte) 222, (byte) 76, - (byte) 60, (byte) 119, (byte) 130, (byte) 199, (byte) 230, - (byte) 229, (byte) 3, (byte) 22, (byte) 100, (byte) 135, - (byte) 103, (byte) 60, (byte) 181, (byte) 191, (byte) 56, - (byte) 249, (byte) 181, (byte) 169, (byte) 210, (byte) 25, - (byte) 152, (byte) 201, (byte) 226, (byte) 119, (byte) 71, - (byte) 204, (byte) 70, (byte) 220, (byte) 103, (byte) 46, - (byte) 166, (byte) 125, (byte) 40, (byte) 86, (byte) 208, - (byte) 114, (byte) 138, (byte) 24, (byte) 27, (byte) 219, - (byte) 123, (byte) 161, (byte) 52, (byte) 14, (byte) 38, - (byte) 244, (byte) 112, (byte) 238, (byte) 121, (byte) 90, - (byte) 34, (byte) 157, (byte) 131, (byte) 53, (byte) 245, - (byte) 162, (byte) 89, (byte) 188, (byte) 6, (byte) 202, - (byte) 164, (byte) 130, (byte) 34, (byte) 232, (byte) 74, - (byte) 45, (byte) 137, (byte) 164, (byte) 200, (byte) 197, - (byte) 247, (byte) 64, (byte) 110, (byte) 122, (byte) 49, - (byte) 116, (byte) 137, (byte) 253, (byte) 170, (byte) 232, - (byte) 120, (byte) 26, (byte) 171, (byte) 228, (byte) 229, - (byte) 49, (byte) 56, (byte) 56, (byte) 106, (byte) 110, (byte) 12, - (byte) 109, (byte) 93, (byte) 105, (byte) 241, (byte) 196, - (byte) 11, (byte) 18, (byte) 89, (byte) 108, (byte) 146, - (byte) 224, (byte) 161, (byte) 181, (byte) 236, (byte) 74, - (byte) 128, (byte) 24, (byte) 239, (byte) 22, (byte) 146, (byte) 0, - (byte) 69, (byte) 182, (byte) 246, (byte) 43, (byte) 59, - (byte) 208, (byte) 33, (byte) 48, (byte) 81, (byte) 0, (byte) 70, - (byte) 225, (byte) 222, (byte) 122, (byte) 178, (byte) 138, - (byte) 12, (byte) 207, (byte) 233, (byte) 164, (byte) 13, - (byte) 176, (byte) 123, (byte) 95, (byte) 68, (byte) 238, - (byte) 134, (byte) 66, (byte) 95, (byte) 194, (byte) 192, - (byte) 225, (byte) 244, (byte) 14, (byte) 78, (byte) 53, - (byte) 189, (byte) 217, (byte) 229, (byte) 203, (byte) 192, - (byte) 34, (byte) 38, (byte) 169, (byte) 63, (byte) 239, - (byte) 128, (byte) 172, (byte) 143, (byte) 75, (byte) 7, - (byte) 237, (byte) 125, (byte) 179, (byte) 235, (byte) 229, - (byte) 98, (byte) 8, (byte) 211, (byte) 237, (byte) 116, (byte) 75, - (byte) 27, (byte) 211, (byte) 131, (byte) 245, (byte) 89, - (byte) 150, (byte) 35, (byte) 49, (byte) 207, (byte) 113, - (byte) 237, (byte) 114, (byte) 125, (byte) 134, (byte) 191, - (byte) 110, (byte) 30, (byte) 119, (byte) 131, (byte) 175, - (byte) 166, (byte) 201, (byte) 255, (byte) 200, (byte) 1, - (byte) 126, (byte) 163, (byte) 172, (byte) 52, (byte) 118, - (byte) 184, (byte) 221, (byte) 165, (byte) 167, (byte) 165, - (byte) 20, (byte) 135, (byte) 32, (byte) 222, (byte) 188, - (byte) 250, (byte) 64, (byte) 161, (byte) 67, (byte) 236, - (byte) 212, (byte) 131, (byte) 44, (byte) 32, (byte) 70, (byte) 0, - (byte) 24, (byte) 178, (byte) 83, (byte) 155, (byte) 145, - (byte) 136, (byte) 131, (byte) 120, (byte) 181, (byte) 164, - (byte) 155, (byte) 172, (byte) 41, (byte) 213, (byte) 164, - (byte) 98, (byte) 169, (byte) 152, (byte) 184, (byte) 170, - (byte) 107, (byte) 7, (byte) 21, (byte) 228, (byte) 175, - (byte) 192, (byte) 238, (byte) 68, (byte) 197, (byte) 119, - (byte) 228, (byte) 225, (byte) 156, (byte) 235, (byte) 241, - (byte) 172, (byte) 171, (byte) 236, (byte) 128, (byte) 78, - (byte) 117, (byte) 152, (byte) 123, (byte) 93, (byte) 156, - (byte) 57, (byte) 238, (byte) 211, (byte) 188, (byte) 47, - (byte) 62, (byte) 45, (byte) 127, (byte) 58, (byte) 38, (byte) 29, - (byte) 131, (byte) 95, (byte) 85, (byte) 149, (byte) 112, - (byte) 215, (byte) 207, (byte) 41, (byte) 201, (byte) 30, - (byte) 149, (byte) 73, (byte) 245, (byte) 179, (byte) 176, - (byte) 246, (byte) 203, (byte) 204, (byte) 252, (byte) 13, - (byte) 98, (byte) 151, (byte) 93, (byte) 87, (byte) 241, - (byte) 166, (byte) 46, (byte) 249, (byte) 148, (byte) 49, - (byte) 141, (byte) 136, (byte) 49, (byte) 77, (byte) 250, - (byte) 191, (byte) 157, (byte) 90, (byte) 84, (byte) 51, - (byte) 129, (byte) 133, (byte) 66, (byte) 253, (byte) 99, - (byte) 243, (byte) 34, (byte) 142, (byte) 197, (byte) 4, - (byte) 126, (byte) 7, (byte) 217, (byte) 126, (byte) 205, - (byte) 250, (byte) 141, (byte) 231, (byte) 225, (byte) 203, - (byte) 171, (byte) 246, (byte) 201, (byte) 48, (byte) 96, - (byte) 207, (byte) 74, (byte) 253, (byte) 120, (byte) 114, - (byte) 163, (byte) 192, (byte) 24, (byte) 12, (byte) 10, - (byte) 210, (byte) 94, (byte) 136, (byte) 152, (byte) 185, - (byte) 109, (byte) 87, (byte) 35, (byte) 159, (byte) 238, - (byte) 122, (byte) 200, (byte) 107, (byte) 103, (byte) 243, - (byte) 250, (byte) 152, (byte) 68, (byte) 66, (byte) 170, (byte) 0, - (byte) 134, (byte) 229, (byte) 168, (byte) 182, (byte) 30, - (byte) 89, (byte) 240, (byte) 121, (byte) 106, (byte) 148, - (byte) 142, (byte) 49, (byte) 242, (byte) 215, (byte) 233, - (byte) 57, (byte) 120, (byte) 204, (byte) 180, (byte) 239, - (byte) 199, (byte) 133, (byte) 255, (byte) 71, (byte) 3, - (byte) 132, (byte) 228, (byte) 110, (byte) 66, (byte) 227, - (byte) 122, (byte) 82, (byte) 118, (byte) 173, (byte) 218, - (byte) 54, (byte) 99, (byte) 167, (byte) 154, (byte) 3, (byte) 189, - (byte) 25, (byte) 123, (byte) 169, (byte) 42, (byte) 184, - (byte) 59, (byte) 36, (byte) 131, (byte) 206, (byte) 248, - (byte) 90, (byte) 32, (byte) 183, (byte) 86, (byte) 62, (byte) 149, - (byte) 107, (byte) 243, (byte) 71, (byte) 197, (byte) 124, - (byte) 155, (byte) 214, (byte) 91, (byte) 29, (byte) 81, (byte) 28, - (byte) 115, (byte) 98, (byte) 130, (byte) 184, (byte) 135, - (byte) 13, (byte) 191, (byte) 147, (byte) 43, (byte) 10, - (byte) 178, (byte) 99, (byte) 165, (byte) 210, (byte) 87, - (byte) 87, (byte) 148, (byte) 31, (byte) 198, (byte) 129, - (byte) 32, (byte) 181, (byte) 3, (byte) 144, (byte) 61, (byte) 5, - (byte) 166, (byte) 252, (byte) 73, (byte) 205, (byte) 230, - (byte) 178, (byte) 162, (byte) 46, (byte) 56, (byte) 99, (byte) 77, - (byte) 97, (byte) 236, (byte) 121, (byte) 157, (byte) 139, - (byte) 153, (byte) 217, (byte) 171, (byte) 19, (byte) 68, - (byte) 36, (byte) 14, (byte) 123, (byte) 249, (byte) 101, - (byte) 127, (byte) 184, (byte) 123, (byte) 7, (byte) 124, - (byte) 68, (byte) 98, (byte) 34, (byte) 139, (byte) 224, - (byte) 173, (byte) 246, (byte) 196, (byte) 180, (byte) 70, - (byte) 207, (byte) 168, (byte) 211, (byte) 255, (byte) 84, - (byte) 0, (byte) 174, (byte) 11, (byte) 160, (byte) 155, - (byte) 127, (byte) 228, (byte) 81, (byte) 226, (byte) 115, - (byte) 142, (byte) 200, (byte) 107, (byte) 4, (byte) 204, - (byte) 219, (byte) 192, (byte) 189, (byte) 56, (byte) 127, - (byte) 184, (byte) 187, (byte) 161, (byte) 106, (byte) 62, - (byte) 225, (byte) 211, (byte) 115, (byte) 30, (byte) 172, - (byte) 191, (byte) 66, (byte) 25, (byte) 66, (byte) 235, - (byte) 107, (byte) 41, (byte) 186, (byte) 40, (byte) 239, - (byte) 173, (byte) 11, (byte) 247, (byte) 89, (byte) 79, - (byte) 135, (byte) 86, (byte) 73, (byte) 77, (byte) 164, (byte) 34, - (byte) 109, (byte) 236, (byte) 56, (byte) 198, (byte) 141, - (byte) 87, (byte) 74, (byte) 172, (byte) 56, (byte) 24, (byte) 150, - (byte) 233, (byte) 233, (byte) 165, (byte) 122, (byte) 201, - (byte) 112, (byte) 232, (byte) 23, (byte) 12, (byte) 166, - (byte) 128, (byte) 114, (byte) 139, (byte) 207, (byte) 233, - (byte) 47, (byte) 220, (byte) 172, (byte) 175, (byte) 40, - (byte) 109, (byte) 82, (byte) 142, (byte) 130, (byte) 177, - (byte) 50, (byte) 127, (byte) 196, (byte) 106, (byte) 172, - (byte) 178, (byte) 71, (byte) 178, (byte) 204, (byte) 99, - (byte) 113, (byte) 33, (byte) 189, (byte) 188, (byte) 168, - (byte) 76, (byte) 92, (byte) 230, (byte) 211, (byte) 239, - (byte) 75, (byte) 71, (byte) 64, (byte) 197, (byte) 26, (byte) 222, - (byte) 19, (byte) 213, (byte) 161, (byte) 144, (byte) 20, - (byte) 126, (byte) 192, (byte) 156, (byte) 15, (byte) 113, - (byte) 64, (byte) 73, (byte) 7, (byte) 241, (byte) 217, (byte) 127, - (byte) 171, (byte) 199, (byte) 66, (byte) 32, (byte) 179, (byte) 4, - (byte) 181, (byte) 93, (byte) 121, (byte) 193, (byte) 10, - (byte) 169, (byte) 255, (byte) 152, (byte) 199, (byte) 95, - (byte) 177, (byte) 227, (byte) 135, (byte) 21, (byte) 64, - (byte) 203, (byte) 9, (byte) 79, (byte) 243, (byte) 114, (byte) 2, - (byte) 201, (byte) 157, (byte) 180, (byte) 52, (byte) 193, - (byte) 66, (byte) 34, (byte) 155, (byte) 52, (byte) 35, (byte) 93, - (byte) 31, (byte) 96, (byte) 77, (byte) 12, (byte) 80, (byte) 195, - (byte) 96, (byte) 247, (byte) 251, (byte) 237, (byte) 36, - (byte) 170, (byte) 7, (byte) 3, (byte) 251, (byte) 243, (byte) 47, - (byte) 180, (byte) 98, (byte) 207, (byte) 176, (byte) 106, - (byte) 237, (byte) 114, (byte) 91, (byte) 229, (byte) 56, - (byte) 94, (byte) 154, (byte) 32, (byte) 62, (byte) 240, - (byte) 132, (byte) 4, (byte) 144, (byte) 227, (byte) 140, - (byte) 137, (byte) 76, (byte) 15, (byte) 117, (byte) 82, - (byte) 223, (byte) 168, (byte) 135, (byte) 33, (byte) 91, - (byte) 173, (byte) 4, (byte) 245, (byte) 192, (byte) 95, - (byte) 135, (byte) 22, (byte) 138, (byte) 89, (byte) 1, (byte) 14, - (byte) 230, (byte) 143, (byte) 195, (byte) 93, (byte) 133, - (byte) 194, (byte) 252, (byte) 188, (byte) 31, (byte) 39, - (byte) 162, (byte) 59, (byte) 148, (byte) 219, (byte) 213, - (byte) 179, (byte) 195, (byte) 165, (byte) 67, (byte) 68, - (byte) 39, (byte) 178, (byte) 143, (byte) 192, (byte) 177, - (byte) 221, (byte) 236, (byte) 63, (byte) 40, (byte) 205, - (byte) 26, (byte) 81, (byte) 127, (byte) 5, (byte) 213, (byte) 192, - (byte) 22, (byte) 147, (byte) 98, (byte) 207, (byte) 153, (byte) 8, - (byte) 108, (byte) 75, (byte) 182, (byte) 148, (byte) 0, - (byte) 151, (byte) 15, (byte) 178, (byte) 98, (byte) 145, - (byte) 255, (byte) 213, (byte) 142, (byte) 63, (byte) 247, - (byte) 42, (byte) 161, (byte) 246, (byte) 21, (byte) 128, - (byte) 47, (byte) 248, (byte) 217, (byte) 70, (byte) 195, - (byte) 151, (byte) 236, (byte) 73, (byte) 153, (byte) 230, - (byte) 152, (byte) 217, (byte) 12, (byte) 189, (byte) 65, - (byte) 85, (byte) 189, (byte) 204, (byte) 212, (byte) 161, - (byte) 210, (byte) 217, (byte) 74, (byte) 75, (byte) 186, - (byte) 122, (byte) 167, (byte) 149, (byte) 178, (byte) 202, - (byte) 205, (byte) 246, (byte) 225, (byte) 225, (byte) 190, - (byte) 56, (byte) 42, (byte) 162, (byte) 215, (byte) 107, - (byte) 45, (byte) 121, (byte) 235, (byte) 195, (byte) 219, - (byte) 22, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 0, - (byte) 5, (byte) 88, (byte) 46, (byte) 53, (byte) 48, (byte) 57, - (byte) 0, (byte) 0, (byte) 2, (byte) 211, (byte) 48, (byte) 130, - (byte) 2, (byte) 207, (byte) 48, (byte) 130, (byte) 1, (byte) 183, - (byte) 160, (byte) 3, (byte) 2, (byte) 1, (byte) 2, (byte) 2, - (byte) 4, (byte) 58, (byte) 247, (byte) 71, (byte) 185, (byte) 48, - (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, - (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, - (byte) 5, (byte) 0, (byte) 48, (byte) 23, (byte) 49, (byte) 21, - (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, (byte) 4, - (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, (byte) 99, - (byte) 117, (byte) 114, (byte) 101, (byte) 115, (byte) 111, - (byte) 99, (byte) 107, (byte) 101, (byte) 116, (byte) 48, - (byte) 32, (byte) 23, (byte) 13, (byte) 49, (byte) 52, (byte) 48, - (byte) 53, (byte) 49, (byte) 48, (byte) 50, (byte) 48, (byte) 49, - (byte) 56, (byte) 52, (byte) 48, (byte) 90, (byte) 24, (byte) 15, - (byte) 50, (byte) 49, (byte) 49, (byte) 52, (byte) 48, (byte) 52, - (byte) 49, (byte) 54, (byte) 50, (byte) 48, (byte) 49, (byte) 56, - (byte) 52, (byte) 48, (byte) 90, (byte) 48, (byte) 23, (byte) 49, - (byte) 21, (byte) 48, (byte) 19, (byte) 6, (byte) 3, (byte) 85, - (byte) 4, (byte) 3, (byte) 19, (byte) 12, (byte) 115, (byte) 101, - (byte) 99, (byte) 117, (byte) 114, (byte) 101, (byte) 115, - (byte) 111, (byte) 99, (byte) 107, (byte) 101, (byte) 116, - (byte) 48, (byte) 130, (byte) 1, (byte) 34, (byte) 48, (byte) 13, - (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, (byte) 134, - (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 1, (byte) 5, - (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 15, (byte) 0, - (byte) 48, (byte) 130, (byte) 1, (byte) 10, (byte) 2, (byte) 130, - (byte) 1, (byte) 1, (byte) 0, (byte) 153, (byte) 113, (byte) 7, - (byte) 44, (byte) 219, (byte) 76, (byte) 101, (byte) 226, - (byte) 138, (byte) 96, (byte) 219, (byte) 60, (byte) 167, - (byte) 138, (byte) 222, (byte) 6, (byte) 78, (byte) 169, (byte) 64, - (byte) 188, (byte) 156, (byte) 190, (byte) 119, (byte) 16, - (byte) 34, (byte) 228, (byte) 250, (byte) 253, (byte) 119, - (byte) 75, (byte) 240, (byte) 60, (byte) 242, (byte) 52, - (byte) 137, (byte) 146, (byte) 20, (byte) 130, (byte) 202, - (byte) 226, (byte) 125, (byte) 19, (byte) 7, (byte) 34, (byte) 8, - (byte) 61, (byte) 243, (byte) 202, (byte) 225, (byte) 206, - (byte) 223, (byte) 53, (byte) 74, (byte) 56, (byte) 222, (byte) 47, - (byte) 99, (byte) 235, (byte) 57, (byte) 73, (byte) 90, (byte) 198, - (byte) 109, (byte) 104, (byte) 36, (byte) 255, (byte) 124, - (byte) 57, (byte) 155, (byte) 248, (byte) 120, (byte) 56, - (byte) 56, (byte) 38, (byte) 41, (byte) 216, (byte) 1, (byte) 216, - (byte) 216, (byte) 100, (byte) 239, (byte) 79, (byte) 222, - (byte) 34, (byte) 21, (byte) 182, (byte) 112, (byte) 136, - (byte) 137, (byte) 16, (byte) 141, (byte) 15, (byte) 83, (byte) 94, - (byte) 245, (byte) 36, (byte) 203, (byte) 178, (byte) 137, - (byte) 159, (byte) 86, (byte) 220, (byte) 253, (byte) 112, - (byte) 200, (byte) 50, (byte) 135, (byte) 215, (byte) 190, - (byte) 21, (byte) 186, (byte) 84, (byte) 21, (byte) 96, (byte) 126, - (byte) 253, (byte) 115, (byte) 209, (byte) 241, (byte) 94, - (byte) 115, (byte) 219, (byte) 0, (byte) 25, (byte) 253, - (byte) 209, (byte) 182, (byte) 118, (byte) 230, (byte) 10, - (byte) 50, (byte) 131, (byte) 39, (byte) 249, (byte) 136, - (byte) 11, (byte) 101, (byte) 192, (byte) 12, (byte) 210, - (byte) 179, (byte) 237, (byte) 213, (byte) 68, (byte) 101, - (byte) 58, (byte) 187, (byte) 255, (byte) 240, (byte) 164, - (byte) 147, (byte) 72, (byte) 148, (byte) 227, (byte) 155, - (byte) 88, (byte) 250, (byte) 101, (byte) 253, (byte) 87, - (byte) 140, (byte) 168, (byte) 39, (byte) 163, (byte) 133, - (byte) 150, (byte) 252, (byte) 226, (byte) 234, (byte) 52, - (byte) 88, (byte) 40, (byte) 56, (byte) 23, (byte) 105, (byte) 236, - (byte) 4, (byte) 113, (byte) 98, (byte) 4, (byte) 0, (byte) 117, - (byte) 59, (byte) 77, (byte) 236, (byte) 135, (byte) 93, (byte) 54, - (byte) 30, (byte) 6, (byte) 126, (byte) 90, (byte) 15, (byte) 105, - (byte) 89, (byte) 216, (byte) 154, (byte) 72, (byte) 134, - (byte) 209, (byte) 74, (byte) 197, (byte) 237, (byte) 51, - (byte) 37, (byte) 33, (byte) 106, (byte) 50, (byte) 71, (byte) 134, - (byte) 169, (byte) 173, (byte) 88, (byte) 111, (byte) 217, - (byte) 117, (byte) 184, (byte) 97, (byte) 1, (byte) 38, (byte) 76, - (byte) 112, (byte) 170, (byte) 190, (byte) 250, (byte) 96, - (byte) 17, (byte) 45, (byte) 117, (byte) 183, (byte) 82, - (byte) 155, (byte) 10, (byte) 53, (byte) 15, (byte) 214, (byte) 36, - (byte) 134, (byte) 249, (byte) 146, (byte) 98, (byte) 99, - (byte) 64, (byte) 158, (byte) 99, (byte) 227, (byte) 21, (byte) 92, - (byte) 98, (byte) 90, (byte) 202, (byte) 214, (byte) 134, - (byte) 233, (byte) 212, (byte) 149, (byte) 2, (byte) 3, (byte) 1, - (byte) 0, (byte) 1, (byte) 163, (byte) 33, (byte) 48, (byte) 31, - (byte) 48, (byte) 29, (byte) 6, (byte) 3, (byte) 85, (byte) 29, - (byte) 14, (byte) 4, (byte) 22, (byte) 4, (byte) 20, (byte) 115, - (byte) 110, (byte) 177, (byte) 165, (byte) 41, (byte) 26, - (byte) 142, (byte) 198, (byte) 221, (byte) 63, (byte) 79, - (byte) 252, (byte) 219, (byte) 159, (byte) 68, (byte) 102, - (byte) 76, (byte) 153, (byte) 128, (byte) 164, (byte) 48, - (byte) 13, (byte) 6, (byte) 9, (byte) 42, (byte) 134, (byte) 72, - (byte) 134, (byte) 247, (byte) 13, (byte) 1, (byte) 1, (byte) 11, - (byte) 5, (byte) 0, (byte) 3, (byte) 130, (byte) 1, (byte) 1, - (byte) 0, (byte) 118, (byte) 55, (byte) 245, (byte) 122, - (byte) 159, (byte) 155, (byte) 98, (byte) 122, (byte) 229, - (byte) 186, (byte) 23, (byte) 207, (byte) 109, (byte) 225, - (byte) 220, (byte) 74, (byte) 51, (byte) 218, (byte) 10, - (byte) 115, (byte) 137, (byte) 103, (byte) 127, (byte) 28, - (byte) 30, (byte) 184, (byte) 149, (byte) 249, (byte) 193, - (byte) 206, (byte) 208, (byte) 181, (byte) 191, (byte) 128, - (byte) 18, (byte) 208, (byte) 24, (byte) 132, (byte) 147, - (byte) 184, (byte) 198, (byte) 82, (byte) 204, (byte) 183, - (byte) 127, (byte) 87, (byte) 234, (byte) 136, (byte) 197, - (byte) 34, (byte) 232, (byte) 124, (byte) 210, (byte) 2, - (byte) 192, (byte) 69, (byte) 246, (byte) 25, (byte) 232, - (byte) 162, (byte) 0, (byte) 157, (byte) 216, (byte) 194, - (byte) 26, (byte) 207, (byte) 225, (byte) 169, (byte) 59, - (byte) 246, (byte) 52, (byte) 51, (byte) 150, (byte) 210, - (byte) 50, (byte) 118, (byte) 58, (byte) 154, (byte) 45, - (byte) 128, (byte) 138, (byte) 47, (byte) 174, (byte) 83, - (byte) 117, (byte) 18, (byte) 224, (byte) 9, (byte) 146, - (byte) 180, (byte) 178, (byte) 22, (byte) 76, (byte) 82, - (byte) 229, (byte) 16, (byte) 150, (byte) 127, (byte) 13, - (byte) 122, (byte) 218, (byte) 159, (byte) 195, (byte) 232, - (byte) 168, (byte) 206, (byte) 105, (byte) 82, (byte) 37, - (byte) 252, (byte) 186, (byte) 223, (byte) 222, (byte) 7, - (byte) 106, (byte) 87, (byte) 218, (byte) 89, (byte) 22, - (byte) 252, (byte) 7, (byte) 177, (byte) 52, (byte) 180, (byte) 9, - (byte) 16, (byte) 29, (byte) 57, (byte) 192, (byte) 209, - (byte) 225, (byte) 155, (byte) 16, (byte) 219, (byte) 38, - (byte) 90, (byte) 174, (byte) 152, (byte) 140, (byte) 252, - (byte) 114, (byte) 133, (byte) 106, (byte) 24, (byte) 107, - (byte) 227, (byte) 80, (byte) 166, (byte) 63, (byte) 47, (byte) 16, - (byte) 15, (byte) 89, (byte) 242, (byte) 19, (byte) 87, (byte) 193, - (byte) 250, (byte) 222, (byte) 223, (byte) 183, (byte) 61, - (byte) 91, (byte) 17, (byte) 92, (byte) 35, (byte) 142, (byte) 44, - (byte) 153, (byte) 135, (byte) 86, (byte) 97, (byte) 70, - (byte) 205, (byte) 38, (byte) 192, (byte) 18, (byte) 244, - (byte) 61, (byte) 46, (byte) 21, (byte) 145, (byte) 99, (byte) 72, - (byte) 142, (byte) 37, (byte) 19, (byte) 219, (byte) 167, - (byte) 62, (byte) 71, (byte) 197, (byte) 86, (byte) 152, - (byte) 139, (byte) 122, (byte) 231, (byte) 122, (byte) 206, - (byte) 42, (byte) 142, (byte) 164, (byte) 237, (byte) 19, - (byte) 60, (byte) 95, (byte) 239, (byte) 191, (byte) 64, - (byte) 188, (byte) 94, (byte) 154, (byte) 199, (byte) 252, - (byte) 62, (byte) 26, (byte) 181, (byte) 194, (byte) 141, - (byte) 13, (byte) 1, (byte) 112, (byte) 161, (byte) 195, - (byte) 149, (byte) 116, (byte) 57, (byte) 118, (byte) 114, - (byte) 248, (byte) 235, (byte) 54, (byte) 229, (byte) 48, - (byte) 53, (byte) 30, (byte) 145, (byte) 199, (byte) 207, - (byte) 49, (byte) 175, (byte) 44, (byte) 172, (byte) 120, - (byte) 254, (byte) 181, (byte) 100, (byte) 113, (byte) 191, - (byte) 64, (byte) 131, (byte) 125, (byte) 80, (byte) 180, - (byte) 229, (byte) 109, (byte) 97, (byte) 8, (byte) 166, - (byte) 155, (byte) 72, (byte) 252, (byte) 84, (byte) 62, (byte) 97, - (byte) 80, (byte) 26, (byte) 17, (byte) 143, (byte) 96, (byte) 16, - (byte) 204, (byte) 86, (byte) 61, (byte) 226, (byte) 149 }; - - - public static KeyStore getKeyStore() - { - KeyStore ks = null; - try{ - ks = KeyStore.getInstance("JKS"); - ks.load(asInputStream(), getKeyStorePassword()); - }catch(Exception ex){ - throw new RuntimeException("Failed to load SSL key store.", ex); - } - return ks; - } - - public static InputStream asInputStream() { - return new ByteArrayInputStream(CERT_BYTES); - } - - public static char[] getCertificatePassword() { - return "inc0rrect".toCharArray(); - } - - public static char[] getKeyStorePassword() { - return "mu$tch8ng3".toCharArray(); - } - - public static String getCertificatePasswordString() { - return "inc0rrect"; - } - - public static String getKeyStorePasswordString() { - return "mu$tch8ng3"; - } - - private SecureSocketKeyStore() { - - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java deleted file mode 100644 index 06d0edd..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSocketSslContextFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.myself.unclecatmyself.common.ssl; - -import io.netty.util.internal.SystemPropertyUtil; - -import javax.net.ssl.*; -import java.security.KeyStore; -import java.security.SecureRandom; - -/** - * Creates a bogus {@link SSLContext}. A client-side context created by this - * factory accepts any certificate even if it is invalid. A server-side context - * created by this factory sends a bogus certificate defined in {@link }. - *

- * You will have to create your context differently in a real world application. - * - *

Client Certificate Authentication

- * - * To enable client certificate authentication: - *
    - *
  • Enable client authentication on the server side by calling - * {@link SSLEngine#setNeedClientAuth(boolean)} before creating - * {@link }.
  • - *
  • When initializing an {@link SSLContext} on the client side, - * specify the {@link KeyManager} that contains the client certificate as - * the first argument of {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)}.
  • - *
  • When initializing an {@link SSLContext} on the server side, - * specify the proper {@link TrustManager} as the second argument of - * {@link SSLContext#init(KeyManager[], TrustManager[], SecureRandom)} - * to validate the client certificate.
  • - *
- */ -public final class SecureSocketSslContextFactory { - - private static final String PROTOCOL = "TLS"; - private static final SSLContext SERVER_CONTEXT; - private static final SSLContext CLIENT_CONTEXT; - - static { - String algorithm = SystemPropertyUtil.get("ssl.KeyManagerFactory.algorithm"); - if (algorithm == null) { - algorithm = "SunX509"; - } - - SSLContext serverContext; - SSLContext clientContext; - try { - // - //SecureSocketSslContextFactory.class.getResourceAsStream("/securesocket.jks") - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(SecureSocketKeyStore.asInputStream(), - SecureSocketKeyStore.getKeyStorePassword()); - - // Set up key manager factory to use our key store - KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm); - kmf.init(ks, SecureSocketKeyStore.getCertificatePassword()); - - // Initialize the SSLContext to work with our key managers. - serverContext = SSLContext.getInstance(PROTOCOL); - serverContext.init(kmf.getKeyManagers(), null, null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the server-side SSLContext", e); - } - - try { - clientContext = SSLContext.getInstance(PROTOCOL); - clientContext.init(null, SecureSokcetTrustManagerFactory.getTrustManagers(), null); - } catch (Exception e) { - throw new Error( - "Failed to initialize the client-side SSLContext", e); - } - - SERVER_CONTEXT = serverContext; - CLIENT_CONTEXT = clientContext; - } - - public static SSLContext getServerContext() { - return SERVER_CONTEXT; - } - - public static SSLContext getClientContext() { - return CLIENT_CONTEXT; - } - - private SecureSocketSslContextFactory() { - // Unused - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java b/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java deleted file mode 100644 index 5cd5e23..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/ssl/SecureSokcetTrustManagerFactory.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.myself.unclecatmyself.common.ssl; - -import javax.net.ssl.ManagerFactoryParameters; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactorySpi; -import javax.net.ssl.X509TrustManager; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.cert.X509Certificate; - -/** - * Bogus {@link TrustManagerFactorySpi} which accepts any certificate - * even if it is invalid. - */ -public class SecureSokcetTrustManagerFactory extends TrustManagerFactorySpi { - - private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { - @Override - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) { - // Always trust - it is an example. - // You should do something in the real world. - // You will reach here only if you enabled client certificate auth, - // as described in SecureChatSslContextFactory. - System.err.println( - "UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN()); - } - - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) { - // Always trust - it is an example. - // You should do something in the real world. - System.err.println( - "UNKNOWN SERVER CERTIFICATE: 222 " + chain[0].getSubjectDN()); - } - }; - - public static TrustManager[] getTrustManagers() { - return new TrustManager[] { DUMMY_TRUST_MANAGER }; - } - - @Override - protected TrustManager[] engineGetTrustManagers() { - return getTrustManagers(); - } - - @Override - protected void engineInit(KeyStore keystore) throws KeyStoreException { - // Unused - } - - @Override - protected void engineInit(ManagerFactoryParameters managerFactoryParameters) - throws InvalidAlgorithmParameterException { - // Unused - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java b/src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java deleted file mode 100644 index b503615..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/ssl/StreamReader.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.myself.unclecatmyself.common.ssl; - -import java.io.InputStream; - -public class StreamReader { - - public String toByteArray(InputStream fin) - { - int i = -1; - StringBuilder buf = new StringBuilder(); - try{ - while((i=fin.read())!=-1){ - if(buf.length()>0) buf.append(","); - buf.append("(byte)"); - buf.append(i); - } - - }catch(Throwable e){ - ; - } - - return buf.toString(); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java b/src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java deleted file mode 100644 index f5996ea..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/ssl/X509CertTool.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.myself.unclecatmyself.common.ssl; - - - - -import sun.security.x509.*; - -import java.io.IOException; -import java.math.BigInteger; -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.PrivateKey; -import java.security.SecureRandom; -import java.security.cert.X509Certificate; -import java.util.Date; - - -/** - * This class would require rt.jar in the class path in order to - * generated it alternative is using keytool. - */ -public class X509CertTool { - - /** - * Create a self-signed X.509 Certificate - * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB" - * @param pair the KeyPair - * @param days how many days from now the Certificate is valid for - * @param algorithm the signing algorithm, eg "SHA1withRSA" - */ - @SuppressWarnings("restriction") - X509Certificate generateCertificate(String dn, KeyPair pair, int days, - String algorithm) throws GeneralSecurityException, IOException { - PrivateKey privkey = pair.getPrivate(); - X509CertInfo info = new X509CertInfo(); - Date from = new Date(); - Date to = new Date(from.getTime() + days * 86400000l); - CertificateValidity interval = new CertificateValidity(from, to); - BigInteger sn = new BigInteger(64, new SecureRandom()); - X500Name owner = new X500Name(dn); - - info.set(X509CertInfo.VALIDITY, interval); - info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn)); - info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); - info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); - info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic())); - info.set(X509CertInfo.VERSION, new CertificateVersion( - CertificateVersion.V3)); - AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); - info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo)); - - // Sign the cert to identify the algorithm that's used. - X509CertImpl cert = new X509CertImpl(info); - cert.sign(privkey, algorithm); - - // Update the algorith, and resign. - algo = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG); - info.set(CertificateAlgorithmId.NAME + "." - + CertificateAlgorithmId.ALGORITHM, algo); - cert = new X509CertImpl(info); - cert.sign(privkey, algorithm); - return cert; - } - - public static void main(String[] args) { - - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java deleted file mode 100644 index b1f8fae..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/ByteBufUtil.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - - -import io.netty.buffer.ByteBuf; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 跨线程情况下 byteBuf 需要转换成byte[] - **/ -public class ByteBufUtil { - - public static byte[] copyByteBuf(ByteBuf byteBuf){ - byte[] bytes = new byte[byteBuf.readableBytes()]; - byteBuf.readBytes(bytes); - return bytes; - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java b/src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java deleted file mode 100644 index 7f2bf92..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/CRC16MySelf.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import java.math.BigInteger; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:31 2018\9\20 0020 - */ -public class CRC16MySelf { - - /** - * 生成指定格式的传输数据 - * @param ChannelId - * @param type - * @param data - * @return - */ - public static String getAllString(String ChannelId,String type,String data){ - String test = ChannelId + type + data; - String crcString = getCRC(test.getBytes()); - String result = Const.HEAD + test + crcString + Const.TAIL; - return result; - } - - /** - * 计算CRC16校验码 - * - * @param bytes 字节数组 - * @return {@link String} 校验码 - * @since 1.0 - */ - public static String getCRC(byte[] bytes) { - int CRC = 0x0000ffff; - int POLYNOMIAL = 0x0000a001; - int i, j; - for (i = 0; i < bytes.length; i++) { - CRC ^= ((int) bytes[i] & 0x000000ff); - for (j = 0; j < 8; j++) { - if ((CRC & 0x00000001) != 0) { - CRC >>= 1; - CRC ^= POLYNOMIAL; - } else { - CRC >>= 1; - } - } - } - return Integer.toHexString(CRC); - } - - /** - * 将16进制单精度浮点型转换为10进制浮点型 - * - * @return float - * @since 1.0 - */ - private float parseHex2Float(String hexStr) { - BigInteger bigInteger = new BigInteger(hexStr, 16); - return Float.intBitsToFloat(bigInteger.intValue()); - } - - /** - * 将十进制浮点型转换为十六进制浮点型 - * - * @return String - * @since 1.0 - */ - private String parseFloat2Hex(float data) { - return Integer.toHexString(Float.floatToIntBits(data)); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java b/src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java deleted file mode 100644 index d2d6a04..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/CallBackMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -import java.nio.charset.Charset; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:30 2018\9\20 0020 - */ -public class CallBackMessage { - - public static final ByteBuf SUCCESS = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("success", Charset.forName("UTF-8"))); - - public static final ByteBuf ERROR = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("error", Charset.forName("UTF-8"))); - - public static final ByteBuf Check1_test = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("Check1\r", Charset.forName("UTF-8"))); - - public static final ByteBuf Check2 = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer("Check2", Charset.forName("UTF-8"))); - - - public static ByteBuf sendString(String send){ - return Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(send, Charset.forName("UTF-8"))); - } - - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/Const.java b/src/main/java/com/myself/unclecatmyself/common/utils/Const.java deleted file mode 100644 index d6af216..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/Const.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import io.netty.channel.Channel; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:30 2018\9\20 0020 - */ -public class Const { - - //帧头 - public static final String HEAD = "gz"; - //帧尾 - public static final String TAIL = "xr"; - //控制锁状态 - public static final String CONTROL_TYPE = "s"; - //24锁 全部关闭状态 - public static final String LOCKS = "nnnnnnnnnnnnnnnnnnnnnnnn"; - //开锁标识 - public static final char OPEN = 'y'; - //客户端执行结果 - public static final String RESULT_TYPE = "j"; - //客户端执行测试结果 - public static final String RESULT_TEXT = "t"; - //服务器执行结果 - public static final String SUCCESS = "yyyyyyyyyyyyyyyyyyyyyyyy"; - public static final String ERROR = "nnnnnnnnnnnnnnnnnnnnnnnn"; - - private static Map map = new ConcurrentHashMap(); - - /** - * Netty连接池添加连接 - * @param clientId 连接ID - * @param channel 连接实例 - */ - public static void add(String clientId,Channel channel){ - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - System.out.println("add ChannelId: " + clientId + " " + formatter.format(new Date())); - map.put(clientId,channel); - } - - /** - * 判断是否存在该连接ID实例 - * @param channelID 连接Id - * @return - */ - public static boolean hasChannelID(String channelID){ - boolean state = map.containsKey(channelID); - return state; - } - - /** - * 根据连接ID 获取连接实例 - * @param clientId 链接Id - * @return - */ - public static Channel get(String clientId){ - return map.get(clientId); - } - - /** - * 根据链接实例移除链接实例 - * @param channel 链接实例 - */ - public static void remove(Channel channel){ - for (Map.Entry entry:map.entrySet()){ - if (entry.getValue()==channel){ - map.remove(entry.getKey()); - } - } - } - - /** - * 获取链接数组个数 - * @return - */ - public static int getSzie(){ - return map.size(); - } - - /** - * 获取链接数组Id - * @return - */ - public static Set getIdList(){ - return map.keySet(); - } - - /** - * 获取连接池数据信息 - */ - public static void mapInfo(){ - System.out.println("channel size : " + map.size()); - for (Map.Entry entry:map.entrySet()){ - System.out.println("clientId: " + entry.getKey()); - } - } - - /** - * 链接实例是否存在链接池中 - * @param channel 链接实例 - * @return 链接Id - */ - public static String isChannel(Channel channel){ - String clientId = null; - for (Map.Entry entry:map.entrySet()){ - if (entry.getValue() == channel){ - clientId = (String) entry.getKey(); - } - } - return clientId; - } - - /** - * 更新链接实例Id - * @param clientId 原始ID - * @param newID 新的连接ID - */ - public static void ChangeClientId(String clientId,String newID){ - for (Map.Entry entry:map.entrySet()){ - if (entry.getKey()==clientId){ - Channel channel = (Channel) entry.getValue(); - map.remove(entry.getKey()); - map.put(newID,channel); - } - } - } - - public static void changeChannel(String channelID, Channel channel) { - map.remove(channelID); - map.put(channelID,channel); - } - - public enum StateEnum{ - SUCCESS(1,"ok"), - FALID(2,"no"); - private int state; - - private String stateInfo; - - StateEnum(int state, String stateInfo) { - this.state = state; - this.stateInfo = stateInfo; - } - - public int getState() { - return state; - } - - public void setState(int state) { - this.state = state; - } - - public String getStateInfo() { - return stateInfo; - } - - public void setStateInfo(String stateInfo) { - this.stateInfo = stateInfo; - } - - public static StateEnum stateOf(int index){ - for (StateEnum item:values()){ - if (item.getState() == index){ - return item; - } - } - return null; - } - } - - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java deleted file mode 100644 index 033312c..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/CookieUtil.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * cookie工具类 - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 12:06 2018\6\13 0013 - */ -public class CookieUtil { - /** - * 设置cookie - * @param response - * @param name - * @param value - * @param maxAge - */ - public static void set(HttpServletResponse response, - String name, - String value, - int maxAge){ - Cookie cookie = new Cookie(name,value); - cookie.setPath("/"); - cookie.setMaxAge(maxAge); - response.addCookie(cookie); - } - - /** - * 获取cookie - * @param request - * @param name - * @return - */ - public static Cookie get(HttpServletRequest request, - String name){ - Map cookieMap = readCookieMap(request); - if (cookieMap.containsKey(name)){ - return cookieMap.get(name); - }else{ - return null; - } - } - - /** - * 将cookie封装成Map - * @param request - * @return - */ - private static Map readCookieMap(HttpServletRequest request){ - Map cookieMap = new HashMap<>(); - Cookie[] cookies = request.getCookies(); - if (cookies != null){ - for (Cookie cookie:cookies){ - cookieMap.put(cookie.getName(),cookie); - } - } - return cookieMap; - } -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java b/src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java deleted file mode 100644 index 2976d33..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/DataResction.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class DataResction { - - /** - * 切除符合协议的帧头帧尾 - * @param data 原始通信数据 - * @return - */ - public static String ResctionHeadAndFeet(String data){ - return data.substring(2,data.length()-2); - } - - /** - * 切除符合协议的帧头帧尾————本地测试方法 - * @param data - * @return - */ - public static String ResctionHeadAndFeet_test(String data){ - return data.substring(2,data.length()-4); - } - - /** - * 返回通信CRC校验码 - * @param data - * @return - */ - public static String ResctionCRCCode(String data){ - return data.substring(39,data.length()); - } - - /** - * 返回通信内容,除去CRC校验码 - * @param data - * @return - */ - public static String ResctionData(String data){ - return data.substring(0,39); - } - - public static String ResctionDataNoID(String data){ - return data.substring(14); - } - - /** - * 返回设备唯一ID - * @param data - * @return - */ - public static String ResctionID(String data){ - return data.substring(0,14); - } - - /** - * 返回数据类型 - * @param data - * @return - */ - public static String ResctionType(String data){ - return data.substring(0,1); - } - - /** - * 返回实际内容值 - * @param data - * @return - */ - public static String ResctionRealData(String data){ - return data.substring(1); - } - - /** - * 截取电量信息,并返回 - * @param data - * @return - */ - public static String ResctionPower(String data){ - return data.substring(0,4); - } - - /** - * 截取纬度信息,并返回 - * @param data - * @return - */ - public static String ResctionLatitude(String data){ - return data.substring(3,11); - } - - /** - * 截取经度信息,并返回 - * @param data - * @return - */ - public static String ResctionLongitude(String data){ - return data.substring(14,data.length()); - } - - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java b/src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java deleted file mode 100644 index b66ed2c..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/DataValida.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class DataValida { - - /** - * 校验数据帧头帧尾是否符合协议规范 - * @param data 通信原始数据 - * @return - */ - public static boolean ValidateHeadAndFeet(String data){ - boolean state = false; - if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-2,data.length()))){ - return true; - } - return state; - } - - /** - * 校验数据帧头是否符合协议数据规范————本地测试 - * @param data - * @return - */ - public static boolean ValidateHeadAndFeet_test(String data){ - boolean state = false; - if (Const.HEAD.equals(data.substring(0,2)) && Const.TAIL.equals(data.substring(data.length()-4,data.length()-2))){ - return true; - } - return state; - } - - /** - * CRC16校验 - * @param data 内容数据 - * @param crcCode 附带CRC校验码 - * @return - */ - public static boolean ValidateCRCCode(String data,String crcCode){ - boolean state = false; - if (crcCode.equals(CRC16MySelf.getCRC(data.getBytes()))){ - return true; - } - return state; - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java b/src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java deleted file mode 100644 index 64fb401..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/IdWorker.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import java.lang.management.ManagementFactory; -import java.net.InetAddress; -import java.net.NetworkInterface; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 全局id生成器 - **/ -public class IdWorker { - - // 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) - private final static long twepoch = 1288834974657L; - // 机器标识位数 - private final static long workerIdBits = 5L; - // 数据中心标识位数 - private final static long datacenterIdBits = 5L; - // 机器ID最大值 - private final static long maxWorkerId = -1L ^ (-1L << workerIdBits); - // 数据中心ID最大值 - private final static long maxDatacenterId = -1L ^ (-1L << datacenterIdBits); - // 毫秒内自增位 - private final static long sequenceBits = 12L; - // 机器ID偏左移12位 - private final static long workerIdShift = sequenceBits; - // 数据中心ID左移17位 - private final static long datacenterIdShift = sequenceBits + workerIdBits; - // 时间毫秒左移22位 - private final static long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits; - - private final static long sequenceMask = -1L ^ (-1L << sequenceBits); - /* 上次生产id时间戳 */ - private static long lastTimestamp = -1L; - // 0,并发控制 - private long sequence = 0L; - - private final long workerId; - // 数据标识id部分 - private final long datacenterId; - - public IdWorker(){ - this.datacenterId = getDatacenterId(maxDatacenterId); - this.workerId = getMaxWorkerId(datacenterId, maxWorkerId); - } - /** - * @param workerId - * 工作机器ID - * @param datacenterId - * 序列号 - */ - public IdWorker(long workerId, long datacenterId) { - if (workerId > maxWorkerId || workerId < 0) { - throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId)); - } - if (datacenterId > maxDatacenterId || datacenterId < 0) { - throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId)); - } - this.workerId = workerId; - this.datacenterId = datacenterId; - } - /** - * 获取下一个ID - * - * @return - */ - public synchronized long nextId() { - long timestamp = timeGen(); - if (timestamp < lastTimestamp) { - throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); - } - - if (lastTimestamp == timestamp) { - // 当前毫秒内,则+1 - sequence = (sequence + 1) & sequenceMask; - if (sequence == 0) { - // 当前毫秒内计数满了,则等待下一秒 - timestamp = tilNextMillis(lastTimestamp); - } - } else { - sequence = 0L; - } - lastTimestamp = timestamp; - // ID偏移组合生成最终的ID,并返回ID - long nextId = ((timestamp - twepoch) << timestampLeftShift) - | (datacenterId << datacenterIdShift) - | (workerId << workerIdShift) | sequence; - - return nextId; - } - - private long tilNextMillis(final long lastTimestamp) { - long timestamp = this.timeGen(); - while (timestamp <= lastTimestamp) { - timestamp = this.timeGen(); - } - return timestamp; - } - - private long timeGen() { - return System.currentTimeMillis(); - } - - /** - *

- * 获取 maxWorkerId - *

- */ - protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) { - StringBuffer mpid = new StringBuffer(); - mpid.append(datacenterId); - String name = ManagementFactory.getRuntimeMXBean().getName(); - if (!name.isEmpty()) { - /* - * GET jvmPid - */ - mpid.append(name.split("@")[0]); - } - /* - * MAC + PID 的 hashcode 获取16个低位 - */ - return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1); - } - - /** - *

- * 数据标识id部分 - *

- */ - protected static long getDatacenterId(long maxDatacenterId) { - long id = 0L; - try { - InetAddress ip = InetAddress.getLocalHost(); - NetworkInterface network = NetworkInterface.getByInetAddress(ip); - if (network == null) { - id = 1L; - } else { - byte[] mac = network.getHardwareAddress(); - id = ((0x000000FF & (long) mac[mac.length - 1]) - | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; - id = id % (maxDatacenterId + 1); - } - } catch (Exception e) { - System.out.println(" getDatacenterId: " + e.getMessage()); - } - return id; - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java b/src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java deleted file mode 100644 index 0405d0c..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/MessageId.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import java.util.concurrent.atomic.AtomicInteger; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 生成messageId - **/ -public class MessageId { - - private static AtomicInteger index = new AtomicInteger(1); - /** - * 获取messageId - * @return id - */ - public static int messageId(){ - for (;;) { - int current = index.get(); - int next = (current >= Integer.MAX_VALUE ? 0: current + 1); - if (index.compareAndSet(current, next)) { - return current; - } - } - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java deleted file mode 100644 index f182055..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/RandomNameUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import java.util.Random; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 11:48 2018\8\14 0014 - */ -public class RandomNameUtil { - - private static Random ran = new Random(); - private final static int delta = 0x9fa5 - 0x4e00 + 1; - - public static char getName(){ - return (char)(0x4e00 + ran.nextInt(delta)); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java deleted file mode 100644 index 7b2c0f0..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/utils/SendUtil.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.myself.unclecatmyself.common.utils; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; - -import java.nio.charset.Charset; - -/** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 19:32 2018\9\20 0020 - */ -public class SendUtil { - - public boolean send(Integer item, Channel channel, String channelID, String type){ - try { - if (item != null && channel != null){ - String items = IntegerToString(item); - String result = CRC16MySelf.getAllString(channelID,type,items); - System.out.println("send:" + result); - ByteBuf msg = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(result, Charset.forName("UTF-8"))); - channel.writeAndFlush(msg.duplicate()); - return true; - } - }catch (Exception e){ - System.out.println(e.getMessage()); - return false; - } - return false; - } - - /** - * 广播发送事件 - * @param items - * @param channel - * @param channelID - * @param type - * @return - */ - public void sendAll(String items, Channel channel, String channelID, String type){ - try { - if (items != null && channel != null){ - String result = CRC16MySelf.getAllString(channelID,type,items); - ByteBuf msg = Unpooled.unreleasableBuffer( - Unpooled.copiedBuffer(result, Charset.forName("UTF-8"))); - channel.writeAndFlush(msg.duplicate()); - } - }catch (Exception e){ - e.printStackTrace(); - System.out.println(e.getMessage()); - } - } - - public String IntegerToString(Integer item){ - char[] locks_char = Const.LOCKS.toCharArray(); - for (int i=0;i maps) { //TODO 写入数据库 return true; } + } From da831bbdb52ad692cf3591900b15b651a4e7679a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 14:42:01 +0800 Subject: [PATCH 061/151] update-pom --- pom.xml | 33 ------------------- .../NettychatApplicationTests.java | 16 --------- 2 files changed, 49 deletions(-) delete mode 100644 src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java diff --git a/pom.xml b/pom.xml index 4ad1e32..12deab0 100644 --- a/pom.xml +++ b/pom.xml @@ -49,10 +49,6 @@ aspectjweaver 1.9.2 - - org.springframework.boot - spring-boot-starter-tomcat - org.springframework.boot spring-boot-starter-websocket @@ -66,11 +62,6 @@ netty-all 4.1.28.Final - - com.google.guava - guava - 26.0-jre - org.apache.commons commons-lang3 @@ -81,30 +72,6 @@ spring-boot-configuration-processor true - - org.apache.curator - curator-recipes - 2.9.1 - - - org.apache.curator - curator-client - 2.9.1 - - - org.apache.curator - curator-framework - 2.9.1 - - - - - - - org.springframework.boot - spring-boot-starter-test - test - diff --git a/src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java b/src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java deleted file mode 100644 index 7ec68ed..0000000 --- a/src/test/java/com/myself/unclecatmyself/NettychatApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.myself.unclecatmyself; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class NettychatApplicationTests { - - @Test - public void contextLoads() { - } - -} From 2a234fa50b2c1aa039ec4e5fcddf915bba0356fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 14:44:10 +0800 Subject: [PATCH 062/151] log --- doc/Project-Log-cn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 2322d4f..96c0a35 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -9,3 +9,5 @@ * 【2018-11-30】 启动赞助功能,新增【服务端向API发送消息】接口功能,暂未测试 * 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 * 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 +* 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 +* 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包 From b1eb26bc9e8397b0afd7230dcdbc15a99b12812e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 15:16:01 +0800 Subject: [PATCH 063/151] =?UTF-8?q?update-=E4=B8=9A=E5=8A=A1=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/WebSocketHandlerService.java | 70 ++++++++----------- .../common/utils/ConstansUtil.java | 20 ++++++ .../ServerWebSocketHandlerService.java | 9 --- .../common/websockets/WebSocketHandler.java | 6 +- .../websockets/WebSocketHandlerApi.java | 2 - 5 files changed, 54 insertions(+), 53 deletions(-) create mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 9a0908e..70fc57e 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -4,16 +4,17 @@ import com.google.gson.Gson; import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.myself.unclecatmyself.bootstrap.WsChannelService; +import com.myself.unclecatmyself.common.utils.ConstansUtil; import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; import com.myself.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.timeout.IdleStateEvent; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; - +import java.util.ArrayList; +import java.util.List; import java.util.Map; /** @@ -44,7 +45,7 @@ public WebSocketHandlerService(Gson gson){ @Override public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 - String token = (String) maps.get("token"); + String token = (String) maps.get(ConstansUtil.TOKEN); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); websocketChannelService.loginWsSuccess(channel,token); @@ -58,7 +59,7 @@ public boolean login(Channel channel, Map maps) { @Override public void sendMeText(Channel channel, Map maps) { channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendMe((String) maps.get("value"))))); + gson.toJson(inChatBackMapService.sendMe((String) maps.get(ConstansUtil.VALUE))))); try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { @@ -68,61 +69,52 @@ public void sendMeText(Channel channel, Map maps) { @Override public void sendToText(Channel channel, Map maps) { - String otherOne = (String) maps.get("one"); - String value = (String) maps.get("value"); - String me = (String) maps.get("me"); + String otherOne = (String) maps.get(ConstansUtil.ONE); + String value = (String) maps.get(ConstansUtil.VALUE); + String me = (String) maps.get(ConstansUtil.ME); + //返回给自己 + channel.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); if (websocketChannelService.hasOther(otherOne)){ - //返回给自己 - channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); - //发送给对方 + //发送给对方--在线 Channel other = websocketChannelService.getChannel(otherOne); other.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.getMsg(me,value)))); + }else { + maps.put(ConstansUtil.ON_ONLINE,otherOne); } try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); } } - - @Override - public void pong(Channel channel) { - log.info("【pong】"+channel.remoteAddress()); - - } - - @Override - public void disconnect(Channel channel) { - log.info("【disconnect】"+channel.remoteAddress()); - - } - - @Override - public void doTimeOut(Channel channel, IdleStateEvent evt) { - log.info("【PingPongService:doTimeOut 心跳超时】" + channel.remoteAddress() + "【channel 关闭】"); - - } - @Override public void sendGroupText(Channel channel, Map maps) { - String groupId = (String) maps.get("groupId"); - String me = (String) maps.get("me"); - String value = (String) maps.get("value"); + String groupId = (String) maps.get(ConstansUtil.GROUPID); + String me = (String) maps.get(ConstansUtil.ME); + String value = (String) maps.get(ConstansUtil.VALUE); + List no_online = new ArrayList<>(); JSONArray array = inChatVerifyService.getArrayByGroupId(groupId); + channel.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); for (Object item:array) { - if (websocketChannelService.hasOther((String) item)){ - Channel other = websocketChannelService.getChannel((String) item); - other.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); + if (!me.equals(item)){ + if (websocketChannelService.hasOther((String) item)){ + Channel other = websocketChannelService.getChannel((String) item); + other.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); + }else{ + no_online.add((String) item); + } } } + maps.put(ConstansUtil.ON_ONLINE,no_online); try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { - e.printStackTrace(); + log.error(e.getMessage()); } } diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java new file mode 100644 index 0000000..6a663dd --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java @@ -0,0 +1,20 @@ +package com.myself.unclecatmyself.common.utils; + +/** + * Created by MySelf on 2018/12/5. + */ +public class ConstansUtil { + + public static final String TOKEN = "token"; + + public static final String VALUE = "value"; + + public static final String ONE = "one"; + + public static final String ME = "me"; + + public static final String ON_ONLINE = "on_online"; + + public static final String GROUPID = "groupId"; + +} diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index 87c99e0..8293274 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -32,15 +32,6 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA */ public abstract void sendToText(Channel channel, Map maps); - public abstract void pong(Channel channel); - - /** - * 主动关闭 - * @param channel {@link Channel} 链接实例 - */ - public abstract void disconnect(Channel channel); - - public abstract void doTimeOut(Channel channel, IdleStateEvent evt); /** * 发送给群聊 diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java index de64e80..7b30b76 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java @@ -43,9 +43,9 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - if(evt instanceof IdleStateEvent){ - webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); - } +// if(evt instanceof IdleStateEvent){ +// webSocketHandlerApi.doTimeOut(ctx.channel(),(IdleStateEvent)evt); +// } super.userEventTriggered(ctx, evt); } } diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java index 5937678..a216c50 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -18,6 +18,4 @@ public interface WebSocketHandlerApi { void sendMeText(Channel channel, Map maps); void sendToText(Channel channel, Map maps); - - void doTimeOut(Channel channel, IdleStateEvent evt); } From 38f4fbd7936816f9f97bc20aa6db2e515dc76943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 15:25:09 +0800 Subject: [PATCH 064/151] log --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 96c0a35..2478ace 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -10,4 +10,4 @@ * 【2018-12-02】 转变部分项目思路,减少用户对框架的依赖与开发成本。 * 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 * 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 -* 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包 +* 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 From f5c0581ef069f4fcca12d61aae7951289e2738c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 17:07:27 +0800 Subject: [PATCH 065/151] update --- .../backmsg/InChatBackMapServiceImpl.java | 34 +++++++++---------- .../handler/DefaultWebSocketHandler.java | 11 +++--- .../bootstrap/verify/InChatVerifyService.java | 1 + .../common/utils/ConstansUtil.java | 17 ++++++++++ 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 2aa1575..7b40c80 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -1,6 +1,6 @@ package com.myself.unclecatmyself.bootstrap.backmsg; -import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; +import com.myself.unclecatmyself.common.utils.ConstansUtil; import org.springframework.stereotype.Service; import java.util.HashMap; @@ -16,52 +16,52 @@ public class InChatBackMapServiceImpl implements InChatBackMapService { @Override public Map loginSuccess() { Map backMap = new HashMap<>(); - backMap.put("type","login"); - backMap.put("success","true"); + backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); + backMap.put(ConstansUtil.SUCCESS,ConstansUtil.TRUE); return backMap; } @Override public Map loginError() { Map backMap = new HashMap<>(); - backMap.put("type","login"); - backMap.put("success","false"); + backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); + backMap.put(ConstansUtil.SUCCESS,ConstansUtil.FALSE); return backMap; } @Override public Map sendMe(String value) { Map backMap = new HashMap<>(); - backMap.put("type","sendMe"); - backMap.put("value",value); + backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDME); + backMap.put(ConstansUtil.VALUE,value); return backMap; } @Override public Map sendBack(String otherOne, String value) { Map backMap = new HashMap<>(); - backMap.put("type","sendTo"); - backMap.put("value",value); - backMap.put("one",otherOne); + backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); + backMap.put(ConstansUtil.VALUE,value); + backMap.put(ConstansUtil.ONE,otherOne); return backMap; } @Override public Map getMsg(String me, String value) { Map backMap = new HashMap<>(); - backMap.put("type","get"); - backMap.put("from",me); - backMap.put("value",value); + backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); + backMap.put(ConstansUtil.FROM,me); + backMap.put(ConstansUtil.VALUE,value); return backMap; } @Override public Map sendGroup(String me, String value, String groupId) { Map backMap = new HashMap<>(); - backMap.put("type","sendGroup"); - backMap.put("from",me); - backMap.put("value",value); - backMap.put("groupId",groupId); + backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDGROUP); + backMap.put(ConstansUtil.FROM,me); + backMap.put(ConstansUtil.VALUE,value); + backMap.put(ConstansUtil.GROUPID,groupId); return backMap; } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index b40475c..47f6388 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.myself.unclecatmyself.common.exception.NoFindHandlerException; +import com.myself.unclecatmyself.common.utils.ConstansUtil; import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.myself.unclecatmyself.common.websockets.WebSocketHandler; import com.myself.unclecatmyself.common.websockets.WebSocketHandlerApi; @@ -48,23 +49,23 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) throw new NoFindHandlerException("Server Handler 不匹配"); } Map maps = (Map) JSON.parse(msg.text()); - switch ((String)maps.get("type")){ - case "login": + switch ((String)maps.get(ConstansUtil.TYPE)){ + case ConstansUtil.LOGIN: log.info("【用户链接登录操作】"); serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 - case "sendMe": + case ConstansUtil.SENDME: log.info("【用户链接发送给自己】"); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 - case "sendTo": + case ConstansUtil.SENDTO: log.info("【用户链接发送给某人】"); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 - case "sendGroup": + case ConstansUtil.SENDGROUP: log.info("【用户链接发送给群聊】"); serverWebSocketHandlerService.sendGroupText(channel,maps); break; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java index d7da9a8..18fc87f 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java @@ -11,4 +11,5 @@ public interface InChatVerifyService { boolean verifyToken(String token); JSONArray getArrayByGroupId(String groupId); + } \ No newline at end of file diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java index 6a663dd..3fa10bc 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java @@ -17,4 +17,21 @@ public class ConstansUtil { public static final String GROUPID = "groupId"; + public static final String TYPE = "type"; + + public static final String LOGIN = "login"; + + public static final String SUCCESS = "success"; + + public static final String TRUE = "true"; + + public static final String FALSE = "false"; + + public static final String SENDME = "sendMe"; + + public static final String SENDTO = "sendTo"; + + public static final String FROM = "from"; + + public static final String SENDGROUP = "sendGroup"; } From 0ea6bee5e46ff40c836fd7d1a71ad3a9b12b3a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AE=8F=E9=9F=AC?= <3183764662@qq.com> Date: Wed, 5 Dec 2018 17:33:07 +0800 Subject: [PATCH 066/151] update --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 12deab0..fc363fc 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ io.netty netty-all - 4.1.28.Final + 4.1.32.Final org.apache.commons From 785eb571c6a136c20b6f65af091ba4d753bbd393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= Date: Thu, 6 Dec 2018 14:41:37 +0800 Subject: [PATCH 067/151] update --- README.md | 1 - .../bootstrap/channel/WebSocketChannelService.java | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index abb484b..0bb24be 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) -#### [开发者在线交流室](https://gitter.im/In-Chat/Lobby) #### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 1dcc8e7..62024f9 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -18,7 +18,6 @@ @Component public class WebSocketChannelService implements WsChannelService { - @Autowired WsCacheMap wsCacheMap; private final Gson gson; From 68678dd53ba9ceb831cb057b00f256216a6a21f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 6 Dec 2018 17:50:19 +0800 Subject: [PATCH 068/151] update --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0bb24be..d429323 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/login.png) + + #### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** From 07fbe342a03594d7697b9993b57e454e2616df10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 6 Dec 2018 17:55:41 +0800 Subject: [PATCH 069/151] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d429323..5c51286 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/login.png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) #### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 From efc9a85144db0b95d5c788c3fdabeee73459b1cc Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 22:58:20 +0800 Subject: [PATCH 070/151] logo-center --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5c51286..15093c3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ -# InChat + + +
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png)
[![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) - - #### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 **master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** From bc72c7a83304a0c50129efe486196e1f8e908759 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 22:59:37 +0800 Subject: [PATCH 071/151] center --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15093c3..4b8197f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png)
+
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) From ad8d70dd50f1fe2392af5bb9ec3e53a2509c0a2b Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 23:00:36 +0800 Subject: [PATCH 072/151] center --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b8197f..711873e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ +
-
![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) +![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) + +
[![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) From fa7e0e79427f6c339defb9e9b14c8c61a5d7dcb4 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 23:01:33 +0800 Subject: [PATCH 073/151] update --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 711873e..8a56492 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,11 @@ ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/logo.png) -
- [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) +
#### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 From 4c80b557f3d28e732e1e83275797537daee16711 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 23:04:38 +0800 Subject: [PATCH 074/151] update --- README.md | 8 ++++---- doc/Project-Log-cn.md | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a56492..1d10548 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,16 @@ -#### 欢迎参与QQ群交流与提供建议、业务场景、需求功能等 - -**master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** - ## 简介 ***(InChat)Iot Netty Chat*** 一个轻量级、高效的通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 +**欢迎参与QQ群交流与提供建议、业务场景、需求功能等** + +**master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** + ## 项目日志 * [项目研发日志更新](doc/Project-Log-cn.md) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 2478ace..9f82994 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -11,3 +11,4 @@ * 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 * 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 +* 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立 From 4215b611d5183de970409f45da989a218025add3 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 23:20:20 +0800 Subject: [PATCH 075/151] md --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 1d10548..1ad08c0 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,6 @@ https://github.com/UncleCatMySelf/SBToNettyChat/issues -QQ群:628793702 - ## 赞助 打赏时请记得备注上你的github账号或者其他链接,谢谢支持! @@ -89,7 +87,3 @@ QQ群:628793702 ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E4%BB%98%E6%AC%BE.png) ![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E6%94%AF%E4%BB%98%E5%AE%9D.png) -## 关于作者 - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/%E5%85%AC%E4%BC%97%E5%8F%B7.png) - From a12b4707576011c901ccc5ee4e1e5c5d1c661cce Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 6 Dec 2018 23:50:10 +0800 Subject: [PATCH 076/151] update --- doc/Project-Log-cn.md | 2 +- pom.xml | 6 - .../bootstrap/NettyBootstrapServer.java | 13 +- .../channel/WebSocketChannelService.java | 5 - .../channel/WebSocketHandlerService.java | 7 +- .../bootstrap/channel/cache/CacheMap.java | 2 - .../bootstrap/channel/cache/WsCacheMap.java | 5 - .../handler/DefaultWebSocketHandler.java | 10 +- .../common/properties/InitNetty.java | 130 +++++++++++++++++- .../common/websockets/WebSocketHandler.java | 5 +- .../task/DataAsynchronousTask.java | 4 +- .../user/InChatVerifyServiceImpl.java | 4 +- src/main/resources/securesocket.jks | Bin 2080 -> 0 bytes 13 files changed, 141 insertions(+), 52 deletions(-) delete mode 100644 src/main/resources/securesocket.jks diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 9f82994..e2ec9fe 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -11,4 +11,4 @@ * 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 * 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 -* 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立 +* 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式 diff --git a/pom.xml b/pom.xml index fc363fc..beb9931 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,11 @@ - com.alibaba fastjson 1.2.53 - com.google.code.gson gson @@ -53,10 +51,6 @@ org.springframework.boot spring-boot-starter-websocket - - org.projectlombok - lombok - io.netty netty-all diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java index 0227263..b84af1e 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -3,8 +3,6 @@ import com.myself.unclecatmyself.common.ip.IpUtils; import com.myself.unclecatmyself.common.properties.InitNetty; import com.myself.unclecatmyself.common.utils.RemotingUtil; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.ChannelFutureListener; @@ -26,8 +24,6 @@ * @create 2018/9/22 * @desc mtqq netty启动服务类 **/ -@Slf4j -@Data public class NettyBootstrapServer extends AbstractBootstrapServer { private InitNetty serverBean; @@ -67,9 +63,11 @@ protected void initChannel(SocketChannel ch) throws Exception { .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) - log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); +// log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + System.out.println("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); else - log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); +// log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + System.out.println("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); }); } /** @@ -121,7 +119,8 @@ public void shutdown() { bossGroup.shutdownGracefully().sync();// 优雅关闭 workGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { - log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); +// log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + System.out.println("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); } } } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 62024f9..774af32 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -5,8 +5,6 @@ import com.myself.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; @@ -14,7 +12,6 @@ /** * Created by MySelf on 2018/11/26. */ -@Slf4j @Component public class WebSocketChannelService implements WsChannelService { @@ -44,7 +41,6 @@ public Channel getChannel(String otherOne) { @Override public void close(Channel channel) { - log.info("【退出统一移除】"); String token = wsCacheMap.getByAddress(channel.remoteAddress().toString()); wsCacheMap.deleteAd(channel.remoteAddress().toString()); wsCacheMap.deleteWs(token); @@ -57,7 +53,6 @@ public boolean sendFromServer(Channel channel, Map map) { channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(map))); return true; }catch (Exception e){ - log.error("【发送异常】:" + e.getMessage()); return false; } } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 70fc57e..6ec5112 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -10,7 +10,6 @@ import com.myself.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -20,7 +19,6 @@ /** * Created by MySelf on 2018/11/21. */ -@Slf4j @Component public class WebSocketHandlerService extends ServerWebSocketHandlerService{ @@ -86,7 +84,7 @@ public void sendToText(Channel channel, Map maps) { try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { - log.error(e.getMessage()); + return; } } @@ -114,13 +112,12 @@ public void sendGroupText(Channel channel, Map maps) { try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { - log.error(e.getMessage()); + return; } } @Override public void close(Channel channel) { - log.info("【close】"+channel.remoteAddress()); websocketChannelService.close(channel); } } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java index 5486b84..2162cd4 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java @@ -1,6 +1,5 @@ package com.myself.unclecatmyself.bootstrap.channel.cache; -import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -10,7 +9,6 @@ * @create 2018/9/22 * @desc 缓存操作 **/ -@Slf4j public class CacheMap { private ConcurrentHashMap> datas = new ConcurrentHashMap<>(); diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index ba77197..1154b66 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,7 +1,6 @@ package com.myself.unclecatmyself.bootstrap.channel.cache; import io.netty.channel.Channel; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.Map; @@ -11,7 +10,6 @@ * WebSocket链接实例本地存储 * Created by MySelf on 2018/11/26. */ -@Slf4j @Component public class WsCacheMap { @@ -31,7 +29,6 @@ public class WsCacheMap { * @param channel {@link Channel} 链接实例 */ public void saveWs(String token,Channel channel){ - log.info("【新增用户链接实例】"+token); maps.put(token,channel); } @@ -50,7 +47,6 @@ public void saveAd(String address,String token){ * @return {@link Channel} 链接实例 */ public Channel getByToken(String token){ - log.info("【获取用户链接实例】"+token); return maps.get(token); } @@ -68,7 +64,6 @@ public String getByAddress(String address){ * @param token {@link String} 用户标识 */ public void deleteWs(String token){ - log.info("【删除用户链接实例】"+token); maps.remove(token); } diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 47f6388..fcba097 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -11,7 +11,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.Map; @@ -22,7 +21,6 @@ * @QQ:1341933031 * @Date:Created in 20:15 2018\11\16 0016 */ -@Slf4j @Component @ChannelHandler.Sharable public class DefaultWebSocketHandler extends WebSocketHandler { @@ -51,22 +49,18 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) Map maps = (Map) JSON.parse(msg.text()); switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: - log.info("【用户链接登录操作】"); serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: - log.info("【用户链接发送给自己】"); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: - log.info("【用户链接发送给某人】"); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: - log.info("【用户链接发送给群聊】"); serverWebSocketHandlerService.sendGroupText(channel,maps); break; default: @@ -76,12 +70,12 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); +// log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ - log.error("exception",cause); +// log.error("exception",cause); webSocketHandlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java index 62c1b91..61643fa 100644 --- a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java @@ -1,8 +1,6 @@ package com.myself.unclecatmyself.common.properties; import com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; -import com.myself.unclecatmyself.common.websockets.WebSocketHandler; -import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -11,7 +9,6 @@ * @QQ:1341933031 * @Date:Created in 10:54 2018\8\14 0014 */ -@Data @ConfigurationProperties(prefix = "inchat") public class InitNetty { @@ -47,4 +44,131 @@ public class InitNetty { private Class webSocketHandler = DefaultWebSocketHandler.class; + public int getWebport() { + return webport; + } + + public void setWebport(int webport) { + this.webport = webport; + } + + public int getBossThread() { + return bossThread; + } + + public void setBossThread(int bossThread) { + this.bossThread = bossThread; + } + + public int getWorkerThread() { + return workerThread; + } + + public void setWorkerThread(int workerThread) { + this.workerThread = workerThread; + } + + public boolean isKeepalive() { + return keepalive; + } + + public void setKeepalive(boolean keepalive) { + this.keepalive = keepalive; + } + + public int getBacklog() { + return backlog; + } + + public void setBacklog(int backlog) { + this.backlog = backlog; + } + + public boolean isNodelay() { + return nodelay; + } + + public void setNodelay(boolean nodelay) { + this.nodelay = nodelay; + } + + public boolean isReuseaddr() { + return reuseaddr; + } + + public void setReuseaddr(boolean reuseaddr) { + this.reuseaddr = reuseaddr; + } + + public int getSndbuf() { + return sndbuf; + } + + public void setSndbuf(int sndbuf) { + this.sndbuf = sndbuf; + } + + public int getRevbuf() { + return revbuf; + } + + public void setRevbuf(int revbuf) { + this.revbuf = revbuf; + } + + public int getHeart() { + return heart; + } + + public void setHeart(int heart) { + this.heart = heart; + } + + public int getPeriod() { + return period; + } + + public void setPeriod(int period) { + this.period = period; + } + + public String getServerName() { + return serverName; + } + + public void setServerName(String serverName) { + this.serverName = serverName; + } + + public int getInitalDelay() { + return initalDelay; + } + + public void setInitalDelay(int initalDelay) { + this.initalDelay = initalDelay; + } + + public int getMaxContext() { + return maxContext; + } + + public void setMaxContext(int maxContext) { + this.maxContext = maxContext; + } + + public String getWebSocketPath() { + return webSocketPath; + } + + public void setWebSocketPath(String webSocketPath) { + this.webSocketPath = webSocketPath; + } + + public Class getWebSocketHandler() { + return webSocketHandler; + } + + public void setWebSocketHandler(Class webSocketHandler) { + this.webSocketHandler = webSocketHandler; + } } diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java index 7b30b76..de58943 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java @@ -4,8 +4,6 @@ import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.handler.timeout.IdleStateEvent; -import lombok.extern.slf4j.Slf4j; /** * @Author:UncleCatMySelf @@ -13,7 +11,6 @@ * @QQ:1341933031 * @Date:Created in 20:19 2018\11\16 0016 */ -@Slf4j public abstract class WebSocketHandler extends SimpleChannelInboundHandler { WebSocketHandlerApi webSocketHandlerApi; @@ -37,7 +34,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); +// log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); webSocketHandlerApi.close(ctx.channel()); } diff --git a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java index d8bc407..d85c892 100644 --- a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java @@ -1,7 +1,6 @@ package com.myself.unclecatmyself.task; import com.myself.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; @@ -13,7 +12,6 @@ /** * Created by MySelf on 2018/12/3. */ -@Slf4j @Component public class DataAsynchronousTask { @@ -22,7 +20,7 @@ public class DataAsynchronousTask { @Async public Future writeData(Map maps) throws Exception { - log.info("异步写入数据:"+maps.toString()); +// log.info("异步写入数据:"+maps.toString()); return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); } diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java index 7e580f0..9dd9997 100644 --- a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java @@ -2,21 +2,19 @@ import com.alibaba.fastjson.JSONArray; import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; -import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; /** * 不属于项目代码 * Created by MySelf on 2018/11/22. */ -@Slf4j @Service public class InChatVerifyServiceImpl implements InChatVerifyService { @Override public boolean verifyToken(String token) { //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 - log.info("verify---"+token); +// log.info("verify---"+token); return true; } diff --git a/src/main/resources/securesocket.jks b/src/main/resources/securesocket.jks deleted file mode 100644 index 2a9d8c069117e759069c36ef42e6027d5cd17f4c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2080 zcmZ{kX*AReAIJZH#=eY*(6vpnOqLmq?#R+y*_R4Mqii$Wp2j6cmWGVRE=z^7K97jW)b6Blb-?Qn^%oIrZy9Ww*lRD(ja1tO zp(psT-#cE&e{nGMiOkuIHdf6PfKB$Lw2_1VRYY%P!>_t-p$Ka$m)YD)q5=~ugPAA3Qxavwa&{JYb^ur>H0a<(k3RnR zO9wk)b5k;f>d`SiW+>Nbl;85UY5`!dKpyza;>))4;mfqiTCL`sX5My_H3cz-vlZkWFSQ(KI?pSbcf_r(p2+S#9_<9^ zn!>MD+i&LECx0Y7S$~fa{f&$JVTyRs4sAqi+QuN5(zC$kmhz0fVNlpXj@9Q0BSZ<{5Rw1^9x1UOZEm~>DQ+vC1Fuo+@ z?fCuj#Sqzwc{UP_Cin{bxZGUt6cWe&_2^SU{fbqD^qSNoz_elel>QqfgdJeUnkLZ_ zgqcfJk>{aqCSPNW-ComKo1zzVTPN59beKxnxwVMO6l=cKyS2+~9RJAbZR_JBkz3fu zCy-44RpQ;4c3=76$Y;fU2fbkU(@IoO)5oHcqNA~j(=B_Lg7YiyA~h7v0BM>-_QSZy zka}u%rTQopSC-LK?#(AT|BU|Cq$_xym9xBFS+NpvAuuDm&vm|h`d+m0K7Iq1+yx2en+PA= zOZv82x-a4 z?_*1PA&k1Up6CN}?x=ZR<2jOjP}Srad`T8}t4wGayh&dh)6u_EoMrvz#EqG2beG==VaiuK$N40(zEla#JW@mS*3r_I3iDY(cPBYnRidRIFD(_3`urA;2^U8Y?=zRQKU6+b z^RZ8+)aZ~q36(T+8UydI)Y?*NbA4fC&DtE(B|9xKTJYd#I6VjIkFn%ipCDKC7%SF7 z>Rs-<5-dB&=y9u=imS@^vD(n^!ZB~nJIftYQh(c#=c<-2LhsO* zBM1r?6F~tR^SQY|E-uK~9rG6m5ncg!j77|j2nY%t3iB9J5+T9MeFefT@jq5YC>|3* zq7b@Bgbo6UMj@P~p*qMzfI^=6FZlnb6cF~$nnMS3Q$XmUoIyb@3J3z3{(Kr!HeRy{ z?o$RO3Ddk6$}lZCZNXx&`Mv#M>u(0%QSpzCQu=4_O7Ow>4LAB(Lo>Qo=xJ^IvYw@L zx6i+n55n}ae}tgXD(d6l__*iV#c7yigI`>{SQ6C1bxV1G7N6(%Vc)M;Cw8n&viY*4 zd-#69+jZA~DL`ibZ9~w4piZRfZk&)8U3j>5b=1V`?8}31)KrVKx$LWZUi(gorK(S( zA9H5EpsuQ+kKJ5>_~RfzpuX)&tjigB-f(B=P3(A zQZOL?2KhJnru5xcLvQNaBgEfGN2NA(+cO%;PG91>V2feHTy)cInZ-gNcl@<1lU1g_ zjXM2!SSRRgmS#kPcC|yG_$Pr!bu=j(d$!nPvIuE1uVb-v=%)QiPV>w(AHiu7E5+ff zLDdO}$?4JGva-ddRGh0b5;??Zg0%PCrQ&niVo>aN38z*!%N zs6rRtG}MxOh_^^SDKS-IWZvbNai8>=Gz3qku1XlVt+iuXT(f#OMzZy Date: Thu, 6 Dec 2018 23:55:21 +0800 Subject: [PATCH 077/151] update --- Front-End-Testing/chat.html | 2 +- .../bootstrap/channel/WebSocketChannelService.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 4cb8e6a..c70561f 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 774af32..bb6d708 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -5,6 +5,7 @@ import com.myself.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Map; @@ -15,6 +16,7 @@ @Component public class WebSocketChannelService implements WsChannelService { + @Autowired WsCacheMap wsCacheMap; private final Gson gson; From 924a2592aac1dc5fc73ef661de8a2b90a4c11272 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 7 Dec 2018 00:01:39 +0800 Subject: [PATCH 078/151] =?UTF-8?q?update-=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/myself/unclecatmyself/auto/InitServer.java | 4 +--- .../unclecatmyself/auto/ServerAutoConfigure.java | 4 +--- .../bootstrap/AbstractBootstrapServer.java | 4 +--- .../unclecatmyself/bootstrap/BootstrapServer.java | 4 +--- .../bootstrap/NettyBootstrapServer.java | 4 +--- .../bootstrap/channel/cache/CacheMap.java | 4 +--- .../bootstrap/handler/DefaultWebSocketHandler.java | 5 +---- .../common/exception/ConnectionException.java | 14 -------------- .../common/exception/NoFindHandlerException.java | 4 +--- .../myself/unclecatmyself/common/ip/IpUtils.java | 4 +--- .../common/pool/DefaultThreadFactory.java | 4 +--- .../unclecatmyself/common/pool/ExecutorQueue.java | 5 ++--- .../unclecatmyself/common/pool/Scheduled.java | 4 +--- .../common/pool/StandardThreadExecutor.java | 4 +--- .../common/properties/InitNetty.java | 5 +---- .../common/utils/SpringBeanUtils.java | 4 +--- .../common/websockets/WebSocketHandler.java | 5 +---- .../common/websockets/WebSocketHandlerApi.java | 5 +---- .../myself/unclecatmyself/task/ScheduledPool.java | 4 +--- 19 files changed, 19 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java diff --git a/src/main/java/com/myself/unclecatmyself/auto/InitServer.java b/src/main/java/com/myself/unclecatmyself/auto/InitServer.java index 145d346..02a2ddb 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/InitServer.java +++ b/src/main/java/com/myself/unclecatmyself/auto/InitServer.java @@ -6,9 +6,7 @@ import com.myself.unclecatmyself.common.properties.InitNetty; /** - * @author MySelf - * @create 2018/9/22 - * @desc 初始化服务 + * Create by UncleCatMySelf in 2018/12/06 **/ public class InitServer { diff --git a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java index e1ab79b..e16cf29 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java @@ -10,9 +10,7 @@ /** - * @author MySelf - * @create 2018/9/22 - * @desc 自动化配置初始化服务 + * Create by UncleCatMySelf in 2018/12/06 **/ @Configuration @ConditionalOnClass diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 840e00e..006015c 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -11,9 +11,7 @@ import io.netty.handler.timeout.IdleStateHandler; /** - * @author MySelf - * @create 2018/9/22 - * @desc 抽象类,负责加载edec handler + * Create by UncleCatMySelf in 2018/12/06 **/ public abstract class AbstractBootstrapServer implements BootstrapServer { diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java index 6d75f71..31c9c26 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java @@ -3,9 +3,7 @@ import com.myself.unclecatmyself.common.properties.InitNetty; /** - * @author MySelf - * @create 2018/9/22 - * @desc 启动类接口 + * Create by UncleCatMySelf in 2018/12/06 **/ public interface BootstrapServer { diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java index b84af1e..5b9297b 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -20,9 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * @author MySelf - * @create 2018/9/22 - * @desc mtqq netty启动服务类 + * Create by UncleCatMySelf in 2018/12/06 **/ public class NettyBootstrapServer extends AbstractBootstrapServer { diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java index 2162cd4..c18fb84 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java @@ -5,9 +5,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; /** - * @author MySelf - * @create 2018/9/22 - * @desc 缓存操作 + * Create by UncleCatMySelf in 2018/12/06 **/ public class CacheMap { diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index fcba097..12284f9 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -16,10 +16,7 @@ import java.util.Map; /** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:15 2018\11\16 0016 + * Create by UncleCatMySelf in 2018/12/06 */ @Component @ChannelHandler.Sharable diff --git a/src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java b/src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java deleted file mode 100644 index cfedebd..0000000 --- a/src/main/java/com/myself/unclecatmyself/common/exception/ConnectionException.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.myself.unclecatmyself.common.exception; - -/** - * @author MySelf - * @create 2018/9/22 - * @desc 连接异常 - **/ -public class ConnectionException extends RuntimeException { - - public ConnectionException(String message) { - super(message); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java b/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java index e05464a..6a76b14 100644 --- a/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java +++ b/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java @@ -1,9 +1,7 @@ package com.myself.unclecatmyself.common.exception; /** - * @author MySelf - * @create 2018/9/22 - * @desc 找不到Handler异常 + * Create by UncleCatMySelf in 2018/12/06 **/ public class NoFindHandlerException extends RuntimeException { diff --git a/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java b/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java index 8068203..6d452fe 100644 --- a/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java +++ b/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java @@ -6,9 +6,7 @@ import java.util.Enumeration; /** - * @author MySelf - * @create 2018/9/22 - * @desc ip操作 + * Create by UncleCatMySelf in 2018/12/06 **/ public class IpUtils { diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java b/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java index 1396e08..7d08f86 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java @@ -4,9 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * @author MySelf - * @create 2018/9/22 - * @desc 线程池 + * Create by UncleCatMySelf in 2018/12/06 **/ public class DefaultThreadFactory implements ThreadFactory { diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java b/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java index 4dd8ba3..4f4f57c 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java @@ -4,10 +4,9 @@ import java.util.concurrent.RejectedExecutionException; /** - * @author MySelf - * @create 2018/9/22 - * @desc LinkedTransferQueue 能保证更高性能,相比与LinkedBlockingQueue有明显提升 + * LinkedTransferQueue 能保证更高性能,相比与LinkedBlockingQueue有明显提升 * 不过LinkedTransferQueue的缺点是没有队列长度控制,需要在外层协助控制 + * Create by UncleCatMySelf in 2018/12/06 **/ public class ExecutorQueue extends LinkedTransferQueue { diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java b/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java index 7b9e1f6..da92c38 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java @@ -3,9 +3,7 @@ import java.util.concurrent.ScheduledFuture; /** - * @author MySelf - * @create 2018/9/22 - * @desc 接口 + * Create by UncleCatMySelf in 2018/12/06 **/ @FunctionalInterface public interface Scheduled { diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java b/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java index 75d1129..0374004 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java +++ b/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java @@ -4,9 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger; /** - * @author MySelf - * @create 2018/9/22 - * @desc 代码和思路主要来自于: + * Create by UncleCatMySelf in 2018/12/06 * tomcat: org.apache.catalina.core.StandardThreadExecutor * * java.util.concurrent.threadPoolExecutor execute执行策略: diff --git a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java index 61643fa..109c01b 100644 --- a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java @@ -4,10 +4,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; /** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 10:54 2018\8\14 0014 + * Create by UncleCatMySelf in 2018/12/06 */ @ConfigurationProperties(prefix = "inchat") public class InitNetty { diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java b/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java index e29a237..93a49be 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java @@ -6,9 +6,7 @@ import org.springframework.stereotype.Component; /** - * @author MySelf - * @create 2018/9/22 - * @desc 获取spring当前Bean + * Create by UncleCatMySelf in 2018/12/06 **/ @Component public class SpringBeanUtils implements ApplicationContextAware { diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java index de58943..76bab25 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java @@ -6,10 +6,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; /** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:19 2018\11\16 0016 + * Create by UncleCatMySelf in 2018/12/06 */ public abstract class WebSocketHandler extends SimpleChannelInboundHandler { diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java index a216c50..efd92a6 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -6,10 +6,7 @@ import java.util.Map; /** - * @Author:UncleCatMySelf - * @Email:zhupeijie_java@126.com - * @QQ:1341933031 - * @Date:Created in 20:22 2018\11\16 0016 + * Create by UncleCatMySelf in 2018/12/06 */ public interface WebSocketHandlerApi { diff --git a/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java b/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java index a7ce31c..26e8a94 100644 --- a/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java +++ b/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java @@ -8,9 +8,7 @@ /** - * @author MySelf - * @create 2018/9/22 - * @desc 定时任务 + * Create by UncleCatMySelf in 2018/12/06 **/ @Service public class ScheduledPool implements Scheduled { From 0316fc319e53b4013ca574f9cb764a64cafcf5a0 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 7 Dec 2018 00:02:26 +0800 Subject: [PATCH 079/151] log --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index e2ec9fe..8d70af2 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -11,4 +11,4 @@ * 【2018-12-03】 构建【组建群聊】模块功能,整改数据接收Map转为Map,放弃【组建群聊】,仅作基本im业务,完成功能【发送群聊】 * 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 -* 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式 +* 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式,统一注释说明 From 202ef8d44230834f200239fbcab62c23fb592474 Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Fri, 7 Dec 2018 12:23:01 +0800 Subject: [PATCH 080/151] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d58727d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 MySelf + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From c64ccc06b5fdef1ffe69d77ca739ce01a754759f Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Fri, 7 Dec 2018 12:33:33 +0800 Subject: [PATCH 081/151] Update issue templates --- .github/ISSUE_TEMPLATE/----.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/----.md diff --git a/.github/ISSUE_TEMPLATE/----.md b/.github/ISSUE_TEMPLATE/----.md new file mode 100644 index 0000000..9224525 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/----.md @@ -0,0 +1,22 @@ +--- +name: 提交报告 +about: 发现BUG +title: 发现BUG +labels: '' +assignees: '' + +--- + +**发现了一个什么的BUG与问题** + +**复现BUG的步骤与流程** + +* 1、启动。。 +* 2、运行。。 +* 3、结果。。 + +**预期的结果与实际的结果** + +**你的猜想与建议** + +**期望InChat的最终核心功能** From c298dc2eb0f1189f1e05de6c7295ff1debd8d23b Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Fri, 7 Dec 2018 12:38:34 +0800 Subject: [PATCH 082/151] Update issue templates --- .github/ISSUE_TEMPLATE/----.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/----.md b/.github/ISSUE_TEMPLATE/----.md index 9224525..e11187b 100644 --- a/.github/ISSUE_TEMPLATE/----.md +++ b/.github/ISSUE_TEMPLATE/----.md @@ -1,22 +1,22 @@ --- -name: 提交报告 -about: 发现BUG -title: 发现BUG +name: 功能请求 +about: 功能请求 +title: 功能请求 labels: '' -assignees: '' +assignees: UncleCatMySelf --- -**发现了一个什么的BUG与问题** +**建议这个项目的想法** -**复现BUG的步骤与流程** +**您的功能请求是否与问题有关?请描述一下。** +简明扼要地描述了问题所在。防爆。[...]我总是感到沮丧 -* 1、启动。。 -* 2、运行。。 -* 3、结果。。 +**描述您想要的解决方案** +清晰简洁地描述您想要发生的事情。 -**预期的结果与实际的结果** +**描述您考虑过** +的替代方案对您考虑过的任何替代解决方案或功能的简明扼要描述。 -**你的猜想与建议** - -**期望InChat的最终核心功能** +**其他上下文** +在此处添加有关功能请求的任何其他上下文或屏幕截图。 From 27a07de99af6baa79cfe6e758b4f5ccad2770847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 7 Dec 2018 22:09:56 +0800 Subject: [PATCH 083/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 13 +++--- pom.xml | 10 ++++- .../backmsg/InChatBackMapServiceImpl.java | 8 ++-- .../channel/WebSocketHandlerService.java | 44 ++++++++++++------- .../handler/DefaultWebSocketHandler.java | 8 +++- .../common/utils/ConstansUtil.java | 2 - .../unclecatmyself/common/utils/TimeUtil.java | 19 ++++++++ .../ServerWebSocketHandlerService.java | 7 ++- .../task/DataAsynchronousTask.java | 2 +- .../user/InChatToDataBaseServiceImpl.java | 1 + 10 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index c70561f..2e88de2 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data @@ -78,7 +78,7 @@ if (socket.readyState == WebSocket.OPEN) { var message = { type: "login", - token: value + token: "1111" } socket.send(JSON.stringify(message)); } else { @@ -93,7 +93,8 @@ if (socket.readyState == WebSocket.OPEN) { var message = { type: "sendMe", - value: value + value: value, + token: "1111" } socket.send(JSON.stringify(message)); } else { @@ -107,8 +108,8 @@ } if (socket.readyState == WebSocket.OPEN) { var message = { - type: "sendTo", - me: "3333", + type : "sendTo", + token : "1111", value: value, one: "2222", } @@ -126,7 +127,7 @@ var message = { type: "sendGroup", groupId: "2", - me: "3333", + token: "1111", value: value } socket.send(JSON.stringify(message)); diff --git a/pom.xml b/pom.xml index beb9931..c7f8f1e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,19 @@ com.myself.UncleCatMySelf inchat - 0.0.1-SNAPSHOT + 0.1-alpha jar inchat 一个轻量级、高效率的支持聊天与物联网的通讯框架 + https://github.com/UncleCatMySelf + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + org.springframework.boot diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 7b40c80..428013c 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -47,19 +47,19 @@ public Map sendBack(String otherOne, String value) { } @Override - public Map getMsg(String me, String value) { + public Map getMsg(String token, String value) { Map backMap = new HashMap<>(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); - backMap.put(ConstansUtil.FROM,me); + backMap.put(ConstansUtil.FROM,token); backMap.put(ConstansUtil.VALUE,value); return backMap; } @Override - public Map sendGroup(String me, String value, String groupId) { + public Map sendGroup(String token, String value, String groupId) { Map backMap = new HashMap<>(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDGROUP); - backMap.put(ConstansUtil.FROM,me); + backMap.put(ConstansUtil.FROM,token); backMap.put(ConstansUtil.VALUE,value); backMap.put(ConstansUtil.GROUPID,groupId); return backMap; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 6ec5112..582c9d9 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -43,15 +43,7 @@ public WebSocketHandlerService(Gson gson){ @Override public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 - String token = (String) maps.get(ConstansUtil.TOKEN); - if (inChatVerifyService.verifyToken(token)){ - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); - websocketChannelService.loginWsSuccess(channel,token); - return true; - } - channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); - close(channel); - return false; + return check(channel, maps); } @Override @@ -69,7 +61,7 @@ public void sendMeText(Channel channel, Map maps) { public void sendToText(Channel channel, Map maps) { String otherOne = (String) maps.get(ConstansUtil.ONE); String value = (String) maps.get(ConstansUtil.VALUE); - String me = (String) maps.get(ConstansUtil.ME); + String token = (String) maps.get(ConstansUtil.TOKEN); //返回给自己 channel.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); @@ -77,7 +69,7 @@ public void sendToText(Channel channel, Map maps) { //发送给对方--在线 Channel other = websocketChannelService.getChannel(otherOne); other.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.getMsg(me,value)))); + gson.toJson(inChatBackMapService.getMsg(token,value)))); }else { maps.put(ConstansUtil.ON_ONLINE,otherOne); } @@ -91,18 +83,18 @@ public void sendToText(Channel channel, Map maps) { @Override public void sendGroupText(Channel channel, Map maps) { String groupId = (String) maps.get(ConstansUtil.GROUPID); - String me = (String) maps.get(ConstansUtil.ME); + String token = (String) maps.get(ConstansUtil.TOKEN); String value = (String) maps.get(ConstansUtil.VALUE); List no_online = new ArrayList<>(); JSONArray array = inChatVerifyService.getArrayByGroupId(groupId); channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); + gson.toJson(inChatBackMapService.sendGroup(token,value,groupId)))); for (Object item:array) { - if (!me.equals(item)){ + if (!token.equals(item)){ if (websocketChannelService.hasOther((String) item)){ Channel other = websocketChannelService.getChannel((String) item); other.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendGroup(me,value,groupId)))); + gson.toJson(inChatBackMapService.sendGroup(token,value,groupId)))); }else{ no_online.add((String) item); } @@ -116,6 +108,28 @@ public void sendGroupText(Channel channel, Map maps) { } } + @Override + public void verify(Channel channel, Map maps) { + String token = (String) maps.get(ConstansUtil.TOKEN); + System.out.println(token); + if (inChatVerifyService.verifyToken(token)){ + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); + close(channel); + } + } + + private Boolean check(Channel channel, Map maps){ + String token = (String) maps.get(ConstansUtil.TOKEN); + if (inChatVerifyService.verifyToken(token)){ + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); + websocketChannelService.loginWsSuccess(channel,token); + return true; + } + channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); + close(channel); + return false; + } + @Override public void close(Channel channel) { websocketChannelService.close(channel); diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 12284f9..0a8dce5 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.myself.unclecatmyself.common.exception.NoFindHandlerException; import com.myself.unclecatmyself.common.utils.ConstansUtil; +import com.myself.unclecatmyself.common.utils.TimeUtil; import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.myself.unclecatmyself.common.websockets.WebSocketHandler; import com.myself.unclecatmyself.common.websockets.WebSocketHandlerApi; @@ -14,6 +15,7 @@ import org.springframework.stereotype.Component; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * Create by UncleCatMySelf in 2018/12/06 @@ -31,7 +33,7 @@ public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { @Override protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { - + //暂未实现 } @Override @@ -44,20 +46,24 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) throw new NoFindHandlerException("Server Handler 不匹配"); } Map maps = (Map) JSON.parse(msg.text()); + maps.put("time", TimeUtil.getTime()); switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: + serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: + serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: + serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendGroupText(channel,maps); break; default: diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java index 3fa10bc..b340be4 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java @@ -11,8 +11,6 @@ public class ConstansUtil { public static final String ONE = "one"; - public static final String ME = "me"; - public static final String ON_ONLINE = "on_online"; public static final String GROUPID = "groupId"; diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java b/src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java new file mode 100644 index 0000000..dab1e50 --- /dev/null +++ b/src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java @@ -0,0 +1,19 @@ +package com.myself.unclecatmyself.common.utils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created by MySelf on 2018/12/7. + */ +public class TimeUtil { + + private final static String format = "yyyy-MM-dd HH:mm:ss"; + + public static String getTime(){ + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat(format); + return dateFormat.format(date); + } + +} diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index 8293274..eae16ef 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -32,7 +32,6 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA */ public abstract void sendToText(Channel channel, Map maps); - /** * 发送给群聊 * @param channel {@link Channel} 链接实例 @@ -40,4 +39,10 @@ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerA */ public abstract void sendGroupText(Channel channel, Map maps); + /** + * 登录校验 + * @param channel {@link Channel} 链接实例 + * @param maps {@link Map} 数据信息 + */ + public abstract void verify(Channel channel, Map maps); } diff --git a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java index d85c892..2a0779f 100644 --- a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java @@ -20,7 +20,7 @@ public class DataAsynchronousTask { @Async public Future writeData(Map maps) throws Exception { -// log.info("异步写入数据:"+maps.toString()); + //异步写入数据 return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); } diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java index c9fe6fc..e9ff96e 100644 --- a/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java +++ b/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java @@ -15,6 +15,7 @@ public class InChatToDataBaseServiceImpl implements InChatToDataBaseService { @Override public Boolean writeMapToDB(Map maps) { //TODO 写入数据库 + System.out.println("异步写入数据:"+maps.toString()); return true; } From cd97251e47db2fdc3a94ddbfc0f4d6739dad3077 Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Fri, 7 Dec 2018 22:11:20 +0800 Subject: [PATCH 084/151] Delete LICENSE --- LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 LICENSE diff --git a/LICENSE b/LICENSE deleted file mode 100644 index d58727d..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 MySelf - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From f7692c2bc40b88701833865a1c7ada0abca0e83a Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Fri, 7 Dec 2018 22:14:47 +0800 Subject: [PATCH 085/151] Create LICENSE --- LICENSE | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. From 9f7971b41294c8526f2887c04be47deb02d3af24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 7 Dec 2018 22:17:47 +0800 Subject: [PATCH 086/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9pom=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 95 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index c7f8f1e..59ceee4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 com.myself.UncleCatMySelf - inchat + InChat 0.1-alpha jar - inchat + InChat 一个轻量级、高效率的支持聊天与物联网的通讯框架 https://github.com/UncleCatMySelf @@ -19,6 +19,19 @@ + + + MySelf + zhupeijie_java@126.com + + + + + scm:git:git@github.com:UncleCatMySelf/InChat.git + scm:git:git@github.com:UncleCatMySelf/InChat.git + git@github.com:UncleCatMySelf/InChat.git + + org.springframework.boot spring-boot-starter-parent @@ -76,15 +89,73 @@ - - nettychat - - - org.springframework.boot - spring-boot-maven-plugin - - - - + + + release + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + package + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + private + true + UTF-8 + UTF-8 + UTF-8 + + + + package + + jar + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + verify + + sign + + + + + + + + + oss + https://oss.sonatype.org/content/repositories/snapshots/ + + + oss + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + From 04373ddf460af58ddc7b8dc54cf9140e0edfe34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 7 Dec 2018 23:13:44 +0800 Subject: [PATCH 087/151] update --- pom.xml | 6 ++--- .../unclecatmyself/auto/InitServer.java | 8 +++--- .../auto/ServerAutoConfigure.java | 4 +-- .../bootstrap/AbstractBootstrapServer.java | 6 ++--- .../bootstrap/BootstrapServer.java | 4 +-- .../bootstrap/NettyBootstrapServer.java | 8 +++--- .../bootstrap/WsChannelService.java | 2 +- .../backmsg/InChatBackMapService.java | 2 +- .../backmsg/InChatBackMapServiceImpl.java | 4 +-- .../channel/WebSocketChannelService.java | 6 ++--- .../channel/WebSocketHandlerService.java | 16 ++++++------ .../bootstrap/channel/cache/CacheMap.java | 2 +- .../bootstrap/channel/cache/WsCacheMap.java | 2 +- .../data/InChatToDataBaseService.java | 2 +- .../handler/DefaultWebSocketHandler.java | 15 +++++------ .../bootstrap/verify/InChatVerifyService.java | 2 +- .../exception/NoFindHandlerException.java | 2 +- .../unclecatmyself/common/ip/IpUtils.java | 2 +- .../common/pool/DefaultThreadFactory.java | 2 +- .../common/pool/ExecutorQueue.java | 2 +- .../unclecatmyself/common/pool/Scheduled.java | 2 +- .../common/pool/StandardThreadExecutor.java | 2 +- .../common/properties/InitNetty.java | 4 +-- .../common/utils/ConstansUtil.java | 2 +- .../common/utils/RemotingUtil.java | 2 +- .../common/utils/SpringBeanUtils.java | 2 +- .../unclecatmyself/common/utils/TimeUtil.java | 2 +- .../ServerWebSocketHandlerService.java | 3 +-- .../common/websockets/WebSocketHandler.java | 2 +- .../websockets/WebSocketHandlerApi.java | 2 +- .../task/DataAsynchronousTask.java | 4 +-- .../unclecatmyself/task/ScheduledPool.java | 6 ++--- .../unclecatmyself/NettychatApplication.java | 17 ------------ .../user/InChatToDataBaseServiceImpl.java | 22 ---------------- .../user/InChatVerifyServiceImpl.java | 26 ------------------- src/main/resources/application.yml | 0 36 files changed, 63 insertions(+), 132 deletions(-) rename src/main/java/com/{myself => github}/unclecatmyself/auto/InitServer.java (72%) rename src/main/java/com/{myself => github}/unclecatmyself/auto/ServerAutoConfigure.java (95%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/AbstractBootstrapServer.java (88%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/BootstrapServer.java (62%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/NettyBootstrapServer.java (95%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/WsChannelService.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java (94%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/channel/WebSocketChannelService.java (89%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java (91%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/channel/cache/CacheMap.java (98%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java (97%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/data/InChatToDataBaseService.java (76%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java (86%) rename src/main/java/com/{myself => github}/unclecatmyself/bootstrap/verify/InChatVerifyService.java (81%) rename src/main/java/com/{myself => github}/unclecatmyself/common/exception/NoFindHandlerException.java (79%) rename src/main/java/com/{myself => github}/unclecatmyself/common/ip/IpUtils.java (97%) rename src/main/java/com/{myself => github}/unclecatmyself/common/pool/DefaultThreadFactory.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/common/pool/ExecutorQueue.java (97%) rename src/main/java/com/{myself => github}/unclecatmyself/common/pool/Scheduled.java (81%) rename src/main/java/com/{myself => github}/unclecatmyself/common/pool/StandardThreadExecutor.java (98%) rename src/main/java/com/{myself => github}/unclecatmyself/common/properties/InitNetty.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/common/utils/ConstansUtil.java (94%) rename src/main/java/com/{myself => github}/unclecatmyself/common/utils/RemotingUtil.java (99%) rename src/main/java/com/{myself => github}/unclecatmyself/common/utils/SpringBeanUtils.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/common/utils/TimeUtil.java (88%) rename src/main/java/com/{myself => github}/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java (92%) rename src/main/java/com/{myself => github}/unclecatmyself/common/websockets/WebSocketHandler.java (96%) rename src/main/java/com/{myself => github}/unclecatmyself/common/websockets/WebSocketHandlerApi.java (87%) rename src/main/java/com/{myself => github}/unclecatmyself/task/DataAsynchronousTask.java (86%) rename src/main/java/com/{myself => github}/unclecatmyself/task/ScheduledPool.java (82%) delete mode 100644 src/main/java/com/myself/unclecatmyself/NettychatApplication.java delete mode 100644 src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java delete mode 100644 src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java delete mode 100644 src/main/resources/application.yml diff --git a/pom.xml b/pom.xml index 59ceee4..0bfdc70 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.myself.UncleCatMySelf + com.github.UncleCatMySelf InChat 0.1-alpha jar InChat - 一个轻量级、高效率的支持聊天与物联网的通讯框架 + A lightweight, efficient communication framework that supports chat and the Internet of Things https://github.com/UncleCatMySelf @@ -56,13 +56,11 @@ gson 2.8.5 - org.aspectj aspectjrt 1.9.2 - org.aspectj aspectjweaver diff --git a/src/main/java/com/myself/unclecatmyself/auto/InitServer.java b/src/main/java/com/github/unclecatmyself/auto/InitServer.java similarity index 72% rename from src/main/java/com/myself/unclecatmyself/auto/InitServer.java rename to src/main/java/com/github/unclecatmyself/auto/InitServer.java index 02a2ddb..ff36e39 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/InitServer.java +++ b/src/main/java/com/github/unclecatmyself/auto/InitServer.java @@ -1,9 +1,9 @@ -package com.myself.unclecatmyself.auto; +package com.github.unclecatmyself.auto; -import com.myself.unclecatmyself.bootstrap.BootstrapServer; -import com.myself.unclecatmyself.bootstrap.NettyBootstrapServer; -import com.myself.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.bootstrap.BootstrapServer; +import com.github.unclecatmyself.bootstrap.NettyBootstrapServer; +import com.github.unclecatmyself.common.properties.InitNetty; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java similarity index 95% rename from src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java rename to src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java index e16cf29..edb661c 100644 --- a/src/main/java/com/myself/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java @@ -1,6 +1,6 @@ -package com.myself.unclecatmyself.auto; +package com.github.unclecatmyself.auto; -import com.myself.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.properties.InitNetty; import org.apache.commons.lang3.ObjectUtils; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java similarity index 88% rename from src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java rename to src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 006015c..f1275f8 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -1,8 +1,8 @@ -package com.myself.unclecatmyself.bootstrap; +package com.github.unclecatmyself.bootstrap; -import com.myself.unclecatmyself.common.properties.InitNetty; -import com.myself.unclecatmyself.common.utils.SpringBeanUtils; +import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.utils.SpringBeanUtils; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java similarity index 62% rename from src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java rename to src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java index 31c9c26..b55aeca 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/BootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java @@ -1,6 +1,6 @@ -package com.myself.unclecatmyself.bootstrap; +package com.github.unclecatmyself.bootstrap; -import com.myself.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.properties.InitNetty; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java similarity index 95% rename from src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java rename to src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index 5b9297b..0a861af 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -1,8 +1,8 @@ -package com.myself.unclecatmyself.bootstrap; +package com.github.unclecatmyself.bootstrap; -import com.myself.unclecatmyself.common.ip.IpUtils; -import com.myself.unclecatmyself.common.properties.InitNetty; -import com.myself.unclecatmyself.common.utils.RemotingUtil; +import com.github.unclecatmyself.common.ip.IpUtils; +import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.utils.RemotingUtil; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.ChannelFutureListener; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java index c898994..d8eaca1 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/WsChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap; +package com.github.unclecatmyself.bootstrap; import io.netty.channel.Channel; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java index ed16e4d..5ae7425 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap.backmsg; +package com.github.unclecatmyself.bootstrap.backmsg; import java.util.Map; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java similarity index 94% rename from src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java rename to src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 428013c..4e71429 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -1,6 +1,6 @@ -package com.myself.unclecatmyself.bootstrap.backmsg; +package com.github.unclecatmyself.bootstrap.backmsg; -import com.myself.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.common.utils.ConstansUtil; import org.springframework.stereotype.Service; import java.util.HashMap; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java similarity index 89% rename from src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index bb6d708..362891c 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -1,8 +1,8 @@ -package com.myself.unclecatmyself.bootstrap.channel; +package com.github.unclecatmyself.bootstrap.channel; import com.google.gson.Gson; -import com.myself.unclecatmyself.bootstrap.WsChannelService; -import com.myself.unclecatmyself.bootstrap.channel.cache.WsCacheMap; +import com.github.unclecatmyself.bootstrap.WsChannelService; +import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java similarity index 91% rename from src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 582c9d9..09e3038 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -1,13 +1,13 @@ -package com.myself.unclecatmyself.bootstrap.channel; +package com.github.unclecatmyself.bootstrap.channel; import com.alibaba.fastjson.JSONArray; +import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; +import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.google.gson.Gson; -import com.myself.unclecatmyself.bootstrap.backmsg.InChatBackMapService; -import com.myself.unclecatmyself.bootstrap.WsChannelService; -import com.myself.unclecatmyself.common.utils.ConstansUtil; -import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; -import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; -import com.myself.unclecatmyself.task.DataAsynchronousTask; +import com.github.unclecatmyself.bootstrap.WsChannelService; +import com.github.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; +import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +20,7 @@ * Created by MySelf on 2018/11/21. */ @Component -public class WebSocketHandlerService extends ServerWebSocketHandlerService{ +public class WebSocketHandlerService extends ServerWebSocketHandlerService { @Autowired InChatVerifyService inChatVerifyService; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java similarity index 98% rename from src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java index c18fb84..0a61357 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/CacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap.channel.cache; +package com.github.unclecatmyself.bootstrap.channel.cache; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java similarity index 97% rename from src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 1154b66..3b482a6 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap.channel.cache; +package com.github.unclecatmyself.bootstrap.channel.cache; import io.netty.channel.Channel; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java similarity index 76% rename from src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java index f8737a0..76b5c8f 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/data/InChatToDataBaseService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap.data; +package com.github.unclecatmyself.bootstrap.data; import java.util.Map; diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java similarity index 86% rename from src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java rename to src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 0a8dce5..50fd558 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -1,12 +1,12 @@ -package com.myself.unclecatmyself.bootstrap.handler; +package com.github.unclecatmyself.bootstrap.handler; import com.alibaba.fastjson.JSON; -import com.myself.unclecatmyself.common.exception.NoFindHandlerException; -import com.myself.unclecatmyself.common.utils.ConstansUtil; -import com.myself.unclecatmyself.common.utils.TimeUtil; -import com.myself.unclecatmyself.common.websockets.ServerWebSocketHandlerService; -import com.myself.unclecatmyself.common.websockets.WebSocketHandler; -import com.myself.unclecatmyself.common.websockets.WebSocketHandlerApi; +import com.github.unclecatmyself.common.exception.NoFindHandlerException; +import com.github.unclecatmyself.common.utils.TimeUtil; +import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; +import com.github.unclecatmyself.common.websockets.WebSocketHandler; +import com.github.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.common.websockets.WebSocketHandlerApi; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; @@ -15,7 +15,6 @@ import org.springframework.stereotype.Component; import java.util.Map; -import java.util.concurrent.TimeUnit; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java b/src/main/java/com/github/unclecatmyself/bootstrap/verify/InChatVerifyService.java similarity index 81% rename from src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/verify/InChatVerifyService.java index 18fc87f..0854bfd 100644 --- a/src/main/java/com/myself/unclecatmyself/bootstrap/verify/InChatVerifyService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/verify/InChatVerifyService.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.bootstrap.verify; +package com.github.unclecatmyself.bootstrap.verify; import com.alibaba.fastjson.JSONArray; diff --git a/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java similarity index 79% rename from src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java rename to src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java index 6a76b14..7da4cd4 100644 --- a/src/main/java/com/myself/unclecatmyself/common/exception/NoFindHandlerException.java +++ b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.exception; +package com.github.unclecatmyself.common.exception; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java b/src/main/java/com/github/unclecatmyself/common/ip/IpUtils.java similarity index 97% rename from src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java rename to src/main/java/com/github/unclecatmyself/common/ip/IpUtils.java index 6d452fe..b06e994 100644 --- a/src/main/java/com/myself/unclecatmyself/common/ip/IpUtils.java +++ b/src/main/java/com/github/unclecatmyself/common/ip/IpUtils.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.ip; +package com.github.unclecatmyself.common.ip; import java.net.Inet4Address; import java.net.InetAddress; diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java b/src/main/java/com/github/unclecatmyself/common/pool/DefaultThreadFactory.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java rename to src/main/java/com/github/unclecatmyself/common/pool/DefaultThreadFactory.java index 7d08f86..014999d 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/DefaultThreadFactory.java +++ b/src/main/java/com/github/unclecatmyself/common/pool/DefaultThreadFactory.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.pool; +package com.github.unclecatmyself.common.pool; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java b/src/main/java/com/github/unclecatmyself/common/pool/ExecutorQueue.java similarity index 97% rename from src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java rename to src/main/java/com/github/unclecatmyself/common/pool/ExecutorQueue.java index 4f4f57c..89cde71 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/ExecutorQueue.java +++ b/src/main/java/com/github/unclecatmyself/common/pool/ExecutorQueue.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.pool; +package com.github.unclecatmyself.common.pool; import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.RejectedExecutionException; diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java b/src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java similarity index 81% rename from src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java rename to src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java index da92c38..054a9a1 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/Scheduled.java +++ b/src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.pool; +package com.github.unclecatmyself.common.pool; import java.util.concurrent.ScheduledFuture; diff --git a/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java b/src/main/java/com/github/unclecatmyself/common/pool/StandardThreadExecutor.java similarity index 98% rename from src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java rename to src/main/java/com/github/unclecatmyself/common/pool/StandardThreadExecutor.java index 0374004..6fdab50 100644 --- a/src/main/java/com/myself/unclecatmyself/common/pool/StandardThreadExecutor.java +++ b/src/main/java/com/github/unclecatmyself/common/pool/StandardThreadExecutor.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.pool; +package com.github.unclecatmyself.common.pool; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java rename to src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java index 109c01b..08e1629 100644 --- a/src/main/java/com/myself/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java @@ -1,6 +1,6 @@ -package com.myself.unclecatmyself.common.properties; +package com.github.unclecatmyself.common.properties; -import com.myself.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; +import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; import org.springframework.boot.context.properties.ConfigurationProperties; /** diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java similarity index 94% rename from src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java rename to src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java index b340be4..9accd0c 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.utils; +package com.github.unclecatmyself.common.utils; /** * Created by MySelf on 2018/12/5. diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/RemotingUtil.java similarity index 99% rename from src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java rename to src/main/java/com/github/unclecatmyself/common/utils/RemotingUtil.java index 1604a9f..c2c72b7 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/RemotingUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/RemotingUtil.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.utils; +package com.github.unclecatmyself.common.utils; /* * Licensed to the Apache Software Foundation (ASF) under one or more diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java rename to src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java index 93a49be..672004c 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/SpringBeanUtils.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.utils; +package com.github.unclecatmyself.common.utils; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; diff --git a/src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java similarity index 88% rename from src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java rename to src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java index dab1e50..7294874 100644 --- a/src/main/java/com/myself/unclecatmyself/common/utils/TimeUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.utils; +package com.github.unclecatmyself.common.utils; import java.text.SimpleDateFormat; import java.util.Date; diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java similarity index 92% rename from src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java rename to src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index eae16ef..a67add9 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -1,7 +1,6 @@ -package com.myself.unclecatmyself.common.websockets; +package com.github.unclecatmyself.common.websockets; import io.netty.channel.Channel; -import io.netty.handler.timeout.IdleStateEvent; import java.util.Map; diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java similarity index 96% rename from src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java rename to src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java index 76bab25..4162a3f 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.websockets; +package com.github.unclecatmyself.common.websockets; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; diff --git a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java similarity index 87% rename from src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java rename to src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java index efd92a6..7aadde9 100644 --- a/src/main/java/com/myself/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -1,4 +1,4 @@ -package com.myself.unclecatmyself.common.websockets; +package com.github.unclecatmyself.common.websockets; import io.netty.channel.Channel; import io.netty.handler.timeout.IdleStateEvent; diff --git a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java similarity index 86% rename from src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java rename to src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index 2a0779f..4bd9812 100644 --- a/src/main/java/com/myself/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,6 +1,6 @@ -package com.myself.unclecatmyself.task; +package com.github.unclecatmyself.task; -import com.myself.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; diff --git a/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java b/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java similarity index 82% rename from src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java rename to src/main/java/com/github/unclecatmyself/task/ScheduledPool.java index 26e8a94..49aeb6e 100644 --- a/src/main/java/com/myself/unclecatmyself/task/ScheduledPool.java +++ b/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java @@ -1,7 +1,7 @@ -package com.myself.unclecatmyself.task; +package com.github.unclecatmyself.task; -import com.myself.unclecatmyself.common.properties.InitNetty; -import com.myself.unclecatmyself.common.pool.Scheduled; +import com.github.unclecatmyself.common.pool.Scheduled; +import com.github.unclecatmyself.common.properties.InitNetty; import org.springframework.stereotype.Service; import java.util.concurrent.*; diff --git a/src/main/java/com/myself/unclecatmyself/NettychatApplication.java b/src/main/java/com/myself/unclecatmyself/NettychatApplication.java deleted file mode 100644 index e0190dc..0000000 --- a/src/main/java/com/myself/unclecatmyself/NettychatApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.myself.unclecatmyself; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.scheduling.annotation.EnableScheduling; - -@SpringBootApplication -@EnableScheduling //定时任务支持 -@EnableAspectJAutoProxy //注解开启对aspectJ的支持 -public class NettychatApplication { - - public static void main(String[] args) throws Exception{ - SpringApplication.run(NettychatApplication.class, args); - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java deleted file mode 100644 index e9ff96e..0000000 --- a/src/main/java/com/myself/unclecatmyself/user/InChatToDataBaseServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.myself.unclecatmyself.user; - -import com.myself.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import org.springframework.stereotype.Service; - -import java.util.Map; - -/** - * 不属于项目文件 - * Created by MySelf on 2018/12/3. - */ -@Service -public class InChatToDataBaseServiceImpl implements InChatToDataBaseService { - - @Override - public Boolean writeMapToDB(Map maps) { - //TODO 写入数据库 - System.out.println("异步写入数据:"+maps.toString()); - return true; - } - -} diff --git a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java b/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java deleted file mode 100644 index 9dd9997..0000000 --- a/src/main/java/com/myself/unclecatmyself/user/InChatVerifyServiceImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.myself.unclecatmyself.user; - -import com.alibaba.fastjson.JSONArray; -import com.myself.unclecatmyself.bootstrap.verify.InChatVerifyService; -import org.springframework.stereotype.Service; - -/** - * 不属于项目代码 - * Created by MySelf on 2018/11/22. - */ -@Service -public class InChatVerifyServiceImpl implements InChatVerifyService { - - @Override - public boolean verifyToken(String token) { - //与Redis中的Token做比较,请用户自己实现,查找是否存在该Token值 -// log.info("verify---"+token); - return true; - } - - @Override - public JSONArray getArrayByGroupId(String groupId) { - return JSONArray.parseArray("['1111','2222','3333']"); - } - -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index e69de29..0000000 From a3cafe25a6517ece54114ab145015fb9c7ba1203 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 9 Dec 2018 22:21:13 +0800 Subject: [PATCH 088/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86ser?= =?UTF-8?q?vice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- .../bootstrap/channel/WebSocketHandlerService.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 2e88de2..7e29eb6 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 09e3038..8b1ea27 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -113,6 +113,8 @@ public void verify(Channel channel, Map maps) { String token = (String) maps.get(ConstansUtil.TOKEN); System.out.println(token); if (inChatVerifyService.verifyToken(token)){ + return; + }else{ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginError()))); close(channel); } From b27a62301b29a7d966fa149f7580fea7ef08fa0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 11 Dec 2018 16:11:02 +0800 Subject: [PATCH 089/151] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++++++++- .../bootstrap/NettyBootstrapServer.java | 14 ++++++++------ .../bootstrap/channel/WebSocketChannelService.java | 2 ++ .../bootstrap/handler/DefaultWebSocketHandler.java | 10 ++++++++-- .../unclecatmyself/task/DataAsynchronousTask.java | 4 +++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 0bfdc70..2714731 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.UncleCatMySelf InChat - 0.1-alpha + 1.0-alpha jar InChat @@ -46,6 +46,13 @@ + + + org.projectlombok + lombok + 1.18.4 + provided + com.alibaba fastjson diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index 0a861af..81c3268 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -15,6 +15,7 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; +import lombok.extern.slf4j.Slf4j; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; @@ -22,6 +23,7 @@ /** * Create by UncleCatMySelf in 2018/12/06 **/ +@Slf4j public class NettyBootstrapServer extends AbstractBootstrapServer { private InitNetty serverBean; @@ -60,12 +62,12 @@ protected void initChannel(SocketChannel ch) throws Exception { .childOption(ChannelOption.SO_KEEPALIVE, serverBean.isKeepalive()) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { - if (channelFuture.isSuccess()) -// log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + if (channelFuture.isSuccess()) { + log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); System.out.println("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); - else -// log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); - System.out.println("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + }else{ + log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + System.out.println("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】");} }); } /** @@ -117,7 +119,7 @@ public void shutdown() { bossGroup.shutdownGracefully().sync();// 优雅关闭 workGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { -// log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); System.out.println("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 362891c..d0e01c9 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -5,6 +5,7 @@ import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -13,6 +14,7 @@ /** * Created by MySelf on 2018/11/26. */ +@Slf4j @Component public class WebSocketChannelService implements WsChannelService { diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 50fd558..364a61a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -12,6 +12,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import java.util.Map; @@ -19,6 +20,7 @@ /** * Create by UncleCatMySelf in 2018/12/06 */ +@Slf4j @Component @ChannelHandler.Sharable public class DefaultWebSocketHandler extends WebSocketHandler { @@ -48,20 +50,24 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) maps.put("time", TimeUtil.getTime()); switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: + log.info("【登录校验】"); serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: + log.info("【发送给自己】"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: + log.info("【发送给某人】"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: + log.info("发送到群组"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendGroupText(channel,maps); break; @@ -72,12 +78,12 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { -// log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); + log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ -// log.error("exception",cause); + log.error("exception",cause); webSocketHandlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index 4bd9812..75e81c5 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncResult; @@ -12,6 +13,7 @@ /** * Created by MySelf on 2018/12/3. */ +@Slf4j @Component public class DataAsynchronousTask { @@ -20,7 +22,7 @@ public class DataAsynchronousTask { @Async public Future writeData(Map maps) throws Exception { - //异步写入数据 + log.info("【异步写入数据】"); return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); } From c99306d35904842af36f17b623c5ec540039ca5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 14 Dec 2018 09:32:57 +0800 Subject: [PATCH 090/151] =?UTF-8?q?=E6=8F=90=E4=BA=A4v1.0.0Maven=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++++- doc/goal/goal.md | 13 +++++++++++-- doc/version/v1.0.0.md | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 doc/version/v1.0.0.md diff --git a/README.md b/README.md index 1ad08c0..5085e51 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,18 @@ **欢迎参与QQ群交流与提供建议、业务场景、需求功能等** -**master项目目前在重新构建,运行可能报错,请转到demo分支运行项目。其为原核心项目** +## Maven版本 + +[V1.0.0版本使用说明](doc/version/v1.0.0.md) + +``` + + + com.github.UncleCatMySelf + InChat + 1.0-alpha + +``` ## 项目日志 diff --git a/doc/goal/goal.md b/doc/goal/goal.md index ff72d84..a5c82eb 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -2,10 +2,19 @@ > 项目研发的开放目标,以Maven包为基本的发布(兼对应版本的文档输出)设定为每个里程碑的产出。 -## V1.0.0版本 +## V1.0.0版本 【2018-12-14】 > 版本昵称:赤猫 版本目标:完成基本的消息通讯(仅支持文本消息),离线消息存储,历史消息查询,一对一聊天、自我聊天、群聊等 -> 目前正在重构中····· \ No newline at end of file +[V1.0.0版本使用说明](../version/v1.0.0.md) + +``` + + + com.github.UncleCatMySelf + InChat + 1.0-alpha + +``` \ No newline at end of file diff --git a/doc/version/v1.0.0.md b/doc/version/v1.0.0.md new file mode 100644 index 0000000..b0be14c --- /dev/null +++ b/doc/version/v1.0.0.md @@ -0,0 +1,20 @@ +## v1.0.0版本使用说明 + +### 关于InChat的Maven依赖 + +* fastjson 》 1.2.53 +* gson 》 2.8.5 +* netty 》 4.1.32.Final +* commons-lang 》 3.5 +* aspectj 》 1.9.2 +* lombok 》 1.18.4 +* spring-boot 》 2.0.2.RELEASE +* spring-boot-starter-websocket + +关于一版依旧使用SpringBoot的环境,同时为应用注入了web环境,引入InChat依赖包后,对于SpringBoot相关的web可以无需引入,同时请注意相关版本的兼容性。 +引入InChat默认可以自动运行web环境。 + +### 创建项目 + +创建一个空的Maven项目,并引入**InChat**Maven包, + From b62e07376993a4c0480445ca857ea6891f35f2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 14 Dec 2018 09:35:06 +0800 Subject: [PATCH 091/151] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 8d70af2..f236570 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -12,3 +12,5 @@ * 【2018-12-04】 明确项目文档的重要性,并设定Netty相关文档说明,与Netty入门说明 * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 * 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式,统一注释说明 +* 【2018-12-14】 打包完成v1.0.0Maven版本,并提交说明文档与相关资料,正对v1.0.0提交对应demo分支。 + From 74c8e1b1c2ab64f5c3e20b9775832f1d87a55e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 14 Dec 2018 11:13:33 +0800 Subject: [PATCH 092/151] =?UTF-8?q?=E6=8F=90=E4=BA=A4v1.0.0=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 4 +- doc/version/v1.0.0.md | 269 +++++++++++++++++++++++++++++++++++- 2 files changed, 270 insertions(+), 3 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 7e29eb6..b1f5299 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data @@ -78,7 +78,7 @@ if (socket.readyState == WebSocket.OPEN) { var message = { type: "login", - token: "1111" + token: "2222" } socket.send(JSON.stringify(message)); } else { diff --git a/doc/version/v1.0.0.md b/doc/version/v1.0.0.md index b0be14c..7cf9d53 100644 --- a/doc/version/v1.0.0.md +++ b/doc/version/v1.0.0.md @@ -16,5 +16,272 @@ ### 创建项目 -创建一个空的Maven项目,并引入**InChat**Maven包, +创建一个空的Maven项目,并引入**InChat**Maven包,(注意,请不要使用与本项目相同的包目录)。 + +可能你只需要这样的Maven依赖即可 + +``` + + + com.github.UncleCatMySelf + InChat + 1.0-alpha + + + org.springframework.boot + spring-boot-starter-test + test + + +``` + +### 注入InChat的项目到自身项目中 + +你可能需要在你的项目上进行报扫描 + +```java +@SpringBootApplication +@ComponentScan({"com.inchat"}) //你的demo包目录 +@ComponentScan({"com.github.unclecatmyself"}) //InChat的包目录 --请将InChat的放到最下面 +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} +``` + +### 对接InChat的接口与实现 + +这次你仅需写两个实现接口即可啦!!! + +```java +@Service +public class ToDataBaseServiceImpl implements InChatToDataBaseService{ + + @Override + public Boolean writeMapToDB(Map maps) { + //异步写入数据库 + System.out.println(maps.toString()); + return true; + } +} +``` + +* 这个接口是每个人通讯的信息,InChat自带实现了异步的数据外抛得接口**InChatToDataBaseService**,目前一版只有一个方法, +就是上面得writeMapToDB,你仅需要map的内容转为对应的对象(一版还没提供对应的转换类,下一版对提供),并将数据存入自己喜欢的数据库中。 +如果数据并发大,也可以先放到MQ中,再写入数据库。 + +```java +@Service +public class verifyServiceImpl implements InChatVerifyService { + + + @Override + public boolean verifyToken(String token) { + //登录校验 + return true; + } + + @Override + public JSONArray getArrayByGroupId(String groupId) { + //根据群聊id获取对应的群聊人员ID + JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); + return jsonArray; + } +} +``` + +* 这个接口是InChat的校验层实现,对于Token的校验就是,**verifyToken**,websocket链接的时候,你将在初次做登录校验,你可以将从InChat拿到的websocket传过来的 +Token,你可以与自己的用户登录的token做校验,返回true,则用户成功链接InChat。 + +* 关于**getArrayByGroupId**,目前是否应该放在这个接口中还有待确定,不过目前一版暂时这样,你可以去数据库中查询对应的群聊id所对应的人员ID(或Token),并返回对应的 +JSONArray即可啦。 + +### 自定义配置InChat参数 + +这个你可以直接在application中按照自己的意思配置,不过你最好先了解netty + +![Image](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181214104225.png) + +### 启动项目 + +接着启动项目即可啦 + +当你看到这个日志就标志着Inchat搭建成功了!!! + +``` +2018-12-14 10:29:09.269 INFO 4920 --- [ BOSS_1] c.g.u.bootstrap.NettyBootstrapServer : 服务端启动成功【192.168.1.121:8090】 +``` + +### 关于前端 + +这里你可以来到[InChat](https://github.com/UncleCatMySelf/InChat)的Front-End-Testing文档夹中的chat.html。 + +你可以直接使用,你进需要修改对应的对接IP即可。 + +> 关于前端的js暂时还是模板 + +### 关于登录 + +你会看到chat.html中的登录按钮对应的js + +```js +function send(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "login", //与InChat对应的 不可修改 + token: "1111" + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } +} +``` + +本demo,默认登录的Token是“1111”,关于用户校验则直接返回true即可。 + +登录成功,返回以下内容。(不需要显示给用户看) + +``` +{"success":"true","type":"login"} +``` + +InChat不会有登录记录 + +### 发送给自己 + +你会看到chat.html中的登录按钮对应的js + +```js +function sendToMe(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "sendMe", //与InChat对应的 不可修改 + value: value, //发送的内容 + token: "1111" //发送用户的token + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } +} +``` + +发送成功,InChat返回内容.(你仅需将value显示到前端即可) + +``` +{"type":"sendMe","value":"发送给自己的内容"} +``` + +InChat消息记录,你将在异步消息中接受到InChat传递给你的用户通讯消息,你可以进行对应的入库操作 + +``` +{"time":"2018-12-14 10:56:24","type":"sendMe","value":"发送给自己的内容","token":"1111"} +``` + +### 发送给某人 + +你会看到chat.html中的登录按钮对应的js + +```js +function sendToOne(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type : "sendTo", //与InChat对应的 不可修改 + token : "1111", //发送用户Token + value: value, //发送内容 + one: "2222", //接受用户Token(唯一标识) + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } +} +``` + +发送成功,接受的用户是否登录,你都能接受到返回信息。(value应用于自己界面展示) + +``` +{"one":"2222","type":"sendTo","value":"发送给朋友的内容"} +``` + +但是用户那边就不一样了。 + +登录正常在线。 + +``` +{"from":"1111","type":"sendTo","value":"发送给朋友的内容"} +``` + +离线接受不到信息 + +InChat异步消息推送,你可以看到两种 + +``` +在线: {"one":"2222","time":"2018-12-14 11:01:36","type":"sendTo","value":"发送给朋友的内容","token":"1111"} +``` + +``` +离线: {"one":"2222","time":"2018-12-14 10:59:04","on_online":"2222","type":"sendTo","value":"发送给朋友的内容","token":"1111"} +``` + +如果出现用户发送给用户的状态是离线的,则会在消息多出on_online的字段,该字段的内容就是离线用户的Token,你可以针对性的数据入库,并在用户上线的时候,读写信息的时候,有一个未读消息的状态。 + +### 发送群聊 + +你会看到chat.html中的登录按钮对应的js + +```js +function sendGroup(value) { + if (!window.WebSocket) { + return; + } + if (socket.readyState == WebSocket.OPEN) { + var message = { + type: "sendGroup", //与InChat对应的 不可修改 + groupId: "2", //群聊ID + token: "1111", //发送用户的Token + value: value //发送的消息 + } + socket.send(JSON.stringify(message)); + } else { + alert("连接没有开启."); + } +} +``` + +发送成功,本人将接受到消息 + +``` +{"groupId":"2","from":"1111","type":"sendGroup","value":"大家明天一起去唱K吧"} +``` + +群组中有些人在线接受、离线不接受 + +``` +在线:{"groupId":"2","from":"1111","type":"sendGroup","value":"大家明天一起去唱K吧"} +``` + +InChat异步消息入库,群组只会异步给你一个消息,你可以看到on_online中,3333用户是没有接受到信息的,所以你可以在他上线发送未读消息。 + +``` +{"groupId":"2","time":"2018-12-14 11:09:17","on_online":["3333"],"type":"sendGroup","value":"大家明天一起去唱K吧","token":"1111"} +``` + +### 关于数据库设计 + +> 当前一版不会固定大家的数据库设计,大家可以自己自由设计,同时搭上自己的项目,构建一个附带IM的自项目。 + From e3163af5ad57e85bbd5172e133a62614fed73fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 14 Dec 2018 11:17:31 +0800 Subject: [PATCH 093/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/version/v1.0.0.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/version/v1.0.0.md b/doc/version/v1.0.0.md index 7cf9d53..f5fce28 100644 --- a/doc/version/v1.0.0.md +++ b/doc/version/v1.0.0.md @@ -284,4 +284,12 @@ InChat异步消息入库,群组只会异步给你一个消息,你可以看到o > 当前一版不会固定大家的数据库设计,大家可以自己自由设计,同时搭上自己的项目,构建一个附带IM的自项目。 +### 前端效果 +发送人 + +![Image](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181214111435.png) + +接收人 + +![Image](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/inchat/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20181214111438.png) \ No newline at end of file From 5162416f7aed657040996181647e8fd21ccc62c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 14 Dec 2018 11:38:52 +0800 Subject: [PATCH 094/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0maven?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5085e51..ee2c959 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) +[![Maven](https://img.shields.io/badge/Maven-1.0--alpha-orange.svg)](https://mvnrepository.com/artifact/com.github.UncleCatMySelf/InChat/1.0-alpha) + From 4d34bbe061193bbaf45a16f1629602d7aa8b655a Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 15 Dec 2018 11:11:56 +0800 Subject: [PATCH 095/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=95=99=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 4 ++-- README.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index b1f5299..7e29eb6 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data @@ -78,7 +78,7 @@ if (socket.readyState == WebSocket.OPEN) { var message = { type: "login", - token: "2222" + token: "1111" } socket.send(JSON.stringify(message)); } else { diff --git a/README.md b/README.md index ee2c959..4f5b38d 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ ## Maven版本 [V1.0.0版本使用说明](doc/version/v1.0.0.md) +[V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) ``` From 9da86aa1d1a0b2cacf1e6576085a17f67f3942d3 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 15 Dec 2018 11:12:58 +0800 Subject: [PATCH 096/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4f5b38d..d96a516 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,8 @@ ## Maven版本 -[V1.0.0版本使用说明](doc/version/v1.0.0.md) -[V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) +* [V1.0.0版本使用说明](doc/version/v1.0.0.md) +* [V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) ``` From e64e995a6884f8eb09c54cd00c7e45945b838303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 18 Dec 2018 09:29:36 +0800 Subject: [PATCH 097/151] log --- doc/Project-Log-cn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index f236570..397223b 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -13,4 +13,6 @@ * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 * 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式,统一注释说明 * 【2018-12-14】 打包完成v1.0.0Maven版本,并提交说明文档与相关资料,正对v1.0.0提交对应demo分支。 +* 【2018-12-15】 录制V1.0.0使用说明视频 +* 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。 From ac1df0a2e205c434ff63726dd190f7a12fc000fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 18 Dec 2018 16:20:39 +0800 Subject: [PATCH 098/151] log --- doc/Project-Log-cn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 397223b..1832aa2 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -13,6 +13,6 @@ * 【2018-12-05】 移除部分Iot使用的代码(一版暂时还没使用到),清楚pom文件中不用的jar包,需添加【系统时间】参数 * 【2018-12-06】 确定LOGO并上传,InChat QQ群项目组成立,移除对lombok的依赖,使用传统形式,统一注释说明 * 【2018-12-14】 打包完成v1.0.0Maven版本,并提交说明文档与相关资料,正对v1.0.0提交对应demo分支。 -* 【2018-12-15】 录制V1.0.0使用说明视频 -* 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。 +* 【2018-12-15】 [录制V1.0.0使用说明视频](https://v.qq.com/x/page/i0813oy0lov.html) +* 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) From 5d10452c63cf3d48ae868b644ae639ce3d657fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 18 Dec 2018 16:34:13 +0800 Subject: [PATCH 099/151] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 26 ------------------- .../github/unclecatmyself/Application.java | 18 +++++++++++++ .../backmsg/InChatBackMapServiceImpl.java | 1 - .../channel/WebSocketChannelService.java | 1 - .../channel/WebSocketHandlerService.java | 1 - .../bootstrap/channel/cache/WsCacheMap.java | 1 - .../handler/DefaultWebSocketHandler.java | 2 -- .../common/properties/InitNetty.java | 2 -- .../common/utils/SpringBeanUtils.java | 1 - .../unclecatmyself/task/ScheduledPool.java | 2 -- 10 files changed, 18 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/Application.java diff --git a/pom.xml b/pom.xml index 2714731..a7023fb 100644 --- a/pom.xml +++ b/pom.xml @@ -32,13 +32,6 @@ git@github.com:UncleCatMySelf/InChat.git - - org.springframework.boot - spring-boot-starter-parent - 2.0.2.RELEASE - - - UTF-8 UTF-8 @@ -63,20 +56,6 @@ gson 2.8.5 - - org.aspectj - aspectjrt - 1.9.2 - - - org.aspectj - aspectjweaver - 1.9.2 - - - org.springframework.boot - spring-boot-starter-websocket - io.netty netty-all @@ -87,11 +66,6 @@ commons-lang3 3.5 - - org.springframework.boot - spring-boot-configuration-processor - true - diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java new file mode 100644 index 0000000..afd0582 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/Application.java @@ -0,0 +1,18 @@ +package com.github.unclecatmyself; + +/** + * Created by MySelf on 2018/12/18. + */ +public class Application { + + public static void main(String[] args) { + //注册InChat相关配置 + + //预制InChat的用户接口 + + //启动InChat流程 + + + } + +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 4e71429..e2ea1af 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -10,7 +10,6 @@ * 列入项目中 * Created by MySelf on 2018/11/23. */ -@Service public class InChatBackMapServiceImpl implements InChatBackMapService { @Override diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index d0e01c9..805dd0d 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -15,7 +15,6 @@ * Created by MySelf on 2018/11/26. */ @Slf4j -@Component public class WebSocketChannelService implements WsChannelService { @Autowired diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 8b1ea27..6f08c14 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -19,7 +19,6 @@ /** * Created by MySelf on 2018/11/21. */ -@Component public class WebSocketHandlerService extends ServerWebSocketHandlerService { @Autowired diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 3b482a6..db07cc4 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -10,7 +10,6 @@ * WebSocket链接实例本地存储 * Created by MySelf on 2018/11/26. */ -@Component public class WsCacheMap { /** diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 364a61a..b9a663a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -13,7 +13,6 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Component; import java.util.Map; @@ -21,7 +20,6 @@ * Create by UncleCatMySelf in 2018/12/06 */ @Slf4j -@Component @ChannelHandler.Sharable public class DefaultWebSocketHandler extends WebSocketHandler { diff --git a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java index 08e1629..6e9fb58 100644 --- a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java @@ -1,12 +1,10 @@ package com.github.unclecatmyself.common.properties; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; -import org.springframework.boot.context.properties.ConfigurationProperties; /** * Create by UncleCatMySelf in 2018/12/06 */ -@ConfigurationProperties(prefix = "inchat") public class InitNetty { private int webport = 8090; diff --git a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java index 672004c..a61ba39 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java @@ -8,7 +8,6 @@ /** * Create by UncleCatMySelf in 2018/12/06 **/ -@Component public class SpringBeanUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; diff --git a/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java b/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java index 49aeb6e..607a861 100644 --- a/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java +++ b/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java @@ -2,7 +2,6 @@ import com.github.unclecatmyself.common.pool.Scheduled; import com.github.unclecatmyself.common.properties.InitNetty; -import org.springframework.stereotype.Service; import java.util.concurrent.*; @@ -10,7 +9,6 @@ /** * Create by UncleCatMySelf in 2018/12/06 **/ -@Service public class ScheduledPool implements Scheduled { private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(20); From 3b861d2856d2a6ebdc3a3f16114873d986cf3605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 18 Dec 2018 16:52:33 +0800 Subject: [PATCH 100/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 19 ++++- .../auto/ServerAutoConfigure.java | 11 --- .../bootstrap/NettyBootstrapServer.java | 4 - .../backmsg/InChatBackMapService.java | 2 + .../backmsg/InChatBackMapServiceImpl.java | 25 +++--- .../channel/WebSocketChannelService.java | 3 - .../channel/WebSocketHandlerService.java | 10 +-- .../bootstrap/channel/cache/CacheMap.java | 3 +- .../bootstrap/channel/cache/WsCacheMap.java | 2 - .../handler/DefaultWebSocketHandler.java | 6 -- .../common/properties/InitNetty.java | 1 + .../common/utils/SpringBeanUtils.java | 84 +++++++++---------- .../task/DataAsynchronousTask.java | 12 +-- 13 files changed, 84 insertions(+), 98 deletions(-) diff --git a/pom.xml b/pom.xml index a7023fb..769bcdd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,18 @@ com.github.UncleCatMySelf InChat 1.0-alpha + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + jar InChat @@ -39,12 +51,15 @@ - + + org.slf4j + slf4j-log4j12 + 1.7.25 + org.projectlombok lombok 1.18.4 - provided com.alibaba diff --git a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java index edb661c..9b03a48 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java @@ -2,19 +2,11 @@ import com.github.unclecatmyself.common.properties.InitNetty; import org.apache.commons.lang3.ObjectUtils; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; /** * Create by UncleCatMySelf in 2018/12/06 **/ -@Configuration -@ConditionalOnClass -@EnableConfigurationProperties({InitNetty.class}) public class ServerAutoConfigure { private static final int _BLACKLOG = 1024; @@ -43,9 +35,6 @@ public ServerAutoConfigure(){ // return sacnScheduled; // } - - @Bean(initMethod = "open", destroyMethod = "close") - @ConditionalOnMissingBean public InitServer initServer(InitNetty serverBean){ if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ throw new NullPointerException("not set port"); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index 81c3268..629f03f 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -23,7 +23,6 @@ /** * Create by UncleCatMySelf in 2018/12/06 **/ -@Slf4j public class NettyBootstrapServer extends AbstractBootstrapServer { private InitNetty serverBean; @@ -63,10 +62,8 @@ protected void initChannel(SocketChannel ch) throws Exception { .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) { - log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); System.out.println("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); }else{ - log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); System.out.println("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】");} }); } @@ -119,7 +116,6 @@ public void shutdown() { bossGroup.shutdownGracefully().sync();// 优雅关闭 workGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { - log.info("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); System.out.println("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java index 5ae7425..33813c8 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java @@ -1,5 +1,7 @@ package com.github.unclecatmyself.bootstrap.backmsg; +import lombok.Data; + import java.util.Map; /** diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index e2ea1af..5a44a0f 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -1,7 +1,6 @@ package com.github.unclecatmyself.bootstrap.backmsg; import com.github.unclecatmyself.common.utils.ConstansUtil; -import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.Map; @@ -12,51 +11,51 @@ */ public class InChatBackMapServiceImpl implements InChatBackMapService { - @Override + public Map loginSuccess() { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); backMap.put(ConstansUtil.SUCCESS,ConstansUtil.TRUE); return backMap; } - @Override + public Map loginError() { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); backMap.put(ConstansUtil.SUCCESS,ConstansUtil.FALSE); return backMap; } - @Override + public Map sendMe(String value) { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDME); backMap.put(ConstansUtil.VALUE,value); return backMap; } - @Override + public Map sendBack(String otherOne, String value) { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); backMap.put(ConstansUtil.VALUE,value); backMap.put(ConstansUtil.ONE,otherOne); return backMap; } - @Override + public Map getMsg(String token, String value) { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); backMap.put(ConstansUtil.FROM,token); backMap.put(ConstansUtil.VALUE,value); return backMap; } - @Override + public Map sendGroup(String token, String value, String groupId) { - Map backMap = new HashMap<>(); + Map backMap = new HashMap(); backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDGROUP); backMap.put(ConstansUtil.FROM,token); backMap.put(ConstansUtil.VALUE,value); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 805dd0d..0f5cb15 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -6,8 +6,6 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import java.util.Map; @@ -17,7 +15,6 @@ @Slf4j public class WebSocketChannelService implements WsChannelService { - @Autowired WsCacheMap wsCacheMap; private final Gson gson; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 6f08c14..b44566c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -10,8 +10,6 @@ import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -21,16 +19,16 @@ */ public class WebSocketHandlerService extends ServerWebSocketHandlerService { - @Autowired + InChatVerifyService inChatVerifyService; - @Autowired + InChatBackMapService inChatBackMapService; - @Autowired + WsChannelService websocketChannelService; - @Autowired + DataAsynchronousTask dataAsynchronousTask; private final Gson gson; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java index 0a61357..3ed8d75 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/CacheMap.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; + /** * Create by UncleCatMySelf in 2018/12/06 **/ @@ -71,7 +72,7 @@ public List getData(K[] ks){ public Node buildOne(K k,V v){ Node node = this.datas.computeIfAbsent(k, key -> { - Node kObjectNode = new Node<>(k); + Node kObjectNode = new Node(k); return kObjectNode; }); if(v!=null){ diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index db07cc4..6e74dee 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,8 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.cache; import io.netty.channel.Channel; -import org.springframework.stereotype.Component; - import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index b9a663a..f7575f0 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -48,24 +48,20 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) maps.put("time", TimeUtil.getTime()); switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: - log.info("【登录校验】"); serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: - log.info("【发送给自己】"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: - log.info("【发送给某人】"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: - log.info("发送到群组"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendGroupText(channel,maps); break; @@ -76,12 +72,10 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelActive】"+ctx.channel().remoteAddress().toString()+"链接成功"); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ - log.error("exception",cause); webSocketHandlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java index 6e9fb58..007384e 100644 --- a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.common.properties; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; +import lombok.Data; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java index a61ba39..3fce766 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java @@ -1,42 +1,42 @@ -package com.github.unclecatmyself.common.utils; - -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Component; - -/** - * Create by UncleCatMySelf in 2018/12/06 - **/ -public class SpringBeanUtils implements ApplicationContextAware { - - private static ApplicationContext applicationContext; - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - if (SpringBeanUtils.applicationContext == null){ - SpringBeanUtils.applicationContext = applicationContext; - } - } - - //获取applicationContext - public static ApplicationContext getApplicationContext() { - return applicationContext; - } - - //通过name获取 Bean. - public static Object getBean(String name){ - return getApplicationContext().getBean(name); - } - - //通过class获取Bean. - public static T getBean(Class clazz){ - return getApplicationContext().getBean(clazz); - } - - //通过name,以及Clazz返回指定的Bean - public static T getBean(String name,Class clazz){ - return getApplicationContext().getBean(name, clazz); - } - -} +//package com.github.unclecatmyself.common.utils; +// +//import org.springframework.beans.BeansException; +//import org.springframework.context.ApplicationContext; +//import org.springframework.context.ApplicationContextAware; +//import org.springframework.stereotype.Component; +// +///** +// * Create by UncleCatMySelf in 2018/12/06 +// **/ +//public class SpringBeanUtils implements ApplicationContextAware { +// +// private static ApplicationContext applicationContext; +// +// @Override +// public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { +// if (SpringBeanUtils.applicationContext == null){ +// SpringBeanUtils.applicationContext = applicationContext; +// } +// } +// +// //获取applicationContext +// public static ApplicationContext getApplicationContext() { +// return applicationContext; +// } +// +// //通过name获取 Bean. +// public static Object getBean(String name){ +// return getApplicationContext().getBean(name); +// } +// +// //通过class获取Bean. +// public static T getBean(Class clazz){ +// return getApplicationContext().getBean(clazz); +// } +// +// //通过name,以及Clazz返回指定的Bean +// public static T getBean(String name,Class clazz){ +// return getApplicationContext().getBean(name, clazz); +// } +// +//} diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index 75e81c5..f5ad2df 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -2,10 +2,6 @@ import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncResult; -import org.springframework.stereotype.Component; import java.util.Map; import java.util.concurrent.Future; @@ -14,16 +10,16 @@ * Created by MySelf on 2018/12/3. */ @Slf4j -@Component public class DataAsynchronousTask { - @Autowired + InChatToDataBaseService inChatToDataBaseService; - @Async + public Future writeData(Map maps) throws Exception { log.info("【异步写入数据】"); - return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); +// return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); + return null; } } From 72525cd8fb25aafc46bcc974414d039f71079c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Wed, 19 Dec 2018 14:03:33 +0800 Subject: [PATCH 101/151] =?UTF-8?q?log4j=E8=BF=81=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- doc/Project-Log-cn.md | 1 + firestorm.log | 47 +++++++++++++++++++ pom.xml | 5 -- .../github/unclecatmyself/Application.java | 6 ++- .../bootstrap/AbstractBootstrapServer.java | 5 +- .../bootstrap/NettyBootstrapServer.java | 15 +++--- .../backmsg/InChatBackMapService.java | 1 - .../channel/WebSocketChannelService.java | 25 ++++------ .../channel/WebSocketHandlerService.java | 10 ++-- .../bootstrap/channel/cache/WsCacheMap.java | 20 ++++---- .../handler/DefaultWebSocketHandler.java | 8 +++- .../common/properties/InitNetty.java | 1 - .../task/DataAsynchronousTask.java | 5 +- .../user/InChatVerifyServiceImpl.java | 21 +++++++++ src/main/resources/log4j.properties | 17 +++++++ 16 files changed, 134 insertions(+), 55 deletions(-) create mode 100644 firestorm.log create mode 100644 src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java create mode 100644 src/main/resources/log4j.properties diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 7e29eb6..2e88de2 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 1832aa2..56ec8c5 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -15,4 +15,5 @@ * 【2018-12-14】 打包完成v1.0.0Maven版本,并提交说明文档与相关资料,正对v1.0.0提交对应demo分支。 * 【2018-12-15】 [录制V1.0.0使用说明视频](https://v.qq.com/x/page/i0813oy0lov.html) * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) +* 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息。 diff --git a/firestorm.log b/firestorm.log new file mode 100644 index 0000000..40916dc --- /dev/null +++ b/firestorm.log @@ -0,0 +1,47 @@ +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 19968 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 diff --git a/pom.xml b/pom.xml index 769bcdd..9fee722 100644 --- a/pom.xml +++ b/pom.xml @@ -56,11 +56,6 @@ slf4j-log4j12 1.7.25 - - org.projectlombok - lombok - 1.18.4 - com.alibaba fastjson diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java index afd0582..40762e9 100644 --- a/src/main/java/com/github/unclecatmyself/Application.java +++ b/src/main/java/com/github/unclecatmyself/Application.java @@ -1,5 +1,8 @@ package com.github.unclecatmyself; +import com.github.unclecatmyself.auto.InitServer; +import com.github.unclecatmyself.common.properties.InitNetty; + /** * Created by MySelf on 2018/12/18. */ @@ -7,7 +10,8 @@ public class Application { public static void main(String[] args) { //注册InChat相关配置 - + InitServer initServer = new InitServer(new InitNetty()); + initServer.open(); //预制InChat的用户接口 //启动InChat流程 diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index f1275f8..691a623 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -1,8 +1,9 @@ package com.github.unclecatmyself.bootstrap; +import com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService; +import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; import com.github.unclecatmyself.common.properties.InitNetty; -import com.github.unclecatmyself.common.utils.SpringBeanUtils; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; @@ -22,7 +23,7 @@ public abstract class AbstractBootstrapServer implements BootstrapServer { protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ intProtocolHandler(channelPipeline,serverBean); channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast(SpringBeanUtils.getBean(serverBean.getWebSocketHandler())); + channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerService())); } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index 629f03f..4a5ec17 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -15,7 +15,8 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; @@ -25,6 +26,8 @@ **/ public class NettyBootstrapServer extends AbstractBootstrapServer { + private final Logger log = LoggerFactory.getLogger(NettyBootstrapServer.class); + private InitNetty serverBean; public InitNetty getServerBean() { @@ -62,9 +65,9 @@ protected void initChannel(SocketChannel ch) throws Exception { .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) { - System.out.println("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); }else{ - System.out.println("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】");} + log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】");} }); } /** @@ -75,14 +78,12 @@ private void initEventPool(){ if(useEpoll()){ bossGroup = new EpollEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { private AtomicInteger index = new AtomicInteger(0); - public Thread newThread(Runnable r) { return new Thread(r, "LINUX_BOSS_" + index.incrementAndGet()); } }); workGroup = new EpollEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { private AtomicInteger index = new AtomicInteger(0); - public Thread newThread(Runnable r) { return new Thread(r, "LINUX_WORK_" + index.incrementAndGet()); } @@ -92,14 +93,12 @@ public Thread newThread(Runnable r) { else { bossGroup = new NioEventLoopGroup(serverBean.getBossThread(), new ThreadFactory() { private AtomicInteger index = new AtomicInteger(0); - public Thread newThread(Runnable r) { return new Thread(r, "BOSS_" + index.incrementAndGet()); } }); workGroup = new NioEventLoopGroup(serverBean.getWorkerThread(), new ThreadFactory() { private AtomicInteger index = new AtomicInteger(0); - public Thread newThread(Runnable r) { return new Thread(r, "WORK_" + index.incrementAndGet()); } @@ -116,7 +115,7 @@ public void shutdown() { bossGroup.shutdownGracefully().sync();// 优雅关闭 workGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { - System.out.println("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + log.error("服务端关闭资源失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); } } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java index 33813c8..ffb7a07 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapService.java @@ -1,6 +1,5 @@ package com.github.unclecatmyself.bootstrap.backmsg; -import lombok.Data; import java.util.Map; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java index 0f5cb15..082507a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java @@ -5,50 +5,41 @@ import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import lombok.extern.slf4j.Slf4j; import java.util.Map; /** * Created by MySelf on 2018/11/26. */ -@Slf4j public class WebSocketChannelService implements WsChannelService { - WsCacheMap wsCacheMap; - - private final Gson gson; - - public WebSocketChannelService(Gson gson){ - this.gson = gson; - } - @Override public void loginWsSuccess(Channel channel, String token) { - wsCacheMap.saveWs(token,channel); - wsCacheMap.saveAd(channel.remoteAddress().toString(),token); + WsCacheMap.saveWs(token,channel); + WsCacheMap.saveAd(channel.remoteAddress().toString(),token); } @Override public boolean hasOther(String otherOne) { - return wsCacheMap.hasToken(otherOne); + return WsCacheMap.hasToken(otherOne); } @Override public Channel getChannel(String otherOne) { - return wsCacheMap.getByToken(otherOne); + return WsCacheMap.getByToken(otherOne); } @Override public void close(Channel channel) { - String token = wsCacheMap.getByAddress(channel.remoteAddress().toString()); - wsCacheMap.deleteAd(channel.remoteAddress().toString()); - wsCacheMap.deleteWs(token); + String token = WsCacheMap.getByAddress(channel.remoteAddress().toString()); + WsCacheMap.deleteAd(channel.remoteAddress().toString()); + WsCacheMap.deleteWs(token); channel.close(); } @Override public boolean sendFromServer(Channel channel, Map map) { + Gson gson = new Gson(); try { channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(map))); return true; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index b44566c..5e868f4 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -31,11 +31,6 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService { DataAsynchronousTask dataAsynchronousTask; - private final Gson gson; - - public WebSocketHandlerService(Gson gson){ - this.gson = gson; - } @Override public boolean login(Channel channel, Map maps) { @@ -45,6 +40,7 @@ public boolean login(Channel channel, Map maps) { @Override public void sendMeText(Channel channel, Map maps) { + Gson gson = new Gson(); channel.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.sendMe((String) maps.get(ConstansUtil.VALUE))))); try { @@ -56,6 +52,7 @@ public void sendMeText(Channel channel, Map maps) { @Override public void sendToText(Channel channel, Map maps) { + Gson gson = new Gson(); String otherOne = (String) maps.get(ConstansUtil.ONE); String value = (String) maps.get(ConstansUtil.VALUE); String token = (String) maps.get(ConstansUtil.TOKEN); @@ -79,6 +76,7 @@ public void sendToText(Channel channel, Map maps) { @Override public void sendGroupText(Channel channel, Map maps) { + Gson gson = new Gson(); String groupId = (String) maps.get(ConstansUtil.GROUPID); String token = (String) maps.get(ConstansUtil.TOKEN); String value = (String) maps.get(ConstansUtil.VALUE); @@ -107,6 +105,7 @@ public void sendGroupText(Channel channel, Map maps) { @Override public void verify(Channel channel, Map maps) { + Gson gson = new Gson(); String token = (String) maps.get(ConstansUtil.TOKEN); System.out.println(token); if (inChatVerifyService.verifyToken(token)){ @@ -118,6 +117,7 @@ public void verify(Channel channel, Map maps) { } private Boolean check(Channel channel, Map maps){ + Gson gson = new Gson(); String token = (String) maps.get(ConstansUtil.TOKEN); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 6e74dee..d1aff3b 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -13,19 +13,19 @@ public class WsCacheMap { /** * 存储用户标识与链接实例 */ - Map maps = new ConcurrentHashMap(); + private final static Map maps = new ConcurrentHashMap(); /** * 存储链接地址与用户标识 */ - Map addMaps = new ConcurrentHashMap<>(); + private final static Map addMaps = new ConcurrentHashMap<>(); /** * 存储链接 * @param token {@link String} 用户标签 * @param channel {@link Channel} 链接实例 */ - public void saveWs(String token,Channel channel){ + public static void saveWs(String token,Channel channel){ maps.put(token,channel); } @@ -34,7 +34,7 @@ public void saveWs(String token,Channel channel){ * @param address 登录地址 * @param token 用户标签 */ - public void saveAd(String address,String token){ + public static void saveAd(String address,String token){ addMaps.put(address, token); } @@ -43,7 +43,7 @@ public void saveAd(String address,String token){ * @param token {@link String} 用户标识 * @return {@link Channel} 链接实例 */ - public Channel getByToken(String token){ + public static Channel getByToken(String token){ return maps.get(token); } @@ -52,7 +52,7 @@ public Channel getByToken(String token){ * @param address {@link String} 链接地址 * @return {@link String} */ - public String getByAddress(String address){ + public static String getByAddress(String address){ return addMaps.get(address); } @@ -60,7 +60,7 @@ public String getByAddress(String address){ * 删除链接数据 * @param token {@link String} 用户标识 */ - public void deleteWs(String token){ + public static void deleteWs(String token){ maps.remove(token); } @@ -68,7 +68,7 @@ public void deleteWs(String token){ * 删除链接地址 * @param address */ - public void deleteAd(String address){ + public static void deleteAd(String address){ addMaps.remove(address); } @@ -76,7 +76,7 @@ public void deleteAd(String address){ * 获取链接数 * @return {@link Integer} 链接数 */ - public Integer getSize(){ + public static Integer getSize(){ return maps.size(); } @@ -85,7 +85,7 @@ public Integer getSize(){ * @param token {@link String} 用户标识 * @return {@link Boolean} 是否存在 */ - public boolean hasToken(String token){ + public static boolean hasToken(String token){ return maps.containsKey(token); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index f7575f0..cff29ea 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -12,17 +12,19 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Map; /** * Create by UncleCatMySelf in 2018/12/06 */ -@Slf4j @ChannelHandler.Sharable public class DefaultWebSocketHandler extends WebSocketHandler { + private final Logger log = LoggerFactory.getLogger(DefaultWebSocketHandler.class); + private final WebSocketHandlerApi webSocketHandlerApi; public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { @@ -72,10 +74,12 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { + log.info("[DefaultWebSocketHandler.channelActive]"+ctx.channel().remoteAddress().toString()+"链接成功"); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ + log.error("exception",cause); webSocketHandlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java index 007384e..6e9fb58 100644 --- a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java @@ -1,7 +1,6 @@ package com.github.unclecatmyself.common.properties; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; -import lombok.Data; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index f5ad2df..b8793c9 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,7 +1,8 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.Map; import java.util.concurrent.Future; @@ -9,9 +10,9 @@ /** * Created by MySelf on 2018/12/3. */ -@Slf4j public class DataAsynchronousTask { + private final Logger log = LoggerFactory.getLogger(DataAsynchronousTask.class); InChatToDataBaseService inChatToDataBaseService; diff --git a/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java new file mode 100644 index 0000000..cbdfd41 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java @@ -0,0 +1,21 @@ +package com.github.unclecatmyself.user; + +import com.alibaba.fastjson.JSONArray; +import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; + +/** + * Created by MySelf on 2018/12/19. + */ +public class InChatVerifyServiceImpl implements InChatVerifyService { + + @Override + public boolean verifyToken(String token) { + return true; + } + + @Override + public JSONArray getArrayByGroupId(String groupId) { + JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); + return jsonArray; + } +} diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..f690c90 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=firestorm.log + +log4j.appender.R.MaxFileSize=100KB +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n + +log4j.logger.com.codefutures=DEBUG \ No newline at end of file From 853b462401cd5e1690c1bd5b58724cb86c493c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Wed, 19 Dec 2018 14:32:43 +0800 Subject: [PATCH 102/151] =?UTF-8?q?=E7=A7=BB=E9=99=A4boot=E5=B9=B6?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E8=BF=90=E8=A1=8C=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 2 +- firestorm.log | 468 ++++++++++++++++++ .../channel/WebSocketHandlerService.java | 14 +- .../task/DataAsynchronousTask.java | 14 +- .../user/DataBaseServiceImpl.java | 17 + 5 files changed, 503 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 56ec8c5..beef494 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -15,5 +15,5 @@ * 【2018-12-14】 打包完成v1.0.0Maven版本,并提交说明文档与相关资料,正对v1.0.0提交对应demo分支。 * 【2018-12-15】 [录制V1.0.0使用说明视频](https://v.qq.com/x/page/i0813oy0lov.html) * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) -* 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息。 +* 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 diff --git a/firestorm.log b/firestorm.log index 40916dc..347d406 100644 --- a/firestorm.log +++ b/firestorm.log @@ -45,3 +45,471 @@ DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 12036 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33454链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x229d4369, L:/192.168.1.121:8090 - R:/192.168.1.121:33454] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: OBChivwmOuVGx47F/CiBVw==, response: weS+NhSjWHKJiSOsYlWcXalDokw= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) + at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) + at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +was thrown by a user handler's exceptionCaught() method while handling the following exception: +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 23412 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@12efe45a +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33519链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xdcd1018a, L:/192.168.1.121:8090 - R:/192.168.1.121:33519] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: RofVwS705IRh3Adu3hEyFA==, response: HZfm+0nxEXcf666dLUacJo6vqrU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) + at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) + at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +was thrown by a user handler's exceptionCaught() method while handling the following exception: +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 29824 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33825链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x7aed7702, L:/192.168.1.121:8090 - R:/192.168.1.121:33825] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 59U5AwAxQ8lzpvcEKpfhgQ==, response: SRYWk4ZBrm8oCh0hy5W+aChg1P0= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=64 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=49 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=77 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=81 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=80 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 5e868f4..dcc66a1 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -2,7 +2,9 @@ import com.alibaba.fastjson.JSONArray; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; +import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; +import com.github.unclecatmyself.user.InChatVerifyServiceImpl; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.WsChannelService; import com.github.unclecatmyself.common.utils.ConstansUtil; @@ -20,16 +22,16 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService { - InChatVerifyService inChatVerifyService; + private final InChatVerifyService inChatVerifyService = new InChatVerifyServiceImpl(); + private final InChatBackMapService inChatBackMapService = new InChatBackMapServiceImpl(); - InChatBackMapService inChatBackMapService; + private final WsChannelService websocketChannelService = new WebSocketChannelService(); + private final DataAsynchronousTask dataAsynchronousTask = new DataAsynchronousTask(); - WsChannelService websocketChannelService; - - - DataAsynchronousTask dataAsynchronousTask; + public WebSocketHandlerService() { + } @Override diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index b8793c9..e689475 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,11 +1,11 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.user.DataBaseServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Map; -import java.util.concurrent.Future; /** * Created by MySelf on 2018/12/3. @@ -14,13 +14,17 @@ public class DataAsynchronousTask { private final Logger log = LoggerFactory.getLogger(DataAsynchronousTask.class); - InChatToDataBaseService inChatToDataBaseService; + private final InChatToDataBaseService inChatToDataBaseService = new DataBaseServiceImpl(); - - public Future writeData(Map maps) throws Exception { + public void writeData(Map maps) throws Exception { log.info("【异步写入数据】"); // return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); - return null; + new Thread(new Runnable() { + @Override + public void run() { + inChatToDataBaseService.writeMapToDB(maps); + } + }).start(); } } diff --git a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java new file mode 100644 index 0000000..b48f9ea --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java @@ -0,0 +1,17 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; + +import java.util.Map; + +/** + * Created by MySelf on 2018/12/19. + */ +public class DataBaseServiceImpl implements InChatToDataBaseService{ + + @Override + public Boolean writeMapToDB(Map maps) { + System.out.println(maps.toString()); + return true; + } +} From 1f9245e0621f35dded42c1b8428f1f0e845e66be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Wed, 19 Dec 2018 14:34:41 +0800 Subject: [PATCH 103/151] log --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d96a516..02c7d81 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ * [V1.0.0版本使用说明](doc/version/v1.0.0.md) * [V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) +> 目前项目代码已经推进入了下一版本,如果你想下载这个版本的源码,可以到这里下载[V1.0.0-alpha](https://github.com/UncleCatMySelf/InChat/releases/tag/V1.0.0-alpha) + ``` From bdb97f398f36b96a480faf92844c7be52312e0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Wed, 19 Dec 2018 17:28:23 +0800 Subject: [PATCH 104/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E6=B6=88=E6=81=AFBean?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firestorm.log | 480 ++++++++++++++++++ .../github/unclecatmyself/Application.java | 2 +- .../unclecatmyself/auto/InitServer.java | 3 +- .../auto/ServerAutoConfigure.java | 13 +- .../bootstrap/AbstractBootstrapServer.java | 2 +- .../bootstrap/BootstrapServer.java | 2 +- .../bootstrap/NettyBootstrapServer.java | 2 +- .../channel/WebSocketHandlerService.java | 1 - .../data/InChatToDataBaseService.java | 4 +- .../handler/DefaultWebSocketHandler.java | 8 +- .../common/bean/InChatMessage.java | 92 ++++ .../{properties => bean}/InitNetty.java | 2 +- .../unclecatmyself/common/pool/Scheduled.java | 13 - .../common/utils/ConstansUtil.java | 2 + .../common/utils/MessageChangeUtil.java | 39 ++ .../common/utils/SpringBeanUtils.java | 42 -- .../unclecatmyself/common/utils/TimeUtil.java | 19 - .../task/DataAsynchronousTask.java | 5 +- .../unclecatmyself/task/ScheduledPool.java | 29 -- .../user/DataBaseServiceImpl.java | 5 +- 20 files changed, 635 insertions(+), 130 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java rename src/main/java/com/github/unclecatmyself/common/{properties => bean}/InitNetty.java (98%) delete mode 100644 src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java create mode 100644 src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java delete mode 100644 src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java delete mode 100644 src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java delete mode 100644 src/main/java/com/github/unclecatmyself/task/ScheduledPool.java diff --git a/firestorm.log b/firestorm.log index 347d406..b4221fd 100644 --- a/firestorm.log +++ b/firestorm.log @@ -513,3 +513,483 @@ DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - De DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=81 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=80 INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 34076 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6bd82a1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:34697链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xc4d62168, L:/192.168.1.121:8090 - R:/192.168.1.121:34697] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: qgEqz92Ioygmhk3gRdQQaw==, response: 7Pm7Izdtx2zCKE1xY6cJKnIT+og= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18512 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2966e252 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:35360链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x0cf6fdc3, L:/192.168.1.121:8090 - R:/192.168.1.121:35360] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 5rEmIyW1tsiWCuX2w0INNw==, response: nUOpghNJpNrSM/guWcgWALrkHGU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=43 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 17364 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@57e6b81e +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37659链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xd470a2b6, L:/192.168.1.121:8090 - R:/192.168.1.121:37659] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 46i6nomThnz0IoYa70QG/A==, response: PQriNOnfZMe0A+W13CLzRFFp1Ag= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 20876 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37750链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xa1dac098, L:/192.168.1.121:8090 - R:/192.168.1.121:37750] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 7aHAsYtx2ScKUSUOHKWMag==, response: 9Q9074/wnR89AErYj8WkqTuush4= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 39208 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动失败【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=2 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=8 length=2 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37820链接成功 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xbdf6f285, L:/192.168.1.121:8090 - R:/192.168.1.121:37820] WebSocket version V13 server handshake +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: mjD3d333VWLm5zYERDk7lA==, response: 4tGH4E8jCi592zyrnYNhiFdffRU= +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_2 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 26864 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@a1cc7eb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37946链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x32ec9d73, L:/192.168.1.121:8090 - R:/192.168.1.121:37946] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: TM5+FgH97iB/bsupfniAXA==, response: YGdbMj80V5OQOtNAR/Z4ZhoN9z0= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 11772 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37971链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xf42ac2f4, L:/192.168.1.121:8090 - R:/192.168.1.121:37971] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: C4cY2+cPopV14ZhOdZzvWg==, response: lgeUcarZO/rCKPbEtAnaBFCAsbc= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java index 40762e9..6e3982a 100644 --- a/src/main/java/com/github/unclecatmyself/Application.java +++ b/src/main/java/com/github/unclecatmyself/Application.java @@ -1,7 +1,7 @@ package com.github.unclecatmyself; import com.github.unclecatmyself.auto.InitServer; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; /** * Created by MySelf on 2018/12/18. diff --git a/src/main/java/com/github/unclecatmyself/auto/InitServer.java b/src/main/java/com/github/unclecatmyself/auto/InitServer.java index ff36e39..9519d6e 100644 --- a/src/main/java/com/github/unclecatmyself/auto/InitServer.java +++ b/src/main/java/com/github/unclecatmyself/auto/InitServer.java @@ -3,7 +3,7 @@ import com.github.unclecatmyself.bootstrap.BootstrapServer; import com.github.unclecatmyself.bootstrap.NettyBootstrapServer; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; /** * Create by UncleCatMySelf in 2018/12/06 @@ -26,7 +26,6 @@ public void open(){ } } - public void close(){ if(bootstrapServer!=null){ bootstrapServer.shutdown(); diff --git a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java index 9b03a48..1c40e74 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.auto; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; import org.apache.commons.lang3.ObjectUtils; @@ -24,17 +24,6 @@ public ServerAutoConfigure(){ } -// @Bean -// @ConditionalOnMissingBean(name = "sacnScheduled") -// public ScanRunnable initRunable(@Autowired InitNetty serverBean){ -// long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod(); -// ScanRunnable sacnScheduled = new SacnScheduled(time); -// Thread scanRunnable = new Thread(sacnScheduled); -// scanRunnable.setDaemon(true); -// scanRunnable.start(); -// return sacnScheduled; -// } - public InitServer initServer(InitNetty serverBean){ if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ throw new NullPointerException("not set port"); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 691a623..c5f207b 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -3,7 +3,7 @@ import com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java index b55aeca..00c36fa 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/BootstrapServer.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.bootstrap; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; /** * Create by UncleCatMySelf in 2018/12/06 diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index 4a5ec17..d286b84 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -1,7 +1,7 @@ package com.github.unclecatmyself.bootstrap; import com.github.unclecatmyself.common.ip.IpUtils; -import com.github.unclecatmyself.common.properties.InitNetty; +import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.common.utils.RemotingUtil; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index dcc66a1..b43fb1a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -21,7 +21,6 @@ */ public class WebSocketHandlerService extends ServerWebSocketHandlerService { - private final InChatVerifyService inChatVerifyService = new InChatVerifyServiceImpl(); private final InChatBackMapService inChatBackMapService = new InChatBackMapServiceImpl(); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java index 76b5c8f..937fa69 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java @@ -1,5 +1,7 @@ package com.github.unclecatmyself.bootstrap.data; +import com.github.unclecatmyself.common.bean.InChatMessage; + import java.util.Map; /** @@ -7,6 +9,6 @@ */ public interface InChatToDataBaseService { - Boolean writeMapToDB(Map maps); + Boolean writeMapToDB(InChatMessage message); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index cff29ea..925baaa 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -2,7 +2,6 @@ import com.alibaba.fastjson.JSON; import com.github.unclecatmyself.common.exception.NoFindHandlerException; -import com.github.unclecatmyself.common.utils.TimeUtil; import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; import com.github.unclecatmyself.common.websockets.WebSocketHandler; import com.github.unclecatmyself.common.utils.ConstansUtil; @@ -15,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; import java.util.Map; /** @@ -47,23 +47,27 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) throw new NoFindHandlerException("Server Handler 不匹配"); } Map maps = (Map) JSON.parse(msg.text()); - maps.put("time", TimeUtil.getTime()); + maps.put("time", new Date()); switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: + log.info("[DefaultWebSocketHandler.textdoMessage.LOGIN]"); serverWebSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: + log.info("[DefaultWebSocketHandler.textdoMessage.SENDME]"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: + log.info("[DefaultWebSocketHandler.textdoMessage.SENDTO]"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: + log.info("[DefaultWebSocketHandler.textdoMessage.SENDGROUP]"); serverWebSocketHandlerService.verify(channel,maps); serverWebSocketHandlerService.sendGroupText(channel,maps); break; diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java new file mode 100644 index 0000000..97cda1b --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java @@ -0,0 +1,92 @@ +package com.github.unclecatmyself.common.bean; + +import java.util.Date; + +/** + * Created by MySelf on 2018/12/19. + */ +public class InChatMessage { + + private Date time; + + private String type; + + private String value; + + private String token; + + private String groudId; + + private String online; + + private String one; + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getGroudId() { + return groudId; + } + + public void setGroudId(String groudId) { + this.groudId = groudId; + } + + public String getOnline() { + return online; + } + + public void setOnline(String online) { + this.online = online; + } + + public String getOne() { + return one; + } + + public void setOne(String one) { + this.one = one; + } + + @Override + public String toString() { + return "InChatMessage{" + + "time=" + time + + ", type='" + type + '\'' + + ", value='" + value + '\'' + + ", token='" + token + '\'' + + ", groudId='" + groudId + '\'' + + ", online='" + online + '\'' + + ", one='" + one + '\'' + + '}'; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java similarity index 98% rename from src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java rename to src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java index 6e9fb58..80f14a8 100644 --- a/src/main/java/com/github/unclecatmyself/common/properties/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java @@ -1,4 +1,4 @@ -package com.github.unclecatmyself.common.properties; +package com.github.unclecatmyself.common.bean; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; diff --git a/src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java b/src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java deleted file mode 100644 index 054a9a1..0000000 --- a/src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.github.unclecatmyself.common.pool; - -import java.util.concurrent.ScheduledFuture; - -/** - * Create by UncleCatMySelf in 2018/12/06 - **/ -@FunctionalInterface -public interface Scheduled { - - ScheduledFuture submit(Runnable runnable); - -} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java index 9accd0c..a1cfcb7 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java @@ -32,4 +32,6 @@ public class ConstansUtil { public static final String FROM = "from"; public static final String SENDGROUP = "sendGroup"; + + public static final String TIME = "time"; } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java new file mode 100644 index 0000000..373f214 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java @@ -0,0 +1,39 @@ +package com.github.unclecatmyself.common.utils; + +import com.github.unclecatmyself.common.bean.InChatMessage; + +import java.util.Date; +import java.util.Map; + +/** + * Created by MySelf on 2018/12/19. + */ +public class MessageChangeUtil { + + public static InChatMessage Change(Map maps){ + InChatMessage message = new InChatMessage(); + if (maps.containsKey(ConstansUtil.TOKEN)){ + message.setToken((String) maps.get(ConstansUtil.TOKEN)); + } + if (maps.containsKey(ConstansUtil.TIME)){ + message.setTime((Date) maps.get(ConstansUtil.TIME)); + } + if (maps.containsKey(ConstansUtil.VALUE)){ + message.setValue((String)maps.get(ConstansUtil.VALUE)); + } + if (maps.containsKey(ConstansUtil.TYPE)){ + message.setType((String)maps.get(ConstansUtil.TYPE)); + } + if (maps.containsKey(ConstansUtil.ONE)){ + message.setOne((String)maps.get(ConstansUtil.ONE)); + } + if (maps.containsKey(ConstansUtil.GROUPID)){ + message.setGroudId((String)maps.get(ConstansUtil.GROUPID)); + } + if (maps.containsKey(ConstansUtil.ON_ONLINE)){ + message.setOnline((String)maps.get(ConstansUtil.ON_ONLINE)); + } + return message; + } + +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java b/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java deleted file mode 100644 index 3fce766..0000000 --- a/src/main/java/com/github/unclecatmyself/common/utils/SpringBeanUtils.java +++ /dev/null @@ -1,42 +0,0 @@ -//package com.github.unclecatmyself.common.utils; -// -//import org.springframework.beans.BeansException; -//import org.springframework.context.ApplicationContext; -//import org.springframework.context.ApplicationContextAware; -//import org.springframework.stereotype.Component; -// -///** -// * Create by UncleCatMySelf in 2018/12/06 -// **/ -//public class SpringBeanUtils implements ApplicationContextAware { -// -// private static ApplicationContext applicationContext; -// -// @Override -// public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { -// if (SpringBeanUtils.applicationContext == null){ -// SpringBeanUtils.applicationContext = applicationContext; -// } -// } -// -// //获取applicationContext -// public static ApplicationContext getApplicationContext() { -// return applicationContext; -// } -// -// //通过name获取 Bean. -// public static Object getBean(String name){ -// return getApplicationContext().getBean(name); -// } -// -// //通过class获取Bean. -// public static T getBean(Class clazz){ -// return getApplicationContext().getBean(clazz); -// } -// -// //通过name,以及Clazz返回指定的Bean -// public static T getBean(String name,Class clazz){ -// return getApplicationContext().getBean(name, clazz); -// } -// -//} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java deleted file mode 100644 index 7294874..0000000 --- a/src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.unclecatmyself.common.utils; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Created by MySelf on 2018/12/7. - */ -public class TimeUtil { - - private final static String format = "yyyy-MM-dd HH:mm:ss"; - - public static String getTime(){ - Date date = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat(format); - return dateFormat.format(date); - } - -} diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index e689475..a834e57 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,6 +1,8 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.bean.InChatMessage; +import com.github.unclecatmyself.common.utils.MessageChangeUtil; import com.github.unclecatmyself.user.DataBaseServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,11 +20,10 @@ public class DataAsynchronousTask { public void writeData(Map maps) throws Exception { log.info("【异步写入数据】"); -// return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps)); new Thread(new Runnable() { @Override public void run() { - inChatToDataBaseService.writeMapToDB(maps); + inChatToDataBaseService.writeMapToDB(MessageChangeUtil.Change(maps)); } }).start(); } diff --git a/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java b/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java deleted file mode 100644 index 607a861..0000000 --- a/src/main/java/com/github/unclecatmyself/task/ScheduledPool.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.unclecatmyself.task; - -import com.github.unclecatmyself.common.pool.Scheduled; -import com.github.unclecatmyself.common.properties.InitNetty; - -import java.util.concurrent.*; - - -/** - * Create by UncleCatMySelf in 2018/12/06 - **/ -public class ScheduledPool implements Scheduled { - - private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(20); - - private final InitNetty serverBean; - - public ScheduledPool(InitNetty serverBean) { - this.serverBean = serverBean; - } - - @Override - public ScheduledFuture submit(Runnable runnable) { - int initalDelay = serverBean.getInitalDelay(); - int period = serverBean.getPeriod(); - return scheduledExecutorService.scheduleAtFixedRate(runnable, initalDelay, period, TimeUnit.SECONDS); - } - -} diff --git a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java index b48f9ea..4dc8fc8 100644 --- a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.user; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.bean.InChatMessage; import java.util.Map; @@ -10,8 +11,8 @@ public class DataBaseServiceImpl implements InChatToDataBaseService{ @Override - public Boolean writeMapToDB(Map maps) { - System.out.println(maps.toString()); + public Boolean writeMapToDB(InChatMessage message) { + System.out.println(message.toString()); return true; } } From 981b43ffb0ec630acb2442c8a700351b582cf506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 10:25:47 +0800 Subject: [PATCH 105/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firestorm.log | 741 +----------- firestorm.log.1 | 1007 +++++++++++++++++ .../github/unclecatmyself/Application.java | 6 + .../unclecatmyself/auto/ConfigFactory.java | 31 + .../bootstrap/AbstractBootstrapServer.java | 4 +- .../channel/WebSocketHandlerService.java | 8 +- .../websockets/WebSocketHandlerApi.java | 1 + .../task/DataAsynchronousTask.java | 6 +- 8 files changed, 1088 insertions(+), 716 deletions(-) create mode 100644 firestorm.log.1 create mode 100644 src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java diff --git a/firestorm.log b/firestorm.log index b4221fd..1ea81eb 100644 --- a/firestorm.log +++ b/firestorm.log @@ -1,62 +1,3 @@ -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 19968 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available @@ -82,7 +23,7 @@ DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTr DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 12036 (auto-detected) +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 31304 (auto-detected) DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) @@ -92,157 +33,6 @@ DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33454链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x229d4369, L:/192.168.1.121:8090 - R:/192.168.1.121:33454] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: OBChivwmOuVGx47F/CiBVw==, response: weS+NhSjWHKJiSOsYlWcXalDokw= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) - at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) - at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -was thrown by a user handler's exceptionCaught() method while handling the following exception: -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false @@ -280,7 +70,7 @@ DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTr DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 23412 (auto-detected) +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18804 (auto-detected) DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) @@ -292,21 +82,22 @@ DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@12efe45a -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33519链接成功 +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2393b7e4 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:57252链接成功 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xdcd1018a, L:/192.168.1.121:8090 - R:/192.168.1.121:33519] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: RofVwS705IRh3Adu3hEyFA==, response: HZfm+0nxEXcf666dLUacJo6vqrU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x008fdee1, L:/192.168.1.121:8090 - R:/192.168.1.121:57252] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: JChFkxTAVPiDnQ2PSrSpHg==, response: KGtOaNLwJbPissBkzdTNvR2XlvM= DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:125) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:41) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:54) at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) @@ -350,8 +141,12 @@ java.lang.NullPointerException at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) at java.lang.Thread.run(Thread.java:745) DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) + at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) + at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) + at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) + at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:137) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:87) at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) @@ -396,9 +191,9 @@ DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java. at java.lang.Thread.run(Thread.java:745) was thrown by a user handler's exceptionCaught() method while handling the following exception: java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:125) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:41) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:54) at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) @@ -478,7 +273,7 @@ DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTr DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 29824 (auto-detected) +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 21052 (auto-detected) DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) @@ -490,506 +285,30 @@ DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33825链接成功 +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1fa2b12a +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:57280链接成功 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x7aed7702, L:/192.168.1.121:8090 - R:/192.168.1.121:33825] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 59U5AwAxQ8lzpvcEKpfhgQ==, response: SRYWk4ZBrm8oCh0hy5W+aChg1P0= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=64 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=49 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=77 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=81 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=80 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 34076 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6bd82a1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:34697链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xc4d62168, L:/192.168.1.121:8090 - R:/192.168.1.121:34697] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: qgEqz92Ioygmhk3gRdQQaw==, response: 7Pm7Izdtx2zCKE1xY6cJKnIT+og= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18512 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2966e252 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:35360链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x0cf6fdc3, L:/192.168.1.121:8090 - R:/192.168.1.121:35360] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 5rEmIyW1tsiWCuX2w0INNw==, response: nUOpghNJpNrSM/guWcgWALrkHGU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x25814987, L:/192.168.1.121:8090 - R:/192.168.1.121:57280] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: /ChZBkLNT63GqXEvj1vW6w==, response: I7J2YmNfzfwFbgDYmkC1Tir1OD0= DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=43 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 17364 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@57e6b81e -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37659链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xd470a2b6, L:/192.168.1.121:8090 - R:/192.168.1.121:37659] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 46i6nomThnz0IoYa70QG/A==, response: PQriNOnfZMe0A+W13CLzRFFp1Ag= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 20876 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37750链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xa1dac098, L:/192.168.1.121:8090 - R:/192.168.1.121:37750] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 7aHAsYtx2ScKUSUOHKWMag==, response: 9Q9074/wnR89AErYj8WkqTuush4= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 39208 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动失败【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=2 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=8 length=2 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37820链接成功 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xbdf6f285, L:/192.168.1.121:8090 - R:/192.168.1.121:37820] WebSocket version V13 server handshake -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: mjD3d333VWLm5zYERDk7lA==, response: 4tGH4E8jCi592zyrnYNhiFdffRU= -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_2 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 26864 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@a1cc7eb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37946链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x32ec9d73, L:/192.168.1.121:8090 - R:/192.168.1.121:37946] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: TM5+FgH97iB/bsupfniAXA==, response: YGdbMj80V5OQOtNAR/Z4ZhoN9z0= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 11772 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37971链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xf42ac2f4, L:/192.168.1.121:8090 - R:/192.168.1.121:37971] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: C4cY2+cPopV14ZhOdZzvWg==, response: lgeUcarZO/rCKPbEtAnaBFCAsbc= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=56 INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=41 INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=60 INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=59 INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 diff --git a/firestorm.log.1 b/firestorm.log.1 new file mode 100644 index 0000000..2d6e174 --- /dev/null +++ b/firestorm.log.1 @@ -0,0 +1,1007 @@ +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 19968 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 12036 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33454链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x229d4369, L:/192.168.1.121:8090 - R:/192.168.1.121:33454] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: OBChivwmOuVGx47F/CiBVw==, response: weS+NhSjWHKJiSOsYlWcXalDokw= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) + at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) + at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +was thrown by a user handler's exceptionCaught() method while handling the following exception: +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 23412 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@12efe45a +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33519链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xdcd1018a, L:/192.168.1.121:8090 - R:/192.168.1.121:33519] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: RofVwS705IRh3Adu3hEyFA==, response: HZfm+0nxEXcf666dLUacJo6vqrU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) + at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) + at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +was thrown by a user handler's exceptionCaught() method while handling the following exception: +java.lang.NullPointerException + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 29824 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33825链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x7aed7702, L:/192.168.1.121:8090 - R:/192.168.1.121:33825] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 59U5AwAxQ8lzpvcEKpfhgQ==, response: SRYWk4ZBrm8oCh0hy5W+aChg1P0= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=64 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=49 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=77 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=81 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=80 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 34076 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6bd82a1 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:34697链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xc4d62168, L:/192.168.1.121:8090 - R:/192.168.1.121:34697] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: qgEqz92Ioygmhk3gRdQQaw==, response: 7Pm7Izdtx2zCKE1xY6cJKnIT+og= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18512 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2966e252 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:35360链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x0cf6fdc3, L:/192.168.1.121:8090 - R:/192.168.1.121:35360] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 5rEmIyW1tsiWCuX2w0INNw==, response: nUOpghNJpNrSM/guWcgWALrkHGU= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=43 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 17364 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@57e6b81e +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37659链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xd470a2b6, L:/192.168.1.121:8090 - R:/192.168.1.121:37659] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 46i6nomThnz0IoYa70QG/A==, response: PQriNOnfZMe0A+W13CLzRFFp1Ag= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 20876 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37750链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xa1dac098, L:/192.168.1.121:8090 - R:/192.168.1.121:37750] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 7aHAsYtx2ScKUSUOHKWMag==, response: 9Q9074/wnR89AErYj8WkqTuush4= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 39208 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动失败【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=2 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=8 length=2 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37820链接成功 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xbdf6f285, L:/192.168.1.121:8090 - R:/192.168.1.121:37820] WebSocket version V13 server handshake +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: mjD3d333VWLm5zYERDk7lA==, response: 4tGH4E8jCi592zyrnYNhiFdffRU= +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_2 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 26864 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@a1cc7eb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37946链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x32ec9d73, L:/192.168.1.121:8090 - R:/192.168.1.121:37946] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: TM5+FgH97iB/bsupfniAXA==, response: YGdbMj80V5OQOtNAR/Z4ZhoN9z0= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 11772 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37971链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xf42ac2f4, L:/192.168.1.121:8090 - R:/192.168.1.121:37971] WebSocket version V13 server handshake +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: C4cY2+cPopV14ZhOdZzvWg==, response: lgeUcarZO/rCKPbEtAnaBFCAsbc= +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] +DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 +INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java index 6e3982a..1d078e8 100644 --- a/src/main/java/com/github/unclecatmyself/Application.java +++ b/src/main/java/com/github/unclecatmyself/Application.java @@ -1,7 +1,10 @@ package com.github.unclecatmyself; +import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.auto.InitServer; import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.user.DataBaseServiceImpl; +import com.github.unclecatmyself.user.InChatVerifyServiceImpl; /** * Created by MySelf on 2018/12/18. @@ -10,6 +13,9 @@ public class Application { public static void main(String[] args) { //注册InChat相关配置 + ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); + ConfigFactory.inChatVerifyService = new InChatVerifyServiceImpl(); + InitServer initServer = new InitServer(new InitNetty()); initServer.open(); //预制InChat的用户接口 diff --git a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java new file mode 100644 index 0000000..c9f9794 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java @@ -0,0 +1,31 @@ +package com.github.unclecatmyself.auto; + +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; + +/** + * 默认配置工厂 + * Created by MySelf on 2018/12/21. + */ +public class ConfigFactory { + + public static InChatVerifyService inChatVerifyService; + + public static InChatToDataBaseService inChatToDataBaseService; + + public InChatVerifyService getInChatVerifyService() { + return inChatVerifyService; + } + + public void setInChatVerifyService(InChatVerifyService inChatVerifyService) { + this.inChatVerifyService = inChatVerifyService; + } + + public InChatToDataBaseService getInChatToDataBaseService() { + return inChatToDataBaseService; + } + + public void setInChatToDataBaseService(InChatToDataBaseService inChatToDataBaseService) { + this.inChatToDataBaseService = inChatToDataBaseService; + } +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index c5f207b..3709f82 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -1,9 +1,11 @@ package com.github.unclecatmyself.bootstrap; +import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; @@ -23,7 +25,7 @@ public abstract class AbstractBootstrapServer implements BootstrapServer { protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ intProtocolHandler(channelPipeline,serverBean); channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerService())); + channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerService(new DataAsynchronousTask(ConfigFactory.inChatToDataBaseService),ConfigFactory.inChatVerifyService))); } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index b43fb1a..dec32ca 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -21,15 +21,17 @@ */ public class WebSocketHandlerService extends ServerWebSocketHandlerService { - private final InChatVerifyService inChatVerifyService = new InChatVerifyServiceImpl(); + private final InChatVerifyService inChatVerifyService; private final InChatBackMapService inChatBackMapService = new InChatBackMapServiceImpl(); private final WsChannelService websocketChannelService = new WebSocketChannelService(); - private final DataAsynchronousTask dataAsynchronousTask = new DataAsynchronousTask(); + private final DataAsynchronousTask dataAsynchronousTask; - public WebSocketHandlerService() { + public WebSocketHandlerService(DataAsynchronousTask dataAsynchronousTask,InChatVerifyService inChatVerifyService) { + this.dataAsynchronousTask = dataAsynchronousTask; + this.inChatVerifyService = inChatVerifyService; } diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java index 7aadde9..b6bc225 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -10,6 +10,7 @@ */ public interface WebSocketHandlerApi { + void close(Channel channel); void sendMeText(Channel channel, Map maps); diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index a834e57..c8f6c81 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -16,7 +16,11 @@ public class DataAsynchronousTask { private final Logger log = LoggerFactory.getLogger(DataAsynchronousTask.class); - private final InChatToDataBaseService inChatToDataBaseService = new DataBaseServiceImpl(); + private final InChatToDataBaseService inChatToDataBaseService; + + public DataAsynchronousTask(InChatToDataBaseService inChatToDataBaseService){ + this.inChatToDataBaseService = inChatToDataBaseService; + } public void writeData(Map maps) throws Exception { log.info("【异步写入数据】"); From 12d7ae3f0a97b643ed200a18e8ccb36ad4956a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 10:27:29 +0800 Subject: [PATCH 106/151] log --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index beef494..a8133a1 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -16,4 +16,4 @@ * 【2018-12-15】 [录制V1.0.0使用说明视频](https://v.qq.com/x/page/i0813oy0lov.html) * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) * 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 - +* 【2018-12-21】 添加静态配置 From 1a0455dbeee615516fd174480f5a4e9079348380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 10:29:03 +0800 Subject: [PATCH 107/151] =?UTF-8?q?=E7=A7=BB=E9=99=A4log=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 6 +- firestorm.log | 314 --------------- firestorm.log.1 | 1007 ----------------------------------------------- 3 files changed, 5 insertions(+), 1322 deletions(-) delete mode 100644 firestorm.log delete mode 100644 firestorm.log.1 diff --git a/.gitignore b/.gitignore index 82eca33..421462b 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,8 @@ /nbbuild/ /dist/ /nbdist/ -/.nb-gradle/ \ No newline at end of file +/.nb-gradle/ + +### log ### + +*.log \ No newline at end of file diff --git a/firestorm.log b/firestorm.log deleted file mode 100644 index 1ea81eb..0000000 --- a/firestorm.log +++ /dev/null @@ -1,314 +0,0 @@ -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 31304 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18804 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2393b7e4 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:57252链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x008fdee1, L:/192.168.1.121:8090 - R:/192.168.1.121:57252] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: JChFkxTAVPiDnQ2PSrSpHg==, response: KGtOaNLwJbPissBkzdTNvR2XlvM= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:125) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:41) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:54) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) - at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) - at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) - at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:137) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:87) - at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) - at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -was thrown by a user handler's exceptionCaught() method while handling the following exception: -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:125) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:41) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:54) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 21052 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1fa2b12a -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:57280链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x25814987, L:/192.168.1.121:8090 - R:/192.168.1.121:57280] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: /ChZBkLNT63GqXEvj1vW6w==, response: I7J2YmNfzfwFbgDYmkC1Tir1OD0= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=43 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=56 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=41 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=60 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=59 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 diff --git a/firestorm.log.1 b/firestorm.log.1 deleted file mode 100644 index 2d6e174..0000000 --- a/firestorm.log.1 +++ /dev/null @@ -1,1007 +0,0 @@ -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 19968 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 12036 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33454链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x229d4369, L:/192.168.1.121:8090 - R:/192.168.1.121:33454] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: OBChivwmOuVGx47F/CiBVw==, response: weS+NhSjWHKJiSOsYlWcXalDokw= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) - at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) - at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -was thrown by a user handler's exceptionCaught() method while handling the following exception: -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 23412 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@12efe45a -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33519链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xdcd1018a, L:/192.168.1.121:8090 - R:/192.168.1.121:33519] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: RofVwS705IRh3Adu3hEyFA==, response: HZfm+0nxEXcf666dLUacJo6vqrU= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:134) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:83) - at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) - at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -was thrown by a user handler's exceptionCaught() method while handling the following exception: -java.lang.NullPointerException - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.check(WebSocketHandlerService.java:122) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.login(WebSocketHandlerService.java:38) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.textdoMessage(DefaultWebSocketHandler.java:53) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelRead0(WebSocketHandler.java:22) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:211) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 29824 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@217951b1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:33825链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x7aed7702, L:/192.168.1.121:8090 - R:/192.168.1.121:33825] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 59U5AwAxQ8lzpvcEKpfhgQ==, response: SRYWk4ZBrm8oCh0hy5W+aChg1P0= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=64 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=49 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=77 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=81 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=80 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 34076 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6bd82a1 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:34697链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xc4d62168, L:/192.168.1.121:8090 - R:/192.168.1.121:34697] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: qgEqz92Ioygmhk3gRdQQaw==, response: 7Pm7Izdtx2zCKE1xY6cJKnIT+og= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 18512 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2966e252 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:35360链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x0cf6fdc3, L:/192.168.1.121:8090 - R:/192.168.1.121:35360] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 5rEmIyW1tsiWCuX2w0INNw==, response: nUOpghNJpNrSM/guWcgWALrkHGU= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=43 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=28 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 17364 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@57e6b81e -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37659链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xd470a2b6, L:/192.168.1.121:8090 - R:/192.168.1.121:37659] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 46i6nomThnz0IoYa70QG/A==, response: PQriNOnfZMe0A+W13CLzRFFp1Ag= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 20876 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37750链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xa1dac098, L:/192.168.1.121:8090 - R:/192.168.1.121:37750] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: 7aHAsYtx2ScKUSUOHKWMag==, response: 9Q9074/wnR89AErYj8WkqTuush4= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 39208 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动失败【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=2 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=8 length=2 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37820链接成功 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xbdf6f285, L:/192.168.1.121:8090 - R:/192.168.1.121:37820] WebSocket version V13 server handshake -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: mjD3d333VWLm5zYERDk7lA==, response: 4tGH4E8jCi592zyrnYNhiFdffRU= -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_2 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_2 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 26864 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@a1cc7eb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37946链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0x32ec9d73, L:/192.168.1.121:8090 - R:/192.168.1.121:37946] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: TM5+FgH97iB/bsupfniAXA==, response: YGdbMj80V5OQOtNAR/Z4ZhoN9z0= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 11772 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@e716aa8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:37971链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - [id: 0xf42ac2f4, L:/192.168.1.121:8090 - R:/192.168.1.121:37971] WebSocket version V13 server handshake -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker - WebSocket version 13 server handshake key: C4cY2+cPopV14ZhOdZzvWg==, response: lgeUcarZO/rCKPbEtAnaBFCAsbc= -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=31 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.LOGIN] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=33 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=46 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDME] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=31 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=59 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDTO] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=44 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame opCode=1 -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder - Decoding WebSocket Frame length=63 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.textdoMessage.SENDGROUP] -DEBUG WORK_1 io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder - Encoding WebSocket Frame opCode=1 length=62 -INFO WORK_1 com.github.unclecatmyself.task.DataAsynchronousTask - 【异步写入数据】 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true From 9c7f765837d5ee9641f6accc6c527b6979e845b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 10:39:27 +0800 Subject: [PATCH 108/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BD=AC=E5=9E=8BBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/WebSocketHandlerService.java | 2 +- .../unclecatmyself/common/bean/InChatMessage.java | 14 ++++++++++++++ .../unclecatmyself/common/utils/ConstansUtil.java | 2 ++ .../common/utils/MessageChangeUtil.java | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index dec32ca..8129f3a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -98,7 +98,7 @@ public void sendGroupText(Channel channel, Map maps) { } } } - maps.put(ConstansUtil.ON_ONLINE,no_online); + maps.put(ConstansUtil.ONLINE_GROUP,no_online); try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java index 97cda1b..18b7ede 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java @@ -1,5 +1,8 @@ package com.github.unclecatmyself.common.bean; +import com.alibaba.fastjson.JSONArray; + +import java.util.ArrayList; import java.util.Date; /** @@ -19,8 +22,18 @@ public class InChatMessage { private String online; + private ArrayList onlineGroup; + private String one; + public ArrayList getOnlineGroup() { + return onlineGroup; + } + + public void setOnlineGroup(ArrayList onlineGroup) { + this.onlineGroup = onlineGroup; + } + public Date getTime() { return time; } @@ -86,6 +99,7 @@ public String toString() { ", token='" + token + '\'' + ", groudId='" + groudId + '\'' + ", online='" + online + '\'' + + ", onlineGroup=" + onlineGroup + ", one='" + one + '\'' + '}'; } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java index a1cfcb7..64b9915 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java @@ -13,6 +13,8 @@ public class ConstansUtil { public static final String ON_ONLINE = "on_online"; + public static final String ONLINE_GROUP = "online_group"; + public static final String GROUPID = "groupId"; public static final String TYPE = "type"; diff --git a/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java index 373f214..48f1371 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/MessageChangeUtil.java @@ -2,6 +2,7 @@ import com.github.unclecatmyself.common.bean.InChatMessage; +import java.util.ArrayList; import java.util.Date; import java.util.Map; @@ -33,6 +34,9 @@ public static InChatMessage Change(Map maps){ if (maps.containsKey(ConstansUtil.ON_ONLINE)){ message.setOnline((String)maps.get(ConstansUtil.ON_ONLINE)); } + if (maps.containsKey(ConstansUtil.ONLINE_GROUP)){ + message.setOnlineGroup((ArrayList)maps.get(ConstansUtil.ONLINE_GROUP)); + } return message; } From 65421747091f861b0263085a1315e68aec10e7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 10:52:56 +0800 Subject: [PATCH 109/151] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/unclecatmyself/Application.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java index 1d078e8..82f13c7 100644 --- a/src/main/java/com/github/unclecatmyself/Application.java +++ b/src/main/java/com/github/unclecatmyself/Application.java @@ -2,9 +2,15 @@ import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.auto.InitServer; +import com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService; import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.user.DataBaseServiceImpl; import com.github.unclecatmyself.user.InChatVerifyServiceImpl; +import io.netty.channel.Channel; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; /** * Created by MySelf on 2018/12/18. @@ -12,16 +18,32 @@ public class Application { public static void main(String[] args) { - //注册InChat相关配置 + //配置InChat配置工厂 ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); ConfigFactory.inChatVerifyService = new InChatVerifyServiceImpl(); - + //默认启动InChat InitServer initServer = new InitServer(new InitNetty()); initServer.open(); - //预制InChat的用户接口 - //启动InChat流程 - + //获取用户值 + WebSocketChannelService webSocketChannelService = new WebSocketChannelService(); + + //启动新线程 + new Thread(new Runnable() { + @Override + public void run() { + //设定默认服务器发送值 + Map map = new HashMap<>(); + map.put("server","服务器"); + //获取控制台用户想发送的用户Token + Scanner scanner = new Scanner(System.in); + String token = scanner.nextLine(); + //获取用户连接 + Channel channel = (Channel) webSocketChannelService.getChannel(token); + //调用接口发送 + webSocketChannelService.sendFromServer(channel,map); + } + }).start(); } From 726e64e768c88cee42e280edbddb524baaf91364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 13:57:49 +0800 Subject: [PATCH 110/151] =?UTF-8?q?=E6=95=B4=E5=90=88=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/unclecatmyself/Application.java | 50 ------------------- .../user/DataBaseServiceImpl.java | 18 ------- .../user/InChatVerifyServiceImpl.java | 21 -------- 3 files changed, 89 deletions(-) delete mode 100644 src/main/java/com/github/unclecatmyself/Application.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java diff --git a/src/main/java/com/github/unclecatmyself/Application.java b/src/main/java/com/github/unclecatmyself/Application.java deleted file mode 100644 index 82f13c7..0000000 --- a/src/main/java/com/github/unclecatmyself/Application.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.unclecatmyself; - -import com.github.unclecatmyself.auto.ConfigFactory; -import com.github.unclecatmyself.auto.InitServer; -import com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService; -import com.github.unclecatmyself.common.bean.InitNetty; -import com.github.unclecatmyself.user.DataBaseServiceImpl; -import com.github.unclecatmyself.user.InChatVerifyServiceImpl; -import io.netty.channel.Channel; - -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; - -/** - * Created by MySelf on 2018/12/18. - */ -public class Application { - - public static void main(String[] args) { - //配置InChat配置工厂 - ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); - ConfigFactory.inChatVerifyService = new InChatVerifyServiceImpl(); - //默认启动InChat - InitServer initServer = new InitServer(new InitNetty()); - initServer.open(); - - //获取用户值 - WebSocketChannelService webSocketChannelService = new WebSocketChannelService(); - - //启动新线程 - new Thread(new Runnable() { - @Override - public void run() { - //设定默认服务器发送值 - Map map = new HashMap<>(); - map.put("server","服务器"); - //获取控制台用户想发送的用户Token - Scanner scanner = new Scanner(System.in); - String token = scanner.nextLine(); - //获取用户连接 - Channel channel = (Channel) webSocketChannelService.getChannel(token); - //调用接口发送 - webSocketChannelService.sendFromServer(channel,map); - } - }).start(); - - } - -} diff --git a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java deleted file mode 100644 index 4dc8fc8..0000000 --- a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import com.github.unclecatmyself.common.bean.InChatMessage; - -import java.util.Map; - -/** - * Created by MySelf on 2018/12/19. - */ -public class DataBaseServiceImpl implements InChatToDataBaseService{ - - @Override - public Boolean writeMapToDB(InChatMessage message) { - System.out.println(message.toString()); - return true; - } -} diff --git a/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java deleted file mode 100644 index cbdfd41..0000000 --- a/src/main/java/com/github/unclecatmyself/user/InChatVerifyServiceImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.alibaba.fastjson.JSONArray; -import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; - -/** - * Created by MySelf on 2018/12/19. - */ -public class InChatVerifyServiceImpl implements InChatVerifyService { - - @Override - public boolean verifyToken(String token) { - return true; - } - - @Override - public JSONArray getArrayByGroupId(String groupId) { - JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); - return jsonArray; - } -} From 0037e736978e67102734e6d2558e2fb0f8bb1ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 13:59:14 +0800 Subject: [PATCH 111/151] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9fee722..bd40b76 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.UncleCatMySelf InChat - 1.0-alpha + 1.1.0-alpha From a377a66ddd3767983e97dae859dd22b38893758f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 21 Dec 2018 14:09:26 +0800 Subject: [PATCH 112/151] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 3 ++- .../bootstrap/channel/WebSocketHandlerService.java | 1 - .../com/github/unclecatmyself/task/DataAsynchronousTask.java | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index a8133a1..fd0e487 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -16,4 +16,5 @@ * 【2018-12-15】 [录制V1.0.0使用说明视频](https://v.qq.com/x/page/i0813oy0lov.html) * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) * 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 -* 【2018-12-21】 添加静态配置 +* 【2018-12-21】 添加静态配置,添加服务端发送接口,发布V1.1.0-alpha版本,标识性版本。 + diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java index 8129f3a..39c4f83 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java @@ -4,7 +4,6 @@ import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; -import com.github.unclecatmyself.user.InChatVerifyServiceImpl; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.WsChannelService; import com.github.unclecatmyself.common.utils.ConstansUtil; diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index c8f6c81..a5c8bae 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,9 +1,7 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import com.github.unclecatmyself.common.bean.InChatMessage; import com.github.unclecatmyself.common.utils.MessageChangeUtil; -import com.github.unclecatmyself.user.DataBaseServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From d2bea78e0430b6dc3676417789d891be86309d53 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 21 Dec 2018 20:59:03 +0800 Subject: [PATCH 113/151] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +++----- doc/goal/goal.md | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 02c7d81..f82bb71 100644 --- a/README.md +++ b/README.md @@ -21,17 +21,15 @@ ## Maven版本 -* [V1.0.0版本使用说明](doc/version/v1.0.0.md) -* [V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) +版本目标:移除对SpringBoot的环境依赖,InChat独立生存与使用,结合上一版的功能,并添加服务器发送消息接口 -> 目前项目代码已经推进入了下一版本,如果你想下载这个版本的源码,可以到这里下载[V1.0.0-alpha](https://github.com/UncleCatMySelf/InChat/releases/tag/V1.0.0-alpha) +* [V1.1.0-alpha版本使用说明](https://unclecatmyself.github.io/2018/12/21/InChatV1.1.0%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/) ``` - com.github.UncleCatMySelf InChat - 1.0-alpha + 1.1.0-alpha ``` diff --git a/doc/goal/goal.md b/doc/goal/goal.md index a5c82eb..c53ccbf 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -8,7 +8,10 @@ 版本目标:完成基本的消息通讯(仅支持文本消息),离线消息存储,历史消息查询,一对一聊天、自我聊天、群聊等 -[V1.0.0版本使用说明](../version/v1.0.0.md) +* [V1.0.0版本使用说明](doc/version/v1.0.0.md) +* [V1.0.0版本使用说明视频教程](https://v.qq.com/x/page/i0813oy0lov.html) + +> 目前项目代码已经推进入了下一版本,如果你想下载这个版本的源码,可以到这里下载[V1.0.0-alpha](https://github.com/UncleCatMySelf/InChat/releases/tag/V1.0.0-alpha) ``` @@ -17,4 +20,19 @@ InChat 1.0-alpha -``` \ No newline at end of file +``` + +## V1.1.0-alpha版本 + +版本目标:移除对SpringBoot的环境依赖,InChat独立生存与使用,结合上一版的功能,并添加服务器发送消息接口 + +* [V1.1.0-alpha版本使用说明](https://unclecatmyself.github.io/2018/12/21/InChatV1.1.0%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/) + +``` + + com.github.UncleCatMySelf + InChat + 1.1.0-alpha + +``` + From 94e3665dd955d8ec4081d3607b5fd5e75db583dc Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 22 Dec 2018 13:01:05 +0800 Subject: [PATCH 114/151] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 2e88de2..7e29eb6 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/README.md b/README.md index f82bb71..1f369d5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ 版本目标:移除对SpringBoot的环境依赖,InChat独立生存与使用,结合上一版的功能,并添加服务器发送消息接口 * [V1.1.0-alpha版本使用说明](https://unclecatmyself.github.io/2018/12/21/InChatV1.1.0%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/) +* [V1.1.0-alpha版本视频教学](https://v.qq.com/x/page/i08165ym286.html) ``` From 3dfb5dc3951303287cfceef8753ffae3efda8ebc Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 22 Dec 2018 13:06:14 +0800 Subject: [PATCH 115/151] =?UTF-8?q?=E6=9B=B4=E6=96=B0maven?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f369d5..8f8bd2a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) -[![Maven](https://img.shields.io/badge/Maven-1.0--alpha-orange.svg)](https://mvnrepository.com/artifact/com.github.UncleCatMySelf/InChat/1.0-alpha) +[![Maven](https://img.shields.io/badge/Maven-1.1.0--alpha-orange.svg)](https://mvnrepository.com/artifact/com.github.UncleCatMySelf/InChat/1.1.0-alpha) From 0f2ca1d7089af723449d839110585fa207f0b886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 11:45:45 +0800 Subject: [PATCH 116/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8C=E7=A8=8B?= =?UTF-8?q?=E7=A2=91=E6=96=87=E6=A1=A3-12271145?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/goal/goal.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/goal/goal.md b/doc/goal/goal.md index c53ccbf..8b173a2 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -22,11 +22,14 @@ ``` -## V1.1.0-alpha版本 +## V1.1.0-alpha版本 【2018-12-21】 + +> 版本昵称:赤猫-1 版本目标:移除对SpringBoot的环境依赖,InChat独立生存与使用,结合上一版的功能,并添加服务器发送消息接口 * [V1.1.0-alpha版本使用说明](https://unclecatmyself.github.io/2018/12/21/InChatV1.1.0%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/) +* [V1.1.0-alpha版本视频教学](https://v.qq.com/x/page/i08165ym286.html) ``` From a31d695f3f903ef8f766eca41c9b0a527d9e18d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 13:51:00 +0800 Subject: [PATCH 117/151] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=89=88=E8=BF=9B=E5=85=A5=E6=96=B0=E7=89=88=E5=BC=80=E5=8F=91?= =?UTF-8?q?-12271350?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- .../unclecatmyself/DemoApplication.java | 47 +++++++++++++++++++ .../user/ToDataBaseServiceImpl.java | 17 +++++++ .../user/verifyServiceImpl.java | 25 ++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/github/unclecatmyself/DemoApplication.java create mode 100644 src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java create mode 100644 src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 7e29eb6..2e88de2 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java new file mode 100644 index 0000000..8b5c41a --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -0,0 +1,47 @@ +package com.github.unclecatmyself; + +import com.github.unclecatmyself.auto.ConfigFactory; +import com.github.unclecatmyself.auto.InitServer; +import com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService; +import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.user.ToDataBaseServiceImpl; +import com.github.unclecatmyself.user.verifyServiceImpl; +import io.netty.channel.Channel; + +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class DemoApplication { + + public static void main(String[] args) { + //配置InChat配置工厂 + ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); + ConfigFactory.inChatVerifyService = new verifyServiceImpl(); + //默认启动InChat + InitServer initServer = new InitServer(new InitNetty()); + initServer.open(); + + //获取用户值 + WebSocketChannelService webSocketChannelService = new WebSocketChannelService(); + + //启动新线程 + new Thread(new Runnable() { + @Override + public void run() { + //设定默认服务器发送值 + Map map = new HashMap<>(); + map.put("server","服务器"); + //获取控制台用户想发送的用户Token + Scanner scanner = new Scanner(System.in); + String token = scanner.nextLine(); + //获取用户连接 + Channel channel = (Channel) webSocketChannelService.getChannel(token); + //调用接口发送 + webSocketChannelService.sendFromServer(channel,map); + } + }).start(); + } + +} + diff --git a/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java new file mode 100644 index 0000000..9232276 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java @@ -0,0 +1,17 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.bean.InChatMessage; + +/** + * Created by MySelf on 2018/12/14. + */ +public class ToDataBaseServiceImpl implements InChatToDataBaseService { + + + @Override + public Boolean writeMapToDB(InChatMessage message) { + System.out.println(message.toString()); + return true; + } +} diff --git a/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java new file mode 100644 index 0000000..d2d31bc --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java @@ -0,0 +1,25 @@ +package com.github.unclecatmyself.user; + +import com.alibaba.fastjson.JSONArray; +import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; + + +/** + * Created by MySelf on 2018/12/14. + */ +public class verifyServiceImpl implements InChatVerifyService { + + + @Override + public boolean verifyToken(String token) { + //登录校验 + return true; + } + + @Override + public JSONArray getArrayByGroupId(String groupId) { + //根据群聊id获取对应的群聊人员ID + JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); + return jsonArray; + } +} From 9313526a8c221fb54a07f5d459774f819566a971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 14:41:09 +0800 Subject: [PATCH 118/151] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E9=85=8D=E7=BD=AEBea?= =?UTF-8?q?n=E4=B8=8E=E7=BB=A7=E6=89=BFDemo-12271441?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unclecatmyself/DemoApplication.java | 4 +- .../unclecatmyself/common/bean/InitNetty.java | 97 ++++++++++++------- .../github/unclecatmyself/user/MyInit.java | 14 +++ 3 files changed, 76 insertions(+), 39 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/user/MyInit.java diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java index 8b5c41a..0d5a5b3 100644 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -3,7 +3,7 @@ import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.auto.InitServer; import com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService; -import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.user.MyInit; import com.github.unclecatmyself.user.ToDataBaseServiceImpl; import com.github.unclecatmyself.user.verifyServiceImpl; import io.netty.channel.Channel; @@ -19,7 +19,7 @@ public static void main(String[] args) { ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); ConfigFactory.inChatVerifyService = new verifyServiceImpl(); //默认启动InChat - InitServer initServer = new InitServer(new InitNetty()); + InitServer initServer = new InitServer(new MyInit()); initServer.open(); //获取用户值 diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java index 80f14a8..1651aa2 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java @@ -3,6 +3,7 @@ import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; /** + * 初始化Netty配置 * Create by UncleCatMySelf in 2018/12/06 */ public class InitNetty { @@ -39,14 +40,18 @@ public class InitNetty { private Class webSocketHandler = DefaultWebSocketHandler.class; + /** + * 返回WebSocket启动监听端口 + * @return {@link Integer} WebSocket端口 + */ public int getWebport() { return webport; } - public void setWebport(int webport) { - this.webport = webport; - } - + /** + * 返回Netty核心线程个数 + * @return {@link Integer} Netty线程个数 + */ public int getBossThread() { return bossThread; } @@ -55,6 +60,10 @@ public void setBossThread(int bossThread) { this.bossThread = bossThread; } + /** + * 返回Netty工作线程个数 + * @return {@link Integer} Netty工作线程个数 + */ public int getWorkerThread() { return workerThread; } @@ -63,14 +72,18 @@ public void setWorkerThread(int workerThread) { this.workerThread = workerThread; } + /** + * 是否保持链接 + * @return {@link Boolean} 是否保持链接 + */ public boolean isKeepalive() { return keepalive; } - public void setKeepalive(boolean keepalive) { - this.keepalive = keepalive; - } - + /** + * 服务端接受连接的队列长度,如果队列已满,客户端连接将被拒绝 + * @return {@link Integer} 服务端接受连接的队列长度 + */ public int getBacklog() { return backlog; } @@ -79,30 +92,33 @@ public void setBacklog(int backlog) { this.backlog = backlog; } + /** + * TCP参数,立即发送数据,默认值为Ture(Netty默认为True而操作系统默认为False)。 + * 该值设置Nagle算法的启用,改算法将小的碎片数据连接成更大的报文来最小化所发送的报文的数量, + * 如果需要发送一些较小的报文,则需要禁用该算法。Netty默认禁用该算法,从而最小化报文传输延时。 + * @return {@link Boolean} Nagle算法是否启用 + */ public boolean isNodelay() { return nodelay; } - public void setNodelay(boolean nodelay) { - this.nodelay = nodelay; - } - + /** + * 地址复用,默认值False。有四种情况可以使用: + * (1).当有一个有相同本地地址和端口的socket1处于TIME_WAIT状态时,而你希望启动的程序的socket2要占用该地址和端口,比如重启服务且保持先前端口。 + * (2).有多块网卡或用IP Alias技术的机器在同一端口启动多个进程,但每个进程绑定的本地IP地址不能相同。 + * (3).单个进程绑定相同的端口到多个socket上,但每个socket绑定的ip地址不同。 + * (4).完全相同的地址和端口的重复绑定。但这只用于UDP的多播,不用于TCP。 + * @return {@link Boolean} 地址复用 + */ public boolean isReuseaddr() { return reuseaddr; } - public void setReuseaddr(boolean reuseaddr) { - this.reuseaddr = reuseaddr; - } - - public int getSndbuf() { - return sndbuf; - } - - public void setSndbuf(int sndbuf) { - this.sndbuf = sndbuf; - } + /** + * TCP数据接收缓冲区大小。 + * @return {@link Integer} TCP数据接收缓冲区大小。 + */ public int getRevbuf() { return revbuf; } @@ -111,6 +127,10 @@ public void setRevbuf(int revbuf) { this.revbuf = revbuf; } + /** + * 读超时时间 + * @return {@link Integer} 读超时时间 + */ public int getHeart() { return heart; } @@ -119,6 +139,10 @@ public void setHeart(int heart) { this.heart = heart; } + /** + * 消息 重发周期 + * @return {@link Integer} 消息重发周期 + */ public int getPeriod() { return period; } @@ -127,14 +151,18 @@ public void setPeriod(int period) { this.period = period; } + /** + * 服务名称 + * @return {@link String} 服务名称 + */ public String getServerName() { return serverName; } - public void setServerName(String serverName) { - this.serverName = serverName; - } - + /** + * 消息 重发延迟 + * @return {@link Integer} 消息重发延迟 + */ public int getInitalDelay() { return initalDelay; } @@ -147,23 +175,18 @@ public int getMaxContext() { return maxContext; } - public void setMaxContext(int maxContext) { - this.maxContext = maxContext; - } - + /** + * WebSocket URL 后缀地址 + * @return {@link String} WebSocket URL 后缀地址 + */ public String getWebSocketPath() { return webSocketPath; } - public void setWebSocketPath(String webSocketPath) { - this.webSocketPath = webSocketPath; - } public Class getWebSocketHandler() { return webSocketHandler; } - public void setWebSocketHandler(Class webSocketHandler) { - this.webSocketHandler = webSocketHandler; - } + } diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java new file mode 100644 index 0000000..ba179e3 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -0,0 +1,14 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.common.bean.InitNetty; + +/** + * Created by MySelf on 2018/12/27. + */ +public class MyInit extends InitNetty{ + + @Override + public int getWebport() { + return 8070; + } +} From 20dd9d575125cb3b91bc8d3e934351e8cbc5737b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 14:55:31 +0800 Subject: [PATCH 119/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BF=AE=E6=94=B9=E6=96=B0=E7=89=88=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=9C=8D=E5=8A=A1=E6=96=B9=E5=BC=8F-12271455?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unclecatmyself/DemoApplication.java | 5 +- .../unclecatmyself/auto/ConfigFactory.java | 6 +++ .../unclecatmyself/auto/InitServer.java | 17 +++--- .../auto/ServerAutoConfigure.java | 54 +++++++++---------- .../task/DataAsynchronousTask.java | 9 +++- .../github/unclecatmyself/user/MyInit.java | 2 +- 6 files changed, 55 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java index 0d5a5b3..b2744e4 100644 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -18,9 +18,10 @@ public static void main(String[] args) { //配置InChat配置工厂 ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); ConfigFactory.inChatVerifyService = new verifyServiceImpl(); + ConfigFactory.initNetty = new MyInit(); //默认启动InChat - InitServer initServer = new InitServer(new MyInit()); - initServer.open(); +// InitServer initServer = InitServer(new MyInit()); + InitServer.open(); //获取用户值 WebSocketChannelService webSocketChannelService = new WebSocketChannelService(); diff --git a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java index c9f9794..2b26d6b 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java +++ b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java @@ -2,6 +2,7 @@ import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; +import com.github.unclecatmyself.common.bean.InitNetty; /** * 默认配置工厂 @@ -9,10 +10,15 @@ */ public class ConfigFactory { + /** 用户校验伪接口 */ public static InChatVerifyService inChatVerifyService; + /** 用户获取数据伪接口 */ public static InChatToDataBaseService inChatToDataBaseService; + /** InChat项目配置 */ + public static InitNetty initNetty; + public InChatVerifyService getInChatVerifyService() { return inChatVerifyService; } diff --git a/src/main/java/com/github/unclecatmyself/auto/InitServer.java b/src/main/java/com/github/unclecatmyself/auto/InitServer.java index 9519d6e..afc179a 100644 --- a/src/main/java/com/github/unclecatmyself/auto/InitServer.java +++ b/src/main/java/com/github/unclecatmyself/auto/InitServer.java @@ -6,19 +6,22 @@ import com.github.unclecatmyself.common.bean.InitNetty; /** + * InChat项目启动服务 * Create by UncleCatMySelf in 2018/12/06 **/ -public class InitServer { +public abstract class InitServer { - private InitNetty serverBean; +// private InitNetty serverBean; - public InitServer(InitNetty serverBean) { - this.serverBean = serverBean; - } + private static InitNetty serverBean = ConfigFactory.initNetty; + +// public InitServer(InitNetty serverBean) { +// this.serverBean = serverBean; +// } - BootstrapServer bootstrapServer; + static BootstrapServer bootstrapServer; - public void open(){ + public static void open(){ if(serverBean!=null){ bootstrapServer = new NettyBootstrapServer(); bootstrapServer.setServerBean(serverBean); diff --git a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java index 1c40e74..e47d692 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java +++ b/src/main/java/com/github/unclecatmyself/auto/ServerAutoConfigure.java @@ -24,32 +24,32 @@ public ServerAutoConfigure(){ } - public InitServer initServer(InitNetty serverBean){ - if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ - throw new NullPointerException("not set port"); - } - if(serverBean.getBacklog()<1){ - serverBean.setBacklog(_BLACKLOG); - } - if(serverBean.getBossThread()<1){ - serverBean.setBossThread(CPU); - } - if(serverBean.getInitalDelay()<0){ - serverBean.setInitalDelay(SEDU_DAY); - } - if(serverBean.getPeriod()<1){ - serverBean.setPeriod(SEDU_DAY); - } - if(serverBean.getHeart()<1){ - serverBean.setHeart(TIMEOUT); - } - if(serverBean.getRevbuf()<1){ - serverBean.setRevbuf(BUF_SIZE); - } - if(serverBean.getWorkerThread()<1){ - serverBean.setWorkerThread(CPU*2); - } - return new InitServer(serverBean); - } +// public InitServer initServer(InitNetty serverBean){ +// if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){ +// throw new NullPointerException("not set port"); +// } +// if(serverBean.getBacklog()<1){ +// serverBean.setBacklog(_BLACKLOG); +// } +// if(serverBean.getBossThread()<1){ +// serverBean.setBossThread(CPU); +// } +// if(serverBean.getInitalDelay()<0){ +// serverBean.setInitalDelay(SEDU_DAY); +// } +// if(serverBean.getPeriod()<1){ +// serverBean.setPeriod(SEDU_DAY); +// } +// if(serverBean.getHeart()<1){ +// serverBean.setHeart(TIMEOUT); +// } +// if(serverBean.getRevbuf()<1){ +// serverBean.setRevbuf(BUF_SIZE); +// } +// if(serverBean.getWorkerThread()<1){ +// serverBean.setWorkerThread(CPU*2); +// } +// return new InitServer(serverBean); +// } } diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index a5c8bae..b0f92fe 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -8,19 +8,26 @@ import java.util.Map; /** + * 数据异步转移方法 * Created by MySelf on 2018/12/3. */ public class DataAsynchronousTask { private final Logger log = LoggerFactory.getLogger(DataAsynchronousTask.class); + /** 用户读数据接口伪实现 */ private final InChatToDataBaseService inChatToDataBaseService; + public DataAsynchronousTask(InChatToDataBaseService inChatToDataBaseService){ this.inChatToDataBaseService = inChatToDataBaseService; } - public void writeData(Map maps) throws Exception { + /** + * 将Netty数据消息借助这个方法已新线程发送给用户实现读方法 + * @param maps {@link Map} 传递消息 + */ + public void writeData(Map maps){ log.info("【异步写入数据】"); new Thread(new Runnable() { @Override diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java index ba179e3..3de2ae9 100644 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -9,6 +9,6 @@ public class MyInit extends InitNetty{ @Override public int getWebport() { - return 8070; + return 8090; } } From f00e5ec8db9097b8ee434c2487a0e1cb8585e57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 16:00:40 +0800 Subject: [PATCH 120/151] =?UTF-8?q?=E6=95=B4=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=97=A5=E5=BF=97-12271600?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index fd0e487..9946079 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -17,4 +17,5 @@ * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) * 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 * 【2018-12-21】 添加静态配置,添加服务端发送接口,发布V1.1.0-alpha版本,标识性版本。 +* 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式。 From 4095a4c06f34d3187f5b538086a9d6d3ef2c627f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 27 Dec 2018 17:43:46 +0800 Subject: [PATCH 121/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0HTTP=E9=80=9A?= =?UTF-8?q?=E9=81=93-12271743?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- firestorm.log.1 | 1169 +++++++++++++++++ .../bootstrap/AbstractBootstrapServer.java | 4 + .../handler/DefaultWebSocketHandler.java | 20 + .../common/bean/InChatMessage.java | 11 +- .../exception/NoFindHandlerException.java | 1 + .../ServerWebSocketHandlerService.java | 1 + .../common/websockets/WebSocketHandler.java | 13 +- .../websockets/WebSocketHandlerApi.java | 1 - 8 files changed, 1216 insertions(+), 4 deletions(-) create mode 100644 firestorm.log.1 diff --git a/firestorm.log.1 b/firestorm.log.1 new file mode 100644 index 0000000..0606587 --- /dev/null +++ b/firestorm.log.1 @@ -0,0 +1,1169 @@ +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154788 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:19901链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: c9ec62c8-63ef-43d1-b5b9-c4b6f6d76d58 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 + at io.netty.buffer.AbstractReferenceCountedByteBuf.toLiveRealCnt(AbstractReferenceCountedByteBuf.java:181) + at io.netty.buffer.AbstractReferenceCountedByteBuf.release0(AbstractReferenceCountedByteBuf.java:133) + at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:124) + at io.netty.handler.codec.http.HttpObjectAggregator$AggregatedFullHttpMessage.release(HttpObjectAggregator.java:386) + at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:112) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException + at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) + at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) + at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) + at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:136) + at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:103) + at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) + at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +was thrown by a user handler's exceptionCaught() method while handling the following exception: +io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 + at io.netty.buffer.AbstractReferenceCountedByteBuf.toLiveRealCnt(AbstractReferenceCountedByteBuf.java:181) + at io.netty.buffer.AbstractReferenceCountedByteBuf.release0(AbstractReferenceCountedByteBuf.java:133) + at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:124) + at io.netty.handler.codec.http.HttpObjectAggregator$AggregatedFullHttpMessage.release(HttpObjectAggregator.java:386) + at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88) + at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:112) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) + at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) + at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) + at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) + at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) + at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) + at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) + at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) + at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154828 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6e396fa3 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:19938链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 915be4b3-5f05-4514-b2d2-f8836669f553 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155024 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@725c9757 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20048链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: c9026dbf-9c24-47e2-ba81-48899e70c76f +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 150948 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1898bf3b +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20130链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: a6c22ef5-6f3d-4908-bde1-cad037074e71 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154272 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20182链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 9f32c459-3366-441e-a84c-f7423902bf96 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154696 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20286链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: f143aedf-a6a9-4c56-8605-ce5351b45aef +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154660 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20310链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 638c16df-08f3-46e5-9e57-24a5b81beab3 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155020 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20336链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 10808d48-75a4-4755-a142-9861b0f4202b +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 152260 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20375链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 4ed4e15f-219e-4731-b77e-80d5b704de4b +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155368 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20393链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 41d6bd94-218d-4dfc-8b70-fa2e38a25049 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 153296 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@774f8a43 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20450链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 19b1584a-d663-4944-95b5-bf8937ab0191 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 153556 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20468链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: fedd6fdc-05ea-4d2b-9a09-e100c457cbe3 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20498链接成功 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +Host: 192.168.1.121:8090 +User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0 +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 +Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 +Accept-Encoding: gzip, deflate +Connection: keep-alive +Upgrade-Insecure-Requests: 1 +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 149748 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20541链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 281ba5c4-0b20-4d9c-be21-285b9f5a395a +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework +DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false +DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 +DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows +DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false +DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available +DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available +DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true +DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 +DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available +DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 +DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available +DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false +DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple +DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 +DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 +DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155260 (auto-detected) +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false +DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false +DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) +DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 +DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 +DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 +INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true +DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true +DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20562链接成功 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 +DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf +INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) +GET /?asdf=asdf HTTP/1.1 +cache-control: no-cache +Postman-Token: 045ad380-9a47-42cb-9c37-f280a7828aa9 +User-Agent: PostmanRuntime/7.4.0 +Accept: */* +Host: 192.168.1.121:8090 +accept-encoding: gzip, deflate +Connection: keep-alive +content-length: 0 +INFO WORK_1 com.github.unclecatmyself.common.websockets.WebSocketHandler - 【DefaultWebSocketHandler:channelInactive】0.0.0.0/0.0.0.0:8090关闭成功 +ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception +java.lang.NullPointerException + at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) + at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) + at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) + at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) + at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:136) + at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelInactive(WebSocketHandler.java:46) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) + at io.netty.handler.timeout.IdleStateHandler.channelInactive(IdleStateHandler.java:277) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.handler.stream.ChunkedWriteHandler.channelInactive(ChunkedWriteHandler.java:141) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) + at io.netty.handler.codec.MessageAggregator.channelInactive(MessageAggregator.java:417) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:420) + at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:390) + at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:355) + at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:223) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) + at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1429) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) + at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) + at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:947) + at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:826) + at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) + at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) + at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:474) + at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) + at java.lang.Thread.run(Thread.java:745) diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 3709f82..8352374 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -8,6 +8,8 @@ import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.stream.ChunkedWriteHandler; @@ -30,7 +32,9 @@ protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBea private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ channelPipeline.addLast("httpCode",new HttpServerCodec()); +// channelPipeline.addLast("http-decoder",new HttpRequestDecoder()); channelPipeline.addLast("aggregator", new HttpObjectAggregator(serverBean.getMaxContext())); +// channelPipeline.addLast("http-encoder",new HttpResponseEncoder()); channelPipeline.addLast("chunkedWrite",new ChunkedWriteHandler()); channelPipeline.addLast("webSocketHandler",new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 925baaa..6d12776 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -6,11 +6,15 @@ import com.github.unclecatmyself.common.websockets.WebSocketHandler; import com.github.unclecatmyself.common.utils.ConstansUtil; import com.github.unclecatmyself.common.websockets.WebSocketHandlerApi; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.*; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import io.netty.util.CharsetUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +39,22 @@ public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { @Override protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { //暂未实现 + log.info("[webdoMessage]--暂未实现"); + } + + @Override + protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { + //暂未实现 + log.info("[httpdoMessage]--暂未实现"); + msg.retain(); + log.info(msg.uri()); + log.info(msg.toString()); + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); + response.headers().set("Content-Type","text/html;charset=UTF-8"); + ByteBuf buf = Unpooled.copiedBuffer("【InChat】-HTTP通道返回成功",CharsetUtil.UTF_8); + response.content().writeBytes(buf); + ctx.writeAndFlush(response); + ctx.close(); } @Override diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java index 18b7ede..847e74a 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InChatMessage.java @@ -1,29 +1,36 @@ package com.github.unclecatmyself.common.bean; -import com.alibaba.fastjson.JSONArray; - import java.util.ArrayList; import java.util.Date; /** + * 用户层消息Bean封装 * Created by MySelf on 2018/12/19. */ public class InChatMessage { + /** 消息时间 */ private Date time; + /** 消息类型 */ private String type; + /** 消息值 */ private String value; + /** 用户标识 */ private String token; + /** 群聊Id */ private String groudId; + /** 是否在线-个人 */ private String online; + /** 是否在线-群聊 */ private ArrayList onlineGroup; + /** 消息接收人标识 */ private String one; public ArrayList getOnlineGroup() { diff --git a/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java index 7da4cd4..f8ba5eb 100644 --- a/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java +++ b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.common.exception; /** + * 找不到对应处理类 * Create by UncleCatMySelf in 2018/12/06 **/ public class NoFindHandlerException extends RuntimeException { diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java index a67add9..da9ea07 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java @@ -5,6 +5,7 @@ import java.util.Map; /** + * 业务层伪接口 * Created by MySelf on 2018/11/21. */ public abstract class ServerWebSocketHandlerService implements WebSocketHandlerApi { diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java index 4162a3f..5d25fb6 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java @@ -2,14 +2,21 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.FullHttpMessage; +import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** + * Netty实现初始层 * Create by UncleCatMySelf in 2018/12/06 */ public abstract class WebSocketHandler extends SimpleChannelInboundHandler { + private static final Logger log = LoggerFactory.getLogger(WebSocketHandler.class); + WebSocketHandlerApi webSocketHandlerApi; public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ @@ -22,6 +29,8 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except textdoMessage(ctx,(TextWebSocketFrame)msg); }else if (msg instanceof WebSocketFrame){ webdoMessage(ctx,(WebSocketFrame)msg); + }else if (msg instanceof FullHttpRequest){ + httpdoMessage(ctx,(FullHttpRequest)msg); } } @@ -29,9 +38,11 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except protected abstract void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg); + protected abstract void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg); + @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { -// log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); webSocketHandlerApi.close(ctx.channel()); } diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java index b6bc225..7aadde9 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java @@ -10,7 +10,6 @@ */ public interface WebSocketHandlerApi { - void close(Channel channel); void sendMeText(Channel channel, Map maps); From 5c5ee054a2bda1d04a34e26da741a4124bcc6c0e Mon Sep 17 00:00:00 2001 From: MySelf <38393241+UncleCatMySelf@users.noreply.github.com> Date: Thu, 27 Dec 2018 19:05:37 +0800 Subject: [PATCH 122/151] Delete firestorm.log.1 --- firestorm.log.1 | 1169 ----------------------------------------------- 1 file changed, 1169 deletions(-) delete mode 100644 firestorm.log.1 diff --git a/firestorm.log.1 b/firestorm.log.1 deleted file mode 100644 index 0606587..0000000 --- a/firestorm.log.1 +++ /dev/null @@ -1,1169 +0,0 @@ -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154788 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:19901链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: c9ec62c8-63ef-43d1-b5b9-c4b6f6d76d58 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 - at io.netty.buffer.AbstractReferenceCountedByteBuf.toLiveRealCnt(AbstractReferenceCountedByteBuf.java:181) - at io.netty.buffer.AbstractReferenceCountedByteBuf.release0(AbstractReferenceCountedByteBuf.java:133) - at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:124) - at io.netty.handler.codec.http.HttpObjectAggregator$AggregatedFullHttpMessage.release(HttpObjectAggregator.java:386) - at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:112) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG WORK_1 io.netty.channel.AbstractChannelHandlerContext - An exception java.lang.NullPointerException - at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) - at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) - at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) - at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:136) - at com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler.exceptionCaught(DefaultWebSocketHandler.java:103) - at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285) - at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:856) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:364) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -was thrown by a user handler's exceptionCaught() method while handling the following exception: -io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 - at io.netty.buffer.AbstractReferenceCountedByteBuf.toLiveRealCnt(AbstractReferenceCountedByteBuf.java:181) - at io.netty.buffer.AbstractReferenceCountedByteBuf.release0(AbstractReferenceCountedByteBuf.java:133) - at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:124) - at io.netty.handler.codec.http.HttpObjectAggregator$AggregatedFullHttpMessage.release(HttpObjectAggregator.java:386) - at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88) - at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:112) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:77) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandshakeHandler.channelRead(WebSocketServerProtocolHandshakeHandler.java:66) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:438) - at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323) - at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:297) - at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:253) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) - at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) - at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) - at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:656) - at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:591) - at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:508) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:470) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154828 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@6e396fa3 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:19938链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 915be4b3-5f05-4514-b2d2-f8836669f553 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155024 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@725c9757 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20048链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: c9026dbf-9c24-47e2-ba81-48899e70c76f -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 150948 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1898bf3b -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20130链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: a6c22ef5-6f3d-4908-bde1-cad037074e71 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154272 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20182链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 9f32c459-3366-441e-a84c-f7423902bf96 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154696 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20286链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: f143aedf-a6a9-4c56-8605-ce5351b45aef -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 154660 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20310链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 638c16df-08f3-46e5-9e57-24a5b81beab3 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155020 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20336链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 10808d48-75a4-4755-a142-9861b0f4202b -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 152260 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@7df33e3c -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20375链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 4ed4e15f-219e-4731-b77e-80d5b704de4b -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155368 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20393链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 41d6bd94-218d-4dfc-8b70-fa2e38a25049 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 153296 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@774f8a43 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20450链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 19b1584a-d663-4944-95b5-bf8937ab0191 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 153556 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20468链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: fedd6fdc-05ea-4d2b-9a09-e100c457cbe3 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20498链接成功 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_2 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -Host: 192.168.1.121:8090 -User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0 -Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 -Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 -Accept-Encoding: gzip, deflate -Connection: keep-alive -Upgrade-Insecure-Requests: 1 -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 149748 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@59cb2cfb -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20541链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 281ba5c4-0b20-4d9c-be21-285b9f5a395a -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -DEBUG main io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework -DEBUG main io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 8 -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false -DEBUG main io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 -DEBUG main io.netty.util.internal.PlatformDependent - Platform: Windows -DEBUG main io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false -DEBUG main io.netty.util.internal.PlatformDependent0 - Java version: 8 -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available -DEBUG main io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available -DEBUG main io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true -DEBUG main io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 -DEBUG main io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.(long, int): available -DEBUG main io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\hht\AppData\Local\Temp (java.io.tmpdir) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 1897922560 bytes -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 -DEBUG main io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available -DEBUG main io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false -DEBUG main io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple -DEBUG main io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.targetRecords: 4 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 8 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 11 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 16777216 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.tinyCacheSize: 512 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 -DEBUG main io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: true -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 -DEBUG main io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.processId: 155260 (auto-detected) -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false -DEBUG main io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false -DEBUG main io.netty.util.NetUtil - Loopback interface: [lo, Software Loopback Interface 1, 127.0.0.1] ({}, {}) -DEBUG main io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 -DEBUG main io.netty.channel.DefaultChannelId - -Dio.netty.machineId: f8:bc:12:ff:fe:5b:19:b3 (auto-detected) -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 -DEBUG main io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 -INFO BOSS_1 com.github.unclecatmyself.bootstrap.NettyBootstrapServer - 服务端启动成功【192.168.1.121:8090】 -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkAccessible: true -DEBUG WORK_1 io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.checkBounds: true -DEBUG WORK_1 io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@47fc2e66 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [DefaultWebSocketHandler.channelActive]/192.168.1.121:20562链接成功 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.maxSharedCapacityFactor: 2 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.linkCapacity: 16 -DEBUG WORK_1 io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - [httpdoMessage]--暂未实现 -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - /?asdf=asdf -INFO WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - HttpObjectAggregator$AggregatedFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: CompositeByteBuf(ridx: 0, widx: 0, cap: 0, components=0)) -GET /?asdf=asdf HTTP/1.1 -cache-control: no-cache -Postman-Token: 045ad380-9a47-42cb-9c37-f280a7828aa9 -User-Agent: PostmanRuntime/7.4.0 -Accept: */* -Host: 192.168.1.121:8090 -accept-encoding: gzip, deflate -Connection: keep-alive -content-length: 0 -INFO WORK_1 com.github.unclecatmyself.common.websockets.WebSocketHandler - 【DefaultWebSocketHandler:channelInactive】0.0.0.0/0.0.0.0:8090关闭成功 -ERROR WORK_1 com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler - exception -java.lang.NullPointerException - at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106) - at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097) - at com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap.deleteWs(WsCacheMap.java:64) - at com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService.close(WebSocketChannelService.java:36) - at com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService.close(WebSocketHandlerService.java:136) - at com.github.unclecatmyself.common.websockets.WebSocketHandler.channelInactive(WebSocketHandler.java:46) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) - at io.netty.handler.timeout.IdleStateHandler.channelInactive(IdleStateHandler.java:277) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.handler.stream.ChunkedWriteHandler.channelInactive(ChunkedWriteHandler.java:141) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75) - at io.netty.handler.codec.MessageAggregator.channelInactive(MessageAggregator.java:417) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:420) - at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:390) - at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:355) - at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:223) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:224) - at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1429) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:245) - at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:231) - at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:947) - at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:826) - at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) - at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404) - at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:474) - at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:909) - at java.lang.Thread.run(Thread.java:745) From 72726caab25c1cde527c63ae317584ca5b134f2f Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Thu, 27 Dec 2018 20:08:29 +0800 Subject: [PATCH 123/151] update --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 9946079..af0907e 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -17,5 +17,5 @@ * 【2018-12-18】 明确移除对SpringBoot的依赖于环境,做成自纯应用。[添加NIO服务端与客户端Demo](https://github.com/UncleCatMySelf/InChat/wiki/Java-NIO%E4%B9%8BSelector%EF%BC%88%E9%80%89%E6%8B%A9%E5%99%A8%EF%BC%89) * 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 * 【2018-12-21】 添加静态配置,添加服务端发送接口,发布V1.1.0-alpha版本,标识性版本。 -* 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式。 +* 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式,修改日志配置。 From b281e629d0658a5000a4aa86758e96fbcd3860f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 28 Dec 2018 14:03:22 +0800 Subject: [PATCH 124/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=96=87=E4=BB=B6-12281403?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index af0907e..d61ad0b 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -18,4 +18,5 @@ * 【2018-12-19】 移除lombok,嵌入log4j的依赖,并配置日志信息,移除对SpringBoot的依赖成功,普通main方法既可以运行项目。 * 【2018-12-21】 添加静态配置,添加服务端发送接口,发布V1.1.0-alpha版本,标识性版本。 * 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式,修改日志配置。 +* 【2018-12-28】 预计整改常量、修改部分方法(类)命名,下一版加wss通道。 From 4e46e6aa4a82c7d152aef21c969db52d75b384bb Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 30 Dec 2018 11:45:31 +0800 Subject: [PATCH 125/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BB=BB=E5=8A=A1-12301145?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- doc/goal/goal.md | 2 ++ .../task/DataAsynchronousTask.java | 27 ++++++++++++----- .../unclecatmyself/task/DataCallable.java | 30 +++++++++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/task/DataCallable.java diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 2e88de2..7e29eb6 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/doc/goal/goal.md b/doc/goal/goal.md index 8b173a2..1dc87e1 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -39,3 +39,5 @@ ``` +## 【2018-12-20】 项目突破 **150** Star,感谢大家的支持 + diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index b0f92fe..650da3f 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,11 +1,14 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import com.github.unclecatmyself.common.utils.MessageChangeUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.FutureTask; /** * 数据异步转移方法 @@ -28,13 +31,21 @@ public DataAsynchronousTask(InChatToDataBaseService inChatToDataBaseService){ * @param maps {@link Map} 传递消息 */ public void writeData(Map maps){ - log.info("【异步写入数据】"); - new Thread(new Runnable() { - @Override - public void run() { - inChatToDataBaseService.writeMapToDB(MessageChangeUtil.Change(maps)); - } - }).start(); + Boolean result = false; + ExecutorService service = Executors.newCachedThreadPool(); + final FutureTask future = new FutureTask(new DataCallable(inChatToDataBaseService,maps)); + service.execute(future); + try { + result = future.get(); + } catch (InterruptedException e) { + e.printStackTrace(); + log.error("[DataAsynchronousTask.writeData]:数据外抛异常"); + } catch (ExecutionException e) { + log.error("[DataAsynchronousTask.writeData]:数据外抛异常"); + } + if (!result){ + log.error("[DataAsynchronousTask.writeData]:线程任务执行异常"); + } } } diff --git a/src/main/java/com/github/unclecatmyself/task/DataCallable.java b/src/main/java/com/github/unclecatmyself/task/DataCallable.java new file mode 100644 index 0000000..6a85eea --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/task/DataCallable.java @@ -0,0 +1,30 @@ +package com.github.unclecatmyself.task; + +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.utils.MessageChangeUtil; + +import java.util.Map; +import java.util.concurrent.Callable; + +/** + * 获取结果的异步线程任务 + * Create by UncleCatMySelf in 11:25 2018\12\30 0030 + */ +public class DataCallable implements Callable{ + + /** 用户读数据接口伪实现 */ + private final InChatToDataBaseService inChatToDataBaseService; + /** 消息数据 */ + private final Map maps; + + DataCallable(InChatToDataBaseService inChatToDataBaseService,Map maps) { + this.inChatToDataBaseService = inChatToDataBaseService; + this.maps = maps; + } + + @Override + public Boolean call() throws Exception { + inChatToDataBaseService.writeMapToDB(MessageChangeUtil.Change(maps)); + return true; + } +} From ade3ee1b23cfae37b632086f8cc91c2bd56401fc Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 30 Dec 2018 12:04:19 +0800 Subject: [PATCH 126/151] =?UTF-8?q?=E6=95=B4=E6=94=B9=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=8E=E4=BF=AE=E6=94=B9=E6=A0=B8=E5=BF=83=E7=B1=BB=E5=90=8D?= =?UTF-8?q?-12301204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unclecatmyself/DemoApplication.java | 2 +- .../bootstrap/AbstractBootstrapServer.java | 6 +-- .../{ => ws}/WebSocketChannelService.java | 2 +- .../WebSocketHandlerServiceImpl.java} | 8 ++-- .../handler/DefaultWebSocketHandler.java | 38 +++++++++---------- .../Handler.java} | 15 ++++---- .../common/base/HandlerApi.java | 14 +++++++ .../WebSocketHandlerService.java} | 4 +- .../websockets/WebSocketHandlerApi.java | 18 --------- 9 files changed, 50 insertions(+), 57 deletions(-) rename src/main/java/com/github/unclecatmyself/bootstrap/channel/{ => ws}/WebSocketChannelService.java (96%) rename src/main/java/com/github/unclecatmyself/bootstrap/channel/{WebSocketHandlerService.java => ws/WebSocketHandlerServiceImpl.java} (93%) rename src/main/java/com/github/unclecatmyself/common/{websockets/WebSocketHandler.java => base/Handler.java} (76%) create mode 100644 src/main/java/com/github/unclecatmyself/common/base/HandlerApi.java rename src/main/java/com/github/unclecatmyself/common/{websockets/ServerWebSocketHandlerService.java => base/WebSocketHandlerService.java} (89%) delete mode 100644 src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java index b2744e4..c1ee5d7 100644 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -2,7 +2,7 @@ import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.auto.InitServer; -import com.github.unclecatmyself.bootstrap.channel.WebSocketChannelService; +import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; import com.github.unclecatmyself.user.MyInit; import com.github.unclecatmyself.user.ToDataBaseServiceImpl; import com.github.unclecatmyself.user.verifyServiceImpl; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 8352374..9f0f313 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -2,14 +2,12 @@ import com.github.unclecatmyself.auto.ConfigFactory; -import com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService; +import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketHandlerServiceImpl; import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpRequestDecoder; -import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.stream.ChunkedWriteHandler; @@ -27,7 +25,7 @@ public abstract class AbstractBootstrapServer implements BootstrapServer { protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ intProtocolHandler(channelPipeline,serverBean); channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerService(new DataAsynchronousTask(ConfigFactory.inChatToDataBaseService),ConfigFactory.inChatVerifyService))); + channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerServiceImpl(new DataAsynchronousTask(ConfigFactory.inChatToDataBaseService),ConfigFactory.inChatVerifyService))); } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java similarity index 96% rename from src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java index 082507a..218fa47 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java @@ -1,4 +1,4 @@ -package com.github.unclecatmyself.bootstrap.channel; +package com.github.unclecatmyself.bootstrap.channel.ws; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.WsChannelService; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java similarity index 93% rename from src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java index 39c4f83..2c57708 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java @@ -1,9 +1,9 @@ -package com.github.unclecatmyself.bootstrap.channel; +package com.github.unclecatmyself.bootstrap.channel.ws; import com.alibaba.fastjson.JSONArray; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; -import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; +import com.github.unclecatmyself.common.base.WebSocketHandlerService; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.WsChannelService; import com.github.unclecatmyself.common.utils.ConstansUtil; @@ -18,7 +18,7 @@ /** * Created by MySelf on 2018/11/21. */ -public class WebSocketHandlerService extends ServerWebSocketHandlerService { +public class WebSocketHandlerServiceImpl extends WebSocketHandlerService { private final InChatVerifyService inChatVerifyService; @@ -28,7 +28,7 @@ public class WebSocketHandlerService extends ServerWebSocketHandlerService { private final DataAsynchronousTask dataAsynchronousTask; - public WebSocketHandlerService(DataAsynchronousTask dataAsynchronousTask,InChatVerifyService inChatVerifyService) { + public WebSocketHandlerServiceImpl(DataAsynchronousTask dataAsynchronousTask,InChatVerifyService inChatVerifyService) { this.dataAsynchronousTask = dataAsynchronousTask; this.inChatVerifyService = inChatVerifyService; } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 6d12776..bad4e96 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -1,11 +1,11 @@ package com.github.unclecatmyself.bootstrap.handler; import com.alibaba.fastjson.JSON; +import com.github.unclecatmyself.common.base.Handler; +import com.github.unclecatmyself.common.base.HandlerApi; +import com.github.unclecatmyself.common.base.WebSocketHandlerService; import com.github.unclecatmyself.common.exception.NoFindHandlerException; -import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService; -import com.github.unclecatmyself.common.websockets.WebSocketHandler; import com.github.unclecatmyself.common.utils.ConstansUtil; -import com.github.unclecatmyself.common.websockets.WebSocketHandlerApi; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -25,15 +25,15 @@ * Create by UncleCatMySelf in 2018/12/06 */ @ChannelHandler.Sharable -public class DefaultWebSocketHandler extends WebSocketHandler { +public class DefaultWebSocketHandler extends Handler { private final Logger log = LoggerFactory.getLogger(DefaultWebSocketHandler.class); - private final WebSocketHandlerApi webSocketHandlerApi; + private final HandlerApi handlerApi; - public DefaultWebSocketHandler(WebSocketHandlerApi webSocketHandlerApi) { - super(webSocketHandlerApi); - this.webSocketHandlerApi = webSocketHandlerApi; + public DefaultWebSocketHandler(HandlerApi handlerApi) { + super(handlerApi); + this.handlerApi = handlerApi; } @Override @@ -60,9 +60,9 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { @Override protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { Channel channel = ctx.channel(); - ServerWebSocketHandlerService serverWebSocketHandlerService; - if (webSocketHandlerApi instanceof ServerWebSocketHandlerService){ - serverWebSocketHandlerService = (ServerWebSocketHandlerService)webSocketHandlerApi; + WebSocketHandlerService webSocketHandlerService; + if (handlerApi instanceof WebSocketHandlerService){ + webSocketHandlerService = (WebSocketHandlerService)handlerApi; }else{ throw new NoFindHandlerException("Server Handler 不匹配"); } @@ -71,25 +71,25 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: log.info("[DefaultWebSocketHandler.textdoMessage.LOGIN]"); - serverWebSocketHandlerService.login(channel,maps); + webSocketHandlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: log.info("[DefaultWebSocketHandler.textdoMessage.SENDME]"); - serverWebSocketHandlerService.verify(channel,maps); - serverWebSocketHandlerService.sendMeText(channel,maps); + webSocketHandlerService.verify(channel,maps); + webSocketHandlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: log.info("[DefaultWebSocketHandler.textdoMessage.SENDTO]"); - serverWebSocketHandlerService.verify(channel,maps); - serverWebSocketHandlerService.sendToText(channel,maps); + webSocketHandlerService.verify(channel,maps); + webSocketHandlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: log.info("[DefaultWebSocketHandler.textdoMessage.SENDGROUP]"); - serverWebSocketHandlerService.verify(channel,maps); - serverWebSocketHandlerService.sendGroupText(channel,maps); + webSocketHandlerService.verify(channel,maps); + webSocketHandlerService.sendGroupText(channel,maps); break; default: break; @@ -104,6 +104,6 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ log.error("exception",cause); - webSocketHandlerApi.close(ctx.channel()); + handlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java b/src/main/java/com/github/unclecatmyself/common/base/Handler.java similarity index 76% rename from src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java rename to src/main/java/com/github/unclecatmyself/common/base/Handler.java index 5d25fb6..478fab1 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/common/base/Handler.java @@ -1,8 +1,7 @@ -package com.github.unclecatmyself.common.websockets; +package com.github.unclecatmyself.common.base; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; @@ -13,14 +12,14 @@ * Netty实现初始层 * Create by UncleCatMySelf in 2018/12/06 */ -public abstract class WebSocketHandler extends SimpleChannelInboundHandler { +public abstract class Handler extends SimpleChannelInboundHandler { - private static final Logger log = LoggerFactory.getLogger(WebSocketHandler.class); + private static final Logger log = LoggerFactory.getLogger(Handler.class); - WebSocketHandlerApi webSocketHandlerApi; + HandlerApi handlerApi; - public WebSocketHandler(WebSocketHandlerApi webSocketHandlerApi){ - this.webSocketHandlerApi = webSocketHandlerApi; + public Handler(HandlerApi webSocketHandlerApi){ + this.handlerApi = handlerApi; } @Override @@ -43,7 +42,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - webSocketHandlerApi.close(ctx.channel()); + handlerApi.close(ctx.channel()); } @Override diff --git a/src/main/java/com/github/unclecatmyself/common/base/HandlerApi.java b/src/main/java/com/github/unclecatmyself/common/base/HandlerApi.java new file mode 100644 index 0000000..536c0ad --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/base/HandlerApi.java @@ -0,0 +1,14 @@ +package com.github.unclecatmyself.common.base; + +import io.netty.channel.Channel; + +import java.util.Map; + +/** + * Create by UncleCatMySelf in 2018/12/06 + */ +public interface HandlerApi { + + void close(Channel channel); + +} diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java similarity index 89% rename from src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java rename to src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java index da9ea07..385c22e 100644 --- a/src/main/java/com/github/unclecatmyself/common/websockets/ServerWebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java @@ -1,4 +1,4 @@ -package com.github.unclecatmyself.common.websockets; +package com.github.unclecatmyself.common.base; import io.netty.channel.Channel; @@ -8,7 +8,7 @@ * 业务层伪接口 * Created by MySelf on 2018/11/21. */ -public abstract class ServerWebSocketHandlerService implements WebSocketHandlerApi { +public abstract class WebSocketHandlerService implements HandlerApi { /** * 登录类型 diff --git a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java b/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java deleted file mode 100644 index 7aadde9..0000000 --- a/src/main/java/com/github/unclecatmyself/common/websockets/WebSocketHandlerApi.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.github.unclecatmyself.common.websockets; - -import io.netty.channel.Channel; -import io.netty.handler.timeout.IdleStateEvent; - -import java.util.Map; - -/** - * Create by UncleCatMySelf in 2018/12/06 - */ -public interface WebSocketHandlerApi { - - void close(Channel channel); - - void sendMeText(Channel channel, Map maps); - - void sendToText(Channel channel, Map maps); -} From adcbfdc0b2f066b7f0857b1633197bd2ababf38f Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 30 Dec 2018 14:10:41 +0800 Subject: [PATCH 127/151] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E6=9C=AA=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E5=BC=82=E5=B8=B8-12301410?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/cache/WsCacheMap.java | 7 ++++++- .../bootstrap/handler/DefaultWebSocketHandler.java | 1 + .../github/unclecatmyself/common/base/Handler.java | 9 +++++++-- .../exception/NotFindLoginChannlException.java | 14 ++++++++++++++ src/main/resources/log4j.properties | 6 +++--- 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index d1aff3b..cd1ac47 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.cache; +import com.github.unclecatmyself.exception.NotFindLoginChannlException; import io.netty.channel.Channel; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -61,7 +62,11 @@ public static String getByAddress(String address){ * @param token {@link String} 用户标识 */ public static void deleteWs(String token){ - maps.remove(token); + try { + maps.remove(token); + }catch (NullPointerException e){ + throw new NotFindLoginChannlException("未找到正常注册的连接"); + } } /** diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index bad4e96..78751ec 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -104,6 +104,7 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ log.error("exception",cause); + log.info("[DefaultWebSocketHandler.exceptionCaught]"+ctx.channel().remoteAddress().toString()+"异常断开"); handlerApi.close(ctx.channel()); } } diff --git a/src/main/java/com/github/unclecatmyself/common/base/Handler.java b/src/main/java/com/github/unclecatmyself/common/base/Handler.java index 478fab1..a88cdf3 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/Handler.java +++ b/src/main/java/com/github/unclecatmyself/common/base/Handler.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.common.base; +import com.github.unclecatmyself.exception.NotFindLoginChannlException; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpRequest; @@ -18,7 +19,7 @@ public abstract class Handler extends SimpleChannelInboundHandler { HandlerApi handlerApi; - public Handler(HandlerApi webSocketHandlerApi){ + public Handler(HandlerApi handlerApi){ this.handlerApi = handlerApi; } @@ -42,7 +43,11 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); - handlerApi.close(ctx.channel()); + try { + handlerApi.close(ctx.channel()); + }catch (NotFindLoginChannlException e){ + log.error("【捕获异常:NotFindLoginChannlException】-【DefaultWebSocketHandler:channelInactive】关闭未正常注册链接!"); + } } @Override diff --git a/src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java b/src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java new file mode 100644 index 0000000..5c9370b --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java @@ -0,0 +1,14 @@ +package com.github.unclecatmyself.exception; + +/** + * 未找到正常注册的连接异常 + * Create by UncleCatMySelf in 13:58 2018\12\30 0030 + */ +public class NotFindLoginChannlException extends RuntimeException { + + private static final long serialVersionUID = -2614068393411382075L; + + public NotFindLoginChannlException(String message) { + super(message); + } +} diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index f690c90..30185a7 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -1,12 +1,12 @@ -log4j.rootLogger=debug, stdout, R +log4j.rootLogger=debug, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p - %m%n -log4j.appender.R=org.apache.log4j.RollingFileAppender -log4j.appender.R.File=firestorm.log +#log4j.appender.R=org.apache.log4j.RollingFileAppender +#log4j.appender.R.File=firestorm.log log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1 From 3d73620c5b39784f0297efa999968750a2008c4b Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 30 Dec 2018 23:02:53 +0800 Subject: [PATCH 128/151] =?UTF-8?q?http=E6=8E=A5=E5=8F=A3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=95=B4=E6=94=B9=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= =?UTF-8?q?-12302302?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/cache/WsCacheMap.java | 2 +- .../channel/http/HttpHandlerServiceImpl.java | 30 +++++++++++++ .../handler/DefaultWebSocketHandler.java | 44 ++++++++++++++----- .../unclecatmyself/common/base/Handler.java | 2 +- .../common/base/HttpHandlerService.java | 15 +++++++ .../exception/NoFindHandlerException.java | 2 + .../NotFindLoginChannlException.java | 2 +- .../common/utils/HttpConstantUtil.java | 21 +++++++++ .../unclecatmyself/common/utils/HttpUtil.java | 25 +++++++++++ 9 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java create mode 100644 src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java rename src/main/java/com/github/unclecatmyself/{ => common}/exception/NotFindLoginChannlException.java (83%) create mode 100644 src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java create mode 100644 src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index cd1ac47..7eb98ef 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.cache; -import com.github.unclecatmyself.exception.NotFindLoginChannlException; +import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; import io.netty.channel.Channel; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java new file mode 100644 index 0000000..f4a4444 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java @@ -0,0 +1,30 @@ +package com.github.unclecatmyself.bootstrap.channel.http; + +import com.github.unclecatmyself.common.base.HttpHandlerService; +import io.netty.channel.Channel; + +/** + * Create by UncleCatMySelf in 22:05 2018\12\30 0030 + */ +public class HttpHandlerServiceImpl extends HttpHandlerService { + + @Override + public void getSize(Channel channel) { + + } + + @Override + public void sendFromServer(Channel channel, String token) { + + } + + @Override + public void notFindUri(Channel channel) { + + } + + @Override + public void close(Channel channel) { + + } +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java index 78751ec..45bd417 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java @@ -3,9 +3,12 @@ import com.alibaba.fastjson.JSON; import com.github.unclecatmyself.common.base.Handler; import com.github.unclecatmyself.common.base.HandlerApi; +import com.github.unclecatmyself.common.base.HttpHandlerService; import com.github.unclecatmyself.common.base.WebSocketHandlerService; import com.github.unclecatmyself.common.exception.NoFindHandlerException; import com.github.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.common.utils.HttpConstantUtil; +import com.github.unclecatmyself.common.utils.HttpUtil; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; @@ -44,17 +47,34 @@ protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { @Override protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { - //暂未实现 - log.info("[httpdoMessage]--暂未实现"); - msg.retain(); - log.info(msg.uri()); - log.info(msg.toString()); - FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.headers().set("Content-Type","text/html;charset=UTF-8"); - ByteBuf buf = Unpooled.copiedBuffer("【InChat】-HTTP通道返回成功",CharsetUtil.UTF_8); - response.content().writeBytes(buf); - ctx.writeAndFlush(response); - ctx.close(); +// FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); +// response.headers().set("Content-Type","text/html;charset=UTF-8"); +// ByteBuf buf = Unpooled.copiedBuffer("【InChat】-HTTP通道返回成功",CharsetUtil.UTF_8); +// response.content().writeBytes(buf); +// ctx.writeAndFlush(response); +// ctx.close(); + Channel channel = ctx.channel(); + HttpHandlerService httpHandlerService; + if (handlerApi instanceof HttpHandlerService){ + httpHandlerService = (HttpHandlerService)handlerApi; + }else { + throw new NoFindHandlerException("Server Handler 不匹配"); + } + switch (HttpUtil.checkType(msg)){ + case HttpConstantUtil.GETSIZE: + log.info("[DefaultWebSocketHandler.httpdoMessage.GETSIZE]"); + httpHandlerService.getSize(channel); + break; + case HttpConstantUtil.SENDFROMSERVER: + log.info("[DefaultWebSocketHandler.httpdoMessage.SENDFROMSERVER]"); + break; + case HttpConstantUtil.NOTFINDURI: + log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); + + break; + default: + break; + } } @Override @@ -105,6 +125,6 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ log.error("exception",cause); log.info("[DefaultWebSocketHandler.exceptionCaught]"+ctx.channel().remoteAddress().toString()+"异常断开"); - handlerApi.close(ctx.channel()); + ctx.close(); } } diff --git a/src/main/java/com/github/unclecatmyself/common/base/Handler.java b/src/main/java/com/github/unclecatmyself/common/base/Handler.java index a88cdf3..4395559 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/Handler.java +++ b/src/main/java/com/github/unclecatmyself/common/base/Handler.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.common.base; -import com.github.unclecatmyself.exception.NotFindLoginChannlException; +import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpRequest; diff --git a/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java new file mode 100644 index 0000000..cb49bb0 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java @@ -0,0 +1,15 @@ +package com.github.unclecatmyself.common.base; + +import io.netty.channel.Channel; + +/** + * Create by UncleCatMySelf in 22:02 2018\12\30 0030 + */ +public abstract class HttpHandlerService implements HandlerApi { + + public abstract void getSize(Channel channel); + + public abstract void sendFromServer(Channel channel,String token); + + public abstract void notFindUri(Channel channel); +} diff --git a/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java index f8ba5eb..99cf181 100644 --- a/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java +++ b/src/main/java/com/github/unclecatmyself/common/exception/NoFindHandlerException.java @@ -6,6 +6,8 @@ **/ public class NoFindHandlerException extends RuntimeException { + private static final long serialVersionUID = 6724478022966267728L; + public NoFindHandlerException(String message) { super(message); } diff --git a/src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java b/src/main/java/com/github/unclecatmyself/common/exception/NotFindLoginChannlException.java similarity index 83% rename from src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java rename to src/main/java/com/github/unclecatmyself/common/exception/NotFindLoginChannlException.java index 5c9370b..7670a6c 100644 --- a/src/main/java/com/github/unclecatmyself/exception/NotFindLoginChannlException.java +++ b/src/main/java/com/github/unclecatmyself/common/exception/NotFindLoginChannlException.java @@ -1,4 +1,4 @@ -package com.github.unclecatmyself.exception; +package com.github.unclecatmyself.common.exception; /** * 未找到正常注册的连接异常 diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java new file mode 100644 index 0000000..6cdc450 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java @@ -0,0 +1,21 @@ +package com.github.unclecatmyself.common.utils; + +/** + * Create by UncleCatMySelf in 22:49 2018\12\30 0030 + */ +public class HttpConstantUtil { + + public static final String GET = "GET"; + + public static final String POST = "POST"; + + public static final String GETSIZE = "get_size"; + + public static final String SENDFROMSERVER = "send_from_server"; + + public static final String NOTFINDURI = "not_find_uri"; + + public static final String URI_GETSIZE = "/get_size"; + + public static final String URI_SENDFROMSERVER = "/send_from_server"; +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java new file mode 100644 index 0000000..0e047f8 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -0,0 +1,25 @@ +package com.github.unclecatmyself.common.utils; + +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpMethod; + +/** + * Create by UncleCatMySelf in 22:43 2018\12\30 0030 + */ +public class HttpUtil { + + public static String checkType(FullHttpRequest msg){ + msg.retain(); + String url = msg.uri(); + HttpMethod method = msg.method(); + String meName = method.name(); + if (url.equals(HttpConstantUtil.GETSIZE) && meName.equals(HttpConstantUtil.GET)){ + return HttpConstantUtil.GETSIZE; + }else if (url.equals(HttpConstantUtil.URI_SENDFROMSERVER) && meName.equals(HttpConstantUtil.POST)){ + return HttpConstantUtil.SENDFROMSERVER; + }else { + return HttpConstantUtil.NOTFINDURI; + } + } + +} From 037c4d24712e45c71609ff9a5fdbf4b5500b468d Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sun, 30 Dec 2018 23:05:17 +0800 Subject: [PATCH 129/151] update_log_doc --- doc/Project-Log-cn.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index d61ad0b..00e7ccc 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -19,4 +19,5 @@ * 【2018-12-21】 添加静态配置,添加服务端发送接口,发布V1.1.0-alpha版本,标识性版本。 * 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式,修改日志配置。 * 【2018-12-28】 预计整改常量、修改部分方法(类)命名,下一版加wss通道。 +* 【2018-12-30】 修改异步线程任务(FutureTask启动模式),整改目录与修改核心类名,捕获未注册时客户端异常断开的连接异常,新增Http接口功能整改(未完)。 From 087592c16cbf40914f50784e419193941d157fcb Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Mon, 31 Dec 2018 12:03:10 +0800 Subject: [PATCH 130/151] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90htt?= =?UTF-8?q?p=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5-12311203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/AbstractBootstrapServer.java | 6 +- ...rviceImpl.java => HandlerServiceImpl.java} | 42 ++++++++++-- .../channel/http/HttpChannelService.java | 18 ++++++ .../channel/http/HttpChannelServiceImpl.java | 64 +++++++++++++++++++ .../channel/http/HttpHandlerServiceImpl.java | 30 --------- .../channel/ws/WebSocketChannelService.java | 1 - .../{ => channel/ws}/WsChannelService.java | 2 +- ...SocketHandler.java => DefaultHandler.java} | 40 ++++++------ .../unclecatmyself/common/base/Handler.java | 4 +- ...andlerService.java => HandlerService.java} | 21 +++++- .../common/base/HttpHandlerService.java | 15 ----- .../unclecatmyself/common/bean/InitNetty.java | 6 +- .../common/bean/vo/GetSizeVO.java | 34 ++++++++++ .../common/bean/vo/NotFindUriVO.java | 21 ++++++ .../common/bean/vo/ResultVO.java | 40 ++++++++++++ .../unclecatmyself/common/utils/HttpUtil.java | 3 +- 16 files changed, 262 insertions(+), 85 deletions(-) rename src/main/java/com/github/unclecatmyself/bootstrap/channel/{ws/WebSocketHandlerServiceImpl.java => HandlerServiceImpl.java} (76%) create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java delete mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java rename src/main/java/com/github/unclecatmyself/bootstrap/{ => channel/ws}/WsChannelService.java (95%) rename src/main/java/com/github/unclecatmyself/bootstrap/handler/{DefaultWebSocketHandler.java => DefaultHandler.java} (76%) rename src/main/java/com/github/unclecatmyself/common/base/{WebSocketHandlerService.java => HandlerService.java} (67%) delete mode 100644 src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/GetSizeVO.java create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/NotFindUriVO.java create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/ResultVO.java diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 9f0f313..4b3b2b4 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -2,8 +2,8 @@ import com.github.unclecatmyself.auto.ConfigFactory; -import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketHandlerServiceImpl; -import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; +import com.github.unclecatmyself.bootstrap.channel.HandlerServiceImpl; +import com.github.unclecatmyself.bootstrap.handler.DefaultHandler; import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; @@ -25,7 +25,7 @@ public abstract class AbstractBootstrapServer implements BootstrapServer { protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBean){ intProtocolHandler(channelPipeline,serverBean); channelPipeline.addLast(new IdleStateHandler(serverBean.getHeart(),0,0)); - channelPipeline.addLast(new DefaultWebSocketHandler(new WebSocketHandlerServiceImpl(new DataAsynchronousTask(ConfigFactory.inChatToDataBaseService),ConfigFactory.inChatVerifyService))); + channelPipeline.addLast(new DefaultHandler(new HandlerServiceImpl(new DataAsynchronousTask(ConfigFactory.inChatToDataBaseService),ConfigFactory.inChatVerifyService))); } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java similarity index 76% rename from src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 2c57708..6e1c5ce 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketHandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -1,16 +1,31 @@ -package com.github.unclecatmyself.bootstrap.channel.ws; +package com.github.unclecatmyself.bootstrap.channel; import com.alibaba.fastjson.JSONArray; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; -import com.github.unclecatmyself.common.base.WebSocketHandlerService; +import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; +import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelService; +import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelServiceImpl; +import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; +import com.github.unclecatmyself.common.base.HandlerService; +import com.github.unclecatmyself.common.bean.vo.GetSizeVO; +import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; +import com.github.unclecatmyself.common.bean.vo.ResultVO; import com.google.gson.Gson; -import com.github.unclecatmyself.bootstrap.WsChannelService; +import com.github.unclecatmyself.bootstrap.channel.ws.WsChannelService; import com.github.unclecatmyself.common.utils.ConstansUtil; import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; import com.github.unclecatmyself.task.DataAsynchronousTask; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.util.CharsetUtil; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -18,22 +33,39 @@ /** * Created by MySelf on 2018/11/21. */ -public class WebSocketHandlerServiceImpl extends WebSocketHandlerService { +public class HandlerServiceImpl extends HandlerService { private final InChatVerifyService inChatVerifyService; private final InChatBackMapService inChatBackMapService = new InChatBackMapServiceImpl(); + private final HttpChannelService httpChannelService = new HttpChannelServiceImpl(); + private final WsChannelService websocketChannelService = new WebSocketChannelService(); private final DataAsynchronousTask dataAsynchronousTask; - public WebSocketHandlerServiceImpl(DataAsynchronousTask dataAsynchronousTask,InChatVerifyService inChatVerifyService) { + public HandlerServiceImpl(DataAsynchronousTask dataAsynchronousTask,InChatVerifyService inChatVerifyService) { this.dataAsynchronousTask = dataAsynchronousTask; this.inChatVerifyService = inChatVerifyService; } + @Override + public void getSize(Channel channel) { + httpChannelService.getSize(channel); + } + + @Override + public void sendFromServer(Channel channel, String token) { + //未实现 + } + + @Override + public void notFindUri(Channel channel) { + httpChannelService.notFindUri(channel); + } + @Override public boolean login(Channel channel, Map maps) { //校验规则,自定义校验规则 diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java new file mode 100644 index 0000000..27a2e13 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -0,0 +1,18 @@ +package com.github.unclecatmyself.bootstrap.channel.http; + +import io.netty.channel.Channel; + +/** + * Create by UncleCatMySelf in 11:41 2018\12\31 0031 + */ +public interface HttpChannelService { + + void getSize(Channel channel); + + void sendFromServer(Channel channel,String token); + + void notFindUri(Channel channel); + + void close(Channel channel); + +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java new file mode 100644 index 0000000..8a26830 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -0,0 +1,64 @@ +package com.github.unclecatmyself.bootstrap.channel.http; + +import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; +import com.github.unclecatmyself.common.bean.vo.GetSizeVO; +import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; +import com.github.unclecatmyself.common.bean.vo.ResultVO; +import com.google.gson.Gson; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.util.CharsetUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; + +/** + * Create by UncleCatMySelf in 11:41 2018\12\31 0031 + */ +public class HttpChannelServiceImpl implements HttpChannelService { + + private static final Logger log = LoggerFactory.getLogger(HttpChannelServiceImpl.class); + + @Override + public void getSize(Channel channel) { + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); + response.headers().set("Content-Type","text/html;charset=UTF-8"); + GetSizeVO getSizeVO = new GetSizeVO(WsCacheMap.getSize(),new Date()); + ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getSizeVO); + Gson gson = new Gson(); + ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); + response.content().writeBytes(buf); + channel.writeAndFlush(response); + close(channel); + } + + @Override + public void sendFromServer(Channel channel, String token) { + + } + + @Override + public void notFindUri(Channel channel) { + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); + response.headers().set("Content-Type","text/html;charset=UTF-8"); + NotFindUriVO notFindUriVO = new NotFindUriVO("未找到匹配任务URI"); + ResultVO resultVO = new ResultVO<>(HttpResponseStatus.BAD_REQUEST.code(),notFindUriVO); + Gson gson = new Gson(); + ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); + response.content().writeBytes(buf); + channel.writeAndFlush(response); + close(channel); + } + + @Override + public void close(Channel channel) { + log.info("[HttpChannelServiceImpl.close] 关闭HTTP通道连接"); + channel.close(); + } +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java deleted file mode 100644 index f4a4444..0000000 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpHandlerServiceImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.github.unclecatmyself.bootstrap.channel.http; - -import com.github.unclecatmyself.common.base.HttpHandlerService; -import io.netty.channel.Channel; - -/** - * Create by UncleCatMySelf in 22:05 2018\12\30 0030 - */ -public class HttpHandlerServiceImpl extends HttpHandlerService { - - @Override - public void getSize(Channel channel) { - - } - - @Override - public void sendFromServer(Channel channel, String token) { - - } - - @Override - public void notFindUri(Channel channel) { - - } - - @Override - public void close(Channel channel) { - - } -} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java index 218fa47..f5ad892 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WebSocketChannelService.java @@ -1,7 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.ws; import com.google.gson.Gson; -import com.github.unclecatmyself.bootstrap.WsChannelService; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WsChannelService.java similarity index 95% rename from src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java rename to src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WsChannelService.java index d8eaca1..e3b8113 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/WsChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/ws/WsChannelService.java @@ -1,4 +1,4 @@ -package com.github.unclecatmyself.bootstrap; +package com.github.unclecatmyself.bootstrap.channel.ws; import io.netty.channel.Channel; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java similarity index 76% rename from src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java rename to src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index 45bd417..b9d68f0 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultWebSocketHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -3,21 +3,17 @@ import com.alibaba.fastjson.JSON; import com.github.unclecatmyself.common.base.Handler; import com.github.unclecatmyself.common.base.HandlerApi; -import com.github.unclecatmyself.common.base.HttpHandlerService; -import com.github.unclecatmyself.common.base.WebSocketHandlerService; +import com.github.unclecatmyself.common.base.HandlerService; import com.github.unclecatmyself.common.exception.NoFindHandlerException; import com.github.unclecatmyself.common.utils.ConstansUtil; import com.github.unclecatmyself.common.utils.HttpConstantUtil; import com.github.unclecatmyself.common.utils.HttpUtil; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.*; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.util.CharsetUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,13 +24,13 @@ * Create by UncleCatMySelf in 2018/12/06 */ @ChannelHandler.Sharable -public class DefaultWebSocketHandler extends Handler { +public class DefaultHandler extends Handler { - private final Logger log = LoggerFactory.getLogger(DefaultWebSocketHandler.class); + private final Logger log = LoggerFactory.getLogger(DefaultHandler.class); private final HandlerApi handlerApi; - public DefaultWebSocketHandler(HandlerApi handlerApi) { + public DefaultHandler(HandlerApi handlerApi) { super(handlerApi); this.handlerApi = handlerApi; } @@ -54,9 +50,9 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { // ctx.writeAndFlush(response); // ctx.close(); Channel channel = ctx.channel(); - HttpHandlerService httpHandlerService; - if (handlerApi instanceof HttpHandlerService){ - httpHandlerService = (HttpHandlerService)handlerApi; + HandlerService httpHandlerService; + if (handlerApi instanceof HandlerService){ + httpHandlerService = (HandlerService)handlerApi; }else { throw new NoFindHandlerException("Server Handler 不匹配"); } @@ -70,7 +66,7 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { break; case HttpConstantUtil.NOTFINDURI: log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); - + httpHandlerService.notFindUri(channel); break; default: break; @@ -80,9 +76,9 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { @Override protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) { Channel channel = ctx.channel(); - WebSocketHandlerService webSocketHandlerService; - if (handlerApi instanceof WebSocketHandlerService){ - webSocketHandlerService = (WebSocketHandlerService)handlerApi; + HandlerService handlerService; + if (handlerApi instanceof HandlerService){ + handlerService = (HandlerService)handlerApi; }else{ throw new NoFindHandlerException("Server Handler 不匹配"); } @@ -91,25 +87,25 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) switch ((String)maps.get(ConstansUtil.TYPE)){ case ConstansUtil.LOGIN: log.info("[DefaultWebSocketHandler.textdoMessage.LOGIN]"); - webSocketHandlerService.login(channel,maps); + handlerService.login(channel,maps); break; //针对个人,发送给自己 case ConstansUtil.SENDME: log.info("[DefaultWebSocketHandler.textdoMessage.SENDME]"); - webSocketHandlerService.verify(channel,maps); - webSocketHandlerService.sendMeText(channel,maps); + handlerService.verify(channel,maps); + handlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 case ConstansUtil.SENDTO: log.info("[DefaultWebSocketHandler.textdoMessage.SENDTO]"); - webSocketHandlerService.verify(channel,maps); - webSocketHandlerService.sendToText(channel,maps); + handlerService.verify(channel,maps); + handlerService.sendToText(channel,maps); break; //发送给群组 case ConstansUtil.SENDGROUP: log.info("[DefaultWebSocketHandler.textdoMessage.SENDGROUP]"); - webSocketHandlerService.verify(channel,maps); - webSocketHandlerService.sendGroupText(channel,maps); + handlerService.verify(channel,maps); + handlerService.sendGroupText(channel,maps); break; default: break; diff --git a/src/main/java/com/github/unclecatmyself/common/base/Handler.java b/src/main/java/com/github/unclecatmyself/common/base/Handler.java index 4395559..e28429c 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/Handler.java +++ b/src/main/java/com/github/unclecatmyself/common/base/Handler.java @@ -42,11 +42,11 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【DefaultWebSocketHandler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + log.info("【Handler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); try { handlerApi.close(ctx.channel()); }catch (NotFindLoginChannlException e){ - log.error("【捕获异常:NotFindLoginChannlException】-【DefaultWebSocketHandler:channelInactive】关闭未正常注册链接!"); + log.error("【捕获异常:NotFindLoginChannlException】-【Handler:channelInactive】关闭未正常注册链接!"); } } diff --git a/src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java similarity index 67% rename from src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java rename to src/main/java/com/github/unclecatmyself/common/base/HandlerService.java index 385c22e..d351f02 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/WebSocketHandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java @@ -8,7 +8,26 @@ * 业务层伪接口 * Created by MySelf on 2018/11/21. */ -public abstract class WebSocketHandlerService implements HandlerApi { +public abstract class HandlerService implements HandlerApi { + + /** + * HTTP获取在线用户数 + * @param channel {@link Channel} 链接实例 + */ + public abstract void getSize(Channel channel); + + /** + * HTTP以服务端向指定用户发送通知 + * @param channel {@link Channel} 链接实例 + * @param token {@link String} 用户标识 + */ + public abstract void sendFromServer(Channel channel,String token); + + /** + * 用户未找到匹配Uri + * @param channel {@link Channel} 链接实例 + */ + public abstract void notFindUri(Channel channel); /** * 登录类型 diff --git a/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java deleted file mode 100644 index cb49bb0..0000000 --- a/src/main/java/com/github/unclecatmyself/common/base/HttpHandlerService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.unclecatmyself.common.base; - -import io.netty.channel.Channel; - -/** - * Create by UncleCatMySelf in 22:02 2018\12\30 0030 - */ -public abstract class HttpHandlerService implements HandlerApi { - - public abstract void getSize(Channel channel); - - public abstract void sendFromServer(Channel channel,String token); - - public abstract void notFindUri(Channel channel); -} diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java index 1651aa2..20bbf87 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.common.bean; -import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler; +import com.github.unclecatmyself.bootstrap.handler.DefaultHandler; /** * 初始化Netty配置 @@ -38,7 +38,7 @@ public class InitNetty { private String webSocketPath = "/ws"; - private Class webSocketHandler = DefaultWebSocketHandler.class; + private Class webSocketHandler = DefaultHandler.class; /** * 返回WebSocket启动监听端口 @@ -184,7 +184,7 @@ public String getWebSocketPath() { } - public Class getWebSocketHandler() { + public Class getWebSocketHandler() { return webSocketHandler; } diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/GetSizeVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetSizeVO.java new file mode 100644 index 0000000..691da26 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetSizeVO.java @@ -0,0 +1,34 @@ +package com.github.unclecatmyself.common.bean.vo; + +import java.util.Date; + +/** + * Create by UncleCatMySelf in 11:13 2018\12\31 0031 + */ +public class GetSizeVO { + + private Integer online; + + private Date time; + + public GetSizeVO(Integer online, Date time) { + this.online = online; + this.time = time; + } + + public Integer getOnline() { + return online; + } + + public void setOnline(Integer online) { + this.online = online; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/NotFindUriVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/NotFindUriVO.java new file mode 100644 index 0000000..b4fadba --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/NotFindUriVO.java @@ -0,0 +1,21 @@ +package com.github.unclecatmyself.common.bean.vo; + +/** + * Create by UncleCatMySelf in 11:21 2018\12\31 0031 + */ +public class NotFindUriVO { + + private String message; + + public NotFindUriVO(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/ResultVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/ResultVO.java new file mode 100644 index 0000000..db52fa8 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/ResultVO.java @@ -0,0 +1,40 @@ +package com.github.unclecatmyself.common.bean.vo; + +/** + * Create by UncleCatMySelf in 11:11 2018\12\31 0031 + */ +public class ResultVO { + + private int code; + + private T data; + + public ResultVO(int code, T data) { + this.code = code; + this.data = data; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + @Override + public String toString() { + return "ResultVO{" + + "code=" + code + + ", data=" + data + + '}'; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index 0e047f8..f25e87a 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -13,7 +13,7 @@ public static String checkType(FullHttpRequest msg){ String url = msg.uri(); HttpMethod method = msg.method(); String meName = method.name(); - if (url.equals(HttpConstantUtil.GETSIZE) && meName.equals(HttpConstantUtil.GET)){ + if (url.equals(HttpConstantUtil.URI_GETSIZE) && meName.equals(HttpConstantUtil.GET)){ return HttpConstantUtil.GETSIZE; }else if (url.equals(HttpConstantUtil.URI_SENDFROMSERVER) && meName.equals(HttpConstantUtil.POST)){ return HttpConstantUtil.SENDFROMSERVER; @@ -21,5 +21,4 @@ public static String checkType(FullHttpRequest msg){ return HttpConstantUtil.NOTFINDURI; } } - } From f7f4b93fa8abc977279612c58c84a3365e8a57aa Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Mon, 31 Dec 2018 12:04:26 +0800 Subject: [PATCH 131/151] update_log_doc --- doc/Project-Log-cn.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 00e7ccc..e4d9b2f 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -20,4 +20,5 @@ * 【2018-12-27】 添加部分注释,修改版本启动模式,并预定后期添加HTTP接入模式,修改日志配置。 * 【2018-12-28】 预计整改常量、修改部分方法(类)命名,下一版加wss通道。 * 【2018-12-30】 修改异步线程任务(FutureTask启动模式),整改目录与修改核心类名,捕获未注册时客户端异常断开的连接异常,新增Http接口功能整改(未完)。 +* 【2018-12-31】 下一版InChat 自带几个默认的Http接口 查询【在线用户数】、【服务端发送消息】、【用户在线用户列表】等,暂不支持自定义URI HTTP接口 From edbf81ed9d67b5b7a2eaea3f9560f0f9e29cad39 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Mon, 31 Dec 2018 12:29:40 +0800 Subject: [PATCH 132/151] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=A0=87=E7=AD=BE=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3-12311229?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/HandlerServiceImpl.java | 5 ++++ .../bootstrap/channel/cache/WsCacheMap.java | 13 +++++++++++ .../channel/http/HttpChannelService.java | 2 ++ .../channel/http/HttpChannelServiceImpl.java | 14 +++++++++++ .../bootstrap/handler/DefaultHandler.java | 9 +++----- .../common/base/HandlerService.java | 6 +++++ .../common/bean/vo/GetListVO.java | 23 +++++++++++++++++++ .../common/utils/HttpConstantUtil.java | 4 ++++ .../unclecatmyself/common/utils/HttpUtil.java | 2 ++ 9 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 6e1c5ce..e43b53c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -51,6 +51,11 @@ public HandlerServiceImpl(DataAsynchronousTask dataAsynchronousTask,InChatVerify } + @Override + public void getList(Channel channel) { + httpChannelService.getList(channel); + } + @Override public void getSize(Channel channel) { httpChannelService.getSize(channel); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 7eb98ef..0473da8 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -2,7 +2,11 @@ import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; import io.netty.channel.Channel; + +import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; /** @@ -94,4 +98,13 @@ public static boolean hasToken(String token){ return maps.containsKey(token); } + /** + * 获取在线用户标签列表 + * @return {@link Set} 标识列表 + */ + public static Set getTokenList(){ + Set keys = maps.keySet(); + return keys; + } + } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java index 27a2e13..a1c5e49 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -15,4 +15,6 @@ public interface HttpChannelService { void close(Channel channel); + void getList(Channel channel); + } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index 8a26830..44fb69c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.bootstrap.channel.http; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; +import com.github.unclecatmyself.common.bean.vo.GetListVO; import com.github.unclecatmyself.common.bean.vo.GetSizeVO; import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; import com.github.unclecatmyself.common.bean.vo.ResultVO; @@ -61,4 +62,17 @@ public void close(Channel channel) { log.info("[HttpChannelServiceImpl.close] 关闭HTTP通道连接"); channel.close(); } + + @Override + public void getList(Channel channel) { + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); + response.headers().set("Content-Type","text/html;charset=UTF-8"); + GetListVO getListVO = new GetListVO(WsCacheMap.getTokenList()); + ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getListVO); + Gson gson = new Gson(); + ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); + response.content().writeBytes(buf); + channel.writeAndFlush(response); + close(channel); + } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index b9d68f0..5fb2486 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -43,12 +43,6 @@ protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { @Override protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { -// FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); -// response.headers().set("Content-Type","text/html;charset=UTF-8"); -// ByteBuf buf = Unpooled.copiedBuffer("【InChat】-HTTP通道返回成功",CharsetUtil.UTF_8); -// response.content().writeBytes(buf); -// ctx.writeAndFlush(response); -// ctx.close(); Channel channel = ctx.channel(); HandlerService httpHandlerService; if (handlerApi instanceof HandlerService){ @@ -68,6 +62,9 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); httpHandlerService.notFindUri(channel); break; + case HttpConstantUtil.GETLIST: + log.info("[DefaultWebSocketHandler.httpdoMessage.GETLIST]"); + httpHandlerService.getList(channel); default: break; } diff --git a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java index d351f02..13ac8ea 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java @@ -10,6 +10,12 @@ */ public abstract class HandlerService implements HandlerApi { + /** + * HTTP获取在线用户标签列表 + * @param channel {@link Channel} 链接实例 + */ + public abstract void getList(Channel channel); + /** * HTTP获取在线用户数 * @param channel {@link Channel} 链接实例 diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java new file mode 100644 index 0000000..cefdcad --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java @@ -0,0 +1,23 @@ +package com.github.unclecatmyself.common.bean.vo; + +import java.util.Set; + +/** + * Create by UncleCatMySelf in 12:26 2018\12\31 0031 + */ +public class GetListVO { + + private Set tokens; + + public GetListVO(Set tokens) { + this.tokens = tokens; + } + + public Set getTokens() { + return tokens; + } + + public void setTokens(Set tokens) { + this.tokens = tokens; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java index 6cdc450..5472d1a 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java @@ -11,11 +11,15 @@ public class HttpConstantUtil { public static final String GETSIZE = "get_size"; + public static final String GETLIST = "get_list"; + public static final String SENDFROMSERVER = "send_from_server"; public static final String NOTFINDURI = "not_find_uri"; public static final String URI_GETSIZE = "/get_size"; + public static final String URI_GETLIST = "/get_list"; + public static final String URI_SENDFROMSERVER = "/send_from_server"; } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index f25e87a..042bef2 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -17,6 +17,8 @@ public static String checkType(FullHttpRequest msg){ return HttpConstantUtil.GETSIZE; }else if (url.equals(HttpConstantUtil.URI_SENDFROMSERVER) && meName.equals(HttpConstantUtil.POST)){ return HttpConstantUtil.SENDFROMSERVER; + }else if (url.equals(HttpConstantUtil.URI_GETLIST) && meName.equals(HttpConstantUtil.GET)){ + return HttpConstantUtil.GETLIST; }else { return HttpConstantUtil.NOTFINDURI; } From a91abb6d76bb3392fb1e953154a45a22c2a5339d Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Tue, 1 Jan 2019 19:31:54 +0800 Subject: [PATCH 133/151] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=96=B9=E6=B3=95-01011831?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/handler/DefaultHandler.java | 2 ++ .../github/unclecatmyself/common/utils/HttpUtil.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index 5fb2486..70753be 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -57,6 +57,8 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { break; case HttpConstantUtil.SENDFROMSERVER: log.info("[DefaultWebSocketHandler.httpdoMessage.SENDFROMSERVER]"); + String token = HttpUtil.getToken(msg); + httpHandlerService.sendFromServer(null,null); break; case HttpConstantUtil.NOTFINDURI: log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index 042bef2..dce0d70 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -1,7 +1,11 @@ package com.github.unclecatmyself.common.utils; +import io.netty.buffer.ByteBuf; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpMethod; +import io.netty.util.CharsetUtil; + +import java.nio.charset.Charset; /** * Create by UncleCatMySelf in 22:43 2018\12\30 0030 @@ -23,4 +27,11 @@ public static String checkType(FullHttpRequest msg){ return HttpConstantUtil.NOTFINDURI; } } + + public static String getToken(FullHttpRequest msg){ + msg.retain(); + String url = msg.content().toString(CharsetUtil.UTF_8); + System.out.println(url); + return null; + } } From 88565a87e29a6898d9d31ab2ebfe08619d81c477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Wed, 2 Jan 2019 17:36:52 +0800 Subject: [PATCH 134/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8DhttpPost=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=8E=A5=E5=8F=A3-01021736?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unclecatmyself/DemoApplication.java | 2 + .../unclecatmyself/auto/ConfigFactory.java | 19 ++----- .../bootstrap/AbstractBootstrapServer.java | 2 + .../bootstrap/channel/HandlerServiceImpl.java | 5 +- .../channel/http/FromServerService.java | 11 ++++ .../channel/http/HttpChannelService.java | 3 +- .../channel/http/HttpChannelServiceImpl.java | 36 +++++++++++-- .../bootstrap/handler/DefaultHandler.java | 11 +++- .../common/base/HandlerService.java | 5 +- .../common/bean/vo/SendServerVO.java | 27 ++++++++++ .../unclecatmyself/common/utils/HttpUtil.java | 25 ++++++++-- .../user/FromServerServiceImpl.java | 50 +++++++++++++++++++ 12 files changed, 164 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/SendServerVO.java create mode 100644 src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java index c1ee5d7..8017d30 100644 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -3,6 +3,7 @@ import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.auto.InitServer; import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; +import com.github.unclecatmyself.user.FromServerServiceImpl; import com.github.unclecatmyself.user.MyInit; import com.github.unclecatmyself.user.ToDataBaseServiceImpl; import com.github.unclecatmyself.user.verifyServiceImpl; @@ -19,6 +20,7 @@ public static void main(String[] args) { ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); ConfigFactory.inChatVerifyService = new verifyServiceImpl(); ConfigFactory.initNetty = new MyInit(); + ConfigFactory.fromServerService = new FromServerServiceImpl(); //默认启动InChat // InitServer initServer = InitServer(new MyInit()); InitServer.open(); diff --git a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java index 2b26d6b..c7ac9f3 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java +++ b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.auto; +import com.github.unclecatmyself.bootstrap.channel.http.FromServerService; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; import com.github.unclecatmyself.common.bean.InitNetty; @@ -16,22 +17,8 @@ public class ConfigFactory { /** 用户获取数据伪接口 */ public static InChatToDataBaseService inChatToDataBaseService; + public static FromServerService fromServerService; + /** InChat项目配置 */ public static InitNetty initNetty; - - public InChatVerifyService getInChatVerifyService() { - return inChatVerifyService; - } - - public void setInChatVerifyService(InChatVerifyService inChatVerifyService) { - this.inChatVerifyService = inChatVerifyService; - } - - public InChatToDataBaseService getInChatToDataBaseService() { - return inChatToDataBaseService; - } - - public void setInChatToDataBaseService(InChatToDataBaseService inChatToDataBaseService) { - this.inChatToDataBaseService = inChatToDataBaseService; - } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 4b3b2b4..5a8aba4 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -8,6 +8,8 @@ import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpServerCodec; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.stream.ChunkedWriteHandler; diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index e43b53c..81fdf2c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -11,6 +11,7 @@ import com.github.unclecatmyself.common.bean.vo.GetSizeVO; import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; import com.github.unclecatmyself.common.bean.vo.ResultVO; +import com.github.unclecatmyself.common.bean.vo.SendServerVO; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.channel.ws.WsChannelService; import com.github.unclecatmyself.common.utils.ConstansUtil; @@ -62,8 +63,8 @@ public void getSize(Channel channel) { } @Override - public void sendFromServer(Channel channel, String token) { - //未实现 + public void sendFromServer(Channel channel, SendServerVO serverVO) { + httpChannelService.sendFromServer(channel,serverVO); } @Override diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java new file mode 100644 index 0000000..d940cba --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java @@ -0,0 +1,11 @@ +package com.github.unclecatmyself.bootstrap.channel.http; + +/** + * Created by MySelf on 2019/1/2. + */ +public interface FromServerService { + + Integer getCode(); + + String findByCode(Integer code); +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java index a1c5e49..b8f977a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.http; +import com.github.unclecatmyself.common.bean.vo.SendServerVO; import io.netty.channel.Channel; /** @@ -9,7 +10,7 @@ public interface HttpChannelService { void getSize(Channel channel); - void sendFromServer(Channel channel,String token); + void sendFromServer(Channel channel,SendServerVO serverVO); void notFindUri(Channel channel); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index 44fb69c..3d27d3c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -1,10 +1,8 @@ package com.github.unclecatmyself.bootstrap.channel.http; +import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; -import com.github.unclecatmyself.common.bean.vo.GetListVO; -import com.github.unclecatmyself.common.bean.vo.GetSizeVO; -import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; -import com.github.unclecatmyself.common.bean.vo.ResultVO; +import com.github.unclecatmyself.common.bean.vo.*; import com.google.gson.Gson; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -26,6 +24,8 @@ public class HttpChannelServiceImpl implements HttpChannelService { private static final Logger log = LoggerFactory.getLogger(HttpChannelServiceImpl.class); + private static FromServerService fromServerService = ConfigFactory.fromServerService; + @Override public void getSize(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); @@ -40,10 +40,36 @@ public void getSize(Channel channel) { } @Override - public void sendFromServer(Channel channel, String token) { + public void sendFromServer(Channel channel, SendServerVO serverVO) { + if (serverVO.getToken() == ""){ + notFindUri(channel); + } + try { + Channel userChannel = WsCacheMap.getByToken(serverVO.getToken()); + String value = fromServerService.findByCode(serverVO.getValue()); + }catch (NullPointerException e){ + log.info("[HttpChannelServiceImpl.sendFromServer] 未找到用户在线标识"); + notFindToken(channel); + } + + } + + private void sendServer(Channel channel, SendServerVO serverVO){ } + private void notFindToken(Channel channel) { + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); + response.headers().set("Content-Type","text/html;charset=UTF-8"); + NotFindUriVO notFindUriVO = new NotFindUriVO("未找到在线用户标识"); + ResultVO resultVO = new ResultVO<>(HttpResponseStatus.BAD_REQUEST.code(),notFindUriVO); + Gson gson = new Gson(); + ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); + response.content().writeBytes(buf); + channel.writeAndFlush(response); + close(channel); + } + @Override public void notFindUri(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index 70753be..270d8a2 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -4,6 +4,7 @@ import com.github.unclecatmyself.common.base.Handler; import com.github.unclecatmyself.common.base.HandlerApi; import com.github.unclecatmyself.common.base.HandlerService; +import com.github.unclecatmyself.common.bean.vo.SendServerVO; import com.github.unclecatmyself.common.exception.NoFindHandlerException; import com.github.unclecatmyself.common.utils.ConstansUtil; import com.github.unclecatmyself.common.utils.HttpConstantUtil; @@ -17,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Map; @@ -57,8 +59,13 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { break; case HttpConstantUtil.SENDFROMSERVER: log.info("[DefaultWebSocketHandler.httpdoMessage.SENDFROMSERVER]"); - String token = HttpUtil.getToken(msg); - httpHandlerService.sendFromServer(null,null); + SendServerVO serverVO = null; + try { + serverVO = HttpUtil.getToken(msg); + } catch (UnsupportedEncodingException e) { + log.error(e.getMessage()); + } + httpHandlerService.sendFromServer(channel,serverVO); break; case HttpConstantUtil.NOTFINDURI: log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); diff --git a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java index 13ac8ea..fd7688e 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.common.base; +import com.github.unclecatmyself.common.bean.vo.SendServerVO; import io.netty.channel.Channel; import java.util.Map; @@ -25,9 +26,9 @@ public abstract class HandlerService implements HandlerApi { /** * HTTP以服务端向指定用户发送通知 * @param channel {@link Channel} 链接实例 - * @param token {@link String} 用户标识 + * @param sendServerVO {@link SendServerVO} 用户标识 */ - public abstract void sendFromServer(Channel channel,String token); + public abstract void sendFromServer(Channel channel,SendServerVO sendServerVO); /** * 用户未找到匹配Uri diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServerVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServerVO.java new file mode 100644 index 0000000..f5c66fb --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServerVO.java @@ -0,0 +1,27 @@ +package com.github.unclecatmyself.common.bean.vo; + +/** + * Created by MySelf on 2019/1/2. + */ +public class SendServerVO { + + private String token; + + private String value; + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index dce0d70..3e69df9 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -1,13 +1,17 @@ package com.github.unclecatmyself.common.utils; +import com.github.unclecatmyself.common.bean.vo.SendServerVO; import io.netty.buffer.ByteBuf; +import io.netty.handler.codec.DecoderResult; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpMethod; import io.netty.util.CharsetUtil; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; /** + * HTTP接口处理方法 * Create by UncleCatMySelf in 22:43 2018\12\30 0030 */ public class HttpUtil { @@ -28,10 +32,23 @@ public static String checkType(FullHttpRequest msg){ } } - public static String getToken(FullHttpRequest msg){ + public static SendServerVO getToken(FullHttpRequest msg) throws UnsupportedEncodingException { msg.retain(); - String url = msg.content().toString(CharsetUtil.UTF_8); - System.out.println(url); - return null; + SendServerVO sendServerVO = new SendServerVO(); + String content = msg.content().toString(CharsetUtil.UTF_8); + String[] stars = content.split("&"); + for (int i=0,len=stars.length;i Date: Thu, 3 Jan 2019 09:52:33 +0800 Subject: [PATCH 135/151] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=96=B0=E7=89=88http=E6=8E=A5=E5=8F=A3=E5=A4=84=E7=90=86-0103?= =?UTF-8?q?0952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 4 +- .../unclecatmyself/DemoApplication.java | 2 +- .../channel/http/HttpChannelServiceImpl.java | 52 +++++++++---------- .../common/bean/vo/SendServer.java | 33 ++++++++++++ .../common/utils/ConstansUtil.java | 2 + .../user/FromServerServiceImpl.java | 3 +- 6 files changed, 65 insertions(+), 31 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index 7e29eb6..ee47697 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data @@ -145,7 +145,7 @@

SpringBoot netty 聊天室


- + diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java index 8017d30..818feee 100644 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ b/src/main/java/com/github/unclecatmyself/DemoApplication.java @@ -20,7 +20,7 @@ public static void main(String[] args) { ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); ConfigFactory.inChatVerifyService = new verifyServiceImpl(); ConfigFactory.initNetty = new MyInit(); - ConfigFactory.fromServerService = new FromServerServiceImpl(); + ConfigFactory.fromServerService = FromServerServiceImpl.TYPE1; //默认启动InChat // InitServer initServer = InitServer(new MyInit()); InitServer.open(); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index 3d27d3c..fdefa14 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.bootstrap.channel.http; +import com.alibaba.fastjson.JSONObject; import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import com.github.unclecatmyself.common.bean.vo.*; @@ -7,15 +8,15 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.*; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.util.CharsetUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; +import java.util.HashMap; +import java.util.Map; /** * Create by UncleCatMySelf in 11:41 2018\12\31 0031 @@ -29,7 +30,7 @@ public class HttpChannelServiceImpl implements HttpChannelService { @Override public void getSize(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.headers().set("Content-Type","text/html;charset=UTF-8"); + response.headers().set("Content-Type","application/json;charset=UTF-8"); GetSizeVO getSizeVO = new GetSizeVO(WsCacheMap.getSize(),new Date()); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getSizeVO); Gson gson = new Gson(); @@ -44,24 +45,25 @@ public void sendFromServer(Channel channel, SendServerVO serverVO) { if (serverVO.getToken() == ""){ notFindUri(channel); } - try { - Channel userChannel = WsCacheMap.getByToken(serverVO.getToken()); - String value = fromServerService.findByCode(serverVO.getValue()); - }catch (NullPointerException e){ + Channel userChannel = WsCacheMap.getByToken(serverVO.getToken()); + if (userChannel == null){ log.info("[HttpChannelServiceImpl.sendFromServer] 未找到用户在线标识"); notFindToken(channel); } - - } - - private void sendServer(Channel channel, SendServerVO serverVO){ - + String value = fromServerService.findByCode(Integer.parseInt(serverVO.getValue())); + SendServer sendServer = new SendServer(value); + try { + userChannel.writeAndFlush(new TextWebSocketFrame(JSONObject.toJSONString(sendServer))); + sendServer(channel,"通知发送成功"); + }catch (Exception e){ + log.info("[HttpChannelServiceImpl.sendFromServer] 发送通知异常"); + } } - private void notFindToken(Channel channel) { + private void sendServer(Channel channel,String msg){ FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); - response.headers().set("Content-Type","text/html;charset=UTF-8"); - NotFindUriVO notFindUriVO = new NotFindUriVO("未找到在线用户标识"); + response.headers().set("Content-Type","application/json;charset=UTF-8"); + NotFindUriVO notFindUriVO = new NotFindUriVO(msg); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.BAD_REQUEST.code(),notFindUriVO); Gson gson = new Gson(); ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); @@ -70,17 +72,13 @@ private void notFindToken(Channel channel) { close(channel); } + private void notFindToken(Channel channel) { + sendServer(channel,"未找到在线用户标识"); + } + @Override public void notFindUri(Channel channel) { - FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); - response.headers().set("Content-Type","text/html;charset=UTF-8"); - NotFindUriVO notFindUriVO = new NotFindUriVO("未找到匹配任务URI"); - ResultVO resultVO = new ResultVO<>(HttpResponseStatus.BAD_REQUEST.code(),notFindUriVO); - Gson gson = new Gson(); - ByteBuf buf = Unpooled.copiedBuffer(gson.toJson(resultVO), CharsetUtil.UTF_8); - response.content().writeBytes(buf); - channel.writeAndFlush(response); - close(channel); + sendServer(channel,"未找到匹配任务URI"); } @Override @@ -92,7 +90,7 @@ public void close(Channel channel) { @Override public void getList(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.headers().set("Content-Type","text/html;charset=UTF-8"); + response.headers().set("Content-Type","application/json;charset=UTF-8"); GetListVO getListVO = new GetListVO(WsCacheMap.getTokenList()); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getListVO); Gson gson = new Gson(); diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java new file mode 100644 index 0000000..c653f0d --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java @@ -0,0 +1,33 @@ +package com.github.unclecatmyself.common.bean.vo; + +import com.github.unclecatmyself.common.utils.ConstansUtil; + +/** + * Created by MySelf on 2019/1/3. + */ +public class SendServer { + + private String type = ConstansUtil.SERVER; + + private String value; + + public SendServer(String value) { + this.value = value; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java index 64b9915..aa385e9 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java @@ -36,4 +36,6 @@ public class ConstansUtil { public static final String SENDGROUP = "sendGroup"; public static final String TIME = "time"; + + public static final String SERVER = "server"; } diff --git a/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java index b22e9fc..1e7024f 100644 --- a/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java @@ -7,7 +7,8 @@ */ public enum FromServerServiceImpl implements FromServerService { - TYPE1(1,"【系统通知】您的账号存在异常,请注意安全保密信息。"); + TYPE1(1,"【系统通知】您的账号存在异常,请注意安全保密信息。"), + TYPE2(2,"【系统通知】恭喜您连续登录超过5天,奖励5积分。"); private Integer code; From 5318a5432f19c4961de76c116c6622db5645c4d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 3 Jan 2019 11:46:53 +0800 Subject: [PATCH 136/151] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87-01031146?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Project-Log-cn.md | 4 +- .../bootstrap/AbstractBootstrapServer.java | 9 +- .../backmsg/InChatBackMapServiceImpl.java | 34 +++--- .../bootstrap/channel/HandlerServiceImpl.java | 35 ++---- .../bootstrap/channel/cache/WsCacheMap.java | 5 +- .../channel/http/HttpChannelServiceImpl.java | 23 ++-- .../data/InChatToDataBaseService.java | 2 +- .../bootstrap/handler/DefaultHandler.java | 57 +++++----- .../unclecatmyself/common/base/Handler.java | 5 +- .../common/bean/vo/GetListVO.java | 2 + .../common/bean/vo/SendServer.java | 4 +- .../common/constant/BootstrapConstant.java | 16 +++ .../Constans.java} | 4 +- .../HttpConstant.java} | 54 +++++---- .../common/constant/LogConstant.java | 49 ++++++++ .../common/constant/NotInChatConstant.java | 18 +++ .../unclecatmyself/common/utils/HttpUtil.java | 107 +++++++++--------- .../common/utils/MessageChangeUtil.java | 33 +++--- .../task/DataAsynchronousTask.java | 7 +- .../unclecatmyself/task/DataCallable.java | 2 +- .../user/ToDataBaseServiceImpl.java | 2 +- 21 files changed, 278 insertions(+), 194 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/common/constant/BootstrapConstant.java rename src/main/java/com/github/unclecatmyself/common/{utils/ConstansUtil.java => constant/Constans.java} (92%) rename src/main/java/com/github/unclecatmyself/common/{utils/HttpConstantUtil.java => constant/HttpConstant.java} (72%) create mode 100644 src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java create mode 100644 src/main/java/com/github/unclecatmyself/common/constant/NotInChatConstant.java diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index e4d9b2f..9cc0fc0 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -21,4 +21,6 @@ * 【2018-12-28】 预计整改常量、修改部分方法(类)命名,下一版加wss通道。 * 【2018-12-30】 修改异步线程任务(FutureTask启动模式),整改目录与修改核心类名,捕获未注册时客户端异常断开的连接异常,新增Http接口功能整改(未完)。 * 【2018-12-31】 下一版InChat 自带几个默认的Http接口 查询【在线用户数】、【服务端发送消息】、【用户在线用户列表】等,暂不支持自定义URI HTTP接口 - +* 【2018-01-01】 添加工具方法 +* 【2018-01-02】 修复httpPOST请求接口 +* 【2018-01-03】 完成新版http接口处理与测试,预计发包 diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java index 5a8aba4..c1d34aa 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/AbstractBootstrapServer.java @@ -5,6 +5,7 @@ import com.github.unclecatmyself.bootstrap.channel.HandlerServiceImpl; import com.github.unclecatmyself.bootstrap.handler.DefaultHandler; import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.common.constant.BootstrapConstant; import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.HttpObjectAggregator; @@ -31,12 +32,12 @@ protected void initHandler(ChannelPipeline channelPipeline, InitNetty serverBea } private void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){ - channelPipeline.addLast("httpCode",new HttpServerCodec()); + channelPipeline.addLast(BootstrapConstant.HTTPCODE,new HttpServerCodec()); // channelPipeline.addLast("http-decoder",new HttpRequestDecoder()); - channelPipeline.addLast("aggregator", new HttpObjectAggregator(serverBean.getMaxContext())); + channelPipeline.addLast(BootstrapConstant.AGGREGATOR, new HttpObjectAggregator(serverBean.getMaxContext())); // channelPipeline.addLast("http-encoder",new HttpResponseEncoder()); - channelPipeline.addLast("chunkedWrite",new ChunkedWriteHandler()); - channelPipeline.addLast("webSocketHandler",new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); + channelPipeline.addLast(BootstrapConstant.CHUNKEDWRITE,new ChunkedWriteHandler()); + channelPipeline.addLast(BootstrapConstant.WEBSOCKETHANDLER,new WebSocketServerProtocolHandler(serverBean.getWebSocketPath())); } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java index 5a44a0f..e84fc93 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/backmsg/InChatBackMapServiceImpl.java @@ -1,6 +1,6 @@ package com.github.unclecatmyself.bootstrap.backmsg; -import com.github.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.common.constant.Constans; import java.util.HashMap; import java.util.Map; @@ -14,52 +14,52 @@ public class InChatBackMapServiceImpl implements InChatBackMapService { public Map loginSuccess() { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); - backMap.put(ConstansUtil.SUCCESS,ConstansUtil.TRUE); + backMap.put(Constans.TYPE,Constans.LOGIN); + backMap.put(Constans.SUCCESS,Constans.TRUE); return backMap; } public Map loginError() { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.LOGIN); - backMap.put(ConstansUtil.SUCCESS,ConstansUtil.FALSE); + backMap.put(Constans.TYPE,Constans.LOGIN); + backMap.put(Constans.SUCCESS,Constans.FALSE); return backMap; } public Map sendMe(String value) { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDME); - backMap.put(ConstansUtil.VALUE,value); + backMap.put(Constans.TYPE,Constans.SENDME); + backMap.put(Constans.VALUE,value); return backMap; } public Map sendBack(String otherOne, String value) { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); - backMap.put(ConstansUtil.VALUE,value); - backMap.put(ConstansUtil.ONE,otherOne); + backMap.put(Constans.TYPE,Constans.SENDTO); + backMap.put(Constans.VALUE,value); + backMap.put(Constans.ONE,otherOne); return backMap; } public Map getMsg(String token, String value) { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDTO); - backMap.put(ConstansUtil.FROM,token); - backMap.put(ConstansUtil.VALUE,value); + backMap.put(Constans.TYPE,Constans.SENDTO); + backMap.put(Constans.FROM,token); + backMap.put(Constans.VALUE,value); return backMap; } public Map sendGroup(String token, String value, String groupId) { Map backMap = new HashMap(); - backMap.put(ConstansUtil.TYPE,ConstansUtil.SENDGROUP); - backMap.put(ConstansUtil.FROM,token); - backMap.put(ConstansUtil.VALUE,value); - backMap.put(ConstansUtil.GROUPID,groupId); + backMap.put(Constans.TYPE,Constans.SENDGROUP); + backMap.put(Constans.FROM,token); + backMap.put(Constans.VALUE,value); + backMap.put(Constans.GROUPID,groupId); return backMap; } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 81fdf2c..28705a5 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -3,29 +3,18 @@ import com.alibaba.fastjson.JSONArray; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; -import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelService; import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelServiceImpl; import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; import com.github.unclecatmyself.common.base.HandlerService; -import com.github.unclecatmyself.common.bean.vo.GetSizeVO; -import com.github.unclecatmyself.common.bean.vo.NotFindUriVO; -import com.github.unclecatmyself.common.bean.vo.ResultVO; import com.github.unclecatmyself.common.bean.vo.SendServerVO; +import com.github.unclecatmyself.common.constant.Constans; import com.google.gson.Gson; import com.github.unclecatmyself.bootstrap.channel.ws.WsChannelService; -import com.github.unclecatmyself.common.utils.ConstansUtil; import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; import com.github.unclecatmyself.task.DataAsynchronousTask; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import io.netty.channel.Channel; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.util.CharsetUtil; import java.util.ArrayList; import java.util.List; @@ -82,7 +71,7 @@ public boolean login(Channel channel, Map maps) { public void sendMeText(Channel channel, Map maps) { Gson gson = new Gson(); channel.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.sendMe((String) maps.get(ConstansUtil.VALUE))))); + gson.toJson(inChatBackMapService.sendMe((String) maps.get(Constans.VALUE))))); try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { @@ -93,9 +82,9 @@ public void sendMeText(Channel channel, Map maps) { @Override public void sendToText(Channel channel, Map maps) { Gson gson = new Gson(); - String otherOne = (String) maps.get(ConstansUtil.ONE); - String value = (String) maps.get(ConstansUtil.VALUE); - String token = (String) maps.get(ConstansUtil.TOKEN); + String otherOne = (String) maps.get(Constans.ONE); + String value = (String) maps.get(Constans.VALUE); + String token = (String) maps.get(Constans.TOKEN); //返回给自己 channel.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.sendBack(otherOne,value)))); @@ -105,7 +94,7 @@ public void sendToText(Channel channel, Map maps) { other.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.getMsg(token,value)))); }else { - maps.put(ConstansUtil.ON_ONLINE,otherOne); + maps.put(Constans.ON_ONLINE,otherOne); } try { dataAsynchronousTask.writeData(maps); @@ -117,9 +106,9 @@ public void sendToText(Channel channel, Map maps) { @Override public void sendGroupText(Channel channel, Map maps) { Gson gson = new Gson(); - String groupId = (String) maps.get(ConstansUtil.GROUPID); - String token = (String) maps.get(ConstansUtil.TOKEN); - String value = (String) maps.get(ConstansUtil.VALUE); + String groupId = (String) maps.get(Constans.GROUPID); + String token = (String) maps.get(Constans.TOKEN); + String value = (String) maps.get(Constans.VALUE); List no_online = new ArrayList<>(); JSONArray array = inChatVerifyService.getArrayByGroupId(groupId); channel.writeAndFlush(new TextWebSocketFrame( @@ -135,7 +124,7 @@ public void sendGroupText(Channel channel, Map maps) { } } } - maps.put(ConstansUtil.ONLINE_GROUP,no_online); + maps.put(Constans.ONLINE_GROUP,no_online); try { dataAsynchronousTask.writeData(maps); } catch (Exception e) { @@ -146,7 +135,7 @@ public void sendGroupText(Channel channel, Map maps) { @Override public void verify(Channel channel, Map maps) { Gson gson = new Gson(); - String token = (String) maps.get(ConstansUtil.TOKEN); + String token = (String) maps.get(Constans.TOKEN); System.out.println(token); if (inChatVerifyService.verifyToken(token)){ return; @@ -158,7 +147,7 @@ public void verify(Channel channel, Map maps) { private Boolean check(Channel channel, Map maps){ Gson gson = new Gson(); - String token = (String) maps.get(ConstansUtil.TOKEN); + String token = (String) maps.get(Constans.TOKEN); if (inChatVerifyService.verifyToken(token)){ channel.writeAndFlush(new TextWebSocketFrame(gson.toJson(inChatBackMapService.loginSuccess()))); websocketChannelService.loginWsSuccess(channel,token); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 0473da8..29610b9 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,10 +1,9 @@ package com.github.unclecatmyself.bootstrap.channel.cache; import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; +import com.github.unclecatmyself.common.constant.NotInChatConstant; import io.netty.channel.Channel; -import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -69,7 +68,7 @@ public static void deleteWs(String token){ try { maps.remove(token); }catch (NullPointerException e){ - throw new NotFindLoginChannlException("未找到正常注册的连接"); + throw new NotFindLoginChannlException(NotInChatConstant.Not_Login); } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index fdefa14..449cacc 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -4,6 +4,9 @@ import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import com.github.unclecatmyself.common.bean.vo.*; +import com.github.unclecatmyself.common.constant.HttpConstant; +import com.github.unclecatmyself.common.constant.LogConstant; +import com.github.unclecatmyself.common.constant.NotInChatConstant; import com.google.gson.Gson; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -15,8 +18,6 @@ import org.slf4j.LoggerFactory; import java.util.Date; -import java.util.HashMap; -import java.util.Map; /** * Create by UncleCatMySelf in 11:41 2018\12\31 0031 @@ -30,7 +31,7 @@ public class HttpChannelServiceImpl implements HttpChannelService { @Override public void getSize(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.headers().set("Content-Type","application/json;charset=UTF-8"); + response.headers().set(HttpConstant.CONTENT_TYPE,HttpConstant.APPLICATION_JSON); GetSizeVO getSizeVO = new GetSizeVO(WsCacheMap.getSize(),new Date()); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getSizeVO); Gson gson = new Gson(); @@ -47,22 +48,22 @@ public void sendFromServer(Channel channel, SendServerVO serverVO) { } Channel userChannel = WsCacheMap.getByToken(serverVO.getToken()); if (userChannel == null){ - log.info("[HttpChannelServiceImpl.sendFromServer] 未找到用户在线标识"); + log.info(LogConstant.HTTPCHANNELSERVICEIMPL_NOTFINDLOGIN); notFindToken(channel); } String value = fromServerService.findByCode(Integer.parseInt(serverVO.getValue())); SendServer sendServer = new SendServer(value); try { userChannel.writeAndFlush(new TextWebSocketFrame(JSONObject.toJSONString(sendServer))); - sendServer(channel,"通知发送成功"); + sendServer(channel, NotInChatConstant.SEND_SUCCESS); }catch (Exception e){ - log.info("[HttpChannelServiceImpl.sendFromServer] 发送通知异常"); + log.info(LogConstant.HTTPCHANNELSERVICEIMPL_SEND_EXCEPTION); } } private void sendServer(Channel channel,String msg){ FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); - response.headers().set("Content-Type","application/json;charset=UTF-8"); + response.headers().set(HttpConstant.CONTENT_TYPE,HttpConstant.APPLICATION_JSON); NotFindUriVO notFindUriVO = new NotFindUriVO(msg); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.BAD_REQUEST.code(),notFindUriVO); Gson gson = new Gson(); @@ -73,24 +74,24 @@ private void sendServer(Channel channel,String msg){ } private void notFindToken(Channel channel) { - sendServer(channel,"未找到在线用户标识"); + sendServer(channel,NotInChatConstant.NOT_FIND_LOGIN); } @Override public void notFindUri(Channel channel) { - sendServer(channel,"未找到匹配任务URI"); + sendServer(channel,NotInChatConstant.NOT_FIND_URI); } @Override public void close(Channel channel) { - log.info("[HttpChannelServiceImpl.close] 关闭HTTP通道连接"); + log.info(LogConstant.HTTPCHANNELSERVICEIMPL_CLOSE); channel.close(); } @Override public void getList(Channel channel) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.headers().set("Content-Type","application/json;charset=UTF-8"); + response.headers().set(HttpConstant.CONTENT_TYPE,HttpConstant.APPLICATION_JSON); GetListVO getListVO = new GetListVO(WsCacheMap.getTokenList()); ResultVO resultVO = new ResultVO<>(HttpResponseStatus.OK.code(),getListVO); Gson gson = new Gson(); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java index 937fa69..623f7ca 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/data/InChatToDataBaseService.java @@ -9,6 +9,6 @@ */ public interface InChatToDataBaseService { - Boolean writeMapToDB(InChatMessage message); + Boolean writeMessage(InChatMessage message); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index 270d8a2..aa20c17 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -5,9 +5,11 @@ import com.github.unclecatmyself.common.base.HandlerApi; import com.github.unclecatmyself.common.base.HandlerService; import com.github.unclecatmyself.common.bean.vo.SendServerVO; +import com.github.unclecatmyself.common.constant.Constans; +import com.github.unclecatmyself.common.constant.HttpConstant; +import com.github.unclecatmyself.common.constant.LogConstant; +import com.github.unclecatmyself.common.constant.NotInChatConstant; import com.github.unclecatmyself.common.exception.NoFindHandlerException; -import com.github.unclecatmyself.common.utils.ConstansUtil; -import com.github.unclecatmyself.common.utils.HttpConstantUtil; import com.github.unclecatmyself.common.utils.HttpUtil; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; @@ -17,7 +19,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Map; @@ -39,8 +40,8 @@ public DefaultHandler(HandlerApi handlerApi) { @Override protected void webdoMessage(ChannelHandlerContext ctx, WebSocketFrame msg) { - //暂未实现 - log.info("[webdoMessage]--暂未实现"); + //实现图片处理 + } @Override @@ -50,15 +51,15 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { if (handlerApi instanceof HandlerService){ httpHandlerService = (HandlerService)handlerApi; }else { - throw new NoFindHandlerException("Server Handler 不匹配"); + throw new NoFindHandlerException(NotInChatConstant.NOT_HANDLER); } switch (HttpUtil.checkType(msg)){ - case HttpConstantUtil.GETSIZE: - log.info("[DefaultWebSocketHandler.httpdoMessage.GETSIZE]"); + case HttpConstant.GETSIZE: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_GETSIZE); httpHandlerService.getSize(channel); break; - case HttpConstantUtil.SENDFROMSERVER: - log.info("[DefaultWebSocketHandler.httpdoMessage.SENDFROMSERVER]"); + case HttpConstant.SENDFROMSERVER: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_SENDFROMSERVER); SendServerVO serverVO = null; try { serverVO = HttpUtil.getToken(msg); @@ -67,12 +68,12 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { } httpHandlerService.sendFromServer(channel,serverVO); break; - case HttpConstantUtil.NOTFINDURI: - log.info("[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"); + case HttpConstant.NOTFINDURI: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_NOTFINDURI); httpHandlerService.notFindUri(channel); break; - case HttpConstantUtil.GETLIST: - log.info("[DefaultWebSocketHandler.httpdoMessage.GETLIST]"); + case HttpConstant.GETLIST: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_GETLIST); httpHandlerService.getList(channel); default: break; @@ -86,30 +87,30 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) if (handlerApi instanceof HandlerService){ handlerService = (HandlerService)handlerApi; }else{ - throw new NoFindHandlerException("Server Handler 不匹配"); + throw new NoFindHandlerException(NotInChatConstant.NOT_HANDLER); } Map maps = (Map) JSON.parse(msg.text()); - maps.put("time", new Date()); - switch ((String)maps.get(ConstansUtil.TYPE)){ - case ConstansUtil.LOGIN: - log.info("[DefaultWebSocketHandler.textdoMessage.LOGIN]"); + maps.put(Constans.TIME, new Date()); + switch ((String)maps.get(Constans.TYPE)){ + case Constans.LOGIN: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_LOGIN); handlerService.login(channel,maps); break; //针对个人,发送给自己 - case ConstansUtil.SENDME: - log.info("[DefaultWebSocketHandler.textdoMessage.SENDME]"); + case Constans.SENDME: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_SENDME); handlerService.verify(channel,maps); handlerService.sendMeText(channel,maps); break; //针对个人,发送给某人 - case ConstansUtil.SENDTO: - log.info("[DefaultWebSocketHandler.textdoMessage.SENDTO]"); + case Constans.SENDTO: + log.info(LogConstant.DefaultWebSocketHandler_SENDTO); handlerService.verify(channel,maps); handlerService.sendToText(channel,maps); break; //发送给群组 - case ConstansUtil.SENDGROUP: - log.info("[DefaultWebSocketHandler.textdoMessage.SENDGROUP]"); + case Constans.SENDGROUP: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_SENDGROUP); handlerService.verify(channel,maps); handlerService.sendGroupText(channel,maps); break; @@ -120,13 +121,13 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg) @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { - log.info("[DefaultWebSocketHandler.channelActive]"+ctx.channel().remoteAddress().toString()+"链接成功"); + log.info(LogConstant.CHANNELACTIVE+ctx.channel().remoteAddress().toString()+LogConstant.CHANNEL_SUCCESS); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception{ - log.error("exception",cause); - log.info("[DefaultWebSocketHandler.exceptionCaught]"+ctx.channel().remoteAddress().toString()+"异常断开"); +// log.error("exception",cause); + log.info(LogConstant.EXCEPTIONCAUGHT+ctx.channel().remoteAddress().toString()+LogConstant.DISCONNECT); ctx.close(); } } diff --git a/src/main/java/com/github/unclecatmyself/common/base/Handler.java b/src/main/java/com/github/unclecatmyself/common/base/Handler.java index e28429c..c72e945 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/Handler.java +++ b/src/main/java/com/github/unclecatmyself/common/base/Handler.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.common.base; +import com.github.unclecatmyself.common.constant.LogConstant; import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -42,11 +43,11 @@ protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Except @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - log.info("【Handler:channelInactive】"+ctx.channel().localAddress().toString()+"关闭成功"); + log.info(LogConstant.CHANNELINACTIVE+ctx.channel().localAddress().toString()+LogConstant.CLOSE_SUCCESS); try { handlerApi.close(ctx.channel()); }catch (NotFindLoginChannlException e){ - log.error("【捕获异常:NotFindLoginChannlException】-【Handler:channelInactive】关闭未正常注册链接!"); + log.error(LogConstant.NOTFINDLOGINCHANNLEXCEPTION); } } diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java index cefdcad..43abe08 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/GetListVO.java @@ -7,6 +7,8 @@ */ public class GetListVO { + + private Set tokens; public GetListVO(Set tokens) { diff --git a/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java index c653f0d..e03a0ef 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/vo/SendServer.java @@ -1,13 +1,13 @@ package com.github.unclecatmyself.common.bean.vo; -import com.github.unclecatmyself.common.utils.ConstansUtil; +import com.github.unclecatmyself.common.constant.Constans; /** * Created by MySelf on 2019/1/3. */ public class SendServer { - private String type = ConstansUtil.SERVER; + private String type = Constans.SERVER; private String value; diff --git a/src/main/java/com/github/unclecatmyself/common/constant/BootstrapConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/BootstrapConstant.java new file mode 100644 index 0000000..9060cbf --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/constant/BootstrapConstant.java @@ -0,0 +1,16 @@ +package com.github.unclecatmyself.common.constant; + +/** + * Created by MySelf on 2019/1/3. + */ +public class BootstrapConstant { + + public static final String HTTPCODE = "httpCode"; + + public static final String AGGREGATOR = "aggregator"; + + public static final String CHUNKEDWRITE = "chunkedWrite"; + + public static final String WEBSOCKETHANDLER = "webSocketHandler"; + +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java b/src/main/java/com/github/unclecatmyself/common/constant/Constans.java similarity index 92% rename from src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java rename to src/main/java/com/github/unclecatmyself/common/constant/Constans.java index aa385e9..03d64f8 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/ConstansUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/Constans.java @@ -1,9 +1,9 @@ -package com.github.unclecatmyself.common.utils; +package com.github.unclecatmyself.common.constant; /** * Created by MySelf on 2018/12/5. */ -public class ConstansUtil { +public class Constans { public static final String TOKEN = "token"; diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java b/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java similarity index 72% rename from src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java rename to src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java index 5472d1a..f095324 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpConstantUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java @@ -1,25 +1,29 @@ -package com.github.unclecatmyself.common.utils; - -/** - * Create by UncleCatMySelf in 22:49 2018\12\30 0030 - */ -public class HttpConstantUtil { - - public static final String GET = "GET"; - - public static final String POST = "POST"; - - public static final String GETSIZE = "get_size"; - - public static final String GETLIST = "get_list"; - - public static final String SENDFROMSERVER = "send_from_server"; - - public static final String NOTFINDURI = "not_find_uri"; - - public static final String URI_GETSIZE = "/get_size"; - - public static final String URI_GETLIST = "/get_list"; - - public static final String URI_SENDFROMSERVER = "/send_from_server"; -} +package com.github.unclecatmyself.common.constant; + +/** + * Create by UncleCatMySelf in 22:49 2018\12\30 0030 + */ +public class HttpConstant { + + public static final String GET = "GET"; + + public static final String POST = "POST"; + + public static final String GETSIZE = "get_size"; + + public static final String GETLIST = "get_list"; + + public static final String SENDFROMSERVER = "send_from_server"; + + public static final String NOTFINDURI = "not_find_uri"; + + public static final String URI_GETSIZE = "/get_size"; + + public static final String URI_GETLIST = "/get_list"; + + public static final String URI_SENDFROMSERVER = "/send_from_server"; + + public static final String CONTENT_TYPE = "Content-Type"; + + public static final String APPLICATION_JSON = "application/json;charset=UTF-8"; +} diff --git a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java new file mode 100644 index 0000000..2d2e993 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java @@ -0,0 +1,49 @@ +package com.github.unclecatmyself.common.constant; + +/** + * Created by MySelf on 2019/1/3. + */ +public class LogConstant { + + public static final String HTTPCHANNELSERVICEIMPL_NOTFINDLOGIN = "[HttpChannelServiceImpl.sendFromServer] 未找到用户在线标识"; + + public static final String HTTPCHANNELSERVICEIMPL_CLOSE = "[HttpChannelServiceImpl.close] 关闭HTTP通道连接"; + + public static final String HTTPCHANNELSERVICEIMPL_SEND_EXCEPTION = "[HttpChannelServiceImpl.sendFromServer] 发送通知异常"; + + public static final String DEFAULTWEBSOCKETHANDLER_GETSIZE = "[DefaultWebSocketHandler.httpdoMessage.GETSIZE]"; + + public static final String DEFAULTWEBSOCKETHANDLER_SENDFROMSERVER = "[DefaultWebSocketHandler.httpdoMessage.SENDFROMSERVER]"; + + public static final String DEFAULTWEBSOCKETHANDLER_NOTFINDURI = "[DefaultWebSocketHandler.httpdoMessage.NOTFINDURI]"; + + public static final String DEFAULTWEBSOCKETHANDLER_GETLIST = "[DefaultWebSocketHandler.httpdoMessage.GETLIST]"; + + public static final String DEFAULTWEBSOCKETHANDLER_LOGIN = "[DefaultWebSocketHandler.textdoMessage.LOGIN]"; + + public static final String DEFAULTWEBSOCKETHANDLER_SENDME = "[DefaultWebSocketHandler.textdoMessage.SENDME]"; + + public static final String DefaultWebSocketHandler_SENDTO = "[DefaultWebSocketHandler.textdoMessage.SENDTO]"; + + public static final String DEFAULTWEBSOCKETHANDLER_SENDGROUP = "[DefaultWebSocketHandler.textdoMessage.SENDGROUP]"; + + public static final String CHANNELACTIVE = "[DefaultWebSocketHandler.channelActive]"; + + public static final String CHANNEL_SUCCESS = "链接成功"; + + public static final String DISCONNECT = "异常断开"; + + public static final String EXCEPTIONCAUGHT = "[DefaultWebSocketHandler.exceptionCaught]"; + + public static final String CHANNELINACTIVE = "[Handler:channelInactive]"; + + public static final String CLOSE_SUCCESS = "关闭成功"; + + public static final String NOTFINDLOGINCHANNLEXCEPTION = "[捕获异常:NotFindLoginChannlException]-[Handler:channelInactive] 关闭未正常注册链接!"; + + public static final String DATAASYNCHRONOUSTASK_01 = "[DataAsynchronousTask.writeData]:数据外抛异常"; + + public static final String DATAASYNCHRONOUSTASK_02 = "[DataAsynchronousTask.writeData]:数据外抛异常"; + + public static final String DATAASYNCHRONOUSTASK_03 = "[DataAsynchronousTask.writeData]:线程任务执行异常"; +} diff --git a/src/main/java/com/github/unclecatmyself/common/constant/NotInChatConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/NotInChatConstant.java new file mode 100644 index 0000000..5da4693 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/constant/NotInChatConstant.java @@ -0,0 +1,18 @@ +package com.github.unclecatmyself.common.constant; + +/** + * Created by MySelf on 2019/1/3. + */ +public class NotInChatConstant { + + public static final String Not_Login = "未找到正常注册的连接"; + + public static final String SEND_SUCCESS = "通知发送成功"; + + public static final String NOT_FIND_LOGIN = "未找到在线用户标识"; + + public static final String NOT_FIND_URI = "未找到匹配任务URI"; + + public static final String NOT_HANDLER = "Server Handler 不匹配"; + +} diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index 3e69df9..591780f 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -1,54 +1,53 @@ -package com.github.unclecatmyself.common.utils; - -import com.github.unclecatmyself.common.bean.vo.SendServerVO; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.DecoderResult; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.util.CharsetUtil; - -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; - -/** - * HTTP接口处理方法 - * Create by UncleCatMySelf in 22:43 2018\12\30 0030 - */ -public class HttpUtil { - - public static String checkType(FullHttpRequest msg){ - msg.retain(); - String url = msg.uri(); - HttpMethod method = msg.method(); - String meName = method.name(); - if (url.equals(HttpConstantUtil.URI_GETSIZE) && meName.equals(HttpConstantUtil.GET)){ - return HttpConstantUtil.GETSIZE; - }else if (url.equals(HttpConstantUtil.URI_SENDFROMSERVER) && meName.equals(HttpConstantUtil.POST)){ - return HttpConstantUtil.SENDFROMSERVER; - }else if (url.equals(HttpConstantUtil.URI_GETLIST) && meName.equals(HttpConstantUtil.GET)){ - return HttpConstantUtil.GETLIST; - }else { - return HttpConstantUtil.NOTFINDURI; - } - } - - public static SendServerVO getToken(FullHttpRequest msg) throws UnsupportedEncodingException { - msg.retain(); - SendServerVO sendServerVO = new SendServerVO(); - String content = msg.content().toString(CharsetUtil.UTF_8); - String[] stars = content.split("&"); - for (int i=0,len=stars.length;i maps){ InChatMessage message = new InChatMessage(); - if (maps.containsKey(ConstansUtil.TOKEN)){ - message.setToken((String) maps.get(ConstansUtil.TOKEN)); + if (maps.containsKey(Constans.TOKEN)){ + message.setToken((String) maps.get(Constans.TOKEN)); } - if (maps.containsKey(ConstansUtil.TIME)){ - message.setTime((Date) maps.get(ConstansUtil.TIME)); + if (maps.containsKey(Constans.TIME)){ + message.setTime((Date) maps.get(Constans.TIME)); } - if (maps.containsKey(ConstansUtil.VALUE)){ - message.setValue((String)maps.get(ConstansUtil.VALUE)); + if (maps.containsKey(Constans.VALUE)){ + message.setValue((String)maps.get(Constans.VALUE)); } - if (maps.containsKey(ConstansUtil.TYPE)){ - message.setType((String)maps.get(ConstansUtil.TYPE)); + if (maps.containsKey(Constans.TYPE)){ + message.setType((String)maps.get(Constans.TYPE)); } - if (maps.containsKey(ConstansUtil.ONE)){ - message.setOne((String)maps.get(ConstansUtil.ONE)); + if (maps.containsKey(Constans.ONE)){ + message.setOne((String)maps.get(Constans.ONE)); } - if (maps.containsKey(ConstansUtil.GROUPID)){ - message.setGroudId((String)maps.get(ConstansUtil.GROUPID)); + if (maps.containsKey(Constans.GROUPID)){ + message.setGroudId((String)maps.get(Constans.GROUPID)); } - if (maps.containsKey(ConstansUtil.ON_ONLINE)){ - message.setOnline((String)maps.get(ConstansUtil.ON_ONLINE)); + if (maps.containsKey(Constans.ON_ONLINE)){ + message.setOnline((String)maps.get(Constans.ON_ONLINE)); } - if (maps.containsKey(ConstansUtil.ONLINE_GROUP)){ - message.setOnlineGroup((ArrayList)maps.get(ConstansUtil.ONLINE_GROUP)); + if (maps.containsKey(Constans.ONLINE_GROUP)){ + message.setOnlineGroup((ArrayList)maps.get(Constans.ONLINE_GROUP)); } return message; } diff --git a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java index 650da3f..7714d5e 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java +++ b/src/main/java/com/github/unclecatmyself/task/DataAsynchronousTask.java @@ -1,6 +1,7 @@ package com.github.unclecatmyself.task; import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.constant.LogConstant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,12 +40,12 @@ public void writeData(Map maps){ result = future.get(); } catch (InterruptedException e) { e.printStackTrace(); - log.error("[DataAsynchronousTask.writeData]:数据外抛异常"); + log.error(LogConstant.DATAASYNCHRONOUSTASK_01); } catch (ExecutionException e) { - log.error("[DataAsynchronousTask.writeData]:数据外抛异常"); + log.error(LogConstant.DATAASYNCHRONOUSTASK_02); } if (!result){ - log.error("[DataAsynchronousTask.writeData]:线程任务执行异常"); + log.error(LogConstant.DATAASYNCHRONOUSTASK_03); } } diff --git a/src/main/java/com/github/unclecatmyself/task/DataCallable.java b/src/main/java/com/github/unclecatmyself/task/DataCallable.java index 6a85eea..902b71b 100644 --- a/src/main/java/com/github/unclecatmyself/task/DataCallable.java +++ b/src/main/java/com/github/unclecatmyself/task/DataCallable.java @@ -24,7 +24,7 @@ public class DataCallable implements Callable{ @Override public Boolean call() throws Exception { - inChatToDataBaseService.writeMapToDB(MessageChangeUtil.Change(maps)); + inChatToDataBaseService.writeMessage(MessageChangeUtil.Change(maps)); return true; } } diff --git a/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java index 9232276..48859f4 100644 --- a/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java @@ -10,7 +10,7 @@ public class ToDataBaseServiceImpl implements InChatToDataBaseService { @Override - public Boolean writeMapToDB(InChatMessage message) { + public Boolean writeMessage(InChatMessage message) { System.out.println(message.toString()); return true; } From ab23b7c7ef775da6faf67d92ebc27556e0d4bc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 3 Jan 2019 11:50:17 +0800 Subject: [PATCH 137/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC-01?= =?UTF-8?q?031150?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bd40b76..fd09d07 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.UncleCatMySelf InChat - 1.1.0-alpha + 1.1.2 From 149b92b500968256810b909fa19e9807cf32492d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 3 Jan 2019 12:53:51 +0800 Subject: [PATCH 138/151] =?UTF-8?q?=E6=95=B4=E7=90=86=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=89=88=E4=BB=A3=E7=A0=81-01031253?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unclecatmyself/DemoApplication.java | 50 ------------------ .../channel/http/FromServerService.java | 44 ++++++++++++++++ .../user/FromServerServiceImpl.java | 51 ------------------- .../github/unclecatmyself/user/MyInit.java | 14 ----- .../user/ToDataBaseServiceImpl.java | 17 ------- .../user/verifyServiceImpl.java | 25 --------- 6 files changed, 44 insertions(+), 157 deletions(-) delete mode 100644 src/main/java/com/github/unclecatmyself/DemoApplication.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/MyInit.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java delete mode 100644 src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java diff --git a/src/main/java/com/github/unclecatmyself/DemoApplication.java b/src/main/java/com/github/unclecatmyself/DemoApplication.java deleted file mode 100644 index 818feee..0000000 --- a/src/main/java/com/github/unclecatmyself/DemoApplication.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.github.unclecatmyself; - -import com.github.unclecatmyself.auto.ConfigFactory; -import com.github.unclecatmyself.auto.InitServer; -import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; -import com.github.unclecatmyself.user.FromServerServiceImpl; -import com.github.unclecatmyself.user.MyInit; -import com.github.unclecatmyself.user.ToDataBaseServiceImpl; -import com.github.unclecatmyself.user.verifyServiceImpl; -import io.netty.channel.Channel; - -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; - -public class DemoApplication { - - public static void main(String[] args) { - //配置InChat配置工厂 - ConfigFactory.inChatToDataBaseService = new ToDataBaseServiceImpl(); - ConfigFactory.inChatVerifyService = new verifyServiceImpl(); - ConfigFactory.initNetty = new MyInit(); - ConfigFactory.fromServerService = FromServerServiceImpl.TYPE1; - //默认启动InChat -// InitServer initServer = InitServer(new MyInit()); - InitServer.open(); - - //获取用户值 - WebSocketChannelService webSocketChannelService = new WebSocketChannelService(); - - //启动新线程 - new Thread(new Runnable() { - @Override - public void run() { - //设定默认服务器发送值 - Map map = new HashMap<>(); - map.put("server","服务器"); - //获取控制台用户想发送的用户Token - Scanner scanner = new Scanner(System.in); - String token = scanner.nextLine(); - //获取用户连接 - Channel channel = (Channel) webSocketChannelService.getChannel(token); - //调用接口发送 - webSocketChannelService.sendFromServer(channel,map); - } - }).start(); - } - -} - diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java index d940cba..b54e9aa 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java @@ -1,6 +1,50 @@ package com.github.unclecatmyself.bootstrap.channel.http; /** + * public enum FromServerServiceImpl implements FromServerService { + * + * TYPE1(1,"【系统通知】您的账号存在异常,请注意安全保密信息。"), + * TYPE2(2,"【系统通知】恭喜您连续登录超过5天,奖励5积分。"); + * + * private Integer code; + * + * private String message; + * + * FromServerServiceImpl(Integer code, String message){ + * this.code = code; + * this.message = message; + * } + * + * @Override + * public Integer getCode() { + * return code; + * } + * + * @Override + * public String findByCode(Object code) { + * Integer codes = (Integer)code; + * for (FromServerServiceImpl item: FromServerServiceImpl.values()) { + * if (item.code == codes){ + * return item.message; + * } + * } + * return null; + * } + * + * public void setCode(Integer code) { + * this.code = code; + * } + * + * public String getMessage() { + * return message; + * } + * + * public void setMessage(String message) { + * this.message = message; + * } + * + * + * } * Created by MySelf on 2019/1/2. */ public interface FromServerService { diff --git a/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java deleted file mode 100644 index 1e7024f..0000000 --- a/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.github.unclecatmyself.bootstrap.channel.http.FromServerService; - -/** - * Created by MySelf on 2019/1/2. - */ -public enum FromServerServiceImpl implements FromServerService { - - TYPE1(1,"【系统通知】您的账号存在异常,请注意安全保密信息。"), - TYPE2(2,"【系统通知】恭喜您连续登录超过5天,奖励5积分。"); - - private Integer code; - - private String message; - - FromServerServiceImpl(Integer code, String message){ - this.code = code; - this.message = message; - } - - @Override - public Integer getCode() { - return code; - } - - @Override - public String findByCode(Object code) { - Integer codes = (Integer)code; - for (FromServerServiceImpl item: FromServerServiceImpl.values()) { - if (item.code == codes){ - return item.message; - } - } - return null; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - -} diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java deleted file mode 100644 index 3de2ae9..0000000 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.github.unclecatmyself.common.bean.InitNetty; - -/** - * Created by MySelf on 2018/12/27. - */ -public class MyInit extends InitNetty{ - - @Override - public int getWebport() { - return 8090; - } -} diff --git a/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java deleted file mode 100644 index 48859f4..0000000 --- a/src/main/java/com/github/unclecatmyself/user/ToDataBaseServiceImpl.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; -import com.github.unclecatmyself.common.bean.InChatMessage; - -/** - * Created by MySelf on 2018/12/14. - */ -public class ToDataBaseServiceImpl implements InChatToDataBaseService { - - - @Override - public Boolean writeMessage(InChatMessage message) { - System.out.println(message.toString()); - return true; - } -} diff --git a/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java deleted file mode 100644 index d2d31bc..0000000 --- a/src/main/java/com/github/unclecatmyself/user/verifyServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.unclecatmyself.user; - -import com.alibaba.fastjson.JSONArray; -import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; - - -/** - * Created by MySelf on 2018/12/14. - */ -public class verifyServiceImpl implements InChatVerifyService { - - - @Override - public boolean verifyToken(String token) { - //登录校验 - return true; - } - - @Override - public JSONArray getArrayByGroupId(String groupId) { - //根据群聊id获取对应的群聊人员ID - JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); - return jsonArray; - } -} From dbb714a127f9c9afeeb9c15f845da528add163cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 3 Jan 2019 12:57:54 +0800 Subject: [PATCH 139/151] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81-01?= =?UTF-8?q?031257?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bootstrap/channel/http/FromServerService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java index b54e9aa..c92a28f 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/FromServerService.java @@ -15,12 +15,12 @@ * this.message = message; * } * - * @Override + * * public Integer getCode() { * return code; * } * - * @Override + * * public String findByCode(Object code) { * Integer codes = (Integer)code; * for (FromServerServiceImpl item: FromServerServiceImpl.values()) { From 882020702813b19b70016c5c03ecb738c2efd389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Thu, 3 Jan 2019 13:03:34 +0800 Subject: [PATCH 140/151] update-log --- doc/Project-Log-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 9cc0fc0..0026658 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -23,4 +23,4 @@ * 【2018-12-31】 下一版InChat 自带几个默认的Http接口 查询【在线用户数】、【服务端发送消息】、【用户在线用户列表】等,暂不支持自定义URI HTTP接口 * 【2018-01-01】 添加工具方法 * 【2018-01-02】 修复httpPOST请求接口 -* 【2018-01-03】 完成新版http接口处理与测试,预计发包 +* 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2 From ab0e92c2eb9851d77f794671554d4ab61c90a94e Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 4 Jan 2019 00:15:32 +0800 Subject: [PATCH 141/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9README=E4=B8=8E?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=B0=E7=89=88=E6=9C=AC-01040015?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat.html | 2 +- README.md | 49 ++++++++++++------------------------- doc/Project-Log-cn.md | 2 +- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat.html index ee47697..ee046fc 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.1.121:8090/ws"); + socket = new WebSocket("ws://192.168.56.1:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/README.md b/README.md index 8f8bd2a..a2b5ba2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![QQ群](https://img.shields.io/badge/QQ%E7%BE%A4-628793702-yellow.svg)](https://jq.qq.com/?_wv=1027&k=57X4L74) [![作者](https://img.shields.io/badge/%E4%BD%9C%E8%80%85-MySelf-blue.svg)](https://github.com/UncleCatMySelf) [![Netty入门](https://img.shields.io/badge/%E5%AD%A6%E4%B9%A0-Netty%E5%85%A5%E9%97%A8-ff69b4.svg)](doc/study/mulu.md) -[![Maven](https://img.shields.io/badge/Maven-1.1.0--alpha-orange.svg)](https://mvnrepository.com/artifact/com.github.UncleCatMySelf/InChat/1.1.0-alpha) +[![Maven](https://img.shields.io/badge/Maven-1.1.2-orange.svg)](https://mvnrepository.com/artifact/com.github.UncleCatMySelf/InChat) @@ -21,9 +21,16 @@ ## Maven版本 -版本目标:移除对SpringBoot的环境依赖,InChat独立生存与使用,结合上一版的功能,并添加服务器发送消息接口 +功能列表: -* [V1.1.0-alpha版本使用说明](https://unclecatmyself.github.io/2018/12/21/InChatV1.1.0%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E/) +> * 用户token登录校验 +> * 自我聊天 +> * 点对点聊天 +> * 群聊 +> * 获取在线用户数与用户标签列表 +> * 发送系统通知 + +* [V1.1.2版本使用说明](https://unclecatmyself.github.io/2019/01/03/inchatby112/) * [V1.1.0-alpha版本视频教学](https://v.qq.com/x/page/i08165ym286.html) ``` @@ -54,38 +61,12 @@ * [QQ群建议贡献](doc/advice/advice.md) -## demo分支介绍 - -原始项目核心演示, 您可以先运行了解, 模仿微聊天聊天应用程序, 逐步更新, 基于 springbot-web 套接字的一般框架, 结合 netty 聊天社交, 并记录聊天日志, 异步存储, 前端临时 sui mobile, 添加实现 tcp/后端通信端口 (mqtt 协议、实时和单片机等 tcp 硬件通信), 添加图片处理流、聊天实现文本和图片发送功能,api 调用 netty 长链接执行发送消息 (联机、用户列表的数量) - -## demo分支效果演示 - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(5).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(3).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(4).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(2).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/001%20(1).png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/9.png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/10.png) -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/nettychat/11.png) - -## webrtc分支介绍 - -一个基于web RTC和Netty相结合的例子,实现语音与视频流通讯。 - -![Image text](https://raw.githubusercontent.com/UncleCatMySelf/img-myself/master/img/webrtc/TIM%E5%9B%BE%E7%89%8720181121150540.png) - -## im-api分支介绍 - -腾讯 im (云通信) 后端仿真项目, 以 api 的形式对接, 如果有前端想要停靠可以运行此分支, 预计该分支最终将为一个单一的服务并发 300, 000个用户的 im 后台项目 - -## paho-mqtt分支介绍 - -基于 paho. js 和 java mqtt 客户端消息订阅和通信的小型程序端或移动 web 端, 小程序物联网演示目前支持 ws 格式 - -## tcp-wechat分支介绍 +## 效果展示 -基于小程序端与单片机等硬件 tcp/ip 的主要通信, 将物联网中心作为中转, 本演示将充分实现具体功能 +![demo](https://github.com/UncleCatMySelf/img-myself/blob/master/img/inchatGIF/inchat_demo.gif) +![log](https://github.com/UncleCatMySelf/img-myself/blob/master/img/inchatGIF/inchat_log.gif) +![postman](https://github.com/UncleCatMySelf/img-myself/blob/master/img/inchatGIF/inchat_postman.gif) +![send](https://github.com/UncleCatMySelf/img-myself/blob/master/img/inchatGIF/inchat_send.gif) ## 下载地址 diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index 0026658..f8ea152 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -23,4 +23,4 @@ * 【2018-12-31】 下一版InChat 自带几个默认的Http接口 查询【在线用户数】、【服务端发送消息】、【用户在线用户列表】等,暂不支持自定义URI HTTP接口 * 【2018-01-01】 添加工具方法 * 【2018-01-02】 修复httpPOST请求接口 -* 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2 +* 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2,更新README展示GIF,录制V1.1.2视频教程与使用说明书 From 0ca04f8513b8d2b9a59b20614929e879774afc55 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 4 Jan 2019 00:17:25 +0800 Subject: [PATCH 142/151] =?UTF-8?q?=E4=BF=AE=E6=94=B9maven=E7=89=88?= =?UTF-8?q?=E6=9C=AC-01040017?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2b5ba2..00f5b84 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ com.github.UncleCatMySelf InChat - 1.1.0-alpha + 1.1.2 ``` From a3f20fd0788f012a2ccf8e5452c6c4847b4b5111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Fri, 4 Jan 2019 09:12:15 +0800 Subject: [PATCH 143/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3-01?= =?UTF-8?q?040812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- doc/goal/goal.md | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 00f5b84..264e1f5 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ > * 发送系统通知 * [V1.1.2版本使用说明](https://unclecatmyself.github.io/2019/01/03/inchatby112/) -* [V1.1.0-alpha版本视频教学](https://v.qq.com/x/page/i08165ym286.html) +* [V1.1.2版本视频教学](https://v.qq.com/x/page/y08228i7znk.html) ``` diff --git a/doc/goal/goal.md b/doc/goal/goal.md index 1dc87e1..37d7a86 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -41,3 +41,19 @@ ## 【2018-12-20】 项目突破 **150** Star,感谢大家的支持 +## V1.1.2版本 【2019-01-04】 + +> 版本昵称:赤猫-2 + +版本更新:添加HTTP接口调用,捕获已知异常 + +* [V1.1.2版本使用说明](https://unclecatmyself.github.io/2019/01/03/inchatby112/) +* [V1.1.2版本视频教学](https://v.qq.com/x/page/y08228i7znk.html) + +``` + + com.github.UncleCatMySelf + InChat + 1.1.2 + +``` \ No newline at end of file From e17d995d5e873db05bf3bb0604b304fc9311710a Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Fri, 4 Jan 2019 23:54:20 +0800 Subject: [PATCH 144/151] =?UTF-8?q?=E6=96=B0=E5=A2=9Eredis=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5-01042354?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 +++ .../github/unclecatmyself/application.java | 24 +++++++++ .../redisclient/testApplication.java | 22 +++++++++ .../user/DataBaseServiceImpl.java | 15 ++++++ .../user/FromServerServiceImpl.java | 49 +++++++++++++++++++ .../github/unclecatmyself/user/MyInit.java | 14 ++++++ .../user/VerifyServiceImpl.java | 21 ++++++++ 7 files changed, 151 insertions(+) create mode 100644 src/main/java/com/github/unclecatmyself/application.java create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java create mode 100644 src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java create mode 100644 src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java create mode 100644 src/main/java/com/github/unclecatmyself/user/MyInit.java create mode 100644 src/main/java/com/github/unclecatmyself/user/VerifyServiceImpl.java diff --git a/pom.xml b/pom.xml index fd09d07..cfbbcb9 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,12 @@ + + + redis.clients + jedis + 3.0.1 + org.slf4j slf4j-log4j12 diff --git a/src/main/java/com/github/unclecatmyself/application.java b/src/main/java/com/github/unclecatmyself/application.java new file mode 100644 index 0000000..1190638 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/application.java @@ -0,0 +1,24 @@ +package com.github.unclecatmyself; + +import com.github.unclecatmyself.auto.ConfigFactory; +import com.github.unclecatmyself.auto.InitServer; +import com.github.unclecatmyself.common.bean.InitNetty; +import com.github.unclecatmyself.user.DataBaseServiceImpl; +import com.github.unclecatmyself.user.FromServerServiceImpl; +import com.github.unclecatmyself.user.VerifyServiceImpl; + +/** + * Create by UncleCatMySelf in 22:49 2019\1\4 0004 + */ +public class application { + + public static void main(String[] args) { + ConfigFactory.initNetty = new InitNetty(); + ConfigFactory.inChatVerifyService = new VerifyServiceImpl(); + ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); + ConfigFactory.fromServerService = FromServerServiceImpl.TYPE2; + + InitServer.open(); + } + +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java b/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java new file mode 100644 index 0000000..790c406 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java @@ -0,0 +1,22 @@ +package com.github.unclecatmyself.bootstrap.redisclient; + +import redis.clients.jedis.Jedis; + +/** + * Create by UncleCatMySelf in 23:02 2019\1\4 0004 + */ +public class testApplication { + + public static void main(String[] args) { + //连接redis服务 + Jedis jedis = new Jedis("192.168.12.129"); + System.out.println("连接成功"); + //设置redis字符串数据 + jedis.set("token","inchat"); + //查看服务是否运行 + System.out.println("服务正在运行:"+jedis.ping()); + //获取存储的数据并输出 + System.out.println("redis存储的字符串为:"+jedis.get("token")); + } + +} diff --git a/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java new file mode 100644 index 0000000..781bb42 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/DataBaseServiceImpl.java @@ -0,0 +1,15 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService; +import com.github.unclecatmyself.common.bean.InChatMessage; + +/** + * Created by MySelf on 2019/1/3. + */ +public class DataBaseServiceImpl implements InChatToDataBaseService { + //获取消息 + public Boolean writeMessage(InChatMessage inChatMessage) { + System.out.println(inChatMessage.toString()); + return true; + } +} diff --git a/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java new file mode 100644 index 0000000..d9b4aed --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/FromServerServiceImpl.java @@ -0,0 +1,49 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.bootstrap.channel.http.FromServerService; + +/** + * Created by MySelf on 2019/1/3. + */ +public enum FromServerServiceImpl implements FromServerService { + + TYPE1(1,"【系统通知】您的账号存在异常,请注意安全保密信息。"), + TYPE2(2,"【系统通知】恭喜您连续登录超过5天,奖励5积分。"); + + private Integer code; + + private String message; + + FromServerServiceImpl(Integer code, String message){ + this.code = code; + this.message = message; + } + + public Integer getCode() { + return code; + } + + public String findByCode(Object code) { + Integer codes = (Integer)code; + for (FromServerServiceImpl item: FromServerServiceImpl.values()) { + if (item.code == codes){ + return item.message; + } + } + return null; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + +} diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java new file mode 100644 index 0000000..fc409b9 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -0,0 +1,14 @@ +package com.github.unclecatmyself.user; + +import com.github.unclecatmyself.common.bean.InitNetty; + +/** + * Created by MySelf on 2019/1/3. + */ +public class MyInit extends InitNetty { + + @Override + public int getWebport() { + return 8090; + } +} diff --git a/src/main/java/com/github/unclecatmyself/user/VerifyServiceImpl.java b/src/main/java/com/github/unclecatmyself/user/VerifyServiceImpl.java new file mode 100644 index 0000000..f0fa0c3 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/user/VerifyServiceImpl.java @@ -0,0 +1,21 @@ +package com.github.unclecatmyself.user; + +import com.alibaba.fastjson.JSONArray; +import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; + +/** + * Created by MySelf on 2019/1/3. + */ +public class VerifyServiceImpl implements InChatVerifyService { + + + public boolean verifyToken(String token) { + return true; + } + + + public JSONArray getArrayByGroupId(String groupId) { + JSONArray jsonArray = JSONArray.parseArray("[\"1111\",\"2222\",\"3333\"]"); + return jsonArray; + } +} From 53bb605f2874ab78fe8e7fce489d02cacd7bca04 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 5 Jan 2019 15:48:45 +0800 Subject: [PATCH 145/151] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E8=BD=AC=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F-01051548?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/unclecatmyself/application.java | 4 +- .../unclecatmyself/auto/AutoConfig.java | 10 ++++ .../unclecatmyself/auto/ConfigFactory.java | 3 + .../unclecatmyself/auto/RedisConfig.java | 41 ++++++++++++++ .../bootstrap/NettyBootstrapServer.java | 4 ++ .../bootstrap/channel/cache/WsCacheMap.java | 32 +++++++++++ .../redisclient/testApplication.java | 2 +- .../unclecatmyself/common/bean/InitNetty.java | 11 +++- .../common/constant/LogConstant.java | 2 + .../common/utils/RedisUtil.java | 55 +++++++++++++++++++ .../github/unclecatmyself/user/MyInit.java | 5 ++ 11 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/github/unclecatmyself/auto/AutoConfig.java create mode 100644 src/main/java/com/github/unclecatmyself/auto/RedisConfig.java create mode 100644 src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java diff --git a/src/main/java/com/github/unclecatmyself/application.java b/src/main/java/com/github/unclecatmyself/application.java index 1190638..bfd1114 100644 --- a/src/main/java/com/github/unclecatmyself/application.java +++ b/src/main/java/com/github/unclecatmyself/application.java @@ -5,6 +5,7 @@ import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.user.DataBaseServiceImpl; import com.github.unclecatmyself.user.FromServerServiceImpl; +import com.github.unclecatmyself.user.MyInit; import com.github.unclecatmyself.user.VerifyServiceImpl; /** @@ -13,10 +14,11 @@ public class application { public static void main(String[] args) { - ConfigFactory.initNetty = new InitNetty(); + ConfigFactory.initNetty = new MyInit(); ConfigFactory.inChatVerifyService = new VerifyServiceImpl(); ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); ConfigFactory.fromServerService = FromServerServiceImpl.TYPE2; + ConfigFactory.RedisIP = "192.168.12.129"; InitServer.open(); } diff --git a/src/main/java/com/github/unclecatmyself/auto/AutoConfig.java b/src/main/java/com/github/unclecatmyself/auto/AutoConfig.java new file mode 100644 index 0000000..e0ce10a --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/auto/AutoConfig.java @@ -0,0 +1,10 @@ +package com.github.unclecatmyself.auto; + +/** + * Create by UncleCatMySelf in 14:33 2019\1\5 0005 + */ +public class AutoConfig { + + public static String address = ""; + +} diff --git a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java index c7ac9f3..db5160c 100644 --- a/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java +++ b/src/main/java/com/github/unclecatmyself/auto/ConfigFactory.java @@ -11,6 +11,8 @@ */ public class ConfigFactory { + public static String RedisIP; + /** 用户校验伪接口 */ public static InChatVerifyService inChatVerifyService; @@ -21,4 +23,5 @@ public class ConfigFactory { /** InChat项目配置 */ public static InitNetty initNetty; + } diff --git a/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java b/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java new file mode 100644 index 0000000..997fe78 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java @@ -0,0 +1,41 @@ +package com.github.unclecatmyself.auto; + +import com.github.unclecatmyself.common.constant.LogConstant; +import com.sun.org.apache.regexp.internal.RE; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.Jedis; + +/** + * Create by UncleCatMySelf in 13:56 2019\1\5 0005 + */ +public class RedisConfig { + + private static final Logger log = LoggerFactory.getLogger(RedisConfig.class); + + private static RedisConfig instance = new RedisConfig(); + + public static Jedis jedis; + + private RedisConfig(){ + if (ConfigFactory.initNetty.getDistributed()){ + this.jedis = new Jedis(ConfigFactory.RedisIP); + log.info(LogConstant.REDIS_START + jedis.ping()); + } + } + + + public static RedisConfig getInstance(){ + return instance; + } + +// public static Jedis getJedis(){ +// Jedis jedis = null; +// if (ConfigFactory.initNetty.getDistributed()){ +// jedis = new Jedis(ConfigFactory.RedisIP); +// log.info(LogConstant.REDIS_START + jedis.ping()); +// } +// return jedis; +// } + +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java index d286b84..815cb27 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/NettyBootstrapServer.java @@ -1,5 +1,7 @@ package com.github.unclecatmyself.bootstrap; +import com.github.unclecatmyself.auto.AutoConfig; +import com.github.unclecatmyself.auto.RedisConfig; import com.github.unclecatmyself.common.ip.IpUtils; import com.github.unclecatmyself.common.bean.InitNetty; import com.github.unclecatmyself.common.utils.RemotingUtil; @@ -66,6 +68,8 @@ protected void initChannel(SocketChannel ch) throws Exception { bootstrap.bind(IpUtils.getHost(),serverBean.getWebport()).addListener((ChannelFutureListener) channelFuture -> { if (channelFuture.isSuccess()) { log.info("服务端启动成功【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】"); + AutoConfig.address = IpUtils.getHost()+":"+serverBean.getWebport(); + RedisConfig.getInstance(); }else{ log.info("服务端启动失败【" + IpUtils.getHost() + ":" + serverBean.getWebport() + "】");} }); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 29610b9..1850e5d 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -1,8 +1,13 @@ package com.github.unclecatmyself.bootstrap.channel.cache; +import com.github.unclecatmyself.auto.AutoConfig; +import com.github.unclecatmyself.auto.ConfigFactory; +import com.github.unclecatmyself.auto.RedisConfig; import com.github.unclecatmyself.common.exception.NotFindLoginChannlException; import com.github.unclecatmyself.common.constant.NotInChatConstant; +import com.github.unclecatmyself.common.utils.RedisUtil; import io.netty.channel.Channel; +import redis.clients.jedis.Jedis; import java.util.Map; import java.util.Set; @@ -24,6 +29,18 @@ public class WsCacheMap { */ private final static Map addMaps = new ConcurrentHashMap<>(); + /** + * Redis连接实例 + */ + private final static Jedis jedis = RedisConfig.jedis; + + /** + * 是否启动分布式 + */ + private final static Boolean isDistributed = ConfigFactory.initNetty.getDistributed(); + + private final static String address = AutoConfig.address; + /** * 存储链接 * @param token {@link String} 用户标签 @@ -31,6 +48,9 @@ public class WsCacheMap { */ public static void saveWs(String token,Channel channel){ maps.put(token,channel); + if (isDistributed){ + jedis.set(token, RedisUtil.convertMD5(address,token)); + } } /** @@ -67,6 +87,9 @@ public static String getByAddress(String address){ public static void deleteWs(String token){ try { maps.remove(token); + if (isDistributed){ + jedis.del(token); + } }catch (NullPointerException e){ throw new NotFindLoginChannlException(NotInChatConstant.Not_Login); } @@ -85,6 +108,9 @@ public static void deleteAd(String address){ * @return {@link Integer} 链接数 */ public static Integer getSize(){ + if (isDistributed){ + return jedis.keys("*").size(); + } return maps.size(); } @@ -94,6 +120,9 @@ public static Integer getSize(){ * @return {@link Boolean} 是否存在 */ public static boolean hasToken(String token){ + if (isDistributed){ + return jedis.exists(token); + } return maps.containsKey(token); } @@ -102,6 +131,9 @@ public static boolean hasToken(String token){ * @return {@link Set} 标识列表 */ public static Set getTokenList(){ + if (isDistributed){ + return jedis.keys("*"); + } Set keys = maps.keySet(); return keys; } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java b/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java index 790c406..afcbcc0 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/redisclient/testApplication.java @@ -12,7 +12,7 @@ public static void main(String[] args) { Jedis jedis = new Jedis("192.168.12.129"); System.out.println("连接成功"); //设置redis字符串数据 - jedis.set("token","inchat"); + //jedis.set("token","inchat"); //查看服务是否运行 System.out.println("服务正在运行:"+jedis.ping()); //获取存储的数据并输出 diff --git a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java index 20bbf87..08ca2f3 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/InitNetty.java @@ -38,8 +38,18 @@ public class InitNetty { private String webSocketPath = "/ws"; + private Boolean isDistributed = false; + private Class webSocketHandler = DefaultHandler.class; + public Boolean getDistributed() { + return isDistributed; + } + + public void setDistributed(Boolean distributed) { + isDistributed = distributed; + } + /** * 返回WebSocket启动监听端口 * @return {@link Integer} WebSocket端口 @@ -188,5 +198,4 @@ public Class getWebSocketHandler() { return webSocketHandler; } - } diff --git a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java index 2d2e993..a97d765 100644 --- a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java @@ -46,4 +46,6 @@ public class LogConstant { public static final String DATAASYNCHRONOUSTASK_02 = "[DataAsynchronousTask.writeData]:数据外抛异常"; public static final String DATAASYNCHRONOUSTASK_03 = "[DataAsynchronousTask.writeData]:线程任务执行异常"; + + public static final String REDIS_START = "[RedisConfig.getJedis]:连接成功,测试连接:"; } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java new file mode 100644 index 0000000..088fae4 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java @@ -0,0 +1,55 @@ +package com.github.unclecatmyself.common.utils; + +import java.security.MessageDigest; + +/** + * Create by UncleCatMySelf in 15:13 2019\1\5 0005 + */ +public class RedisUtil { + + private static final String STAL = "InChat"; + + public static String string2MD5(String inStr) { + MessageDigest md5 = null; + try { + md5 = MessageDigest.getInstance("MD5"); + } catch (Exception e) { + System.out.println(e.toString()); + e.printStackTrace(); + return ""; + } + char[] charArray = inStr.toCharArray(); + byte[] byteArray = new byte[charArray.length]; + for (int i = 0; i < charArray.length; i++) byteArray[i] = (byte) charArray[i]; + byte[] md5Bytes = md5.digest(byteArray); + StringBuffer hexValue = new StringBuffer(); + for (int i = 0; i < md5Bytes.length; i++) { + int val = ((int) md5Bytes[i]) & 0xff; + if (val < 16) + hexValue.append("0"); + hexValue.append(Integer.toHexString(val)); + } + return hexValue.toString(); + } + + public static String convertMD5(String address,String token){ + String inStr = address+"&"+token+"%"+STAL; + char[] a = inStr.toCharArray(); + for (int i = 0; i < a.length; i++){ + a[i] = (char) (a[i] ^ 't'); + } + String s = new String(a); + return s; + } + +// public static void main(String[] args) { +// String s = new String("inchat"); +// System.out.println("原始:" + s); +// System.out.println("MD5后:" + string2MD5(s)); +//// System.out.println("原始:" + s); +//// System.out.println("加密后:" + convertMD5(s)); +//// System.out.println("原始:" + s); +//// System.out.println("解密后:" + convertMD5(convertMD5(s))); +// } + +} diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java index fc409b9..a0099a5 100644 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -11,4 +11,9 @@ public class MyInit extends InitNetty { public int getWebport() { return 8090; } + + @Override + public Boolean getDistributed() { + return true; + } } From 650560b45cd74829852daf0728ad82aa70166155 Mon Sep 17 00:00:00 2001 From: hacker <3183764662@qq.com> Date: Sat, 5 Jan 2019 17:51:14 +0800 Subject: [PATCH 146/151] =?UTF-8?q?=E5=A4=84=E7=90=86netty=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E6=9C=AA=E5=AE=8C=E6=88=90-01051751?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat70.html | 156 ++++++++++++++++++ Front-End-Testing/{chat.html => chat90.html} | 2 +- .../bootstrap/channel/HandlerServiceImpl.java | 24 ++- .../bootstrap/channel/cache/WsCacheMap.java | 9 + .../channel/http/HttpChannelService.java | 7 + .../channel/http/HttpChannelServiceImpl.java | 36 ++++ .../bootstrap/channel/http/HttpClient.java | 66 ++++++++ .../bootstrap/handler/DefaultHandler.java | 5 + .../common/base/HandlerService.java | 9 + .../common/bean/SendInChat.java | 37 +++++ .../common/constant/HttpConstant.java | 4 + .../common/constant/LogConstant.java | 2 + .../unclecatmyself/common/utils/HttpUtil.java | 11 +- .../common/utils/RedisUtil.java | 14 ++ .../github/unclecatmyself/user/MyInit.java | 2 +- 15 files changed, 378 insertions(+), 6 deletions(-) create mode 100644 Front-End-Testing/chat70.html rename Front-End-Testing/{chat.html => chat90.html} (98%) create mode 100644 src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java create mode 100644 src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java diff --git a/Front-End-Testing/chat70.html b/Front-End-Testing/chat70.html new file mode 100644 index 0000000..02e9fc7 --- /dev/null +++ b/Front-End-Testing/chat70.html @@ -0,0 +1,156 @@ + + + + + WebSocket Chat + + + + +
+

InChat 聊天室-8070

+ +
+ + + + + +
+
+
+ + \ No newline at end of file diff --git a/Front-End-Testing/chat.html b/Front-End-Testing/chat90.html similarity index 98% rename from Front-End-Testing/chat.html rename to Front-End-Testing/chat90.html index ee046fc..8bb6310 100644 --- a/Front-End-Testing/chat.html +++ b/Front-End-Testing/chat90.html @@ -141,7 +141,7 @@ };
-

SpringBoot netty 聊天室

+

InChat 聊天室-8090


diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 28705a5..1e5efa1 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -1,12 +1,16 @@ package com.github.unclecatmyself.bootstrap.channel; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapService; import com.github.unclecatmyself.bootstrap.backmsg.InChatBackMapServiceImpl; +import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelService; import com.github.unclecatmyself.bootstrap.channel.http.HttpChannelServiceImpl; import com.github.unclecatmyself.bootstrap.channel.ws.WebSocketChannelService; import com.github.unclecatmyself.common.base.HandlerService; +import com.github.unclecatmyself.common.bean.SendInChat; import com.github.unclecatmyself.common.bean.vo.SendServerVO; import com.github.unclecatmyself.common.constant.Constans; import com.google.gson.Gson; @@ -14,7 +18,9 @@ import com.github.unclecatmyself.bootstrap.verify.InChatVerifyService; import com.github.unclecatmyself.task.DataAsynchronousTask; import io.netty.channel.Channel; +import io.netty.handler.codec.http.FullHttpMessage; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.util.CharsetUtil; import java.util.ArrayList; import java.util.List; @@ -56,6 +62,14 @@ public void sendFromServer(Channel channel, SendServerVO serverVO) { httpChannelService.sendFromServer(channel,serverVO); } + @Override + public void sendInChat(Channel channel, FullHttpMessage msg) { + System.out.println(msg); + String content = msg.content().toString(CharsetUtil.UTF_8); + SendInChat sendInChat = (SendInChat) JSON.parse(content); + httpChannelService.sendByInChat(channel,sendInChat); + } + @Override public void notFindUri(Channel channel) { httpChannelService.notFindUri(channel); @@ -91,8 +105,14 @@ public void sendToText(Channel channel, Map maps) { if (websocketChannelService.hasOther(otherOne)){ //发送给对方--在线 Channel other = websocketChannelService.getChannel(otherOne); - other.writeAndFlush(new TextWebSocketFrame( - gson.toJson(inChatBackMapService.getMsg(token,value)))); + if (other == null){ + //转http分布式 + httpChannelService.sendInChat(channel,otherOne,new TextWebSocketFrame( + gson.toJson(inChatBackMapService.getMsg(token,value)))); + }else{ + other.writeAndFlush(new TextWebSocketFrame( + gson.toJson(inChatBackMapService.getMsg(token,value)))); + } }else { maps.put(Constans.ON_ONLINE,otherOne); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java index 1850e5d..a0a9099 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/cache/WsCacheMap.java @@ -68,6 +68,12 @@ public static void saveAd(String address,String token){ * @return {@link Channel} 链接实例 */ public static Channel getByToken(String token){ + if (isDistributed){ + if (!maps.containsKey(token)){ + //转分布式发送 + return null; + } + } return maps.get(token); } @@ -138,4 +144,7 @@ public static Set getTokenList(){ return keys; } + public static String getByJedis(String token) { + return jedis.get(token); + } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java index b8f977a..d542d25 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -1,7 +1,10 @@ package com.github.unclecatmyself.bootstrap.channel.http; +import com.github.unclecatmyself.common.bean.SendInChat; import com.github.unclecatmyself.common.bean.vo.SendServerVO; import io.netty.channel.Channel; +import io.netty.channel.ChannelConfig; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; /** * Create by UncleCatMySelf in 11:41 2018\12\31 0031 @@ -18,4 +21,8 @@ public interface HttpChannelService { void getList(Channel channel); + void sendInChat(Channel channel,String token, TextWebSocketFrame msg); + + void sendByInChat(Channel channel,SendInChat sendInChat); + } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index 449cacc..da44a46 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -3,10 +3,13 @@ import com.alibaba.fastjson.JSONObject; import com.github.unclecatmyself.auto.ConfigFactory; import com.github.unclecatmyself.bootstrap.channel.cache.WsCacheMap; +import com.github.unclecatmyself.common.bean.SendInChat; import com.github.unclecatmyself.common.bean.vo.*; import com.github.unclecatmyself.common.constant.HttpConstant; import com.github.unclecatmyself.common.constant.LogConstant; import com.github.unclecatmyself.common.constant.NotInChatConstant; +import com.github.unclecatmyself.common.utils.HttpUtil; +import com.github.unclecatmyself.common.utils.RedisUtil; import com.google.gson.Gson; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -17,6 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.UnsupportedEncodingException; import java.util.Date; /** @@ -100,4 +104,36 @@ public void getList(Channel channel) { channel.writeAndFlush(response); close(channel); } + + @Override + public void sendInChat(Channel channel,String token, TextWebSocketFrame msg) { + String address = RedisUtil.getAddress(RedisUtil.convertMD5(WsCacheMap.getByJedis(token))); +// FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,address+HttpConstant.URI_SENDINCHAT); +// Gson gson = new Gson(); +// ByteBuf buf = null; +// try { +// buf = Unpooled.wrappedBuffer(gson.toJson(new SendInChat(token,msg)).getBytes("UTF-8")); +// } catch (UnsupportedEncodingException e) { +// e.printStackTrace(); +// } +// System.out.println("------"); +// request.content().writeBytes(buf); +// request.headers().set(HttpHeaderNames.CONTENT_LENGTH,request.content().readableBytes()); +// request.headers().set(HttpHeaderNames.CONTENT_TYPE,HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED); +// channel.writeAndFlush(request); + } + + @Override + public void sendByInChat(Channel channel, SendInChat sendInChat) { + Channel other = WsCacheMap.getByToken(sendInChat.getToken()); + try { + other.writeAndFlush(sendInChat.getFrame()); + }catch (NullPointerException e){ + e.printStackTrace(); + } + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST); + response.headers().set(HttpConstant.CONTENT_TYPE,HttpConstant.APPLICATION_JSON); + channel.writeAndFlush(response); + close(channel); + } } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java new file mode 100644 index 0000000..757d8db --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java @@ -0,0 +1,66 @@ +package com.github.unclecatmyself.bootstrap.channel.http; + +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.http.DefaultFullHttpRequest; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpRequestEncoder; +import io.netty.handler.codec.http.HttpResponseDecoder; +import io.netty.handler.codec.http.HttpVersion; + +import java.net.URI; + +/** + * Create by UncleCatMySelf in 17:47 2019\1\5 0005 + */ +public class HttpClient { + + public void connect(String host, int port) throws Exception { + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + Bootstrap b = new Bootstrap(); + b.group(workerGroup); + b.channel(NioSocketChannel.class); + b.option(ChannelOption.SO_KEEPALIVE, true); + b.handler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + // 客户端接收到的是httpResponse响应,所以要使用HttpResponseDecoder进行解码 + ch.pipeline().addLast(new HttpResponseDecoder()); + // 客户端发送的是httprequest,所以要使用HttpRequestEncoder进行编码 + ch.pipeline().addLast(new HttpRequestEncoder()); + } + }); + + // Start the client. + ChannelFuture f = b.connect(host, port).sync(); + + URI uri = new URI("http://192.168.56.1:8070"); + String msg = "Are you ok?"; + DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, + uri.toASCIIString(), Unpooled.wrappedBuffer(msg.getBytes("UTF-8"))); + + // 构建http请求 + request.headers().set(HttpHeaders.Names.HOST, host); + request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE); + request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, request.content().readableBytes()); + // 发送http请求 + f.channel().write(request); + f.channel().flush(); + f.channel().closeFuture().sync(); + } finally { + workerGroup.shutdownGracefully(); + } + + } + +} diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index aa20c17..c0a4126 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -75,6 +75,11 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { case HttpConstant.GETLIST: log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_GETLIST); httpHandlerService.getList(channel); + break; + case HttpConstant.SENDINCHAT: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_SENDINCHAT); + httpHandlerService.sendInChat(channel,msg); + break; default: break; } diff --git a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java index fd7688e..009ece3 100644 --- a/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java +++ b/src/main/java/com/github/unclecatmyself/common/base/HandlerService.java @@ -2,6 +2,7 @@ import com.github.unclecatmyself.common.bean.vo.SendServerVO; import io.netty.channel.Channel; +import io.netty.handler.codec.http.FullHttpMessage; import java.util.Map; @@ -30,6 +31,12 @@ public abstract class HandlerService implements HandlerApi { */ public abstract void sendFromServer(Channel channel,SendServerVO sendServerVO); + /** + * HTTP以服务端处理发送 + * @param channel + */ + public abstract void sendInChat(Channel channel, FullHttpMessage msg); + /** * 用户未找到匹配Uri * @param channel {@link Channel} 链接实例 @@ -71,4 +78,6 @@ public abstract class HandlerService implements HandlerApi { * @param maps {@link Map} 数据信息 */ public abstract void verify(Channel channel, Map maps); + + } diff --git a/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java b/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java new file mode 100644 index 0000000..eea34b9 --- /dev/null +++ b/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java @@ -0,0 +1,37 @@ +package com.github.unclecatmyself.common.bean; + +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; + +/** + * Create by UncleCatMySelf in 16:06 2019\1\5 0005 + */ +public class SendInChat { + + private String token; + + private TextWebSocketFrame frame; + + public SendInChat() { + } + + public SendInChat(String token, TextWebSocketFrame frame) { + this.token = token; + this.frame = frame; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public TextWebSocketFrame getFrame() { + return frame; + } + + public void setFrame(TextWebSocketFrame frame) { + this.frame = frame; + } +} diff --git a/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java index f095324..971d94e 100644 --- a/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/HttpConstant.java @@ -13,6 +13,8 @@ public class HttpConstant { public static final String GETLIST = "get_list"; + public static final String SENDINCHAT = "send_inchat"; + public static final String SENDFROMSERVER = "send_from_server"; public static final String NOTFINDURI = "not_find_uri"; @@ -21,6 +23,8 @@ public class HttpConstant { public static final String URI_GETLIST = "/get_list"; + public static final String URI_SENDINCHAT = "/send_inchat"; + public static final String URI_SENDFROMSERVER = "/send_from_server"; public static final String CONTENT_TYPE = "Content-Type"; diff --git a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java index a97d765..8db49b6 100644 --- a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java @@ -19,6 +19,8 @@ public class LogConstant { public static final String DEFAULTWEBSOCKETHANDLER_GETLIST = "[DefaultWebSocketHandler.httpdoMessage.GETLIST]"; + public static final String DEFAULTWEBSOCKETHANDLER_SENDINCHAT = "[DefaultWebSocketHandler.httpdoMessage.SENDINCHAT]"; + public static final String DEFAULTWEBSOCKETHANDLER_LOGIN = "[DefaultWebSocketHandler.textdoMessage.LOGIN]"; public static final String DEFAULTWEBSOCKETHANDLER_SENDME = "[DefaultWebSocketHandler.textdoMessage.SENDME]"; diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index 591780f..e79de95 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -1,5 +1,6 @@ package com.github.unclecatmyself.common.utils; +import com.alibaba.fastjson.JSONObject; import com.github.unclecatmyself.common.bean.vo.SendServerVO; import com.github.unclecatmyself.common.constant.Constans; import com.github.unclecatmyself.common.constant.HttpConstant; @@ -7,7 +8,11 @@ import io.netty.handler.codec.http.HttpMethod; import io.netty.util.CharsetUtil; -import java.io.UnsupportedEncodingException; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Map; /** * HTTP接口处理方法 @@ -26,7 +31,7 @@ public static String checkType(FullHttpRequest msg){ return HttpConstant.SENDFROMSERVER; }else if (url.equals(HttpConstant.URI_GETLIST) && meName.equals(HttpConstant.GET)){ return HttpConstant.GETLIST; - }else { + } else { return HttpConstant.NOTFINDURI; } } @@ -50,4 +55,6 @@ public static SendServerVO getToken(FullHttpRequest msg) throws UnsupportedEncod } return sendServerVO; } + + } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java index 088fae4..722f3a7 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/RedisUtil.java @@ -42,6 +42,20 @@ public static String convertMD5(String address,String token){ return s; } + public static String convertMD5(String inStr){ + char[] a = inStr.toCharArray(); + for (int i = 0; i < a.length; i++){ + a[i] = (char) (a[i] ^ 't'); + } + String s = new String(a); + return s; + } + + public static String getAddress(String s) { + String[] stars = s.split("&"); + return stars[0]; + } + // public static void main(String[] args) { // String s = new String("inchat"); // System.out.println("原始:" + s); diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java index a0099a5..0009ad8 100644 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -9,7 +9,7 @@ public class MyInit extends InitNetty { @Override public int getWebport() { - return 8090; + return 8070; } @Override From 30d6572e1b4ea0079697cfe6ee9b4a273a7676c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Mon, 7 Jan 2019 10:44:00 +0800 Subject: [PATCH 147/151] update-doc-01071043 --- doc/Project-Log-cn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index f8ea152..afcb9e0 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -24,3 +24,5 @@ * 【2018-01-01】 添加工具方法 * 【2018-01-02】 修复httpPOST请求接口 * 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2,更新README展示GIF,录制V1.1.2视频教程与使用说明书 +* 【2018-01-04】 修复文档,确定版本,新增Redis对接 +* 【2018-01-05】 初步转分布式、处理netty集群(未完成) From 9b06b56174764e5a6b4d331680cf99115fdf6554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Mon, 7 Jan 2019 14:52:10 +0800 Subject: [PATCH 148/151] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AF=B9=E6=8E=A5-01?= =?UTF-8?q?071452?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat90.html | 2 +- .../github/unclecatmyself/application.java | 3 +- .../bootstrap/channel/HandlerServiceImpl.java | 6 +-- .../channel/http/HttpChannelService.java | 4 +- .../channel/http/HttpChannelServiceImpl.java | 6 ++- .../bootstrap/channel/http/HttpClient.java | 41 +++++++++++++------ .../bootstrap/handler/DefaultHandler.java | 8 ++-- .../common/bean/SendInChat.java | 10 +++-- .../common/constant/LogConstant.java | 2 +- .../unclecatmyself/common/utils/HttpUtil.java | 5 ++- .../github/unclecatmyself/user/MyInit.java | 2 +- 11 files changed, 58 insertions(+), 31 deletions(-) diff --git a/Front-End-Testing/chat90.html b/Front-End-Testing/chat90.html index 8bb6310..e039f7f 100644 --- a/Front-End-Testing/chat90.html +++ b/Front-End-Testing/chat90.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8090/ws"); + socket = new WebSocket("ws://192.168.1.121:8090/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/src/main/java/com/github/unclecatmyself/application.java b/src/main/java/com/github/unclecatmyself/application.java index bfd1114..0cae824 100644 --- a/src/main/java/com/github/unclecatmyself/application.java +++ b/src/main/java/com/github/unclecatmyself/application.java @@ -18,7 +18,8 @@ public static void main(String[] args) { ConfigFactory.inChatVerifyService = new VerifyServiceImpl(); ConfigFactory.inChatToDataBaseService = new DataBaseServiceImpl(); ConfigFactory.fromServerService = FromServerServiceImpl.TYPE2; - ConfigFactory.RedisIP = "192.168.12.129"; +// ConfigFactory.RedisIP = "192.168.12.129"; + ConfigFactory.RedisIP = "192.168.192.132"; InitServer.open(); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 1e5efa1..4c59511 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -66,7 +66,8 @@ public void sendFromServer(Channel channel, SendServerVO serverVO) { public void sendInChat(Channel channel, FullHttpMessage msg) { System.out.println(msg); String content = msg.content().toString(CharsetUtil.UTF_8); - SendInChat sendInChat = (SendInChat) JSON.parse(content); + Gson gson = new Gson(); + SendInChat sendInChat = gson.fromJson(content,SendInChat.class); httpChannelService.sendByInChat(channel,sendInChat); } @@ -107,8 +108,7 @@ public void sendToText(Channel channel, Map maps) { Channel other = websocketChannelService.getChannel(otherOne); if (other == null){ //转http分布式 - httpChannelService.sendInChat(channel,otherOne,new TextWebSocketFrame( - gson.toJson(inChatBackMapService.getMsg(token,value)))); + httpChannelService.sendInChat(channel,otherOne,inChatBackMapService.getMsg(token,value)); }else{ other.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.getMsg(token,value)))); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java index d542d25..460ace6 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -6,6 +6,8 @@ import io.netty.channel.ChannelConfig; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import java.util.Map; + /** * Create by UncleCatMySelf in 11:41 2018\12\31 0031 */ @@ -21,7 +23,7 @@ public interface HttpChannelService { void getList(Channel channel); - void sendInChat(Channel channel,String token, TextWebSocketFrame msg); + void sendInChat(Channel channel,String token, Map msg); void sendByInChat(Channel channel,SendInChat sendInChat); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index da44a46..7f89e8c 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -22,6 +22,7 @@ import java.io.UnsupportedEncodingException; import java.util.Date; +import java.util.Map; /** * Create by UncleCatMySelf in 11:41 2018\12\31 0031 @@ -106,7 +107,7 @@ public void getList(Channel channel) { } @Override - public void sendInChat(Channel channel,String token, TextWebSocketFrame msg) { + public void sendInChat(Channel channel,String token, Map msg) { String address = RedisUtil.getAddress(RedisUtil.convertMD5(WsCacheMap.getByJedis(token))); // FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,address+HttpConstant.URI_SENDINCHAT); // Gson gson = new Gson(); @@ -125,9 +126,10 @@ public void sendInChat(Channel channel,String token, TextWebSocketFrame msg) { @Override public void sendByInChat(Channel channel, SendInChat sendInChat) { + Gson gson = new Gson(); Channel other = WsCacheMap.getByToken(sendInChat.getToken()); try { - other.writeAndFlush(sendInChat.getFrame()); + other.writeAndFlush(new TextWebSocketFrame(gson.toJson(sendInChat.getFrame()))); }catch (NullPointerException e){ e.printStackTrace(); } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java index 757d8db..f87af7f 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java @@ -1,5 +1,9 @@ package com.github.unclecatmyself.bootstrap.channel.http; +import com.github.unclecatmyself.common.bean.SendInChat; +import com.github.unclecatmyself.common.constant.Constans; +import com.google.gson.Gson; +import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; @@ -9,14 +13,12 @@ import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.http.DefaultFullHttpRequest; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpRequestEncoder; -import io.netty.handler.codec.http.HttpResponseDecoder; -import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.*; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import java.net.URI; +import java.util.HashMap; +import java.util.Map; /** * Create by UncleCatMySelf in 17:47 2019\1\5 0005 @@ -44,15 +46,25 @@ public void initChannel(SocketChannel ch) throws Exception { // Start the client. ChannelFuture f = b.connect(host, port).sync(); - URI uri = new URI("http://192.168.56.1:8070"); - String msg = "Are you ok?"; + URI uri = new URI("/send_inchat"); +// String msg = "Are you ok?"; + String token = "1111"; + Map backMap = new HashMap(); + backMap.put(Constans.TYPE,Constans.SENDTO); + backMap.put(Constans.VALUE,"你好"); + backMap.put(Constans.ONE,"1111"); + Gson gson = new Gson(); + String content = gson.toJson(new SendInChat(token,backMap)); +// ByteBuf buf = Unpooled.wrappedBuffer(gson.toJson(new SendInChat(token,msg)).getBytes("UTF-8")); DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, - uri.toASCIIString(), Unpooled.wrappedBuffer(msg.getBytes("UTF-8"))); + uri.toASCIIString(),Unpooled.wrappedBuffer(content.getBytes("UTF-8"))); // 构建http请求 - request.headers().set(HttpHeaders.Names.HOST, host); - request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE); - request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, request.content().readableBytes()); + request.headers().set(HttpHeaderNames.HOST, host); + request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + request.headers().set(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes()); +// request.headers().set(HttpHeaderNames.CONTENT_TYPE,HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED); + // 发送http请求 f.channel().write(request); f.channel().flush(); @@ -63,4 +75,9 @@ public void initChannel(SocketChannel ch) throws Exception { } + public static void main(String[] args) throws Exception { + HttpClient client = new HttpClient(); + client.connect("192.168.1.121",8090); + } + } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java index c0a4126..2a84277 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/handler/DefaultHandler.java @@ -68,10 +68,6 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { } httpHandlerService.sendFromServer(channel,serverVO); break; - case HttpConstant.NOTFINDURI: - log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_NOTFINDURI); - httpHandlerService.notFindUri(channel); - break; case HttpConstant.GETLIST: log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_GETLIST); httpHandlerService.getList(channel); @@ -80,6 +76,10 @@ protected void httpdoMessage(ChannelHandlerContext ctx, FullHttpRequest msg) { log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_SENDINCHAT); httpHandlerService.sendInChat(channel,msg); break; + case HttpConstant.NOTFINDURI: + log.info(LogConstant.DEFAULTWEBSOCKETHANDLER_NOTFINDURI); + httpHandlerService.notFindUri(channel); + break; default: break; } diff --git a/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java b/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java index eea34b9..3946077 100644 --- a/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java +++ b/src/main/java/com/github/unclecatmyself/common/bean/SendInChat.java @@ -2,6 +2,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import java.util.Map; + /** * Create by UncleCatMySelf in 16:06 2019\1\5 0005 */ @@ -9,12 +11,12 @@ public class SendInChat { private String token; - private TextWebSocketFrame frame; + private Map frame; public SendInChat() { } - public SendInChat(String token, TextWebSocketFrame frame) { + public SendInChat(String token, Map frame) { this.token = token; this.frame = frame; } @@ -27,11 +29,11 @@ public void setToken(String token) { this.token = token; } - public TextWebSocketFrame getFrame() { + public Map getFrame() { return frame; } - public void setFrame(TextWebSocketFrame frame) { + public void setFrame(Map frame) { this.frame = frame; } } diff --git a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java index 8db49b6..87f667e 100644 --- a/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java +++ b/src/main/java/com/github/unclecatmyself/common/constant/LogConstant.java @@ -49,5 +49,5 @@ public class LogConstant { public static final String DATAASYNCHRONOUSTASK_03 = "[DataAsynchronousTask.writeData]:线程任务执行异常"; - public static final String REDIS_START = "[RedisConfig.getJedis]:连接成功,测试连接:"; + public static final String REDIS_START = "[RedisConfig.getJedis]:连接成功,测试连接PING->"; } diff --git a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java index e79de95..f9fd8e9 100644 --- a/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java +++ b/src/main/java/com/github/unclecatmyself/common/utils/HttpUtil.java @@ -23,6 +23,7 @@ public class HttpUtil { public static String checkType(FullHttpRequest msg){ msg.retain(); String url = msg.uri(); + System.out.println(url); HttpMethod method = msg.method(); String meName = method.name(); if (url.equals(HttpConstant.URI_GETSIZE) && meName.equals(HttpConstant.GET)){ @@ -31,7 +32,9 @@ public static String checkType(FullHttpRequest msg){ return HttpConstant.SENDFROMSERVER; }else if (url.equals(HttpConstant.URI_GETLIST) && meName.equals(HttpConstant.GET)){ return HttpConstant.GETLIST; - } else { + }else if (url.equals(HttpConstant.URI_SENDINCHAT) && meName.equals(HttpConstant.POST)){ + return HttpConstant.SENDINCHAT; + }else { return HttpConstant.NOTFINDURI; } } diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java index 0009ad8..a0099a5 100644 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -9,7 +9,7 @@ public class MyInit extends InitNetty { @Override public int getWebport() { - return 8070; + return 8090; } @Override From ea3e3073a77929b98fc797ee663cdba5d435af8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Mon, 7 Jan 2019 17:14:22 +0800 Subject: [PATCH 149/151] =?UTF-8?q?netty=E5=88=9D=E7=89=88=E9=9B=86?= =?UTF-8?q?=E7=BE=A4-01071714?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front-End-Testing/chat70.html | 2 +- doc/Project-Log-cn.md | 2 + .../unclecatmyself/auto/RedisConfig.java | 10 -- .../bootstrap/channel/HandlerServiceImpl.java | 2 +- .../channel/http/HttpChannelService.java | 2 +- .../channel/http/HttpChannelServiceImpl.java | 22 ++-- .../bootstrap/channel/http/HttpClient.java | 104 +++++++++--------- .../github/unclecatmyself/user/MyInit.java | 2 +- 8 files changed, 65 insertions(+), 81 deletions(-) diff --git a/Front-End-Testing/chat70.html b/Front-End-Testing/chat70.html index 02e9fc7..ea22f3d 100644 --- a/Front-End-Testing/chat70.html +++ b/Front-End-Testing/chat70.html @@ -54,7 +54,7 @@ window.WebSocket = window.MozWebSocket; } if (window.WebSocket) { - socket = new WebSocket("ws://192.168.56.1:8070/ws"); + socket = new WebSocket("ws://192.168.1.121:8070/ws"); socket.onmessage = function(event) { var ta = document.getElementById('responseText'); ta.value = ta.value + '\n' + event.data diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index afcb9e0..a911214 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -26,3 +26,5 @@ * 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2,更新README展示GIF,录制V1.1.2视频教程与使用说明书 * 【2018-01-04】 修复文档,确定版本,新增Redis对接 * 【2018-01-05】 初步转分布式、处理netty集群(未完成) +* 【2018-01-07】 完成netty集群,多用户跨服务器的消息通讯 + diff --git a/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java b/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java index 997fe78..b0e5940 100644 --- a/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java +++ b/src/main/java/com/github/unclecatmyself/auto/RedisConfig.java @@ -24,18 +24,8 @@ private RedisConfig(){ } } - public static RedisConfig getInstance(){ return instance; } -// public static Jedis getJedis(){ -// Jedis jedis = null; -// if (ConfigFactory.initNetty.getDistributed()){ -// jedis = new Jedis(ConfigFactory.RedisIP); -// log.info(LogConstant.REDIS_START + jedis.ping()); -// } -// return jedis; -// } - } diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java index 4c59511..37dfa32 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/HandlerServiceImpl.java @@ -108,7 +108,7 @@ public void sendToText(Channel channel, Map maps) { Channel other = websocketChannelService.getChannel(otherOne); if (other == null){ //转http分布式 - httpChannelService.sendInChat(channel,otherOne,inChatBackMapService.getMsg(token,value)); + httpChannelService.sendInChat(otherOne,inChatBackMapService.getMsg(token,value)); }else{ other.writeAndFlush(new TextWebSocketFrame( gson.toJson(inChatBackMapService.getMsg(token,value)))); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java index 460ace6..0f730a1 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelService.java @@ -23,7 +23,7 @@ public interface HttpChannelService { void getList(Channel channel); - void sendInChat(Channel channel,String token, Map msg); + void sendInChat(String token, Map msg); void sendByInChat(Channel channel,SendInChat sendInChat); diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java index 7f89e8c..1bfcd8a 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpChannelServiceImpl.java @@ -107,21 +107,15 @@ public void getList(Channel channel) { } @Override - public void sendInChat(Channel channel,String token, Map msg) { + public void sendInChat(String token, Map msg) { String address = RedisUtil.getAddress(RedisUtil.convertMD5(WsCacheMap.getByJedis(token))); -// FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,address+HttpConstant.URI_SENDINCHAT); -// Gson gson = new Gson(); -// ByteBuf buf = null; -// try { -// buf = Unpooled.wrappedBuffer(gson.toJson(new SendInChat(token,msg)).getBytes("UTF-8")); -// } catch (UnsupportedEncodingException e) { -// e.printStackTrace(); -// } -// System.out.println("------"); -// request.content().writeBytes(buf); -// request.headers().set(HttpHeaderNames.CONTENT_LENGTH,request.content().readableBytes()); -// request.headers().set(HttpHeaderNames.CONTENT_TYPE,HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED); -// channel.writeAndFlush(request); + System.out.println(address); + String[] str = address.split(":"); + try { + HttpClient.getInstance().send(str[0],Integer.parseInt(str[1]),token,msg); + } catch (Exception e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java index f87af7f..7afea51 100644 --- a/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java +++ b/src/main/java/com/github/unclecatmyself/bootstrap/channel/http/HttpClient.java @@ -1,23 +1,20 @@ package com.github.unclecatmyself.bootstrap.channel.http; import com.github.unclecatmyself.common.bean.SendInChat; -import com.github.unclecatmyself.common.constant.Constans; +import com.github.unclecatmyself.common.constant.HttpConstant; import com.google.gson.Gson; -import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; +import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.bootstrap.Bootstrap; -import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.*; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.util.CharsetUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.URI; -import java.util.HashMap; import java.util.Map; /** @@ -25,59 +22,60 @@ */ public class HttpClient { - public void connect(String host, int port) throws Exception { + private static final Logger log = LoggerFactory.getLogger(HttpClient.class); + + private static HttpClient instance = new HttpClient(); + + public static Bootstrap bootstrap; + + private HttpClient(){ EventLoopGroup workerGroup = new NioEventLoopGroup(); + Bootstrap b = new Bootstrap(); + b.group(workerGroup); + b.channel(NioSocketChannel.class); + b.option(ChannelOption.SO_KEEPALIVE, true); + b.handler(new ChannelInitializer() { + @Override + public void initChannel(SocketChannel ch) throws Exception { + // 客户端接收到的是httpResponse响应,所以要使用HttpResponseDecoder进行解码 + ch.pipeline().addLast(new HttpResponseDecoder()); + // 客户端发送的是httprequest,所以要使用HttpRequestEncoder进行编码 + ch.pipeline().addLast(new HttpRequestEncoder()); + } + }); + this.bootstrap = b; + } - try { - Bootstrap b = new Bootstrap(); - b.group(workerGroup); - b.channel(NioSocketChannel.class); - b.option(ChannelOption.SO_KEEPALIVE, true); - b.handler(new ChannelInitializer() { - @Override - public void initChannel(SocketChannel ch) throws Exception { - // 客户端接收到的是httpResponse响应,所以要使用HttpResponseDecoder进行解码 - ch.pipeline().addLast(new HttpResponseDecoder()); - // 客户端发送的是httprequest,所以要使用HttpRequestEncoder进行编码 - ch.pipeline().addLast(new HttpRequestEncoder()); - } - }); + public static HttpClient getInstance(){ + return instance; + } - // Start the client. - ChannelFuture f = b.connect(host, port).sync(); + public void send(String host, int port,String token,Map value) throws Exception { + // Start the client. + ChannelFuture f = this.bootstrap.connect(host, port).sync(); - URI uri = new URI("/send_inchat"); -// String msg = "Are you ok?"; - String token = "1111"; - Map backMap = new HashMap(); - backMap.put(Constans.TYPE,Constans.SENDTO); - backMap.put(Constans.VALUE,"你好"); - backMap.put(Constans.ONE,"1111"); - Gson gson = new Gson(); - String content = gson.toJson(new SendInChat(token,backMap)); -// ByteBuf buf = Unpooled.wrappedBuffer(gson.toJson(new SendInChat(token,msg)).getBytes("UTF-8")); - DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, - uri.toASCIIString(),Unpooled.wrappedBuffer(content.getBytes("UTF-8"))); + URI uri = new URI(HttpConstant.URI_SENDINCHAT); - // 构建http请求 - request.headers().set(HttpHeaderNames.HOST, host); - request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); - request.headers().set(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes()); -// request.headers().set(HttpHeaderNames.CONTENT_TYPE,HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED); + Gson gson = new Gson(); + String content = gson.toJson(new SendInChat(token,value)); + DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, + uri.toASCIIString(),Unpooled.wrappedBuffer(content.getBytes(CharsetUtil.UTF_8))); - // 发送http请求 - f.channel().write(request); - f.channel().flush(); - f.channel().closeFuture().sync(); - } finally { - workerGroup.shutdownGracefully(); - } + // 构建http请求 + request.headers().set(HttpHeaderNames.HOST, host); + request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + request.headers().set(HttpHeaderNames.CONTENT_LENGTH, request.content().readableBytes()); +// request.headers().set(HttpHeaderNames.CONTENT_TYPE,HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED); + // 发送http请求 + f.channel().write(request); + f.channel().flush(); + f.channel().closeFuture().sync(); } - public static void main(String[] args) throws Exception { - HttpClient client = new HttpClient(); - client.connect("192.168.1.121",8090); - } +// public static void main(String[] args) throws Exception { +// HttpClient client = new HttpClient(); +// client.connect("192.168.1.121",8090); +// } } diff --git a/src/main/java/com/github/unclecatmyself/user/MyInit.java b/src/main/java/com/github/unclecatmyself/user/MyInit.java index a0099a5..0009ad8 100644 --- a/src/main/java/com/github/unclecatmyself/user/MyInit.java +++ b/src/main/java/com/github/unclecatmyself/user/MyInit.java @@ -9,7 +9,7 @@ public class MyInit extends InitNetty { @Override public int getWebport() { - return 8090; + return 8070; } @Override From 3d21bd88853766bee2aba91f2c37e3497fc283de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 8 Jan 2019 09:22:31 +0800 Subject: [PATCH 150/151] =?UTF-8?q?=E8=AE=BE=E5=AE=9A=E4=B8=8B=E7=89=88?= =?UTF-8?q?=E7=9B=AE=E6=A0=87-01080922?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- doc/Project-Log-cn.md | 3 ++- doc/goal/goal.md | 9 ++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 264e1f5..4df66e4 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ***(InChat)Iot Netty Chat*** -一个轻量级、高效的通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 +一个轻量级、高效、分布式的异步通信框架, 支持聊天和物联网, 您可以使用它来快速构建具有后台的聊天服务器, 并快速自定义自己的通信 api, 包括具有不同的通讯可以支持的协议。 **欢迎参与QQ群交流与提供建议、业务场景、需求功能等** diff --git a/doc/Project-Log-cn.md b/doc/Project-Log-cn.md index a911214..d018b94 100644 --- a/doc/Project-Log-cn.md +++ b/doc/Project-Log-cn.md @@ -26,5 +26,6 @@ * 【2018-01-03】 完成新版http接口处理与测试,预计发包,新版发布 InChatV1.1.2,更新README展示GIF,录制V1.1.2视频教程与使用说明书 * 【2018-01-04】 修复文档,确定版本,新增Redis对接 * 【2018-01-05】 初步转分布式、处理netty集群(未完成) -* 【2018-01-07】 完成netty集群,多用户跨服务器的消息通讯 +* 【2018-01-07】 完成netty集群,多用户跨服务器的消息通讯(HTTP版本) +* 【2018-01-08】 设定下一版本目标 diff --git a/doc/goal/goal.md b/doc/goal/goal.md index 37d7a86..a414ec6 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -56,4 +56,11 @@ InChat 1.1.2 -``` \ No newline at end of file +``` + + +## V1.1.3版本 【待定】 + +> 版本昵称:橙猫 + +版本目标:InChat集群与wss From c993f31efa404193b2c501a8aed12528193e5f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=9F=B9=E6=9D=B0?= <3183764662@qq.com> Date: Tue, 8 Jan 2019 09:55:03 +0800 Subject: [PATCH 151/151] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81-01?= =?UTF-8?q?080954?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/goal/goal.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/goal/goal.md b/doc/goal/goal.md index a414ec6..16a224b 100644 --- a/doc/goal/goal.md +++ b/doc/goal/goal.md @@ -2,6 +2,8 @@ > 项目研发的开放目标,以Maven包为基本的发布(兼对应版本的文档输出)设定为每个里程碑的产出。 +### 项目于2018年8月14号开始成立,前一个月以Demo为发展路线,后期转为框架研发。 + ## V1.0.0版本 【2018-12-14】 > 版本昵称:赤猫