Search in sources :

Example 1 with GpsProxy

use of joynr.vehicle.GpsProxy 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 GpsProxy

use of joynr.vehicle.GpsProxy in project joynr by bmwcarit.

the class JoynrAndroidExampleApplication method createProxy.

public void createProxy() {
    if (runtime == null) {
        logger.error("runtime has not been initialized!");
        logToOutput("runtime has not been initialized!\n");
    }
    logToOutput("Creating joynr GPS proxy and requesting location...\n");
    // 2 minutes ttl
    MessagingQos messagingQos = new MessagingQos(2 * 60 * 1000);
    DiscoveryQos discoveryQos = new // 30 second timeout to find a provider
    DiscoveryQos(// 30 second timeout to find a provider
    30 * 1000, ArbitrationStrategy.HighestPriority, Integer.MAX_VALUE, DiscoveryScope.LOCAL_ONLY);
    try {
        ProxyBuilder<GpsProxy> builder = runtime.getProxyBuilder(PROVIDER_DOMAIN, GpsProxy.class);
        builder.setDiscoveryQos(discoveryQos).setMessagingQos(messagingQos).build(new ProxyBuilder.ProxyCreatedCallback<GpsProxy>() {

            @Override
            public void onProxyCreationFinished(GpsProxy newProxy) {
                logToOutput("Proxy created");
                proxy = newProxy;
            }

            @Override
            public void onProxyCreationError(JoynrRuntimeException error) {
                logToOutput("Error during proxy creation: " + error.getMessage() + "\n");
            }
        });
    } catch (Exception e) {
        logToOutput("ERROR: create proxy failed: " + e.getMessage() + "\n");
        logger.error("create proxy failed: ", e);
    }
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) GpsProxy(joynr.vehicle.GpsProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProxyBuilder(io.joynr.proxy.ProxyBuilder)

Aggregations

DiscoveryQos (io.joynr.arbitration.DiscoveryQos)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 GpsProxy (joynr.vehicle.GpsProxy)2 ProxyBuilder (io.joynr.proxy.ProxyBuilder)1 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)1 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)1 GpsLocation (joynr.types.Localisation.GpsLocation)1