Commit 9a1af32a by yangll

屏蔽掉暂时没有使用的类

1 parent 2ba8f6f2
package cn.com.glsx; package cn.com.glsx;
import cn.com.glsx.notify.netty.NettyServer;
import com.glsx.plat.context.EnableRestAdmin; import com.glsx.plat.context.EnableRestAdmin;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -31,8 +30,8 @@ public class Application { ...@@ -31,8 +30,8 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
//启动NettyServer服务端 //启动NettyServer服务端
NettyServer nettyServer = new NettyServer(); // NettyServer nettyServer = new NettyServer();
nettyServer.run(); // nettyServer.run();
} }
@PostConstruct @PostConstruct
......
/*
package cn.com.glsx.notify.modules.controller; package cn.com.glsx.notify.modules.controller;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
...@@ -30,9 +31,11 @@ public class WebSocketServer { ...@@ -30,9 +31,11 @@ public class WebSocketServer {
// concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。 // concurrent包的线程安全Set,用来存放每个客户端对应的Session对象。
private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<>(); private static CopyOnWriteArraySet<Session> SessionSet = new CopyOnWriteArraySet<>();
/** */
/**
* 连接建立成功调用的方法 * 连接建立成功调用的方法
*/ *//*
@OnOpen @OnOpen
public void onOpen(Session session) { public void onOpen(Session session) {
SessionSet.add(session); SessionSet.add(session);
...@@ -47,9 +50,11 @@ public class WebSocketServer { ...@@ -47,9 +50,11 @@ public class WebSocketServer {
SendMessage(session, "连接成功"); SendMessage(session, "连接成功");
} }
/** */
/**
* 连接关闭调用的方法 * 连接关闭调用的方法
*/ *//*
@OnClose @OnClose
public void onClose(Session session) { public void onClose(Session session) {
SessionSet.remove(session); SessionSet.remove(session);
...@@ -59,35 +64,41 @@ public class WebSocketServer { ...@@ -59,35 +64,41 @@ public class WebSocketServer {
log.info("有连接关闭,当前连接数为:{}", cnt); log.info("有连接关闭,当前连接数为:{}", cnt);
} }
/** */
/**
* 收到客户端消息后调用的方法 * 收到客户端消息后调用的方法
* *
* @param message 客户端发送过来的消息 * @param message 客户端发送过来的消息
*/ *//*
@OnMessage @OnMessage
public void onMessage(String message, Session session) { public void onMessage(String message, Session session) {
log.info("来自客户端的消息:{}", message); log.info("来自客户端的消息:{}", message);
SendMessage(session, "收到消息,消息内容:" + message); SendMessage(session, "收到消息,消息内容:" + message);
} }
/** */
/**
* 出现错误 * 出现错误
* *
* @param session * @param session
* @param error * @param error
*/ *//*
@OnError @OnError
public void onError(Session session, Throwable error) { public void onError(Session session, Throwable error) {
log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId()); log.error("发生错误:{},Session ID: {}", error.getMessage(), session.getId());
error.printStackTrace(); error.printStackTrace();
} }
/** */
/**
* 发送消息,实践表明,每次浏览器刷新,session会发生变化。 * 发送消息,实践表明,每次浏览器刷新,session会发生变化。
* *
* @param session * @param session
* @param message * @param message
*/ *//*
public static void SendMessage(Session session, String message) { public static void SendMessage(Session session, String message) {
try { try {
session.getBasicRemote().sendText(message); session.getBasicRemote().sendText(message);
...@@ -97,12 +108,14 @@ public class WebSocketServer { ...@@ -97,12 +108,14 @@ public class WebSocketServer {
} }
} }
/** */
/**
* 群发消息 * 群发消息
* *
* @param message * @param message
* @throws IOException * @throws IOException
*/ *//*
public static void BroadCastInfo(String message) throws IOException { public static void BroadCastInfo(String message) throws IOException {
for (Session session : SessionSet) { for (Session session : SessionSet) {
if (session.isOpen()) { if (session.isOpen()) {
...@@ -111,13 +124,15 @@ public class WebSocketServer { ...@@ -111,13 +124,15 @@ public class WebSocketServer {
} }
} }
/** */
/**
* 指定Session发送消息 * 指定Session发送消息
* *
* @param sessionId * @param sessionId
* @param message * @param message
* @throws IOException * @throws IOException
*/ *//*
public static void SendMessage(String message, String sessionId) throws IOException { public static void SendMessage(String message, String sessionId) throws IOException {
Session session = null; Session session = null;
for (Session s : SessionSet) { for (Session s : SessionSet) {
...@@ -137,3 +152,4 @@ public class WebSocketServer { ...@@ -137,3 +152,4 @@ public class WebSocketServer {
this.session.getBasicRemote().sendText(message); this.session.getBasicRemote().sendText(message);
} }
} }
*/
/*
package cn.com.glsx.notify.modules.kafka; package cn.com.glsx.notify.modules.kafka;
import cn.com.glsx.notify.modules.controller.WebSocketServer; import cn.com.glsx.notify.modules.controller.WebSocketServer;
...@@ -11,9 +12,11 @@ import java.util.Optional; ...@@ -11,9 +12,11 @@ import java.util.Optional;
import static cn.com.glsx.notify.modules.controller.WebSocketServer.SocketSet; import static cn.com.glsx.notify.modules.controller.WebSocketServer.SocketSet;
*/
/** /**
* @author payu * @author payu
*/ *//*
@Slf4j @Slf4j
@Component @Component
public class MessageConsumer { public class MessageConsumer {
...@@ -42,3 +45,4 @@ public class MessageConsumer { ...@@ -42,3 +45,4 @@ public class MessageConsumer {
} }
} }
*/
...@@ -73,7 +73,9 @@ public class MailService { ...@@ -73,7 +73,9 @@ public class MailService {
*/ */
public void sendAttachmentsMail(String to, String subject, String template, List<Map<String, String>> filepaths, Object... arg) throws Exception { public void sendAttachmentsMail(String to, String subject, String template, List<Map<String, String>> filepaths, Object... arg) throws Exception {
MessageTemplate mt = messageTemplateMapper.findByTemplate(template); MessageTemplate mt = messageTemplateMapper.findByTemplate(template);
if (mt == null) return; if (mt == null) {
return;
}
String content = MessageFormat.format(mt.getContent(), arg); String content = MessageFormat.format(mt.getContent(), arg);
mailUtils.sendAttachmentMail(to, subject, content, filepaths); mailUtils.sendAttachmentMail(to, subject, content, filepaths);
......
...@@ -27,7 +27,9 @@ public class SmsService { ...@@ -27,7 +27,9 @@ public class SmsService {
public void sendSms(String phone, String template, Object... arg) { public void sendSms(String phone, String template, Object... arg) {
MessageTemplate mt = messageTemplateMapper.findByTemplate(template); MessageTemplate mt = messageTemplateMapper.findByTemplate(template);
if (mt == null) return; if (mt == null) {
return;
}
String content = MessageFormat.format(mt.getContent(), arg); String content = MessageFormat.format(mt.getContent(), arg);
smsUtils.send(phone, content); smsUtils.send(phone, content);
......
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
...@@ -17,4 +18,4 @@ public class MyByteEncoder extends MessageToByteEncoder<byte[]> { ...@@ -17,4 +18,4 @@ public class MyByteEncoder extends MessageToByteEncoder<byte[]> {
//字节数组 //字节数组
out.writeBytes(bytes); out.writeBytes(bytes);
} }
}
\ No newline at end of file \ No newline at end of file
}*/
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import cn.com.glsx.notify.modules.controller.WebSocketServer; import cn.com.glsx.notify.modules.controller.WebSocketServer;
...@@ -11,21 +12,25 @@ public class NettyDataSvervice { ...@@ -11,21 +12,25 @@ public class NettyDataSvervice {
private static final ReentrantLock Lock = new ReentrantLock(); private static final ReentrantLock Lock = new ReentrantLock();
/** */
/**
* 将传送过来的数据进行解析,包括异或运算 (第一次服务器端给客户端发) * 将传送过来的数据进行解析,包括异或运算 (第一次服务器端给客户端发)
* *
* @param receiveData * @param receiveData
* @return * @return
*/ *//*
public static String sendData(String receiveData) { public static String sendData(String receiveData) {
final ReentrantLock putLock = Lock; final ReentrantLock putLock = Lock;
log.info("接收数据" + receiveData); log.info("接收数据" + receiveData);
putLock.lock(); putLock.lock();
try { try {
//此处需要读数据进行校验以及分包黏包处理,本文主要提供思路所以省略 //此处需要读数据进行校验以及分包黏包处理,本文主要提供思路所以省略
/* */
/*
* 处理分包黏包、拆分、解析等 * 处理分包黏包、拆分、解析等
*/ *//*
//数据解析 //数据解析
parseData(receiveData); parseData(receiveData);
try { try {
...@@ -40,10 +45,13 @@ public class NettyDataSvervice { ...@@ -40,10 +45,13 @@ public class NettyDataSvervice {
} }
} }
/** */
/**
* 数据入库处理 * 数据入库处理
*/ *//*
public static void parseData(String receiveData) { public static void parseData(String receiveData) {
System.out.println("执行入库操作"); System.out.println("执行入库操作");
} }
} }
*/
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import io.netty.channel.Channel; import io.netty.channel.Channel;
...@@ -28,4 +29,4 @@ public class NettyInitializer extends ChannelInitializer { ...@@ -28,4 +29,4 @@ public class NettyInitializer extends ChannelInitializer {
channel.pipeline().addLast(new MyByteEncoder()); channel.pipeline().addLast(new MyByteEncoder());
channel.pipeline().addLast(new NettyServerHandler()); channel.pipeline().addLast(new NettyServerHandler());
} }
}
\ No newline at end of file \ No newline at end of file
}*/
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import cn.com.glsx.notify.netty.utils.NettyByteAndStringUtils; import cn.com.glsx.notify.netty.utils.NettyByteAndStringUtils;
...@@ -32,3 +33,4 @@ public class NettySendThread implements Runnable { ...@@ -32,3 +33,4 @@ public class NettySendThread implements Runnable {
ctx.writeAndFlush(sendData); ctx.writeAndFlush(sendData);
} }
} }
*/
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
...@@ -71,4 +72,4 @@ public class NettyServer { ...@@ -71,4 +72,4 @@ public class NettyServer {
workerGroup.shutdownGracefully(); workerGroup.shutdownGracefully();
} }
} }
}
\ No newline at end of file \ No newline at end of file
}*/
/*
package cn.com.glsx.notify.netty; package cn.com.glsx.notify.netty;
import cn.com.glsx.notify.netty.utils.NettyByteAndStringUtils; import cn.com.glsx.notify.netty.utils.NettyByteAndStringUtils;
...@@ -25,9 +26,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -25,9 +26,11 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
private static Lock lock_4 = new ReentrantLock(); private static Lock lock_4 = new ReentrantLock();
/** */
/**
* 管理一个全局map,保存连接进服务端的通道数量 * 管理一个全局map,保存连接进服务端的通道数量
*/ *//*
private static final ConcurrentHashMap<ChannelId, ChannelHandlerContext> CHANNEL_MAP = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<ChannelId, ChannelHandlerContext> CHANNEL_MAP = new ConcurrentHashMap<>();
@Override //数据读取完毕 @Override //数据读取完毕
...@@ -38,13 +41,15 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -38,13 +41,15 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
//ctx.writeAndFlush(Unpooled.copiedBuffer("hello, 客户端~(>^ω^<)喵1", CharsetUtil.UTF_8)); //ctx.writeAndFlush(Unpooled.copiedBuffer("hello, 客户端~(>^ω^<)喵1", CharsetUtil.UTF_8));
} }
/** */
/**
* 处理异常, 一般是需要关闭通道 * 处理异常, 一般是需要关闭通道
* *
* @param ctx * @param ctx
* @param cause * @param cause
* @throws Exception * @throws Exception
*/ *//*
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.close(); ctx.close();
...@@ -52,11 +57,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -52,11 +57,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
} }
/** */
/**
* @param ctx * @param ctx
* @DESCRIPTION: 有客户端连接服务器会触发此函数 * @DESCRIPTION: 有客户端连接服务器会触发此函数
* @return: void * @return: void
*/ *//*
@Override @Override
public void channelActive(ChannelHandlerContext ctx) throws Exception { public void channelActive(ChannelHandlerContext ctx) throws Exception {
lock_1.lock(); lock_1.lock();
...@@ -78,11 +85,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -78,11 +85,13 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
} }
} }
/** */
/**
* @param ctx * @param ctx
* @DESCRIPTION: 有客户端终止连接服务器会触发此函数 * @DESCRIPTION: 有客户端终止连接服务器会触发此函数
* @return: void * @return: void
*/ *//*
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { public void channelInactive(ChannelHandlerContext ctx) throws Exception {
lock_2.lock(); lock_2.lock();
...@@ -102,12 +111,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -102,12 +111,14 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
} }
/** */
/**
* 1. ChannelHandlerContext ctx:上下文对象, 含有 管道pipeline , 通道channel, 地址 * 1. ChannelHandlerContext ctx:上下文对象, 含有 管道pipeline , 通道channel, 地址
* 2. Object msg: 就是客户端发送的数据 默认Object * 2. Object msg: 就是客户端发送的数据 默认Object
* <p> * <p>
* 读取数据实际(这里我们可以读取客户端发送的消息) * 读取数据实际(这里我们可以读取客户端发送的消息)
*/ *//*
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
lock_3.lock(); lock_3.lock();
...@@ -155,4 +166,4 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { ...@@ -155,4 +166,4 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
lock_4.unlock(); lock_4.unlock();
} }
} }
}
\ No newline at end of file \ No newline at end of file
}*/
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!