123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package com.its.pis.entity;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.its.app.utils.SysUtils;
- import com.its.pis.domain.NET;
- import com.its.pis.ui.MainUI;
- import com.its.pis.websocket.C2F.message.C2FMessage;
- import com.its.pis.websocket.C2F.message.C2FMessageData;
- import com.its.pis.websocket.C2F.message.C2FMessageRequest;
- import com.its.pis.websocket.C2F.message.PrkPlceRlTimeResponseInfo;
- import com.its.pis.websocket.PisWebSocketSession;
- import io.netty.channel.Channel;
- import lombok.Getter;
- import lombok.Setter;
- import lombok.ToString;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.socket.TextMessage;
- import java.io.IOException;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Map;
- @Slf4j
- @Getter
- @Setter
- @ToString
- public class TbPisInfr {
- private int index;
- private String PIS_NMBR;
- private String PIS_NM;
- private String PIS_TP;
- private String PIS_IP;
- private int PIS_PORT;
- private String PIS_END_POINT;
- private String PIS_ID;
- private String PIS_TOKEN;
- private int PIS_CYCLE;
- private String DEL_YN;
- private Map<String, TbPrltCtlr> rltnPrltMap;
- private int netState;
- private boolean isDupCon;
- private boolean isDupLogin;
- private TbPisInfrStts stts;
- private PisWebSocketSession session;
- private Channel dupChannel;
- private long syncTime;
- private C2FMessage<PrkPlceRlTimeResponseInfo> rlTimeInfo;
- private int connectCount;
- private String connectTm;
- private String disConnectTm;
- private boolean dump = false;
- public Integer getId() {
- return Integer.parseInt(this.PIS_NMBR);
- }
- public TbPisInfr() {
- this.rltnPrltMap = Collections.synchronizedMap(new HashMap<String, TbPrltCtlr>());
- this.stts = new TbPisInfrStts();
- this.connectCount = 0;
- this.connectTm = "";
- this.disConnectTm = "";
- initNet();
- }
- public String getLogKey() {
- return this.PIS_END_POINT;
- }
- public void resetConnectCount() {
- if (this.netState == NET.CLOSED)
- this.connectCount = 0;
- else
- this.connectCount = 1;
- }
- public void setConnectTm() {
- this.connectTm = SysUtils.getSysTimeStrMMDD();
- this.connectCount++;
- getStts().setCONN_DT(SysUtils.getSysTime());
- }
- public void setDisConnectTm() {
- this.disConnectTm = SysUtils.getSysTimeStrMMDD();
- }
- void initNet() {
- this.netState = NET.CLOSED;
- this.isDupCon = false;
- this.isDupLogin = false;
- this.session = null;
- this.dupChannel = null;
- this.syncTime = 0;
- }
- public synchronized void channelOpen(PisWebSocketSession session) {
- this.netState = NET.LOGIN_REQ;
- this.session = session;
- getStts().initStts(true);
- setConnectTm();
- MainUI mainUI = MainUI.getInstance();
- if (mainUI != null) {
- mainUI.updateCtlrStts(this);
- }
- }
- public synchronized void channelLogin(PisWebSocketSession session) {
- this.netState = NET.LOGINED;
- this.session = session;
- getStts().initStts(true);
- setConnectTm();
- MainUI mainUI = MainUI.getInstance();
- if (mainUI != null) {
- mainUI.updateCtlrStts(this);
- }
- }
- public synchronized void channelClosed() {
- if (this.netState != NET.CLOSED) {
- setDisConnectTm();
- }
- getStts().setDIS_CONN_DT(SysUtils.getSysTime());
- this.netState = NET.CLOSED;
- this.session = null;
- getStts().initStts(false);
- MainUI mainUI = MainUI.getInstance();
- if (mainUI != null) {
- mainUI.updateCtlrStts(this);
- }
- }
- public boolean channelClose() {
- if (getSession() == null || getNetState() == NET.CLOSED) {
- log.error("Close Request: channel not connected: [{}]", this);
- return false;
- }
- try {
- getSession().getSession().close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- MainUI mainUI = MainUI.getInstance();
- if (mainUI != null) {
- mainUI.updateCtlrStts(this);
- }
- return true;
- }
- public boolean requestRlTimeInfo() {
- if (getSession() == null || getNetState() == NET.CLOSED) {
- log.error("Reset Request: channel not connected: [{}]", this);
- return false;
- }
- C2FMessageRequest request = C2FMessageRequest.builder()
- .prk_tkn(this.PIS_TOKEN)
- .event_name("prk_plce_rl_time_request_info")
- .event_type("request")
- .build();
- C2FMessage<Object> message = C2FMessage.builder()
- .command("message")
- .data(C2FMessageData.builder()
- .payload(request)
- .build())
- .build();
- ObjectMapper mapper = new ObjectMapper();
- try {
- String strMessage = mapper.writeValueAsString(message);
- log.error("{}", strMessage);
- TextMessage txtMessage = new TextMessage(strMessage);
- getSession().sendMessage(request.getEvent_name(), txtMessage);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- return true;
- }
- }
|