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");
}
}
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");
}
}
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>() {
});
}
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));
}
}
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);
}
}
Aggregations