Search in sources :

Example 1 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class GpsConsumerApplication method run.

@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    // As soon as the arbitration QoS is set on the proxy builder, discovery of suitable providers
    // is triggered. If the discovery process does not find matching providers within the
    // arbitration timeout duration it will be terminated and you will get an arbitration exception.
    discoveryQos.setDiscoveryTimeoutMs(10000);
    // Provider entries in the global capabilities directory are cached locally. Discovery will
    // consider entries in this cache valid if they are younger as the max age of cached
    // providers as defined in the QoS. All valid entries will be processed by the arbitrator when searching
    // for and arbitrating the "best" matching provider.
    // NOTE: Valid cache entries might prevent triggering a lookup in the global capabilities
    // directory. Therefore, not all providers registered with the global capabilities
    // directory might be taken into account during arbitration.
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    // The discovery process outputs a list of matching providers. The arbitration strategy then
    // chooses one or more of them to be used by the proxy.
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    // The provider will maintain at least a minimum interval idle time in milliseconds between
    // successive notifications, even if on-change notifications are enabled and the value changes more
    // often. This prevents the consumer from being flooded by updated values. The filtering happens on
    // the provider's side, thus also preventing excessive network traffic.
    int minInterval_ms = 0;
    // The provider will send notifications every maximum interval in milliseconds, even if the value didn't
    // change. It will send notifications more often if on-change notifications are enabled,
    // the value changes more often, and the minimum interval QoS does not prevent it. The maximum interval
    // can thus be seen as a sort of heart beat.
    int maxInterval_ms = 10000;
    // The provider will send notifications until the end date is reached. The consumer will not receive any
    // notifications (neither value notifications nor missed publication notifications) after
    // this date.
    long validity_ms = 60000;
    // If no notification was received within the last alert interval, a missed publication
    // notification will be raised.
    int alertAfterInterval_ms = 20000;
    // Notification messages will be sent with this time-to-live. If a notification message can not be
    // delivered within its TTL, it will be deleted from the system.
    // NOTE: If a notification message is not delivered due to an expired TTL, it might raise a
    // missed publication notification (depending on the value of the alert interval QoS).
    int publicationTtl_ms = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms).setMaxIntervalMs(maxInterval_ms).setValidityMs(validity_ms);
    subscriptionQos.setAlertAfterIntervalMs(alertAfterInterval_ms).setPublicationTtlMs(publicationTtl_ms);
    ProxyBuilder<GpsProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, GpsProxy.class);
    // reading an attribute value
    gpsProxy = proxyBuilder.setMessagingQos(new MessagingQos()).setDiscoveryQos(discoveryQos).build();
    subscriptionFuture = gpsProxy.subscribeToLocation(new AttributeSubscriptionAdapter<GpsLocation>() {

        @Override
        public void onReceive(GpsLocation value) {
            LOG.info(PRINT_BORDER + "SUBSCRIPTION: location: " + value + PRINT_BORDER);
        }

        @Override
        public void onError(JoynrRuntimeException error) {
            LOG.info(PRINT_BORDER + "SUBSCRIPTION: location, publication missed " + PRINT_BORDER);
        }
    }, subscriptionQos);
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) GpsProxy(joynr.vehicle.GpsProxy) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos)

Example 2 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class CreateSubscriptionTask method subscribeToLocation.

private void subscribeToLocation(GpsProxy proxy) {
    // defines how often an update may be sent
    long minInterval_ms = 1000;
    // defines how long to wait before sending an update even if the value did not
    long periodMs = 10000;
    // change or when onChange is false
    // subscribe for one hour
    long validityMs = 1 * 60 * 60 * 1000;
    // defines how long to wait for an update before publicationMissed is called
    long alertIntervalMs = 20000;
    // time to live for publication messages
    long publicationTtlMs = 20000;
    SubscriptionQos subscriptionQos = new PeriodicSubscriptionQos().setPeriodMs(periodMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertIntervalMs).setPublicationTtlMs(publicationTtlMs);
    AttributeSubscriptionAdapter<GpsLocation> listener = new AttributeSubscriptionAdapter<GpsLocation>() {

        @Override
        public void onReceive(GpsLocation value) {
            logToOutput("Received subscription update: " + value.toString());
        }

        @Override
        public void onError(JoynrRuntimeException error) {
            logToOutput("error in subscription: " + error.getMessage());
        }
    };
    proxy.subscribeToLocation(listener, subscriptionQos);
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) GpsLocation(joynr.types.Localisation.GpsLocation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos)

Example 3 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AndroidLocationProvider method initLocationProviderAndListener.

