result = restTemplate.exchange("http://lingtek.jalasmart.com/api/v1/lingtek/number", HttpMethod.PUT, request, Result.class);
- logger.info("灯光结果" + JsonMapper.nonDefaultMapper().toJson(result));
- }
-
-
- @Override
- public void destory(Channel channel) {
- channels.remove(channel);
- }
-
- @Override
- public void doOffLine(Integer memberId, String nickname, String machineSn) {
-
- }
-
- @Override
- public void sendMessage(MemberDto memberDto) {
-
- }
-
-
- protected Cmd resolveCmd(String message) {
- BaseDto baseDto = JsonMapper.nonEmptyMapper().fromJson(message, BaseDto.class);
- return Cmd.getCmd(baseDto.getCmdId());
- }
-
-
-}
diff --git a/netty-pad/src/main/java/com/sv/netty/utils/CommonUtils.java b/netty-pad/src/main/java/com/sv/netty/utils/CommonUtils.java
deleted file mode 100644
index 7d72218..0000000
--- a/netty-pad/src/main/java/com/sv/netty/utils/CommonUtils.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.sv.netty.utils;
-
-import java.nio.charset.Charset;
-
-/**
- * USER: douya
- * DATE: 2017-08-28
- */
-public class CommonUtils {
-
-
-
- public static byte[] intToBytes2(int n){
- byte[] b = new byte[4];
-
- for(int i = 0;i < 4;i++)
- {
- b[i]=(byte)(n>>(24-i*8));
-
- }
- return b;
- }
-
- /**
- * byte数组转换成16进制字符串
- * @param src
- * @return
- */
- public static String bytesToHexString(byte[] src){
- StringBuilder stringBuilder = new StringBuilder();
- if (src == null || src.length <= 0) {
- return null;
- }
- for (int i = 0; i < src.length; i++) {
- int v = src[i] & 0xFF;
- String hv = Integer.toHexString(v);
- if (hv.length() < 2) {
- stringBuilder.append(0);
- }
- stringBuilder.append(hv);
- }
- return stringBuilder.toString();
- }
-
- /**
- * byte数组转换成16进制字符数组
- * @param src
- * @return
- */
- public static String[] bytesToHexStrings(byte[] src){
- if (src == null || src.length <= 0) {
- return null;
- }
- String[] str = new String[src.length];
-
- for (int i = 0; i < src.length; i++) {
- int v = src[i] & 0xFF;
- String hv = Integer.toHexString(v);
- if (hv.length() < 2) {
- str[i] = "0";
- }
- str[i] = hv;
- }
- return str;
- }
-
-
- public static void main(String[] arg){
- String message = "{\"cmd\":\"text_message\",\"content\":\"开心开心\",\"member_count\":0,\"system\":0,\"vmc_no\":\"322af403825a\"";
- byte[] bodys = message.getBytes(Charset.forName("UTF-8"));
- String magic = bytesToHexString("doll".getBytes(Charset.forName("UTF-8")));
- String length = bytesToHexString(intToBytes2(bodys.length+8));
- System.out.println(magic+length+bytesToHexString(bodys));
- }
-
-}
diff --git a/netty-pad/src/main/java/com/sv/netty/utils/EncodeUtils.java b/netty-pad/src/main/java/com/sv/netty/utils/EncodeUtils.java
deleted file mode 100644
index 7507d59..0000000
--- a/netty-pad/src/main/java/com/sv/netty/utils/EncodeUtils.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Copyright (c) 2005-2009 springside.org.cn
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- *
- * $Id: EncodeUtils.java 984 2010-03-21 13:02:44Z calvinxiu $
- */
-package com.sv.netty.utils;
-
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
-
-/**
- * 各种格式的编码加码工具类.
- *
- * 集成Commons-Codec,Commons-Lang及JDK提供的编解码方法.
- *
- * @author ranfi
- */
-public class EncodeUtils {
-
- private static final String DEFAULT_URL_ENCODING = "UTF-8";
- private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
-
- /**
- * Hex编码.
- */
- public static String encodeHex(byte[] input) {
- return Hex.encodeHexString(input);
- }
-
- /**
- * Hex解码.
- */
- public static byte[] decodeHex(String input) {
- try {
- return Hex.decodeHex(input.toCharArray());
- } catch (DecoderException e) {
- return null;
- }
- }
-
- /**
- * Base64编码.
- */
- public static String encodeBase64(byte[] input) {
- return Base64.encodeBase64String(input);
- }
-
- /**
- * Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
- */
- public static String encodeUrlSafeBase64(byte[] input) {
- return Base64.encodeBase64URLSafeString(input);
- }
-
- /**
- * Base64解码.
- */
- public static byte[] decodeBase64(String input) {
- return Base64.decodeBase64(input);
- }
-
- /**
- * Base62编码。
- */
- public static String encodeBase62(byte[] input) {
- char[] chars = new char[input.length];
- for (int i = 0; i < input.length; i++) {
- chars[i] = BASE62[(input[i] & 0xFF) % BASE62.length];
- }
- return new String(chars);
- }
-
-
-}
diff --git a/netty-pad/src/main/java/com/sv/netty/utils/JsonMapper.java b/netty-pad/src/main/java/com/sv/netty/utils/JsonMapper.java
deleted file mode 100644
index b4d736d..0000000
--- a/netty-pad/src/main/java/com/sv/netty/utils/JsonMapper.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * Copyright (c) 2005-2012 springside.org.cn
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- */
-package com.sv.netty.utils;
-
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.util.JSONPObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * 简单封装Jackson,实现JSON String<->Java Object的Mapper.
- *
- * 封装不同的输出风格, 使用不同的builder函数创建实例.
- *
- * @author calvin
- */
-public class JsonMapper {
-
- private static Logger logger = LoggerFactory.getLogger(JsonMapper.class);
-
- private final ObjectMapper mapper;
-
- public JsonMapper() {
- this(null);
- }
-
- public JsonMapper(Include include) {
- mapper = new ObjectMapper();
- // 设置输出时包含属性的风格
- if (include != null) {
- mapper.setSerializationInclusion(include);
- }
- // 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
- mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
- }
-
- /**
- * 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
- */
- public static JsonMapper nonEmptyMapper() {
- return new JsonMapper(Include.NON_EMPTY);
- }
-
- /**
- * 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
- */
- public static JsonMapper nonDefaultMapper() {
- return new JsonMapper(Include.NON_DEFAULT);
- }
-
- public static JsonMapper nonNullMapper() {
- return new JsonMapper(Include.NON_NULL);
- }
-
- /**
- * Object可以是POJO,也可以是Collection或数组。 如果对象为Null, 返回"null". 如果集合为空集合, 返回"[]".
- */
- public String toJson(Object object) {
-
- try {
- return mapper.writeValueAsString(object);
- } catch (IOException e) {
- logger.warn("write to json string error:" + object, e);
- return null;
- }
- }
-
- /**
- * 反序列化POJO或简单Collection如List.
- *
- * 如果JSON字符串为Null或"null"字符串, 返回Null. 如果JSON字符串为"[]", 返回空集合.
- *
- * 如需反序列化复杂Collection如List, 请使用fromJson(String, JavaType)
- *
- * @see #fromJson(String, JavaType)
- */
- public T fromJson(String jsonString, Class clazz) {
- if (StringUtils.isEmpty(jsonString)) {
- return null;
- }
-
- try {
- return mapper.readValue(jsonString, clazz);
- } catch (IOException e) {
- logger.warn("parse json string error:" + jsonString, e);
- return null;
- }
- }
-
- /**
- * 反序列化复杂Collection如List,
- * 先使用createCollectionType()或contructMapType()构造类型, 然后调用本函数.
- *
- * @see #createCollectionType(Class, Class...)
- */
- public T fromJson(String jsonString, JavaType javaType) {
- if (StringUtils.isEmpty(jsonString)) {
- return null;
- }
-
- try {
- return (T) mapper.readValue(jsonString, javaType);
- } catch (IOException e) {
- logger.warn("parse json string error:" + jsonString, e);
- return null;
- }
- }
-
- /**
- * 构造Collection类型.
- */
- public JavaType contructCollectionType(Class extends Collection> collectionClass, Class> elementClass) {
- return mapper.getTypeFactory().constructCollectionType(collectionClass, elementClass);
- }
-
- /**
- * 构造Map类型.
- */
- public JavaType contructMapType(Class extends Map> mapClass, Class> keyClass, Class> valueClass) {
- return mapper.getTypeFactory().constructMapType(mapClass, keyClass, valueClass);
- }
-
- /**
- * map 转 bean
- *
- * @param map
- * @param beanClass
- * @return
- */
- public T convertMapToBean(Map map, Class beanClass) {
- try {
- return mapper.convertValue(map, beanClass);
- } catch (Exception e) {
- logger.warn("convertMapToBean error! ", e);
- }
- return null;
- }
-
- /**
- * map 转 bean
- *
- * @param bean
- * @param objectClass
- * @return
- */
- public T convertBeanToOther(Object bean, Class objectClass) {
- try {
- return mapper.convertValue(bean, objectClass);
- } catch (Exception e) {
- logger.warn("convertMapToBean error! ", e);
- }
- return null;
- }
-
- /**
- * 当JSON里只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性.
- */
- public void update(String jsonString, Object object) {
- try {
- mapper.readerForUpdating(object).readValue(jsonString);
- } catch (JsonProcessingException e) {
- logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e);
- } catch (IOException e) {
- logger.warn("update json string:" + jsonString + " to object:" + object + " error.", e);
- }
- }
-
- /**
- * 輸出JSONP格式數據.
- */
- public String toJsonP(String functionName, Object object) {
- return toJson(new JSONPObject(functionName, object));
- }
-
- /**
- * 設定是否使用Enum的toString函數來讀寫Enum, 為False時時使用Enum的name()函數來讀寫Enum, 默認為False.
- * 注意本函數一定要在Mapper創建後, 所有的讀寫動作之前調用.
- */
- public void enableEnumUseToString() {
- mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
- mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
- }
-
- /**
- * 取出Mapper做进一步的设置或使用其他序列化API.
- */
- public ObjectMapper getMapper() {
- return mapper;
- }
-
-}
diff --git a/netty-pad/src/main/java/com/sv/netty/utils/JsonUtils.java b/netty-pad/src/main/java/com/sv/netty/utils/JsonUtils.java
deleted file mode 100644
index 250c659..0000000
--- a/netty-pad/src/main/java/com/sv/netty/utils/JsonUtils.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.sv.netty.utils;
-
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-
-/**
- * USER: douya
- * DATE: 2017-11-01
- */
-public class JsonUtils {
-
-
- /**
- * Logger for this class
- */
- private static final Logger logger = LoggerFactory.getLogger(JsonUtils.class);
-
- private final static ObjectMapper objectMapper = new ObjectMapper();
-
- static {
- objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
- objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
- objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
- objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
- objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- }
-
- private JsonUtils() {
- }
-
- public static String encode(Object obj) {
- try {
- return objectMapper.writeValueAsString(obj);
- } catch (JsonGenerationException e) {
- logger.error("encode(Object)", e); //$NON-NLS-1$
- } catch (JsonMappingException e) {
- logger.error("encode(Object)", e); //$NON-NLS-1$
- } catch (IOException e) {
- logger.error("encode(Object)", e); //$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * 将json string反序列化成对象
- *
- * @param json
- * @param valueType
- * @return
- */
- public static T decode(String json, Class valueType) {
- try {
- return objectMapper.readValue(json, valueType);
- } catch (JsonParseException e) {
- logger.error("decode(String, Class)", e);
- } catch (JsonMappingException e) {
- logger.error("decode(String, Class)", e);
- } catch (IOException e) {
- logger.error("decode(String, Class)", e);
- }
- return null;
- }
-
- /**
- * 将json array反序列化为对象
- *
- * @param json
- * @param typeReference
- * @return
- */
- @SuppressWarnings("unchecked")
- public static T decode(String json, TypeReference typeReference) {
- try {
- return (T) objectMapper.readValue(json, typeReference);
- } catch (JsonParseException e) {
- logger.error("decode(String, JsonTypeReference)", e);
- } catch (JsonMappingException e) {
- logger.error("decode(String, JsonTypeReference)", e);
- } catch (IOException e) {
- logger.error("decode(String, JsonTypeReference)", e);
- }
- return null;
- }
-
-}
diff --git a/netty-pad/src/main/java/com/sv/netty/utils/LiveTime.java b/netty-pad/src/main/java/com/sv/netty/utils/LiveTime.java
deleted file mode 100644
index 42788ab..0000000
--- a/netty-pad/src/main/java/com/sv/netty/utils/LiveTime.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.sv.netty.utils;
-
-/**
- * USER: douya
- * DATE: 2017-08-07
- */
-public enum LiveTime {
-
- SECONDS_15(15 * 1000), SECONDS_30(30 * 1000),
-
- MINUTES_1(1 * 60 * 1000), MINUTES_2(2 * 60 * 1000), MINUTES_5(5 * 60 * 1000), MINUTES_10(10 * 60 * 1000), MINUTES_30(
- 30 * 60 * 1000),
-
- HOURS_1(1 * 60 * 60 * 1000), HOURS_2(2 * 60 * 60 * 1000), HOURS_5(5 * 60 * 60 * 1000), HOURS_12(
- 12 * 60 * 60 * 1000),HOURS_36(36*60*60*1000),
-
- DAYS_1(1 * 24 * 60 * 60 * 1000), DAYS_2(2 * 24 * 60 * 60 * 1000), DAYS_5(5 * 24 * 60 * 60 * 1000), DAYS_15(15
- * 24 * 60 * 60 * 1000L),DAYS_30(30* 24 * 60 * 60 * 1000L)
-
- ;
- public final long time;
-
- LiveTime(long time) {
- this.time = time;
- }
-
-
-}
diff --git a/netty-pad/src/main/resources/config/application-dev.yml b/netty-pad/src/main/resources/config/application-dev.yml
deleted file mode 100644
index bf36442..0000000
--- a/netty-pad/src/main/resources/config/application-dev.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-spring:
- datasource:
- url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true&useSSL=false
- username: root
- password: 123456
-
- jpa:
- show-sql: true
-
-sv:
- file:
- store:
- image: imagetest/
- video: videotest/
- health: health-docstest/
diff --git a/netty-pad/src/main/resources/config/application-prod.yml b/netty-pad/src/main/resources/config/application-prod.yml
deleted file mode 100644
index 43c0e55..0000000
--- a/netty-pad/src/main/resources/config/application-prod.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-spring:
- datasource:
- url: jdbc:mysql://127.0.0.1:3306/smart_venue?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&useAffectedRows=true
- username: root
- password: hyty1234
- driver-class-name: com.mysql.cj.jdbc.Driver
-
- jpa:
- show-sql: true
-
-sv:
- file:
- store:
- image: image/
- video: video/
- health: health-docs/
diff --git a/netty-pad/src/main/resources/config/application.yml b/netty-pad/src/main/resources/config/application.yml
deleted file mode 100644
index c085c23..0000000
--- a/netty-pad/src/main/resources/config/application.yml
+++ /dev/null
@@ -1,111 +0,0 @@
-server:
- port: 8021
- context-path: /netty
- tomcat:
- uri-encoding: utf-8
-
-
-
-spring:
- profiles:
- include:
- -dev
- -prod
- active: dev
-
-
- # 数据库连接池配置
- druid:
- filters: stat
- initialSize: 1
- minIdle: 1
- maxActive: 40
- maxWait: 600000
- timeBetweenEvictionRunsMillis: 60000
- minEvictableIdleTimeMillis: 300000
- validationQuery: SELECT 'x'
- testWhileIdle: true
- testOnBorrow: false
- testOnReturn: false
- poolPreparedStatements: true
- maxPoolPreparedStatementPerConnectionSize: 20
- WebStatFilter:
- enabled: false
- urlPattern:
- exclusions:
- sessionStatMaxCount:
- sessionStatEnable:
- principalSessionName:
- principalCookieName:
- profileEnable:
- StatViewServlet:
- enabled: true
- urlPattern: /druid/*
- resetEnable: true
- loginUsername: druid
- loginPassword: druid
- allow:
- deny:
- aop:
- auto: true
- http:
- encoding:
- force: true
- charset: utf-8
- enabled: true
-
- jackson:
- date-format: yyyy-MM-dd HH:mm:ss
- property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
-
- redis:
- pool:
- max-active: 1000
- max-wait: -1
- max-idle: 8
- min-idle: 8
- timeout: 60000
-
-# MyBatis Configuration
-mybatis:
- type-aliases-package: com.ydd.oms.entity
- config-location: classpath:mybatis/mybatis-config.xml
- mapper-locations: classpath:mybatis/mapper/*/*.xml
-
-oss:
- accessKeyId: LTAIlbtS4W2Xe4OV
- accessKeySecret: qWMYkSfmXFtRoIv9q9OCbszcF9U7dX
- protocol: http
- name: smartvenue
- endPoint: http://oss-cn-beijing.aliyuncs.com
- url: https://smartvenue.oss-cn-beijing.aliyuncs.com/
-
-face:
- url: 192.168.1.111
- account: test@test.com
- pwd: 123456
-
-nettym:
- url: http://127.0.0.1:8021/netty/message/send
-
-
-#netty服务器配置
-netty:
- port: 56791
-boss:
- thread:
- count: 1
-worker:
- thread:
- count: 2
-so:
- keepalive: true
- backlog: 128
- reuseaddr: true
-tcp_nodelay: true
-
-logging:
- level:
- com:
- sv:
- mapper: DEBUG
diff --git a/netty-pad/src/main/resources/logback.xml b/netty-pad/src/main/resources/logback.xml
deleted file mode 100644
index b1babd7..0000000
--- a/netty-pad/src/main/resources/logback.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
-
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
-
-
-
-
- ${LOG_HOME}/common-default.log
-
- ${LOG_HOME}/common-default-%d{yyyy-MM-dd}.log
-
- 30
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
-
-
-
-
- ${LOG_HOME}/common-error.log
-
- ERROR
-
-
- ${LOG_HOME}/common-error-%d{yyyy-MM-dd}.log
-
- 30
-
-
- %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
-
-
-
-
-
-
-
-
-
-
diff --git a/netty-pad/src/main/resources/mybatis/mybatis-config.xml b/netty-pad/src/main/resources/mybatis/mybatis-config.xml
deleted file mode 100644
index 491eebd..0000000
--- a/netty-pad/src/main/resources/mybatis/mybatis-config.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/ClientTest.java b/netty-pad/src/main/test/java/test/netty/nio/net/ClientTest.java
deleted file mode 100644
index a280080..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/ClientTest.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package test.netty.nio.net;
-
-import test.netty.nio.net.client.ClientThread;
-
-/**
- * 开启一个客户端,
- */
-public class ClientTest {
- public static void main(String[] args) {
- ClientThread instance = ClientThread.getInstance();
- instance.start();
- }
-}
\ No newline at end of file
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientHandler.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientHandler.java
deleted file mode 100644
index fa584f6..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package test.netty.nio.net.client;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.handler.timeout.IdleState;
-import io.netty.handler.timeout.IdleStateEvent;
-import test.netty.nio.net.dto.HeartBeat;
-import test.netty.nio.net.dto.Message;
-
-/**
- * 通讯服务器请求处理
- *
- * @author peakren
- * @date 05/12/2017 10:27 PM
- */
-@ChannelHandler.Sharable
-public class ClientHandler extends ChannelInboundHandlerAdapter {
-
- private final static String TAG = "ClientHandler";
-
- private boolean hasRead = false;
-
- @Override
- public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
- super.channelRegistered(ctx);
-// ClientTcpSession.getInstance().setContext(ctx);
- }
-
- @Override
- public void channelActive(ChannelHandlerContext ctx) throws Exception {
- super.channelActive(ctx);
- //服务器连上以后立即模拟心跳返回
- ctx.writeAndFlush(getHbMessage());
- }
-
- @Override
- public void channelInactive(ChannelHandlerContext ctx) throws Exception {
- super.channelInactive(ctx);
-// GlobalConfig.isConnected =false;
- ClientThread.getInstance().clearFuture();
- ClientThread.getInstance().restart();
- }
-
- @Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
- super.channelRead(ctx, msg);
-// Message message = JsonMapper.fromJson(msg.toString(), Message.class);
-// MessageService.getInstance().execute(message);
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
- super.exceptionCaught(ctx, cause);
-// GlobalConfig.isConnected = false;
- ctx.close();
- }
-
- /**
- * 获取心跳返回消息
- *
- * @return
- */
- private Message getHbMessage() {
- HeartBeat hb = new HeartBeat();
-// hb.setVersionCode(AppUtil.getVersionCode(StartApplication.getAppContext()));
- Message message = new Message();
- message.setCmdId(Cmd.HB.id);
-// message.setDeviceId(DeviceIdUtil.generateDeviceId(mContext));
- return message;
- }
-
- /**
- * 心跳处理
- *
- * @param ctx
- * @param evt
- * @throws Exception
- */
- @Override
- public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
- if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
- IdleStateEvent event = (IdleStateEvent) evt;
- if (event.state() == IdleState.ALL_IDLE) {
- ctx.writeAndFlush(getHbMessage());
- }
- }
- }
-
-}
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientInitializer.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientInitializer.java
deleted file mode 100644
index 0f345b2..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientInitializer.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package test.netty.nio.net.client;
-
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-import io.netty.handler.timeout.IdleStateHandler;
-
-
-public class ClientInitializer extends ChannelInitializer {
-
- private final static int TIME_HEART_BEAT = 20;
-
- public ClientThread.ReConnectHandler reConnectHandler;
- public ClientHandler dmClientHandler;
-
- public ClientInitializer(ClientThread.ReConnectHandler handler) {
- reConnectHandler = handler;
- }
-
- public ClientInitializer(ClientThread.ReConnectHandler handler, ClientHandler dmClientHandler) {
- reConnectHandler = handler;
- this.dmClientHandler = dmClientHandler;
- }
-
-
- @Override
- protected void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- pipeline.addLast("reconnect", reConnectHandler);
- pipeline.addLast("idleStateHandler", new IdleStateHandler(TIME_HEART_BEAT, TIME_HEART_BEAT, TIME_HEART_BEAT));
- pipeline.addLast(new MessageEncoder());
- pipeline.addFirst(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 4, 4, 0, 0));
- pipeline.addLast(new MessageDecoder());
- pipeline.addLast(dmClientHandler);
- }
-
-}
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientThread.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientThread.java
deleted file mode 100644
index 483b6e3..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/ClientThread.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package test.netty.nio.net.client;
-
-import io.netty.bootstrap.Bootstrap;
-import io.netty.channel.*;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioSocketChannel;
-
-import java.net.InetSocketAddress;
-import java.util.concurrent.TimeUnit;
-
-
-/**
- * 客户端通讯
- *
- * @author peakren
- * @date 07/12/2017 10:12 PM
- */
-public class ClientThread extends Thread{
-
- private static ClientThread instance;
-
- private volatile EventLoopGroup workerGroup;
- private volatile Bootstrap bootstrap;
- private volatile boolean closed = false;
- private String remoteHost;
- private int remotePort;
-
- private ChannelFuture future;
-
-
- public static ClientThread getInstance() {
- if (instance == null) {
- synchronized (ClientThread.class) {
- if (instance == null) {
- instance = new ClientThread("127.0.0.1", 56791);
- }
- }
- }
- return instance;
- }
-
- private ClientThread(String remoteHost, int remotePort) {
- this.remoteHost = remoteHost;
- this.remotePort = remotePort;
- }
-
- public void run() {
-
- closed = false;
- workerGroup = new NioEventLoopGroup();
- bootstrap = new Bootstrap();
- bootstrap.group(workerGroup);
- bootstrap.channel(NioSocketChannel.class);
- bootstrap.option(ChannelOption.TCP_NODELAY, true);
- bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
-
- ReConnectHandler reConnectHandler = new ReConnectHandler();
- ClientHandler dmClientHandler = new ClientHandler();
- ClientInitializer channelInitializer = new ClientInitializer(reConnectHandler, dmClientHandler);
-
- bootstrap.handler(channelInitializer);
- doConnect();
- }
-
- public void clearFuture(){
- future = null;
- }
-
- public void doConnect() {
- System.out.println("现在开始链接了");
- if (closed) {
- return;
- }
- System.out.println("连接 = " + remoteHost + " " + remotePort);
- future = bootstrap.connect(new InetSocketAddress(remoteHost, remotePort));
- future.addListener(new ChannelFutureListener() {
- public void operationComplete(ChannelFuture f) throws Exception {
- f.channel().eventLoop().schedule(new Runnable() {
- @Override
- public void run() {
- if (!f.isSuccess()) {
- doConnect();
- System.out.println("等待连接");
- } else {
- System.out.println("已连接");
- }
- }
- }, 2, TimeUnit.SECONDS);
-
-
- }
- });
-
- }
-
- public void close() {
- closed = true;
- workerGroup.shutdownGracefully();
- }
-
- public void restart() {
- close();
- run();
- }
-
- @ChannelHandler.Sharable
- public class ReConnectHandler extends ChannelInboundHandlerAdapter {
-
-
- @Override
- public void channelInactive(ChannelHandlerContext ctx) throws Exception {
- super.channelInactive(ctx);
- System.out.println("inactive");
- ctx.channel().eventLoop().schedule(new Runnable() {
- @Override
- public void run() {
- doConnect();
- }
- }, 1, TimeUnit.SECONDS);
- }
- }
-
-
-}
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/Cmd.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/Cmd.java
deleted file mode 100644
index c4509f8..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/Cmd.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package test.netty.nio.net.client;
-
-/**
- * 消息协议指令定义
- *
- * @Author peakren
- * @Date 08/12/2017 11:51 AM
- */
-public enum Cmd {
-
-
- HB("hb", "心跳"),
-
- FACEID("faceid", "人脸识别"),
-
- FACEID_RESPONSE("faceid_response_upload", "识别结果"),
-
- RECEV_FACE_IMAGE("recev_face_image", "接收人脸照片"),
-
- RECEV_FACE_IMAGE_R("recev_face_image_r", "返回上传图片结果"),
-
- OPEN_DOOR("open_door", "开门禁");
-
-
- public String id;
-
- public String text;
-
- Cmd(String id, String text) {
- this.id = id;
- this.text = text;
-
- }
-
- public static Cmd getCmd(String id) {
- for (Cmd cmd : Cmd.values()) {
- if (cmd.id.equalsIgnoreCase(id)) {
- return cmd;
- }
- }
- return Cmd.HB;
- }
-
-}
-
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/CustomDecoder.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/CustomDecoder.java
deleted file mode 100644
index 5354b20..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/CustomDecoder.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package test.netty.nio.net.client;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
-
-import java.nio.ByteOrder;
-
-
-/**
- * 自定义解码器,解决粘包和分包问题
- *
- * @author peakren
- * @date 07/12/2017 10:03 PM
- */
-public class CustomDecoder extends LengthFieldBasedFrameDecoder {
-
- public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength) {
- super(maxFrameLength, lengthFieldOffset, lengthFieldLength);
- }
-
- public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip) {
- super(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip);
- }
-
- public CustomDecoder(int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
- super(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
- }
-
- public CustomDecoder(ByteOrder byteOrder, int maxFrameLength, int lengthFieldOffset, int lengthFieldLength, int lengthAdjustment, int initialBytesToStrip, boolean failFast) {
- super(byteOrder, maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip, failFast);
- }
-
-
- @Override
- protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
- return super.decode(ctx, in);
- }
-
-}
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/DataConfig.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/DataConfig.java
deleted file mode 100644
index 95c2880..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/DataConfig.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package test.netty.nio.net.client;
-
-/**
- * Created by hehelt on 16/2/26.
- */
-public class DataConfig {
-
- public static final int MAGIC_WORD = 0x9DDD;
- public static final int MAGIC_WORD_INDEX = 0;
- public static final int LENGTH_INDEX = 4;
- public static final int DATA_INDEX = 8;
-
-
-}
diff --git a/netty-pad/src/main/test/java/test/netty/nio/net/client/MessageDecoder.java b/netty-pad/src/main/test/java/test/netty/nio/net/client/MessageDecoder.java
deleted file mode 100644
index 331abf6..0000000
--- a/netty-pad/src/main/test/java/test/netty/nio/net/client/MessageDecoder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package test.netty.nio.net.client;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ByteToMessageDecoder;
-
-import java.io.UnsupportedEncodingException;
-import java.util.List;
-
-/**
- * Created by hehelt on 16/2/26.
- *
- * 解码器
- */
-public class MessageDecoder extends ByteToMessageDecoder {
-
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf in, List