|
|
@ -1,6 +1,5 @@ |
|
|
|
package a8k.app.controler.api.v1.app.ws; |
|
|
|
|
|
|
|
import a8k.SpringBootBeanUtil; |
|
|
|
import a8k.app.service.engineer.state.EngineerModeStateMgrService; |
|
|
|
import a8k.app.type.AppGetStateFn; |
|
|
|
import a8k.app.type.DeviceRunMode; |
|
|
@ -47,13 +46,6 @@ public class AppWebSocketEndpointMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static public class DeviceContext { |
|
|
|
public DeviceRunMode runMode = DeviceRunMode.RealMode; |
|
|
|
public Boolean loginFlag = false; |
|
|
|
public AppUser loginUser = null; |
|
|
|
public Boolean deviceInitedFlag = false; |
|
|
|
public Boolean fatalErrorFlag = false; |
|
|
|
} |
|
|
|
|
|
|
|
private final AppUserMgrService appUserMgrService; |
|
|
|
private final AppDeviceInitCtrlService appDeviceInitCtrlService; |
|
|
@ -72,9 +64,9 @@ public class AppWebSocketEndpointMgr { |
|
|
|
final private AppEventBusService eventBus; |
|
|
|
|
|
|
|
|
|
|
|
List<Session> stateWebsocketSessions = new ArrayList<>(); |
|
|
|
List<Session> eventWebsocketSessions = new ArrayList<>(); |
|
|
|
Map<String, Integer> stateVersionCache = new HashMap<>(); |
|
|
|
List<Session> stateWebsocketSessions = new ArrayList<>(); |
|
|
|
List<Session> eventWebsocketSessions = new ArrayList<>(); |
|
|
|
Map<String, Object> stateVersionCache = new HashMap<>(); |
|
|
|
final Object sessionLock = new Object(); |
|
|
|
|
|
|
|
AtomicInteger forceUpdateCnt = new AtomicInteger(0); |
|
|
@ -125,12 +117,16 @@ public class AppWebSocketEndpointMgr { |
|
|
|
broadcastState(message); |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public void reportState(String type, Integer version, boolean force, AppGetStateFn getStateFn) { |
|
|
|
synchronized public void reportState(String type, Object version, boolean force, AppGetStateFn getStateFn) { |
|
|
|
reportState(type, type, version, force, getStateFn); |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public void reportState(String typeKey, String reportName, Integer version, boolean force, AppGetStateFn getStateFn) { |
|
|
|
Integer lastVersion = stateVersionCache.get(typeKey); |
|
|
|
synchronized public void reportState(String type, boolean force, AppGetStateFn getStateFn) { |
|
|
|
reportState(type, type, getStateFn.getState(), force, getStateFn); |
|
|
|
} |
|
|
|
|
|
|
|
synchronized public void reportState(String typeKey, String reportName, Object version, boolean force, AppGetStateFn getStateFn) { |
|
|
|
Object lastVersion = stateVersionCache.get(typeKey); |
|
|
|
if (force || lastVersion == null || !lastVersion.equals(version)) { |
|
|
|
stateVersionCache.put(typeKey, version); |
|
|
|
reportState(reportName, getStateFn.getState()); |
|
|
@ -170,17 +166,8 @@ public class AppWebSocketEndpointMgr { |
|
|
|
|
|
|
|
@Scheduled(fixedDelay = 900) |
|
|
|
public void reportDeviceState() { |
|
|
|
reportState("GDeviceState", gStateMgrService.getGState()); |
|
|
|
reportState("IncubationPlateState", incubationPlateStateMgr.get()); |
|
|
|
reportState("SensorState", gStateMgrService.getSensorState()); |
|
|
|
|
|
|
|
DeviceContext deviceContext = new DeviceContext(); |
|
|
|
deviceContext.runMode = gStateMgrService.getDeviceRunMode(); |
|
|
|
deviceContext.loginFlag = appUserMgrService.getLoginUsr() != null; |
|
|
|
deviceContext.loginUser = appUserMgrService.getLoginUsr(); |
|
|
|
deviceContext.deviceInitedFlag = appDeviceInitCtrlService.getState().deviceInited; |
|
|
|
deviceContext.fatalErrorFlag = deviceWorkStateMgrService.getDeviceWorkState().fatalErrorFlag; |
|
|
|
reportState("DeviceContext", deviceContext); |
|
|
|
} |
|
|
|
|
|
|
|
@Scheduled(fixedDelay = 50) |
|
|
@ -189,6 +176,10 @@ public class AppWebSocketEndpointMgr { |
|
|
|
} |
|
|
|
|
|
|
|
public void quickReportStateSchedule(boolean force) { |
|
|
|
|
|
|
|
reportState("EmergencyKeyState", force, this::getEmergencyKeyState); |
|
|
|
reportState("DeviceContext", force, this::getDeviceContext); |
|
|
|
|
|
|
|
reportState("ConsumablesState", consumablesMgrService.getStateVersion(), force, consumablesMgrService::getState); |
|
|
|
reportState("EngineerModeState", engineerModeStateMgrService.getVersion(), force, engineerModeStateMgrService::getState); |
|
|
|
reportState("DeviceWorkState", deviceWorkStateMgrService.getVersion(), force, deviceWorkStateMgrService::getDeviceWorkState); |
|
|
@ -235,6 +226,56 @@ public class AppWebSocketEndpointMgr { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static class EmergencyKeyState { |
|
|
|
public Boolean emergencyKeyTrigger = false; |
|
|
|
|
|
|
|
@Override public boolean equals(Object other) { |
|
|
|
if (other instanceof EmergencyKeyState that) { |
|
|
|
return emergencyKeyTrigger.equals(that.emergencyKeyTrigger); |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private EmergencyKeyState getEmergencyKeyState() { |
|
|
|
EmergencyKeyState state = new EmergencyKeyState(); |
|
|
|
state.emergencyKeyTrigger = gStateMgrService.getGState().getEmergencyKeyTriggered(); |
|
|
|
return state; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static public class DeviceContext { |
|
|
|
public DeviceRunMode runMode = DeviceRunMode.RealMode; |
|
|
|
public Boolean loginFlag = false; |
|
|
|
public AppUser loginUser = null; |
|
|
|
public Boolean deviceInitedFlag = false; |
|
|
|
public Boolean fatalErrorFlag = false; |
|
|
|
|
|
|
|
@Override public boolean equals(Object other) { |
|
|
|
if (other instanceof DeviceContext that) { |
|
|
|
return runMode.equals(that.runMode) && |
|
|
|
loginFlag.equals(that.loginFlag) && |
|
|
|
Objects.equals(loginUser, that.loginUser) && |
|
|
|
deviceInitedFlag.equals(that.deviceInitedFlag) && |
|
|
|
fatalErrorFlag.equals(that.fatalErrorFlag); |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private DeviceContext getDeviceContext() { |
|
|
|
DeviceContext deviceContext = new DeviceContext(); |
|
|
|
deviceContext.runMode = gStateMgrService.getDeviceRunMode(); |
|
|
|
deviceContext.loginFlag = appUserMgrService.getLoginUsr() != null; |
|
|
|
deviceContext.loginUser = appUserMgrService.getLoginUsr(); |
|
|
|
deviceContext.deviceInitedFlag = appDeviceInitCtrlService.getState().deviceInited; |
|
|
|
deviceContext.fatalErrorFlag = deviceWorkStateMgrService.getDeviceWorkState().fatalErrorFlag; |
|
|
|
return deviceContext; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
Map<String, Integer> map = new HashMap<>(); |
|
|
|
} |
|
|
|