| src/main/java/com/zy/core/thread/ShuttleThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/core/thread/impl/NyShuttleThread.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/core/thread/ShuttleThread.java
@@ -1,7 +1,10 @@ package com.zy.core.thread; import com.zy.core.ThreadHandler; import com.zy.core.model.DeviceCommandMsgModel; import com.zy.core.properties.DeviceConfig; import java.net.Socket; public interface ShuttleThread extends ThreadHandler { @@ -9,4 +12,6 @@ void stopThread(); Socket getSocket(); } src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -95,7 +95,13 @@ } // log.info("acceptorThread is end:{}", sb.toString()); JSONObject result = JSON.parseObject(sb.toString()); JSONObject result = null; try { result = JSON.parseObject(sb.toString()); }catch (Exception e) { log.error("error body:{}", sb.toString()); e.printStackTrace(); } if(result == null){ continue; } @@ -178,6 +184,19 @@ continue; } NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo()); if (shuttleThread == null) { // init NyShuttleThread thread = new NyShuttleThread(device, redisUtil);; new Thread(thread).start(); SlaveConnection.put(SlaveType.Shuttle, device.getDeviceNo(), thread); }else { Socket socket = shuttleThread.getSocket(); if(socket == null){ continue; } } log.info("{}:device is run,devices:{}", device.getDeviceNo(),JSON.toJSONString(fakeServerMap)); Thread fakeThread = new Thread(() -> { @@ -195,10 +214,9 @@ fakeThread.start(); fakeThreadMap.put(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), fakeThread); // init ThreadHandler thread = new NyShuttleThread(device, redisUtil);; new Thread(thread).start(); SlaveConnection.put(SlaveType.Shuttle, device.getDeviceNo(), thread); try { Thread.sleep(2000); }catch (Exception e){} } } src/main/java/com/zy/core/thread/impl/NyShuttleThread.java
@@ -108,10 +108,20 @@ writer.flush(); // System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand)); }catch (SocketException e) { this.socket = null; e.printStackTrace(); closeSocket(); } catch (IOException e) { e.printStackTrace(); } } private void closeSocket() { try { this.socket.close(); } catch (Exception e1) { }finally { this.socket = null; } } @@ -200,6 +210,7 @@ } } catch (Exception e) { // e.printStackTrace(); closeSocket(); } } @@ -336,4 +347,8 @@ this.stopThread = true; } @Override public Socket getSocket() { return this.socket; } }