com.envision.energy.eos.sdk.ProxyManager Maven / Gradle / Ivy
package com.envision.energy.eos.sdk;
import com.envision.energy.connective.common.protobuf.generated.Common.KVPairRecord;
import com.envision.energy.connective.protobuf.generated.Sdk;
import com.envision.energy.connective.protobuf.generated.Sdk.AlertStrReq;
import com.envision.energy.connective.protobuf.generated.Sdk.PointDetail;
public enum ProxyManager {
INSTANCE;
private ProxyManager() {
}
private Transport transport = null;
private AlarmProcessProxy alarmProxy = null;
private DataProcessProxy dataProxy = null;
private EventProcessProxy eventProxy = null;
private AssetProcessProxy assetProxy = null;
public void setTransport(Transport transport) {
this.transport = transport;
if(alarmProxy != null) {
alarmProxy.setTransport(transport);
}
if(dataProxy != null) {
dataProxy.setTransport(transport);
}
if(eventProxy != null){
eventProxy.setTransport(transport);
}
if(assetProxy != null ){
assetProxy.setTransport(transport);
}
}
public void setToken(String token) {
transport.setToken(token);
}
public String getToken() {
return transport.getToken();
}
public DataProcessProxy getDataProxy() {
if(dataProxy == null) {
dataProxy = new DataProcessProxy();
dataProxy.setTransport(transport);
}
return dataProxy;
}
public AlarmProcessProxy getAlarmProxy() {
if(alarmProxy == null) {
alarmProxy = new AlarmProcessProxy();
alarmProxy.setTransport(transport);
}
return alarmProxy;
}
public EventProcessProxy getEventProxy() {
if(eventProxy == null) {
eventProxy = new EventProcessProxy();
eventProxy.setTransport(transport);
}
return eventProxy;
}
public AssetProcessProxy getAssetProxy(){
if (assetProxy == null) {
assetProxy = new AssetProcessProxy();
assetProxy.setTransport(transport);
}
return assetProxy;
}
public boolean transportIsOpen() {
return transport != null;
}
public void closeTransport() {
transport.close();
transport = null;
}
public void subscribe() {
if(transport == null) {
return;
}
transport.started();
if(alarmProxy != null) {
alarmProxy.sendSubMsg();
}
if(dataProxy != null) {
dataProxy.sendSubMsg();
}
if(eventProxy != null) {
eventProxy.sendSubMsg();
}
if(assetProxy !=null ){
assetProxy.sendSubMsg();
}
}
public void msgToAlarmProxy(AlertStrReq msg) {
if(alarmProxy == null) {
return;
}
alarmProxy.msgToHandler(msg);
}
public void msgToEventProxy(Sdk.EventStrReq msg){
if(eventProxy == null){
return;
}
eventProxy.msgToHandler(msg);
}
public void msgToEventV2Proxy(Sdk.EventV2StrReq msg){
if(eventProxy == null){
return;
}
eventProxy.msgV2ToHandler(msg);
}
public void msgToAssetProxy(Sdk.AssetChangeRsp msg) {
if(assetProxy == null) {
return;
}
assetProxy.msgToHandler(msg);
}
public void msgToDataProxy(KVPairRecord msg) {
if(dataProxy == null) {
return;
}
dataProxy.msgToHandler(msg);
}
public void msgToDataProxy(PointDetail msg) {
if(dataProxy == null) {
return;
}
dataProxy.msgToHandler(msg);
}
}