use of joynr.system.RoutingTypes.ChannelAddress 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.ChannelAddress 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.ChannelAddress in project joynr by bmwcarit.
the class LegacyCapabilitiesProvisioning method createDiscoveryEntryFor.
private void createDiscoveryEntryFor(Class<?> interfaceClass, String interfaceName, String channelId, String participantId, String urlForAddress, String localChannelId, String domain) {
boolean hasUrl = isPresent(urlForAddress);
boolean hasParticipantId = isPresent(participantId);
if (hasUrl && !hasParticipantId) {
throw new IllegalArgumentException(format("When configuring the discovery directory or domain access controller " + "via properties, you must provide both a URL and a participant ID per service.%n" + "You provided the URL '%s' and the participant ID '%s' for the service %s.%n" + "Please complete the configuration and restart the application.", urlForAddress, participantId, interfaceName));
}
if (hasParticipantId && hasUrl && isPresent(channelId) && isPresent(domain)) {
Address address;
if (localChannelId.equals(channelId)) {
address = new InProcessAddress();
} else if (urlForAddress.startsWith("tcp") || urlForAddress.startsWith("mqtt")) {
address = new MqttAddress(urlForAddress, channelId);
} else {
address = new ChannelAddress(urlForAddress, channelId);
}
DiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), domain, interfaceName, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", address);
logger.debug("Created legacy discovery entry: {}", discoveryEntry);
legacyDiscoveryEntries.put(interfaceClass, discoveryEntry);
legacyAddresses.put(interfaceClass, address);
} else {
logger.trace("Insufficient properties data to create entry for interface {}", interfaceName);
}
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class GlobalCapabilitiesDirectoryEjb method add.
@Override
public void add(GlobalDiscoveryEntry globalDiscoveryEntry) {
logger.debug("Adding global discovery entry {}", globalDiscoveryEntry);
Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
String clusterControllerId;
if (address instanceof MqttAddress) {
clusterControllerId = ((MqttAddress) address).getTopic();
} else if (address instanceof ChannelAddress) {
clusterControllerId = ((ChannelAddress) address).getChannelId();
} else {
clusterControllerId = String.valueOf(address);
}
GlobalDiscoveryEntryPersisted entity = new GlobalDiscoveryEntryPersisted(globalDiscoveryEntry, clusterControllerId);
GlobalDiscoveryEntryPersisted persisted = entityManager.find(GlobalDiscoveryEntryPersisted.class, entity.getParticipantId());
if (persisted == null) {
entityManager.persist(entity);
} else {
entityManager.merge(entity);
}
}
use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.
the class CcMessageRouterTest method testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub.
@Test
public void testNoMessageDuplicationForMulticastForMultipleAddressesWithErrorFromStub() throws Exception {
ChannelAddress receiverAddress1 = new ChannelAddress("http://testUrl", "channelId1");
ChannelAddress receiverAddress2 = new ChannelAddress("http://testUrl", "channelId2");
prepareMulticastForMultipleAddresses(receiverAddress1, receiverAddress2);
ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
doAnswer(new Answer<Void>() {
private int callCount = 0;
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
FailureAction failureAction = invocation.getArgumentAt(2, FailureAction.class);
if (callCount < 2) {
callCount++;
failureAction.execute(new JoynrDelayMessageException(10, "first retry"));
} else {
failureAction.execute(new JoynrMessageNotSentException("do not retry twice"));
}
return null;
}
}).when(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
messageRouter.route(immutableMessage);
Thread.sleep(1000);
verify(messagingStubMock, times(4)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress1);
verify(middlewareMessagingStubFactoryMock, times(2)).create(receiverAddress2);
}
Aggregations