use of org.eclipse.kura.data.DataService in project kura by eclipse.
the class GwtStatusServiceImpl method connectDataService.
@Override
public void connectDataService(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
DataService dataService = ServiceLocator.getInstance().getService(DataService.class);
int counter = 10;
try {
dataService.connect();
while (!dataService.isConnected() && counter > 0) {
Thread.sleep(1000);
counter--;
}
} catch (KuraConnectException e) {
s_logger.warn("Error connecting", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Error connecting");
} catch (InterruptedException e) {
s_logger.warn("Interrupt Exception", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Interrupt Exception");
} catch (IllegalStateException e) {
s_logger.warn("Illegal client state", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Illegal client state");
}
}
use of org.eclipse.kura.data.DataService in project kura by eclipse.
the class GwtStatusServiceImpl method disconnectDataService.
@Override
public void disconnectDataService(GwtXSRFToken xsrfToken, String connectionId) throws GwtKuraException {
checkXSRFToken(xsrfToken);
Collection<ServiceReference<CloudService>> cloudServiceReferences = ServiceLocator.getInstance().getServiceReferences(CloudService.class, null);
for (ServiceReference<CloudService> cloudServiceReference : cloudServiceReferences) {
String cloudServicePid = (String) cloudServiceReference.getProperty(KURA_SERVICE_PID);
if (cloudServicePid.endsWith(connectionId)) {
String dataServiceRef = (String) cloudServiceReference.getProperty(DATA_SERVICE_REFERENCE_NAME + ComponentConstants.REFERENCE_TARGET_SUFFIX);
Collection<ServiceReference<DataService>> dataServiceReferences = ServiceLocator.getInstance().getServiceReferences(DataService.class, dataServiceRef);
for (ServiceReference<DataService> dataServiceReference : dataServiceReferences) {
DataService dataService = ServiceLocator.getInstance().getService(dataServiceReference);
if (dataService != null) {
dataService.disconnect(10);
}
ServiceLocator.getInstance().ungetService(dataServiceReference);
}
}
ServiceLocator.getInstance().ungetService(cloudServiceReference);
}
}
use of org.eclipse.kura.data.DataService in project kura by eclipse.
the class GwtStatusServiceImpl method connectDataService.
@Override
public void connectDataService(GwtXSRFToken xsrfToken, String connectionId) throws GwtKuraException {
checkXSRFToken(xsrfToken);
Collection<ServiceReference<CloudService>> cloudServiceReferences = ServiceLocator.getInstance().getServiceReferences(CloudService.class, null);
for (ServiceReference<CloudService> cloudServiceReference : cloudServiceReferences) {
String cloudServicePid = (String) cloudServiceReference.getProperty(KURA_SERVICE_PID);
if (cloudServicePid.endsWith(connectionId)) {
String dataServiceRef = (String) cloudServiceReference.getProperty(DATA_SERVICE_REFERENCE_NAME + ComponentConstants.REFERENCE_TARGET_SUFFIX);
Collection<ServiceReference<DataService>> dataServiceReferences = ServiceLocator.getInstance().getServiceReferences(DataService.class, dataServiceRef);
for (ServiceReference<DataService> dataServiceReference : dataServiceReferences) {
DataService dataService = ServiceLocator.getInstance().getService(dataServiceReference);
if (dataService != null) {
int counter = 10;
try {
dataService.connect();
while (!dataService.isConnected() && counter > 0) {
Thread.sleep(1000);
counter--;
}
} catch (KuraConnectException e) {
s_logger.warn("Error connecting", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Error connecting");
} catch (InterruptedException e) {
s_logger.warn("Interrupt Exception", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Interrupt Exception");
} catch (IllegalStateException e) {
s_logger.warn("Illegal client state", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e, "Illegal client state");
}
}
ServiceLocator.getInstance().ungetService(dataServiceReference);
}
}
ServiceLocator.getInstance().ungetService(cloudServiceReference);
}
}
use of org.eclipse.kura.data.DataService in project kura by eclipse.
the class GwtStatusServiceImpl method fillFromDataService.
private void fillFromDataService(List<GwtGroupedNVPair> pairs, final String dataServiceRef) throws GwtKuraException {
final Collection<ServiceReference<DataService>> dataServiceReferences = ServiceLocator.getInstance().getServiceReferences(DataService.class, dataServiceRef);
for (ServiceReference<DataService> dataServiceReference : dataServiceReferences) {
final DataService dataService = ServiceLocator.getInstance().getService(dataServiceReference);
try {
if (dataService != null) {
pairs.add(new GwtGroupedNVPair("cloudStatus", "Auto-connect", dataService.isAutoConnectEnabled() ? "ON (Retry Interval is " + Integer.toString(dataService.getRetryInterval()) + "s)" : "OFF"));
}
final String dataTransportRef = (String) dataServiceReference.getProperty(DATA_TRANSPORT_SERVICE_REFERENCE_NAME + ComponentConstants.REFERENCE_TARGET_SUFFIX);
final List<DataTransportService> dataTransportServices = ServiceLocator.getInstance().getServices(DataTransportService.class, dataTransportRef);
for (DataTransportService dataTransportService : dataTransportServices) {
pairs.add(new GwtGroupedNVPair("cloudStatus", "Broker URL", dataTransportService.getBrokerUrl()));
pairs.add(new GwtGroupedNVPair("cloudStatus", "Account", dataTransportService.getAccountName()));
pairs.add(new GwtGroupedNVPair("cloudStatus", "Username", dataTransportService.getUsername()));
pairs.add(new GwtGroupedNVPair("cloudStatus", "Client ID", dataTransportService.getClientId()));
}
} finally {
ServiceLocator.getInstance().ungetService(dataServiceReference);
}
}
}
use of org.eclipse.kura.data.DataService in project kura by eclipse.
the class GwtStatusServiceImpl method disconnectDataService.
@Override
public void disconnectDataService(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
DataService dataService = ServiceLocator.getInstance().getService(DataService.class);
dataService.disconnect(10);
}
Aggregations