Search in sources :

Example 36 with Address

use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.

the class ArbitrationTest method testPriorityArbitrator.

@Test
public void testPriorityArbitrator() throws InterruptedException {
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(testPriority);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    long lessPrior = 1;
    ProviderQos providerQos2 = new ProviderQos();
    providerQos2.setPriority(lessPrior);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    long negativePriority = -10;
    ProviderQos providerQos3 = new ProviderQos();
    providerQos3.setPriority(negativePriority);
    Address thirdEndpointAddress = new ChannelAddress("http://testUrl", "thirdChannelId");
    ArrayList<Address> thirdEndpointAddresses = new ArrayList<Address>();
    thirdEndpointAddresses.add(thirdEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 37 with Address

use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.

the class ArbitrationTest method testPriorityArbitratorOnChangeSubscriptions.

@Test
public void testPriorityArbitratorOnChangeSubscriptions() throws InterruptedException {
    // Expected provider supports onChangeSubscriptions
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(testPriority);
    providerQos.setSupportsOnChangeSubscriptions(true);
    expectedEndpointAddress = new ChannelAddress("http://testUrl", "testChannelId");
    DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, expectedParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true);
    capabilitiesList.add(expectedDiscoveryEntry);
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos2 = new ProviderQos();
    providerQos2.setPriority(testPriority + 1);
    providerQos2.setSupportsOnChangeSubscriptions(false);
    Address otherEndpointAddress = new ChannelAddress("http://testUrl", "otherChannelId");
    ArrayList<Address> otherEndpointAddresses = new ArrayList<Address>();
    otherEndpointAddresses.add(otherEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "wrongParticipantId", providerQos2, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    // A provider with a higher priority that does not support onChangeSubscriptions
    ProviderQos providerQos3 = new ProviderQos();
    providerQos3.setPriority(testPriority + 2);
    providerQos3.setSupportsOnChangeSubscriptions(false);
    Address thirdEndpointAddress = new ChannelAddress("http://testUrl", "thirdChannelId");
    ArrayList<Address> thirdEndpointAddresses = new ArrayList<Address>();
    thirdEndpointAddresses.add(thirdEndpointAddress);
    capabilitiesList.add(new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, "thirdParticipantId", providerQos3, System.currentTimeMillis(), NO_EXPIRY, publicKeyId, true));
    discoveryQos = new DiscoveryQos(ARBITRATION_TIMEOUT, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    discoveryQos.setProviderMustSupportOnChange(true);
    try {
        Arbitrator arbitrator = ArbitratorFactory.create(Sets.newHashSet(domain), interfaceName, interfaceVersion, discoveryQos, localDiscoveryAggregator);
        arbitrator.setArbitrationListener(arbitrationCallback);
        arbitrator.scheduleArbitration();
        assertTrue(localDiscoveryAggregatorSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
        ArbitrationResult expectedArbitrationResult = new ArbitrationResult(expectedDiscoveryEntry);
        verify(arbitrationCallback, times(1)).onSuccess(eq(expectedArbitrationResult));
    } catch (DiscoveryException e) {
        fail("A Joyn Arbitration Exception has been thrown");
    }
}
Also used : Address(joynr.system.RoutingTypes.Address) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Version(joynr.types.Version) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryException(io.joynr.exceptions.DiscoveryException) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 38 with Address

use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.

the class AbstractRuntimeModule method configure.

@Override
protected void configure() {
    requestStaticInjection(CapabilityUtils.class, RpcUtils.class, ArbitratorFactory.class, JoynrDelayMessageException.class, JoynrAppenderManagerFactory.class);
    install(new JsonMessageSerializerModule());
    install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
    install(new JoynrMessageScopeModule());
    messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
    }, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
    }, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
    messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
    messagingSkeletonFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
    }, new TypeLiteral<IMessagingSkeleton>() {
    }, Names.named(MessagingSkeletonFactory.MIDDLEWARE_MESSAGING_SKELETONS));
    messagingSkeletonFactory.addBinding(InProcessAddress.class).to(InProcessLibjoynrMessagingSkeleton.class);
    // other address types must be added to the Multibinder to support global addressing. Created here to make
    // sure the Set exists, even if empty.
    Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
    }, Names.named(GlobalAddressProvider.GLOBAL_ADDRESS_PROVIDER));
    Multibinder.newSetBinder(binder(), new TypeLiteral<GlobalAddressFactory<? extends Address>>() {
    }, Names.named(ReplyToAddressProvider.REPLY_TO_ADDRESS_PROVIDER));
    multicastAddressCalculators = Multibinder.newSetBinder(binder(), new TypeLiteral<MulticastAddressCalculator>() {
    });
    bind(ProxyBuilderFactory.class).to(ProxyBuilderFactoryImpl.class);
    bind(RequestReplyManager.class).to(RequestReplyManagerImpl.class);
    bind(SubscriptionManager.class).to(SubscriptionManagerImpl.class);
    bind(PublicationManager.class).to(PublicationManagerImpl.class);
    bind(Dispatcher.class).to(DispatcherImpl.class);
    bind(LocalDiscoveryAggregator.class).in(Singleton.class);
    bind(DiscoveryAsync.class).to(LocalDiscoveryAggregator.class);
    bind(CapabilitiesRegistrar.class).to(CapabilitiesRegistrarImpl.class);
    bind(ParticipantIdStorage.class).to(PropertiesFileParticipantIdStorage.class);
    bind(SubscriptionRequestStorage.class).to(FileSubscriptionRequestStorage.class);
    bind(MessagingSettings.class).to(ConfigurableMessagingSettings.class);
    bind(RoutingTable.class).to(RoutingTableImpl.class).asEagerSingleton();
    bind(MulticastReceiverRegistry.class).to(InMemoryMulticastReceiverRegistry.class).asEagerSingleton();
    bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
    bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toProvider(DefaultScheduledExecutorServiceProvider.class);
    bind(StatusReceiver.class).to(DefaultStatusReceiver.class);
    install(new StaticCapabilitiesProvisioningModule());
    bind(ScheduledExecutorService.class).annotatedWith(Names.named(JOYNR_SCHEDULER_CLEANUP)).toProvider(DefaultScheduledExecutorServiceProvider.class);
    Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
    });
}
Also used : PublicationManager(io.joynr.dispatching.subscription.PublicationManager) FileSubscriptionRequestStorage(io.joynr.dispatching.subscription.FileSubscriptionRequestStorage) SubscriptionRequestStorage(io.joynr.dispatching.subscription.SubscriptionRequestStorage) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) GlobalAddressFactory(io.joynr.messaging.routing.GlobalAddressFactory) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) PropertiesFileParticipantIdStorage(io.joynr.capabilities.PropertiesFileParticipantIdStorage) ParticipantIdStorage(io.joynr.capabilities.ParticipantIdStorage) SubscriptionManager(io.joynr.dispatching.subscription.SubscriptionManager) Dispatcher(io.joynr.dispatching.Dispatcher) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) StatusReceiver(io.joynr.statusmetrics.StatusReceiver) DefaultStatusReceiver(io.joynr.statusmetrics.DefaultStatusReceiver) MessagingSettings(io.joynr.messaging.MessagingSettings) ConfigurableMessagingSettings(io.joynr.messaging.ConfigurableMessagingSettings) TypeLiteral(com.google.inject.TypeLiteral) RequestReplyManager(io.joynr.dispatching.RequestReplyManager) ProxyInvocationHandlerFactory(io.joynr.proxy.ProxyInvocationHandlerFactory) RoutingTableImpl(io.joynr.messaging.routing.RoutingTableImpl) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) DiscoveryAsync(joynr.system.DiscoveryAsync) CapabilitiesRegistrar(io.joynr.capabilities.CapabilitiesRegistrar) StaticCapabilitiesProvisioningModule(io.joynr.capabilities.StaticCapabilitiesProvisioningModule) InMemoryMulticastReceiverRegistry(io.joynr.messaging.routing.InMemoryMulticastReceiverRegistry) ProxyBuilderFactory(io.joynr.proxy.ProxyBuilderFactory) JoynrMessageScopeModule(io.joynr.context.JoynrMessageScopeModule) LocalDiscoveryAggregator(io.joynr.discovery.LocalDiscoveryAggregator)

