| | |
| | | return new Response().set(1,pinfo); |
| | | } |
| | | //电池告警实时查询-websocket使用 |
| | | @Transactional |
| | | public Response serchByConditionOfWebSocket(AlarmPar par) { |
| | | //分页信息 |
| | | PageHelper.startPage(par.getPage().getPageCurr(), par.getPage().getPageSize()); |
| | |
| | | |
| | | |
| | | //项目下方的滚动,查询最新电池告警(电池告警和设备告警筛选出最新的五条) |
| | | @Transactional |
| | | public Response getRealAlarm(int uId){ |
| | | Calendar instance = Calendar.getInstance(); |
| | | instance.add(Calendar.DAY_OF_MONTH,-1); |
| | |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | @OnMessage |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.BattalarmDataService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | @ServerEndpoint(value = "/battAlarmFoot",encoders = WebSocketEncoder.class) |
| | | public class BattAlarmFootSocket { |
| | | private volatile Thread thread; |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static BattalarmDataService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(BattalarmDataService service){ |
| | | BattAlarmFootSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public synchronized void onMessage(Session session, String uId){ |
| | | thread = new Thread("Thread_battAlarmFoot") { |
| | | public void run() { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getRealAlarm(Integer.parseInt(uId))); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.BattdischargePlan; |
| | | import com.whyc.pojo.PwrdevAlarm; |
| | | import com.whyc.service.BattdischargePlanService; |
| | |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static BattdischargePlanService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(BattdischargePlanService service){ |
| | | BattDischargePlanSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | public synchronized void onMessage(Session session, String message){ |
| | | BattdischargePlan battdischargePlan = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(message, BattdischargePlan.class); |
| | | thread = new Thread("Thread_battDischargePlan") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.searchByConditionOfWebSocket(battdischargePlan)); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.searchByConditionOfWebSocket(battdischargePlan)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.BattScrapPar; |
| | | import com.whyc.service.BattScrapService; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static BattScrapService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(BattScrapService service){ |
| | | BattScrapSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | public synchronized void onMessage(Session session, String message){ |
| | | BattScrapPar battScrapPar = ActionUtil.getGson().fromJson(message, BattScrapPar.class); |
| | | thread = new Thread("Thread_battScrap") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.searchByCondition(battScrapPar.getPageNum(),battScrapPar.getPageSize(),battScrapPar.getBattScrap())); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.searchByCondition(battScrapPar.getPageNum(),battScrapPar.getPageSize(),battScrapPar.getBattScrap())); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | thread = new Thread("Thread_battSpare") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | //while (!thread.isInterrupted()&&!exit) { |
| | | while (!currentThread().isInterrupted()) { |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.searchByCondition(battSparePar.getPageNum(),battSparePar.getPageSize(),battSparePar.getBattSpare())); |
| | |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static DevalarmDataService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(DevalarmDataService service){ |
| | | DevAlarmDataSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | public synchronized void onMessage(Session session, String message){ |
| | | DevAlarmPar alarmPar = ActionUtil.getGson().fromJson(message, DevAlarmPar.class); |
| | | thread = new Thread("Thread_devAlarmData") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询已确认信息 |
| | | alarmPar.setAlmIsConfirmed(1); |
| | | Response confirmedAlarms=service.serchByInfoOfWebSocket(alarmPar); |
| | | res.put("confirmedAlarms",confirmedAlarms); |
| | | alarmPar.setAlmIsConfirmed(0); |
| | | Response unconfirmedAlarms=service.serchByInfoOfWebSocket(alarmPar); |
| | | res.put("unconfirmedAlarms",unconfirmedAlarms); |
| | | if (session.isOpen()) { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询已确认信息 |
| | | alarmPar.setAlmIsConfirmed(1); |
| | | Response confirmedAlarms=service.serchByInfoOfWebSocket(alarmPar); |
| | | res.put("confirmedAlarms",confirmedAlarms); |
| | | alarmPar.setAlmIsConfirmed(0); |
| | | Response unconfirmedAlarms=service.serchByInfoOfWebSocket(alarmPar); |
| | | res.put("unconfirmedAlarms",unconfirmedAlarms); |
| | | //推送信息 |
| | | session.getBasicRemote().sendObject(new Response().set(1,res)); |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.Fbs9100State; |
| | | import com.whyc.service.Fbs9100StateService; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | |
| | | private static final int executeTime = 15000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Fbs9100StateService service; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(Fbs9100StateService service) { |
| | | DeviceWorkStateSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session,String msg){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | public synchronized void onMessage(Session session,String msg){ |
| | | Fbs9100State stateParam = ActionUtil.getGson().fromJson(msg, Fbs9100State.class); |
| | | this.thread = new Thread("Thread_DeviceWorkState") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.getList(stateParam.getDevId().intValue(),stateParam.getDevWorkstate(),Long.parseLong(stateParam.getNote()))); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getList(stateParam.getDevId().intValue(),stateParam.getDevWorkstate(),Long.parseLong(stateParam.getNote()))); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | this.thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | |
| | | private static final int executeTime = 15000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static Fbs9100StateService fbs9100StateService; |
| | | |
| | |
| | | public void setService(Fbs9100StateService fbs9100StateService) { |
| | | FbsStateSocket.fbs9100StateService = fbs9100StateService; |
| | | } |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setService(Fbs9600StateService fbs9600StateService) { |
| | | FbsStateSocket.fbs9600StateService = fbs9600StateService; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit=true; |
| | | } |
| | | public synchronized void onMessage(Session session, String message){ |
| | | FbsStatePar fbsStatePar= ActionUtil.getGson().fromJson(message,FbsStatePar.class); |
| | | thread = new Thread("Thread_FbsState") { |
| | | public void run() { |
| | | exit=false; |
| | | while ( !this.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询fbs9100信息 |
| | | Response f9100stateRes=fbs9100StateService.searchByCondition(fbsStatePar.getPageNum(),fbsStatePar.getPageSize(),fbsStatePar.getDevErrcommcount(),fbsStatePar.getUserId()); |
| | | res.put("f9100state",f9100stateRes); |
| | | |
| | | Response f9600StateRes=fbs9600StateService.searchByCondition(fbsStatePar.getPageNum(),fbsStatePar.getPageSize(),fbsStatePar.getDevErrcommcount(),fbsStatePar.getUserId()); |
| | | res.put("f9600state",f9600StateRes); |
| | | |
| | | if (session.isOpen()) { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询fbs9100信息 |
| | | Response f9100stateRes=fbs9100StateService.searchByCondition(fbsStatePar.getPageNum(),fbsStatePar.getPageSize(),fbsStatePar.getDevErrcommcount(),fbsStatePar.getUserId()); |
| | | res.put("f9100state",f9100stateRes); |
| | | |
| | | Response f9600StateRes=fbs9600StateService.searchByCondition(fbsStatePar.getPageNum(),fbsStatePar.getPageSize(),fbsStatePar.getDevErrcommcount(),fbsStatePar.getUserId()); |
| | | res.put("f9600state",f9600StateRes); |
| | | |
| | | //推送信息 |
| | | session.getBasicRemote().sendObject(new Response().set(1,res)); |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch ( IOException | InterruptedException | EncodeException e ) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.BattSparePar; |
| | | import com.whyc.service.BattSpareService; |
| | | import com.whyc.service.HomePageService; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | @ServerEndpoint(value = "/homePageSocket",encoders = WebSocketEncoder.class) |
| | | public class HomePageSocket { |
| | | private volatile Thread thread; |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static HomePageService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(HomePageService service){ |
| | | HomePageSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String uId){ |
| | | thread = new Thread("Thread_homePage") { |
| | | public void run() { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getDataMap(Integer.parseInt(uId))); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) { |
| | | error.printStackTrace(); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | } |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.DevAlarmPar; |
| | | import com.whyc.pojo.PwrdevAlarm; |
| | | import com.whyc.service.DevalarmDataService; |
| | |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static PwrdevAlarmService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(PwrdevAlarmService service){ |
| | | PowerAlarmRealTimeSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | PwrdevAlarm pwrdevAlarm = ActionUtil.getGson().fromJson(message, PwrdevAlarm.class); |
| | | thread = new Thread("Thread_powerAlarmRt") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.getAllPageOfWebSocket(pwrdevAlarm)); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getAllPageOfWebSocket(pwrdevAlarm)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.PwrdevAcdcdataService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static PwrdevAcdcdataService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(PwrdevAcdcdataService service) { |
| | | PowerRTSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String deviceId){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | } |
| | | thread = new Thread("Thread_PowerRT") { |
| | | public void run() { |
| | | while (!thread.isInterrupted()) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.getPowerInfoById2(Integer.parseInt(deviceId))); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getPowerInfoById2(Integer.parseInt(deviceId))); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.ProcessSurveyService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static ProcessSurveyService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(ProcessSurveyService service){ |
| | | ProcessSurveySocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session,String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | } |
| | | public synchronized void onMessage(Session session,String message){ |
| | | thread = new Thread("Thread_processSurvey") { |
| | | public void run() { |
| | | while (!thread.isInterrupted()) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.getAll()); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getAll()); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.PwrdevAlarm; |
| | | import com.whyc.service.PwrdevAlarmService; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | |
| | | private static final int executeTime = 5000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static PwrdevAlarmService service; |
| | | |
| | | private Session session; |
| | | |
| | | @Autowired |
| | | public void setService(PwrdevAlarmService service){ |
| | | PwrAlarmSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit = true; |
| | | } |
| | | public synchronized void onMessage(Session session, String message){ |
| | | PwrdevAlarm pwrdevAlarm = ActionUtil.getGson().fromJson(message, PwrdevAlarm.class); |
| | | thread = new Thread("Thread_pwrAlarm") { |
| | | public void run() { |
| | | exit=false; |
| | | while (!thread.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | session.getBasicRemote().sendObject(service.getAllPage2OfWebSocket(pwrdevAlarm)); |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(service.getAllPage2OfWebSocket(pwrdevAlarm)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch (IOException | InterruptedException | EncodeException e) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | |
| | | private static final int executeTime = 15000; |
| | | |
| | | private static boolean exit=false; |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static PwrdevTimeAdjAlarmService adjAlarmService; |
| | | |
| | |
| | | PwrAlarmTimeoutSocket.timeOutAlarmService = timeOutAlarmService; |
| | | } |
| | | |
| | | @OnMessage |
| | | public void onMessage(Session session, String uId){ |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | } |
| | | |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit=true; |
| | | } |
| | | @OnMessage |
| | | public synchronized void onMessage(Session session, String uId){ |
| | | thread = new Thread("Thread_powerAlarmTimeout") { |
| | | public void run() { |
| | | exit=false; |
| | | while ( !this.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询fbs9100信息 |
| | | Response adjAlarmRes=adjAlarmService.getListOfWebSocket(Integer.parseInt(uId)); |
| | | res.put("adjAlarmService",adjAlarmRes); |
| | | |
| | | Response timeOutAlarmRes=timeOutAlarmService.getListOfWebSocket(Integer.parseInt(uId)); |
| | | res.put("timeOutAlarmService",timeOutAlarmRes); |
| | | if (session.isOpen()) { |
| | | Map<String, Response> res=new HashMap<>(); |
| | | //查询fbs9100信息 |
| | | Response adjAlarmRes=adjAlarmService.getListOfWebSocket(Integer.parseInt(uId)); |
| | | res.put("adjAlarmService",adjAlarmRes); |
| | | |
| | | Response timeOutAlarmRes=timeOutAlarmService.getListOfWebSocket(Integer.parseInt(uId)); |
| | | res.put("timeOutAlarmService",timeOutAlarmRes); |
| | | |
| | | //推送信息 |
| | | session.getBasicRemote().sendObject(new Response().set(1,res)); |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | sleep(executeTime); |
| | | } catch ( IOException | InterruptedException | EncodeException e ) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | |
| | | |
| | | private static Map<String,Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static BattRtstateService rtstateservice; //组端 |
| | | |
| | | private static Fbs9100StateService f9100service; //fbs9100 |
| | |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message){ |
| | | //停止当前socket的线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | threadBefore.interrupt(); |
| | | exit=true; |
| | | } |
| | | RealTimePar realTimePar= ActionUtil.getGson().fromJson(message,RealTimePar.class); |
| | | realTimePar.setDevType(realTimePar.getDevId()/100000); |
| | | thread = new Thread("Thread_RealTime") { |
| | | public void run() { |
| | | exit=false; |
| | | while ( !this.isInterrupted()&&!exit) { |
| | | while (true) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | try { |
| | | if (session.isOpen()) { |
| | | Response res=new Response(); |
| | | switch (realTimePar.getPageType()){ |
| | | case "standard": res=getStandard(realTimePar);break; |
| | | case "a059": res=getA059(realTimePar);break; |
| | | case "enestorage": res=getEnestorage(realTimePar);break; |
| | | case "btssreen": res=getBtssreen(realTimePar);break; |
| | | case "power": res=getPower(realTimePar);break; |
| | | case "isolating": res=getIsolating(realTimePar);break; |
| | | case "charger": res=getCharger(realTimePar);break; |
| | | case "power1": res=getPower1(realTimePar);break; |
| | | case "totalInfo": res=getTotalInfo(realTimePar);break; |
| | | } |
| | | //推送信息 |
| | | session.getBasicRemote().sendObject(res); |
| | | Response res=new Response(); |
| | | switch (realTimePar.getPageType()){ |
| | | case "standard": res=getStandard(realTimePar);break; |
| | | case "a059": res=getA059(realTimePar);break; |
| | | case "enestorage": res=getEnestorage(realTimePar);break; |
| | | case "btssreen": res=getBtssreen(realTimePar);break; |
| | | case "power": res=getPower(realTimePar);break; |
| | | case "isolating": res=getIsolating(realTimePar);break; |
| | | case "charger": res=getCharger(realTimePar);break; |
| | | case "power1": res=getPower1(realTimePar);break; |
| | | case "totalInfo": res=getTotalInfo(realTimePar);break; |
| | | } |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | } |
| | | threadFlagMap.put(thread.getId(),false); |
| | | } |
| | | //if (session.isOpen()) { |
| | | // Response res=new Response(); |
| | | // switch (realTimePar.getPageType()){ |
| | | // case "standard": res=getStandard(realTimePar);break; |
| | | // case "a059": res=getA059(realTimePar);break; |
| | | // case "enestorage": res=getEnestorage(realTimePar);break; |
| | | // case "btssreen": res=getBtssreen(realTimePar);break; |
| | | // case "power": res=getPower(realTimePar);break; |
| | | // case "isolating": res=getIsolating(realTimePar);break; |
| | | // case "charger": res=getCharger(realTimePar);break; |
| | | // case "power1": res=getPower1(realTimePar);break; |
| | | // case "totalInfo": res=getTotalInfo(realTimePar);break; |
| | | // } |
| | | // //推送信息 |
| | | // session.getBasicRemote().sendObject(res); |
| | | //} |
| | | sleep(executeTime); |
| | | } catch ( IOException | InterruptedException | EncodeException e ) { |
| | | //} catch (IOException | InterruptedException | EncodeException e) { |
| | | } catch (Exception e) { |
| | | interrupt(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | //停止老的socket线程 |
| | | Thread threadBefore = threadMap.get(session.getId()); |
| | | if(threadBefore !=null && threadBefore.isAlive()){ |
| | | while (threadFlagMap.get(threadBefore.getId())){ |
| | | } |
| | | threadBefore.interrupt(); |
| | | } |
| | | //将线程存储,便于调用定位 |
| | | threadMap.put(session.getId(), this.thread); |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(){ |
| | | public void onClose(CloseReason closeReason){ |
| | | System.err.println("closeReason = " + closeReason); |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | |
| | | @OnError |
| | |
| | | if (thread != null && thread.isAlive()) { |
| | | thread.interrupt(); |
| | | } |
| | | threadMap.remove(session.getId()); |
| | | } |
| | | //标准的实时页面信息 |
| | | public Response getStandard(RealTimePar realTimePar){ |