|
@@ -6,12 +6,16 @@ import com.ydl.iec.iec104.core.ControlManageUtil;
|
|
|
import com.ydl.iec.iec104.core.Iec104ThreadLocal;
|
|
|
import com.ydl.iec.iec104.core.ScheduledTaskPool;
|
|
|
import com.ydl.iec.iec104.message.MessageDetail;
|
|
|
+import com.ydl.iec.iec104.server.Iec104MasterFactory;
|
|
|
import com.ydl.iec.iec104.server.handler.ChannelHandlerImpl;
|
|
|
import com.ydl.iec.iec104.server.handler.DataHandler;
|
|
|
+import com.ydl.iec.util.Iec104Util;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
+import io.netty.channel.EventLoop;
|
|
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDetail> {
|
|
|
|
|
@@ -23,7 +27,7 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDeta
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
+ public void channelActive(ChannelHandlerContext ctx) {
|
|
|
// 启动成功后一直发启动链路命令
|
|
|
Iec104ThreadLocal.setScheduledTaskPool(new ScheduledTaskPool(ctx));
|
|
|
Iec104ThreadLocal.getScheduledTaskPool().sendStatrFrame();
|
|
@@ -31,14 +35,11 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDeta
|
|
|
Iec104ThreadLocal.getControlPool().startSendFrameTask();
|
|
|
|
|
|
if (dataHandler != null) {
|
|
|
- CachedThreadPool.getCachedThreadPool().execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ CachedThreadPool.getCachedThreadPool().execute(() -> {
|
|
|
+ try {
|
|
|
+ dataHandler.handlerAdded(new ChannelHandlerImpl(ctx));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -47,19 +48,25 @@ public class Iec104ClientHandler extends SimpleChannelInboundHandler<MessageDeta
|
|
|
@Override
|
|
|
public void channelRead0(ChannelHandlerContext ctx, MessageDetail ruleDetail104) throws IOException {
|
|
|
if (dataHandler != null) {
|
|
|
- CachedThreadPool.getCachedThreadPool().execute(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try {
|
|
|
- dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
|
|
|
- } catch (Exception e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
+ CachedThreadPool.getCachedThreadPool().execute(() -> {
|
|
|
+ try {
|
|
|
+ dataHandler.channelRead(new ChannelHandlerImpl(ctx), ruleDetail104);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ @Override
|
|
|
+ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
|
|
+ System.err.println("掉线了...");
|
|
|
+ //使用过程中断线重连
|
|
|
+ final EventLoop eventLoop = ctx.channel().eventLoop();
|
|
|
+ eventLoop.schedule((Runnable) () -> {
|
|
|
+ Iec104MasterFactory.createTcpClientMaster(Iec104Util.host, Iec104Util.port).run();
|
|
|
+ }, 5L, TimeUnit.SECONDS);
|
|
|
+ super.channelInactive(ctx);
|
|
|
+ }
|
|
|
}
|