netty-删除无用的device-socket module
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
package com.sv.netty.netty;
|
||||
|
||||
import com.sv.netty.utils.JsonMapper;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.timeout.IdleState;
|
||||
import io.netty.handler.timeout.IdleStateEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 客户端处理器
|
||||
*
|
||||
* @author ranfi
|
||||
*/
|
||||
public class ClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ClientHandler.class);
|
||||
|
||||
/**
|
||||
* 当通道就绪就会触发
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当通道失效就会触发
|
||||
* @param ctx
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelInactive(ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当通道有读取事件时触发
|
||||
* @param ctx
|
||||
* @param msg
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
super.channelRead(ctx, msg);
|
||||
logger.info("接收服务器响应msg:[" + msg + "]");
|
||||
// 安卓写,非netty 后台实现
|
||||
// TODO 安卓获取心跳内容(有二维码的唯一识别)显示请求小程序的venueId的二维码,无需拼接url
|
||||
// TODO 安卓获取通知加载页面
|
||||
// TODO 安卓获取通知开门失败消息 (进入一个页面,然后显示倒计时,回到主页(二维码页面))
|
||||
// TODO 安卓获取通知开门的消息 (无需校验,直接操作开门)
|
||||
// Message message = JsonMapper.fromJson(msg, Message.class);
|
||||
// MessageService.getInstance().execute(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
if (event.state() == IdleState.ALL_IDLE) {
|
||||
ctx.writeAndFlush("getHbMessage()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
|
||||
throws Exception {
|
||||
super.exceptionCaught(ctx, cause);
|
||||
logger.error("ClientHandler exceptionCaught",cause);
|
||||
Channel channel = ctx.channel();
|
||||
if(channel.isActive()) {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,18 @@ import java.nio.charset.Charset;
|
||||
* @Author peakren
|
||||
* @Date 07/05/2017 10:43 PM
|
||||
*/
|
||||
public class MessageEncoder extends MessageToByteEncoder<String> {
|
||||
public class MessageEncoder extends MessageToByteEncoder {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(MessageEncoder.class);
|
||||
|
||||
Charset charset = Charset.forName("UTF-8");
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception {
|
||||
// String message = JsonUtils.encode(msg);
|
||||
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
|
||||
String message = JsonUtils.encode(msg);
|
||||
logger.info("send message content:" + msg);
|
||||
msg = msg + Constant.DELIMITER_WORD;
|
||||
byte[] content = msg.getBytes(charset.name());
|
||||
message = message + Constant.DELIMITER_WORD;
|
||||
byte[] content = message.getBytes(charset.name());
|
||||
out.writeBytes(content); //发送消息内容
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,9 @@ public class ServerHandler extends SimpleChannelInboundHandler<String> {
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
||||
super.channelRead(ctx, msg);
|
||||
String clientIp = ctx.channel().attr(Constant.CHANNEL_PARAM).get().getClientIp();
|
||||
try {
|
||||
messageService.receive(ctx.channel(), msg);
|
||||
messageService.receive(clientIp,ctx.channel(), msg);
|
||||
} catch (Exception e) {
|
||||
logger.error("[" + clientIp + "] host unknown error");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public interface MessageService {
|
||||
* @param channel
|
||||
* @param content
|
||||
*/
|
||||
void receive(Channel channel, String content);
|
||||
void receive(String clientId, Channel channel, String content);
|
||||
|
||||
void online(Channel channel);
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ public class TcpMessageHandlerAdapter implements MessageService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(TcpMessageHandlerAdapter.class);
|
||||
|
||||
|
||||
@Value("${nettym.url}")
|
||||
private String url;
|
||||
//
|
||||
// @Value("${nettym.url}")
|
||||
// private String url;
|
||||
|
||||
@Resource
|
||||
private MemberService memberService;
|
||||
@@ -106,11 +106,11 @@ public class TcpMessageHandlerAdapter implements MessageService {
|
||||
* @param content 消息内容
|
||||
*/
|
||||
@Override
|
||||
public void receive(Channel channel, String content) {
|
||||
public void receive(String clientId, Channel channel, String content) {
|
||||
try {
|
||||
//解析数据
|
||||
Cmd cmd = resolveCmd(content);
|
||||
logger.info("收到消息" + cmd.text);
|
||||
logger.info("收到[" + clientId + "]消息" + cmd.text);
|
||||
switch (cmd) {
|
||||
case HB:
|
||||
break;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user