private void initLocationProviderAndListener() {
    // LocationResult.gotLocation will be called when android notifies about a new location
    locationResult = new LocationResult() {

        @Override
        public void gotLocation(Location androidLocation) {
            GpsLocation joynrLocation = new GpsLocation();
            if (androidLocation != null) {
                joynrLocation.setLatitude(androidLocation.getLatitude());
                joynrLocation.setLongitude(androidLocation.getLongitude());
                joynrLocation.setAltitude(androidLocation.getAltitude());
                joynrLocation.setGpsFix(GpsFixEnum.MODE3D);
            } else {
                joynrLocation.setGpsFix(GpsFixEnum.MODENOFIX);
            }
            // applies the location to the location provider and notifies onChange subscriptions
            locationChanged(joynrLocation);
        }
    };
    // Use myLocation to asynchronously obtain a location
    myLocation = new MyLocation();
    myLocation.getLocation(applicationContext, locationResult);
    // Attempt to update the location every 20 seconds
    scheduler.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            myLocation.getLocation(applicationContext, locationResult);
        }
    }, 0, 20000, TimeUnit.MILLISECONDS);
}
Also used : GpsLocation(joynr.types.Localisation.GpsLocation) LocationResult(io.joynr.examples.android_location_provider.MyLocation.LocationResult) GpsLocation(joynr.types.Localisation.GpsLocation) Location(android.location.Location)

Example 4 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method sendObjectsAsArgumentAndReturnValue.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void sendObjectsAsArgumentAndReturnValue() throws DiscoveryException, JoynrIllegalStateException, InterruptedException {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    List<GpsLocation> locationList = new ArrayList<GpsLocation>();
    locationList.add(new GpsLocation(50.1, 20.1, 500.0, GpsFixEnum.MODE3D, 0.0, 0.0, 0.0, 0.0, 0l, 0l, 1000));
    locationList.add(new GpsLocation(50.1, 20.1, 500.0, GpsFixEnum.MODE3D, 0.0, 0.0, 0.0, 0.0, 0l, 0l, 1000));
    locationList.add(new GpsLocation(50.1, 20.1, 500.0, GpsFixEnum.MODE3D, 0.0, 0.0, 0.0, 0.0, 0l, 0l, 1000));
    Trip testObject = new Trip(locationList.toArray(new GpsLocation[0]), "Title");
    Trip result;
    result = proxy.optimizeTrip(testObject);
    assertEquals(Double.valueOf(500.0), result.getLocations()[0].getAltitude());
}
Also used : Trip(joynr.types.Localisation.Trip) joynr.tests.testProxy(joynr.tests.testProxy) ArrayList(java.util.ArrayList) GpsLocation(joynr.types.Localisation.GpsLocation) Test(org.junit.Test)

Example 5 with GpsLocation

use of joynr.types.Localisation.GpsLocation in project joynr by bmwcarit.

the class AbstractProviderProxyEnd2EndTest method calledMethodReturnsMultipleOutputParametersAsyncCallback.

@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void calledMethodReturnsMultipleOutputParametersAsyncCallback() throws Exception {
    ProxyBuilder<testProxy> proxyBuilder = consumerRuntime.getProxyBuilder(domain, testProxy.class);
    testProxy proxy = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
    final Object untilCallbackFinished = new Object();
    final Map<String, Object> result = new HashMap<String, Object>();
    proxy.methodWithMultipleOutputParameters(new MethodWithMultipleOutputParametersCallback() {

        @Override
        public void onFailure(JoynrRuntimeException error) {
            logger.error("error in calledMethodReturnsMultipleOutputParametersAsyncCallback", error);
        }

        @Override
        public void onSuccess(String aString, Integer aNumber, GpsLocation aComplexDataType, TestEnum anEnumResult) {
            result.put("receivedString", aString);
            result.put("receivedNumber", aNumber);
            result.put("receivedComplexDataType", aComplexDataType);
            result.put("receivedEnum", anEnumResult);
            synchronized (untilCallbackFinished) {
                untilCallbackFinished.notify();
            }
        }
    });
    synchronized (untilCallbackFinished) {
        untilCallbackFinished.wait(CONST_DEFAULT_TEST_TIMEOUT);
    }
    assertEquals(TEST_INTEGER, result.get("receivedNumber"));
    assertEquals(TEST_STRING, result.get("receivedString"));
    assertEquals(TEST_COMPLEXTYPE, result.get("receivedComplexDataType"));
    assertEquals(TEST_ENUM, result.get("receivedEnum"));
}
Also used : HashMap(java.util.HashMap) joynr.tests.testProxy(joynr.tests.testProxy) GpsLocation(joynr.types.Localisation.GpsLocation) TestEnum(joynr.tests.testTypes.TestEnum) MethodWithMultipleOutputParametersCallback(joynr.tests.testAsync.MethodWithMultipleOutputParametersCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Aggregations

GpsLocation (joynr.types.Localisation.GpsLocation)22 Test (org.junit.Test)18 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)9 Semaphore (java.util.concurrent.Semaphore)7 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)6 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)6 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 MessagingQos (io.joynr.messaging.MessagingQos)5 ArrayList (java.util.ArrayList)5 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)5 SubscriptionRequest (joynr.SubscriptionRequest)5 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)4 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)4 SubscriptionPublication (joynr.SubscriptionPublication)4 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 joynr.tests.testProxy (joynr.tests.testProxy)3 Ignore (org.junit.Ignore)3 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2