增加netty版本
This commit is contained in:
47
netty-client/pom.xml
Normal file
47
netty-client/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<parent>
|
||||
<groupId>smartvenue</groupId>
|
||||
<artifactId>smartvenue-parent</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>netty-client</artifactId>
|
||||
<version>${smartvenue.version}</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.1.10.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<configuration>
|
||||
<outputDirectory>../target/boot/netty</outputDirectory>
|
||||
<classifier>executable</classifier>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
92
netty-client/src/main/java/com/sv/netty/ClientHandler.java
Normal file
92
netty-client/src/main/java/com/sv/netty/ClientHandler.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package com.sv.netty;
|
||||
|
||||
import com.sv.netty.message.HeartBeat;
|
||||
import com.sv.netty.message.MessageType;
|
||||
import com.sv.netty.message.VenueMessage;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 通讯服务器请求处理
|
||||
*
|
||||
* @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);
|
||||
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);
|
||||
System.err.println("错了Error");
|
||||
System.err.println("Error");
|
||||
// GlobalConfig.isConnected = false;
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取心跳返回消息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private VenueMessage getHbMessage() {
|
||||
HeartBeat hb = new HeartBeat();
|
||||
// hb.setVersionCode(AppUtil.getVersionCode(StartApplication.getAppContext()));
|
||||
VenueMessage message = new VenueMessage();
|
||||
message.setMessageType(MessageType.HB);
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.sv.netty;
|
||||
|
||||
import com.sv.netty.config.Constant;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
|
||||
|
||||
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
||||
|
||||
private final static int TIME_HEART_BEAT = 20;
|
||||
|
||||
public ClientThread.ReConnectHandler reConnectHandler;
|
||||
public ClientHandler dmClientHandler;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
121
netty-client/src/main/java/com/sv/netty/ClientThread.java
Normal file
121
netty-client/src/main/java/com/sv/netty/ClientThread.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package com.sv.netty;
|
||||
|
||||
import com.sv.netty.config.Constant;
|
||||
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", 56792);
|
||||
}
|
||||
}
|
||||
}
|
||||
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(ctx.toString() + "======inactive");
|
||||
ctx.channel().eventLoop().schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doConnect();
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
48
netty-client/src/main/java/com/sv/netty/MessageDecoder.java
Normal file
48
netty-client/src/main/java/com/sv/netty/MessageDecoder.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.sv.netty;
|
||||
|
||||
import com.sv.netty.config.Constant;
|
||||
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.
|
||||
* <p/>
|
||||
* 解码器
|
||||
*/
|
||||
public class MessageDecoder extends ByteToMessageDecoder {
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (in.capacity() >= Constant.LENGTH_INDEX) {
|
||||
int magicWord = in.readInt();
|
||||
if (magicWord == Constant.MAGIC_WORD) {
|
||||
int length = in.readInt();
|
||||
byte[] msg = new byte[length];
|
||||
in.readBytes(msg);
|
||||
String message = new String(msg, "utf-8");
|
||||
out.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析从服务器接受的消息
|
||||
*
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
private String getMessage(ByteBuf buf) {
|
||||
byte[] con = new byte[buf.readableBytes()];
|
||||
buf.readBytes(con);
|
||||
try {
|
||||
return new String(con, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
netty-client/src/main/java/com/sv/netty/MessageEncoder.java
Normal file
24
netty-client/src/main/java/com/sv/netty/MessageEncoder.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.sv.netty;
|
||||
|
||||
import com.sv.netty.config.Constant;
|
||||
import com.sv.netty.message.VenueMessage;
|
||||
import com.sv.utils.JsonMapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
/**
|
||||
* 自定义编码器, 1个字节固定头+4个字节长度+内容
|
||||
*/
|
||||
public class MessageEncoder extends MessageToByteEncoder<VenueMessage> {
|
||||
|
||||
private String charset = "utf-8";
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, VenueMessage message, ByteBuf out) throws Exception {
|
||||
out.writeInt(Constant.MAGIC_WORD);
|
||||
String msg = JsonMapper.toJson(message);
|
||||
out.writeInt(msg.getBytes(charset).length);
|
||||
out.writeBytes(msg.getBytes(charset));
|
||||
}
|
||||
}
|
||||
15
netty-client/src/main/java/com/sv/netty/config/Constant.java
Normal file
15
netty-client/src/main/java/com/sv/netty/config/Constant.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.sv.netty.config;
|
||||
|
||||
public interface Constant {
|
||||
|
||||
String DELIMITER_WORD = "$_$";
|
||||
|
||||
int MAGIC_WORD = 0x9DDD;
|
||||
int LENGTH_INDEX = 4;
|
||||
|
||||
String SERVER_IP = "120.27.209.4";
|
||||
Integer SERVER_PORT = 56791;
|
||||
Integer VENUE_ID = 39;
|
||||
String DEVICE_NAME = "SN2020382013";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sv.netty.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 客户端心跳数据包
|
||||
* HeartBeat.java
|
||||
*
|
||||
* @author peakren
|
||||
* @date 07/12/2017 10:23 PM
|
||||
*/
|
||||
public class HeartBeat implements Serializable {
|
||||
|
||||
private Integer venueId; //场馆号
|
||||
|
||||
private String deviceName; //设备号
|
||||
|
||||
public Integer getVenueId() {
|
||||
return venueId;
|
||||
}
|
||||
|
||||
public void setVenueId(Integer venueId) {
|
||||
this.venueId = venueId;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sv.netty.message;
|
||||
|
||||
public enum MessageType {
|
||||
HB("连接"),
|
||||
OPEN_DOOR("开门");
|
||||
|
||||
private String message;
|
||||
|
||||
MessageType(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.sv.netty.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class VenueMessage implements Serializable {
|
||||
|
||||
private MessageType messageType;
|
||||
private String message;
|
||||
|
||||
public MessageType getMessageType() {
|
||||
return messageType;
|
||||
}
|
||||
|
||||
public void setMessageType(MessageType messageType) {
|
||||
this.messageType = messageType;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
18
netty-client/src/main/java/com/sv/service/ClientService.java
Normal file
18
netty-client/src/main/java/com/sv/service/ClientService.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.sv.service;
|
||||
|
||||
import com.sv.netty.ClientThread;
|
||||
|
||||
/**
|
||||
* 启动socker和websocket服务
|
||||
*
|
||||
* @author peakren
|
||||
* @date 05/12/2017 10:25 PM
|
||||
*/
|
||||
public class ClientService {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ClientThread instance = ClientThread.getInstance();
|
||||
instance.start();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.sv.service;
|
||||
|
||||
import com.sv.netty.message.VenueMessage;
|
||||
|
||||
/**
|
||||
* 消息服务
|
||||
* MessageService.java
|
||||
*
|
||||
* @author peakren
|
||||
* @date 2018/12/20 6:00 PM
|
||||
*/
|
||||
public class MessageService {
|
||||
|
||||
static private MessageService sInstance;
|
||||
|
||||
static public MessageService getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (MessageService.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MessageService();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
/**
|
||||
* 解析并执行接受服务器消息
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void execute(VenueMessage message) {
|
||||
switch (message.getMessageType()) {
|
||||
case OPEN_DOOR:
|
||||
openDoor();
|
||||
break;
|
||||
default:
|
||||
System.out.println( "default");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 门禁开门
|
||||
*/
|
||||
public void openDoor() {
|
||||
// 开门
|
||||
System.out.println("开门成功!!!");
|
||||
}
|
||||
|
||||
}
|
||||
204
netty-client/src/main/java/com/sv/utils/JsonMapper.java
Normal file
204
netty-client/src/main/java/com/sv/utils/JsonMapper.java
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Copyright (c) 2005-2012 springside.org.cn
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
*/
|
||||
package com.sv.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.
|
||||
* <p>
|
||||
* 封装不同的输出风格, 使用不同的builder函数创建实例.
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
public class JsonMapper {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(JsonMapper.class);
|
||||
|
||||
private static 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 static 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<String>.
|
||||
* <p>
|
||||
* 如果JSON字符串为Null或"null"字符串, 返回Null. 如果JSON字符串为"[]", 返回空集合.
|
||||
* <p>
|
||||
* 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String, JavaType)
|
||||
*
|
||||
* @see #fromJson(String, JavaType)
|
||||
*/
|
||||
public static <T> T fromJson(String jsonString, Class<T> 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<Bean>,
|
||||
* 先使用createCollectionType()或contructMapType()构造类型, 然后调用本函数.
|
||||
*
|
||||
* @see #createCollectionType(Class, Class...)
|
||||
*/
|
||||
public <T> 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> T convertMapToBean(Map<String, ?> map, Class<T> 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> T convertBeanToOther(Object bean, Class<T> 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;
|
||||
}
|
||||
|
||||
}
|
||||
15
netty-client/src/main/resources/config/application-dev.yml
Normal file
15
netty-client/src/main/resources/config/application-dev.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
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/
|
||||
15
netty-client/src/main/resources/config/application-prod.yml
Normal file
15
netty-client/src/main/resources/config/application-prod.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
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
|
||||
|
||||
jpa:
|
||||
show-sql: true
|
||||
|
||||
sv:
|
||||
file:
|
||||
store:
|
||||
image: image/
|
||||
video: video/
|
||||
health: health-docs/
|
||||
111
netty-client/src/main/resources/config/application.yml
Normal file
111
netty-client/src/main/resources/config/application.yml
Normal file
@@ -0,0 +1,111 @@
|
||||
server:
|
||||
port: 8023
|
||||
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
|
||||
48
netty-client/src/main/resources/logback.xml
Normal file
48
netty-client/src/main/resources/logback.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF8"?>
|
||||
<configuration>
|
||||
<jmxConfigurator />
|
||||
<property name="LOG_HOME" value="./home/logs/netty_log"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="COMMON-DEFAULT"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_HOME}/common-default.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_HOME}/common-default-%d{yyyy-MM-dd}.log
|
||||
</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="COMMON-ERROR"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${LOG_HOME}/common-error.log</file>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${LOG_HOME}/common-error-%d{yyyy-MM-dd}.log
|
||||
</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- root -->
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="COMMON-DEFAULT" />
|
||||
<appender-ref ref="COMMON-ERROR" />
|
||||
</root>
|
||||
</configuration>
|
||||
41
netty-client/src/main/resources/mybatis/mybatis-config.xml
Normal file
41
netty-client/src/main/resources/mybatis/mybatis-config.xml
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration
|
||||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
|
||||
|
||||
<configuration>
|
||||
<settings>
|
||||
<setting name="cacheEnabled" value="true" />
|
||||
<!-- 打印sql日志 -->
|
||||
<setting name="logImpl" value="SLF4J" />
|
||||
</settings>
|
||||
<!--<settings>-->
|
||||
<!--<setting name="cacheEnabled" value="true"/>-->
|
||||
<!--<setting name="lazyLoadingEnabled" value="true"/>-->
|
||||
<!--<setting name="multipleResultSetsEnabled" value="true"/>-->
|
||||
<!--<setting name="useColumnLabel" value="true"/>-->
|
||||
<!--<setting name="useGeneratedKeys" value="false"/>-->
|
||||
<!--<setting name="autoMappingBehavior" value="PARTIAL"/>-->
|
||||
<!--<setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>-->
|
||||
<!--<setting name="defaultExecutorType" value="SIMPLE"/>-->
|
||||
<!--<setting name="defaultStatementTimeout" value="25"/>-->
|
||||
<!--<setting name="defaultFetchSize" value="100"/>-->
|
||||
<!--<setting name="safeRowBoundsEnabled" value="false"/>-->
|
||||
<!--<setting name="mapUnderscoreToCamelCase" value="false"/>-->
|
||||
<!--<setting name="localCacheScope" value="SESSION"/>-->
|
||||
<!--<setting name="jdbcTypeForNull" value="OTHER"/>-->
|
||||
<!--<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>-->
|
||||
<!--</settings>-->
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Integer" type="java.lang.Integer" />
|
||||
<typeAlias alias="Byte" type="java.lang.Byte"/>
|
||||
<typeAlias alias="String" type="java.lang.String" />
|
||||
<typeAlias alias="Long" type="java.lang.Long" />
|
||||
<typeAlias alias="HashMap" type="java.util.HashMap" />
|
||||
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap" />
|
||||
<typeAlias alias="ArrayList" type="java.util.ArrayList" />
|
||||
<typeAlias alias="LinkedList" type="java.util.LinkedList" />
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,13 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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<SocketChannel> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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.
|
||||
* <p/>
|
||||
* 解码器
|
||||
*/
|
||||
public class MessageDecoder extends ByteToMessageDecoder {
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
if (in.capacity() >= DataConfig.LENGTH_INDEX) {
|
||||
int magicWord = in.readInt();
|
||||
if (magicWord == DataConfig.MAGIC_WORD) {
|
||||
int length = in.readInt();
|
||||
byte[] msg = new byte[length];
|
||||
in.readBytes(msg);
|
||||
String message = new String(msg, "utf-8");
|
||||
out.add(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析从服务器接受的消息
|
||||
*
|
||||
* @param buf
|
||||
* @return
|
||||
*/
|
||||
private String getMessage(ByteBuf buf) {
|
||||
|
||||
byte[] con = new byte[buf.readableBytes()];
|
||||
buf.readBytes(con);
|
||||
try {
|
||||
return new String(con, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package test.netty.nio.net.client;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import test.netty.nio.net.dto.JsonMapper;
|
||||
import test.netty.nio.net.dto.Message;
|
||||
|
||||
/**
|
||||
* 自定义编码器, 1个字节固定头+4个字节长度+内容
|
||||
*/
|
||||
public class MessageEncoder extends MessageToByteEncoder<Message> {
|
||||
|
||||
private String charset = "utf-8";
|
||||
private final static String TAG = "MessageEncoder";
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, Message message, ByteBuf out) throws Exception {
|
||||
out.writeInt(DataConfig.MAGIC_WORD);
|
||||
String msg = JsonMapper.toJson(message);
|
||||
out.writeInt(msg.getBytes(charset).length);
|
||||
out.writeBytes(msg.getBytes(charset));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
public class AddFaceResponse {
|
||||
|
||||
/**
|
||||
* code : 0
|
||||
* data : {"company_id":1,"id":4,"origin_url":"/static/upload/origin/2018-08-09/v2_1ea4b7847d1ea56b773aec99441af52dcbf9ca7d.jpg","quality":0.992649,"subject_id":null,"url":"/static/upload/photo/2018-08-09/v2_fa9dcfd045ff5232aa446f5645cbb031eef7ac74.jpg","version":7}
|
||||
* page : {}
|
||||
*/
|
||||
|
||||
@Expose
|
||||
private int code;
|
||||
|
||||
@Expose
|
||||
private DataBean data;
|
||||
|
||||
@Expose
|
||||
private PageBean page;
|
||||
|
||||
@Expose
|
||||
private String desc;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public DataBean getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(DataBean data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public PageBean getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(PageBean page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public static class DataBean {
|
||||
/**
|
||||
* company_id : 1
|
||||
* id : 4
|
||||
* origin_url : /static/upload/origin/2018-08-09/v2_1ea4b7847d1ea56b773aec99441af52dcbf9ca7d.jpg
|
||||
* quality : 0.992649
|
||||
* subject_id : null
|
||||
* url : /static/upload/photo/2018-08-09/v2_fa9dcfd045ff5232aa446f5645cbb031eef7ac74.jpg
|
||||
* version : 7
|
||||
*/
|
||||
|
||||
@Expose
|
||||
private int company_id;
|
||||
@Expose
|
||||
private int id;
|
||||
@Expose
|
||||
private String origin_url;
|
||||
@Expose
|
||||
private double quality;
|
||||
@Expose
|
||||
private Object subject_id;
|
||||
@Expose
|
||||
private String url;
|
||||
@Expose
|
||||
private int version;
|
||||
|
||||
public int getCompany_id() {
|
||||
return company_id;
|
||||
}
|
||||
|
||||
public void setCompany_id(int company_id) {
|
||||
this.company_id = company_id;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getOrigin_url() {
|
||||
return origin_url;
|
||||
}
|
||||
|
||||
public void setOrigin_url(String origin_url) {
|
||||
this.origin_url = origin_url;
|
||||
}
|
||||
|
||||
public double getQuality() {
|
||||
return quality;
|
||||
}
|
||||
|
||||
public void setQuality(double quality) {
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
public Object getSubject_id() {
|
||||
return subject_id;
|
||||
}
|
||||
|
||||
public void setSubject_id(Object subject_id) {
|
||||
this.subject_id = subject_id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PageBean {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by peakren on 19/01/2018.
|
||||
*/
|
||||
|
||||
public class BaseDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3139438146199448677L;
|
||||
|
||||
@Expose
|
||||
private String cmdId; //指令
|
||||
|
||||
@Expose
|
||||
private String deviceId; //设备ID
|
||||
|
||||
/**
|
||||
* 客户端IP
|
||||
*/
|
||||
@Expose
|
||||
private String clientIp;
|
||||
|
||||
/**
|
||||
* 状态码 0正常 1错误
|
||||
*/
|
||||
@Expose
|
||||
private int errorCode = 0;
|
||||
|
||||
/**
|
||||
* 错误返回信息
|
||||
*/
|
||||
@Expose
|
||||
private String errorMsg;
|
||||
|
||||
|
||||
public String getCmdId() {
|
||||
return cmdId;
|
||||
}
|
||||
|
||||
public void setCmdId(String cmdId) {
|
||||
this.cmdId = cmdId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户端IP,获取的内网IP
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getClientIp() {
|
||||
return clientIp;
|
||||
}
|
||||
|
||||
public void setClientIp(String clientIp) {
|
||||
this.clientIp = clientIp;
|
||||
}
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(int errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* 会员基本信息
|
||||
* MemberDto.java
|
||||
*
|
||||
* @author peakren
|
||||
* @date 2018/12/20 8:39 PM
|
||||
*/
|
||||
public class FaceImageDto implements Serializable {
|
||||
|
||||
|
||||
@Expose
|
||||
private Integer faceId;
|
||||
|
||||
@Expose
|
||||
private Integer memberId;
|
||||
|
||||
|
||||
@Expose
|
||||
private String faceImage;
|
||||
|
||||
|
||||
public Integer getFaceId() {
|
||||
return faceId;
|
||||
}
|
||||
|
||||
public void setFaceId(Integer faceId) {
|
||||
this.faceId = faceId;
|
||||
}
|
||||
|
||||
public Integer getMemberId() {
|
||||
return memberId;
|
||||
}
|
||||
|
||||
public void setMemberId(Integer memberId) {
|
||||
this.memberId = memberId;
|
||||
}
|
||||
|
||||
public String getFaceImage() {
|
||||
return faceImage;
|
||||
}
|
||||
|
||||
public void setFaceImage(String faceImage) {
|
||||
this.faceImage = faceImage;
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,44 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 客户端心跳数据包
|
||||
* HeartBeat.java
|
||||
*
|
||||
* @author peakren
|
||||
* @date 07/12/2017 10:23 PM
|
||||
*/
|
||||
public class HeartBeat implements Serializable {
|
||||
|
||||
@Expose
|
||||
private String versionCode; //客户端版本号
|
||||
|
||||
@Expose
|
||||
private String apkUrl; //升级的软件下载地址
|
||||
|
||||
|
||||
public String getVersionCode() {
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户端版本号
|
||||
*
|
||||
* @param versionCode
|
||||
*/
|
||||
public void setVersionCode(String versionCode) {
|
||||
this.versionCode = versionCode;
|
||||
}
|
||||
|
||||
public String getApkUrl() {
|
||||
return apkUrl;
|
||||
}
|
||||
|
||||
public void setApkUrl(String apkUrl) {
|
||||
this.apkUrl = apkUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ranfi on 12/9/14.
|
||||
*/
|
||||
public class JsonMapper {
|
||||
|
||||
private final static Gson gson;
|
||||
|
||||
static {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
builder.excludeFieldsWithoutExposeAnnotation();
|
||||
gson = builder.create();
|
||||
}
|
||||
|
||||
private JsonMapper() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Object可以是POJO,也可以是Collection或数组。 如果对象为Null, 返回"null". 如果集合为空集合, 返回"[]".
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static String toJson(Object obj) {
|
||||
return gson.toJson(obj);
|
||||
}
|
||||
|
||||
|
||||
public static String toJson(Object obj, Type type) {
|
||||
return gson.toJson(obj, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 反序列化POJO或简单Collection如List<String>.
|
||||
* <p/>
|
||||
* 如果JSON字符串为Null或"null"字符串, 返回Null. 如果JSON字符串为"[]", 返回空集合.
|
||||
* <p/>
|
||||
* 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String, JavaType)
|
||||
*/
|
||||
public static <T> T fromJson(String jsonValue, Class<T> clazz) {
|
||||
return gson.fromJson(jsonValue, clazz);
|
||||
}
|
||||
|
||||
public static <T> T fromJson(String jsonValue, Type type) {
|
||||
return gson.fromJson(jsonValue, type);
|
||||
}
|
||||
|
||||
public static <T> List<T> fromJson(String jsonValue) {
|
||||
return gson.fromJson(jsonValue, new TypeToken<List<T>>() {
|
||||
}.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
/**
|
||||
* 会员基本信息
|
||||
* MemberDto.java
|
||||
*
|
||||
* @author peakren
|
||||
* @date 2018/12/20 8:39 PM
|
||||
*/
|
||||
public class MemberDto implements Serializable {
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Expose
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
@Expose
|
||||
private String mobile;
|
||||
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
@Expose
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 场地名称
|
||||
*/
|
||||
@Expose
|
||||
private String placeName;
|
||||
|
||||
/**
|
||||
* 会员卡名称
|
||||
*/
|
||||
@Expose
|
||||
private String cardName;
|
||||
|
||||
@Expose
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 1成功进场 0不允许进场
|
||||
*/
|
||||
@Expose
|
||||
private int code;
|
||||
|
||||
@Expose
|
||||
private BigDecimal placePrice;
|
||||
|
||||
@Expose
|
||||
private boolean first;
|
||||
|
||||
public BigDecimal getPlacePrice() {
|
||||
return placePrice;
|
||||
}
|
||||
|
||||
public void setPlacePrice(BigDecimal placePrice) {
|
||||
this.placePrice = placePrice;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return first;
|
||||
}
|
||||
|
||||
public void setFirst(boolean first) {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getPlaceName() {
|
||||
return placeName;
|
||||
}
|
||||
|
||||
public void setPlaceName(String placeName) {
|
||||
this.placeName = placeName;
|
||||
}
|
||||
|
||||
public String getCardName() {
|
||||
return cardName;
|
||||
}
|
||||
|
||||
public void setCardName(String cardName) {
|
||||
this.cardName = cardName;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package test.netty.nio.net.dto;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
/**
|
||||
* <pre>上位机与通讯服务器的数据协议格式</pre>
|
||||
*
|
||||
* @author peakren
|
||||
* @date 07/12/2017 9:57 PM
|
||||
*/
|
||||
public class Message extends BaseDto {
|
||||
|
||||
private static final long serialVersionUID = -7944124768291562453L;
|
||||
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
@Expose
|
||||
private MemberDto result;
|
||||
|
||||
|
||||
@Expose
|
||||
private FaceImageDto faceImage;
|
||||
|
||||
/**
|
||||
* 机器识别返回字符串
|
||||
*/
|
||||
@Expose
|
||||
private String content;
|
||||
|
||||
|
||||
public int getDoor() {
|
||||
return door;
|
||||
}
|
||||
|
||||
public void setDoor(int door) {
|
||||
this.door = door;
|
||||
}
|
||||
|
||||
@Expose
|
||||
private int door;
|
||||
|
||||
|
||||
public MemberDto getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(MemberDto result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public FaceImageDto getFaceImage() {
|
||||
return faceImage;
|
||||
}
|
||||
|
||||
public void setFaceImage(FaceImageDto faceImage) {
|
||||
this.faceImage = faceImage;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user