Example 39 with Address

use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioning method substituteInProcessAddressIfLocal.

private void substituteInProcessAddressIfLocal(ObjectMapper objectMapper, String localChannelId, GlobalDiscoveryEntry globalDiscoveryEntry, Address address) throws JsonProcessingException {
    if ((address instanceof ChannelAddress && localChannelId.equals(((ChannelAddress) address).getChannelId())) || (address instanceof MqttAddress && localChannelId.equals(((MqttAddress) address).getTopic()))) {
        Address localAddress = new InProcessAddress();
        globalDiscoveryEntry.setAddress(objectMapper.writeValueAsString(localAddress));
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 40 with Address

use of joynr.system.RoutingTypes.Address in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioning method addEntriesFromJson.

private void addEntriesFromJson(String provisionedCapabilitiesJsonFilename, ObjectMapper objectMapper, String localChannelId) {
    String provisionedCapabilitiesJsonString = resourceContentProvider.readFromFileOrResourceOrUrl(provisionedCapabilitiesJsonFilename);
    logger.trace("Statically provisioned capabilities JSON read: {}", provisionedCapabilitiesJsonString);
    List<GlobalDiscoveryEntry> newEntries = null;
    try {
        newEntries = objectMapper.readValue(provisionedCapabilitiesJsonString, new TypeReference<List<GlobalDiscoveryEntry>>() {
        });
        for (GlobalDiscoveryEntry globalDiscoveryEntry : newEntries) {
            globalDiscoveryEntry.setLastSeenDateMs(System.currentTimeMillis());
            Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
            substituteInProcessAddressIfLocal(objectMapper, localChannelId, globalDiscoveryEntry, address);
            discoveryEntries.add(globalDiscoveryEntry);
        }
    } catch (IOException e) {
        String message = format("Unable to load provisioned capabilities. Invalid JSON value: %s", provisionedCapabilitiesJsonString);
        throw new JoynrRuntimeException(message, e);
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Aggregations

Address (joynr.system.RoutingTypes.Address)43 Test (org.junit.Test)21 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)15 MqttAddress (joynr.system.RoutingTypes.MqttAddress)13 ProviderQos (joynr.types.ProviderQos)9 Version (joynr.types.Version)9 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 TypeLiteral (com.google.inject.TypeLiteral)5 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)5 AbstractModule (com.google.inject.AbstractModule)4 HashSet (java.util.HashSet)4 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)4 DiscoveryException (io.joynr.exceptions.DiscoveryException)3 AbstractMiddlewareMessagingStubFactory (io.joynr.messaging.AbstractMiddlewareMessagingStubFactory)3 IMessagingSkeleton (io.joynr.messaging.IMessagingSkeleton)3 IMessagingStub (io.joynr.messaging.IMessagingStub)3 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)3 ArrayList (java.util.ArrayList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2