use of joynr.types.ProviderQos in project joynr by bmwcarit.
the class LocalDiscoveryTest method testMixedLocalCachedRemoteDiscoveryEntries.
@SuppressWarnings("unchecked")
@Test
public void testMixedLocalCachedRemoteDiscoveryEntries() {
String testDomain = "testDomain";
String remoteDomain = "remoteDomain";
Set<String> testDomains = new HashSet<>();
testDomains.add(testDomain);
testDomains.add(remoteDomain);
String interfaceName = testProxy.INTERFACE_NAME;
final Collection<DiscoveryEntry> localDiscoveryEntries = new HashSet<>();
final Collection<DiscoveryEntry> cachedDiscoveryEntries = new HashSet<>();
final List<GlobalDiscoveryEntry> remoteDiscoveryEntries = new ArrayList<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdLocal", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
DiscoveryEntry cachedDiscoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantIdCached", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
GlobalDiscoveryEntry remoteDiscoveryEntry = CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), remoteDomain, interfaceName, "participantIdRemote", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"), new MqttAddress());
localDiscoveryEntries.add(discoveryEntry);
cachedDiscoveryEntries.add(cachedDiscoveryEntry);
remoteDiscoveryEntries.add(remoteDiscoveryEntry);
Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(true, localDiscoveryEntries);
discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, cachedDiscoveryEntry));
discoveryEntriesWithMetaInfo.add(CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(false, remoteDiscoveryEntry));
when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(localDiscoveryEntries);
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(cachedDiscoveryEntries);
Mockito.doAnswer(new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public List<GlobalDiscoveryEntry> answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assert (arguments[0] instanceof Callback);
((Callback) arguments[0]).resolve((Object) remoteDiscoveryEntries);
return null;
}
}).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomains, testProxy.class);
final Future<Void> future = new Future<Void>();
ArbitrationStrategyFunction arbitrationStrategyFunction = new ArbitrationStrategyFunction() {
@Override
public Set<DiscoveryEntryWithMetaInfo> select(Map<String, String> parameters, Collection<DiscoveryEntryWithMetaInfo> capabilities) {
return Sets.newHashSet(capabilities);
}
};
DiscoveryQos discoveryQos = new DiscoveryQos(30000, arbitrationStrategyFunction, 0, DiscoveryScope.LOCAL_AND_GLOBAL);
proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of joynr.types.ProviderQos in project joynr by bmwcarit.
the class LocalDiscoveryTest method testCachedGlobalDiscoveryEntries.
@Test
public void testCachedGlobalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
discoveryEntries.add(new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId"));
Set<DiscoveryEntryWithMetaInfo> discoveryEntriesWithMetaInfo = CapabilityUtils.convertToDiscoveryEntryWithMetaInfoSet(false, discoveryEntries);
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(discoveryEntries);
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
final Future<Void> future = new Future<Void>();
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.GLOBAL_ONLY);
proxyBuilder.setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<testProxy>() {
@Override
public void onProxyCreationFinished(testProxy result) {
future.onSuccess(null);
}
@Override
public void onProxyCreationError(JoynrRuntimeException error) {
future.onFailure(error);
}
});
try {
future.get(5000);
verify(joynrMessagingConnectorFactoryMock).create(anyString(), eq(discoveryEntriesWithMetaInfo), any(MessagingQos.class));
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of joynr.types.ProviderQos in project joynr by bmwcarit.
the class ServersUtil method createJsonFor.
private static String createJsonFor(String directoriesUrl) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
setObjectMapperOnCapabilitiesUtils(objectMapper);
String channelId = "discoverydirectory_channelid";
String participantId = "capabilitiesdirectory_participantid";
GlobalDiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new ChannelAddress(directoriesUrl, channelId));
String accessParticipantId = "domainaccesscontroller_participantid";
GlobalDiscoveryEntry accessControlEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), "io.joynr", GlobalDomainAccessController.INTERFACE_NAME, accessParticipantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", new InProcessAddress());
List<DiscoveryEntry> entries = new ArrayList<>();
entries.add(discoveryEntry);
entries.add(accessControlEntry);
return objectMapper.writeValueAsString(entries);
}
use of joynr.types.ProviderQos in project joynr by bmwcarit.
the class ProviderApplication method run.
@Override
public void run() {
provider = new Provider();
ProviderQos providerQos = new ProviderQos();
providerQos.setPriority(System.currentTimeMillis());
// access to provider is needed inside the hook, so it must be added here
Thread shutdownHook = new Thread() {
@Override
public void run() {
LOG.info("executing shutdown hook");
synchronized (this) {
LOG.info("notifying any waiting thread from shutdown hook");
notifyAll();
}
LOG.info("shutting down");
if (provider != null) {
try {
runtime.unregisterProvider(localDomain, provider);
} catch (JoynrRuntimeException e) {
LOG.error("unable to unregister capabilities {}", e.getMessage());
}
}
runtime.shutdown(false);
LOG.info("shutdown completed");
}
};
LOG.info("adding shutdown hook");
Runtime.getRuntime().addShutdownHook(shutdownHook);
runtime.registerProvider(localDomain, provider, providerQos);
try {
if (!runForever) {
Thread.sleep(30000);
} else {
synchronized (shutdownHook) {
shutdownHook.wait();
}
}
} catch (Exception e) {
// terminate execution by continuing
}
}
use of joynr.types.ProviderQos in project joynr by bmwcarit.
the class InProcessCapabilitiesProvisioning method getDiscoveryEntries.
@Override
public Collection<DiscoveryEntry> getDiscoveryEntries() {
List<DiscoveryEntry> provisionedList = Lists.newArrayList();
String defaultPulicKeyId = "";
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.LOCAL);
provisionedList.add(CapabilityUtils.newGlobalDiscoveryEntry(getVersionFromAnnotation(DiscoveryProvider.class), systemServicesDomain, Discovery.INTERFACE_NAME, discoveryProviderParticipantId, providerQos, System.currentTimeMillis(), NO_EXPIRY, defaultPulicKeyId, discoveryProviderAddress));
return provisionedList;
}
Aggregations