Search in sources :

Example 1 with DataService

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");
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) KuraConnectException(org.eclipse.kura.KuraConnectException) DataService(org.eclipse.kura.data.DataService)

Example 2 with DataService

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);
    }
}
Also used : CloudService(org.eclipse.kura.cloud.CloudService) ServiceReference(org.osgi.framework.ServiceReference) DataService(org.eclipse.kura.data.DataService)

Example 3 with DataService

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);
    }
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) KuraConnectException(org.eclipse.kura.KuraConnectException) CloudService(org.eclipse.kura.cloud.CloudService) ServiceReference(org.osgi.framework.ServiceReference) DataService(org.eclipse.kura.data.DataService)

Example 4 with DataService

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);
        }
    }
}
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 5 with DataService

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);
}
Also used : DataService(org.eclipse.kura.data.DataService)

Aggregations

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