Search in sources :

Example 1 with DataTransportService

use of org.eclipse.kura.data.DataTransportService 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);
        }
    }
}
Also used : DataTransportService(org.eclipse.kura.data.DataTransportService) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair) ServiceReference(org.osgi.framework.ServiceReference) DataService(org.eclipse.kura.data.DataService)

Example 2 with DataTransportService

use of org.eclipse.kura.data.DataTransportService in project kura by eclipse.

the class GwtStatusServiceImpl method getCloudStatus.

private List<GwtGroupedNVPair> getCloudStatus() throws GwtKuraException {
    List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
    try {
        DataService dataService = ServiceLocator.getInstance().getService(DataService.class);
        DataTransportService dataTransportService = ServiceLocator.getInstance().getService(DataTransportService.class);
        if (dataService != null) {
            pairs.add(new GwtGroupedNVPair("cloudStatus", "Connection Status", dataService.isConnected() ? "CONNECTED" : "DISCONNECTED"));
            pairs.add(new GwtGroupedNVPair("cloudStatus", "Auto-connect", dataService.isAutoConnectEnabled() ? "ON (Retry Interval is " + Integer.toString(dataService.getRetryInterval()) + "s)" : "OFF"));
        }
        if (dataTransportService != null) {
            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()));
        }
    } catch (GwtKuraException e) {
        s_logger.warn("Get cloud status failed", e);
        throw e;
    }
    return pairs;
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) ArrayList(java.util.ArrayList) DataTransportService(org.eclipse.kura.data.DataTransportService) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair) DataService(org.eclipse.kura.data.DataService)

Aggregations

DataService (org.eclipse.kura.data.DataService)2 DataTransportService (org.eclipse.kura.data.DataTransportService)2 GwtGroupedNVPair (org.eclipse.kura.web.shared.model.GwtGroupedNVPair)2 ArrayList (java.util.ArrayList)1 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)1 ServiceReference (org.osgi.framework.ServiceReference)1