com.envision.energy.eos.sdk.EOSClient Maven / Gradle / Ivy
package com.envision.energy.eos.sdk;
import com.envision.energy.eos.exception.EOSClientException;
public class EOSClient {
private static IDataService dataService = null;
private static IAlarmService alarmService = null;
private static IEventService eventService = null;
private static IEventV2Service eventV2Service = null;
private static IAssetService assetService = null;
public EOSClient(String appKey, String appSecret, String url)
throws EOSClientException {
synchronized (this) {
check();
ProxyManager.INSTANCE.setTransport(Transport.create(appKey, appSecret, url));
}
}
public EOSClient(String appKey, String appSecrect, String url, int retryTimeoutSec)
throws EOSClientException {
synchronized (this) {
check();
ProxyManager.INSTANCE.setTransport(Transport.create(appKey, appSecrect, url, retryTimeoutSec));
}
}
private void check() throws EOSClientException {
//一个SDK只能有一个socket连接,避免利用sdk创建过多socket,维护server安全性
if(ProxyManager.INSTANCE.transportIsOpen()) {
throw new EOSClientException("Socket is open. Shutdown the old client first.");
}
}
/**
* if app is invalid, return null.
* @return IDataService
*/
public IDataService getDataService() {
if(dataService == null) {
dataService = new DataServiceImpl();
}
return dataService;
}
public IAlarmService getAlarmService() {
if(alarmService == null) {
alarmService = new AlarmServiceImpl();
}
return alarmService;
}
public IEventService getEventService(){
if(eventService == null){
eventService = new EventServiceImpl();
}
return eventService;
}
public IEventV2Service getEventV2Service() {
if(eventV2Service == null){
eventV2Service = new EventV2ServiceImpl();
}
return eventV2Service;
}
public IAssetService getAssetService(){
if(assetService == null ){
assetService = new AssetServiceImpl();
}
return assetService;
}
public void shutdown() {
if(ProxyManager.INSTANCE.transportIsOpen()) {
ProxyManager.INSTANCE.closeTransport();
if(dataService != null) {
dataService.shutdown();
dataService = null;
}
if(alarmService != null) {
alarmService.shutdown();
alarmService = null;
}
}
}
}