use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class CapabilitiesRegistrarImpl method registerProvider.
/*
* (non-Javadoc)
*
* @see io.joynr.capabilities.CapabilitiesRegistrar# registerProvider(java.lang.String,
* io.joynr.provider.JoynrProvider, java.lang.Class)
*/
@Override
public Future<Void> registerProvider(final String domain, Object provider, ProviderQos providerQos) {
if (providerQos == null) {
throw new JoynrRuntimeException("providerQos == null. It must not be null");
}
ProviderContainer providerContainer = providerContainerFactory.create(provider);
String participantId = participantIdStorage.getProviderParticipantId(domain, providerContainer.getInterfaceName());
String defaultPublicKeyId = "";
DiscoveryEntry discoveryEntry = new DiscoveryEntry(getVersionFromAnnotation(provider.getClass()), domain, providerContainer.getInterfaceName(), participantId, providerQos, System.currentTimeMillis(), System.currentTimeMillis() + defaultExpiryTimeMs, defaultPublicKeyId);
final boolean isGloballyVisible = (discoveryEntry.getQos().getScope() == ProviderScope.GLOBAL);
messageRouter.addNextHop(participantId, libjoynrMessagingAddress, isGloballyVisible);
providerDirectory.add(participantId, providerContainer);
Callback<Void> callback = new Callback<Void>() {
@Override
public void onSuccess(@CheckForNull Void result) {
}
@Override
public void onFailure(JoynrRuntimeException runtimeException) {
logger.error("Unexpected Error while registering Provider:", runtimeException);
}
};
return localDiscoveryAggregator.add(callback, discoveryEntry);
}
use of joynr.types.DiscoveryEntry 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;
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalDiscoveryTest method testRemoteGlobalDiscoveryEntries.
@SuppressWarnings("unchecked")
@Test
public void testRemoteGlobalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
final Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
final List<GlobalDiscoveryEntry> globalDiscoveryEntries = new ArrayList<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
discoveryEntries.add(discoveryEntry);
globalDiscoveryEntries.add(CapabilityUtils.discoveryEntry2GlobalDiscoveryEntry(discoveryEntry, new MqttAddress()));
when(globalDiscoveryEntryCacheMock.lookup(any(String[].class), eq(interfaceName), anyLong())).thenReturn(new HashSet<DiscoveryEntry>());
Mockito.doAnswer(new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assert (arguments[0] instanceof Callback);
((Callback) arguments[0]).resolve((Object) globalDiscoveryEntries);
return null;
}
}).when(globalCapabilitiesDirectoryClientMock).lookup(any(Callback.class), any(String[].class), eq(interfaceName), anyLong());
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(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
assertDiscoveryEntryEqualsCaptured(discoveryEntry);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalDiscoveryTest method testLocalDiscoveryEntries.
@Test
public void testLocalDiscoveryEntries() {
String testDomain = "testDomain";
String interfaceName = testProxy.INTERFACE_NAME;
Collection<DiscoveryEntry> discoveryEntries = new HashSet<>();
DiscoveryEntry discoveryEntry = new DiscoveryEntry(VersionUtil.getVersionFromAnnotation(testProxy.class), testDomain, interfaceName, "participantId", new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + 100000, "publicKeyId");
discoveryEntries.add(discoveryEntry);
when(localDiscoveryEntryStoreMock.lookup(any(String[].class), eq(interfaceName))).thenReturn(discoveryEntries);
ProxyBuilder<testProxy> proxyBuilder = runtime.getProxyBuilder(testDomain, testProxy.class);
final Future<Void> future = new Future<Void>();
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_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(), discoveryEntryWithMetaInfoArgumentCaptor.capture(), any(MessagingQos.class));
assertDiscoveryEntryEqualsCaptured(discoveryEntry);
} catch (Exception e) {
Assert.fail("Unexpected exception from ProxyCreatedCallback: " + e);
}
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalDiscoveryAggregatorTest method findsProvisionedEntryForSingleDomain.
@SuppressWarnings("unchecked")
@Test
public void findsProvisionedEntryForSingleDomain() {
discoveryProviderEntries = new DiscoveryEntryWithMetaInfo[] { discoveryProviderEntry };
oneDomain = new String[] { systemServicesDomain };
// Double Decla. allDomains = new String[]{ anotherDomain, systemServicesDomain };
DiscoveryQos discoveryQos = new DiscoveryQos();
discoveryQos.setDiscoveryScope(DiscoveryScope.LOCAL_ONLY);
Future<DiscoveryEntryWithMetaInfo[]> discoveryEntryFuture = localDiscoveryAggregator.lookup(lookupCallback, oneDomain, Discovery.INTERFACE_NAME, discoveryQos);
ArgumentCaptor<DiscoveryEntry[]> discoveryEntriesCaptor = ArgumentCaptor.forClass(DiscoveryEntry[].class);
verify(lookupCallback).resolve((Object) discoveryEntriesCaptor.capture());
DiscoveryEntry[] discoveryEntriesPassed = discoveryEntriesCaptor.getValue();
assertEquals(1, discoveryEntriesPassed.length);
assertEquals(discoveryProviderEntry.getDomain(), discoveryEntriesPassed[0].getDomain());
assertEquals(discoveryProviderEntry.getInterfaceName(), discoveryEntriesPassed[0].getInterfaceName());
assertEquals(discoveryProviderEntry.getParticipantId(), discoveryEntriesPassed[0].getParticipantId());
assertEquals(discoveryProviderEntry.getQos(), discoveryEntriesPassed[0].getQos());
assertEquals(discoveryProviderEntry.getProviderVersion(), discoveryEntriesPassed[0].getProviderVersion());
try {
discoveryEntriesPassed = discoveryEntryFuture.get();
} catch (Exception e) {
Assert.fail("Got exception from future: " + e);
}
assertEquals(1, discoveryEntriesPassed.length);
assertEquals(discoveryProviderEntry.getDomain(), discoveryEntriesPassed[0].getDomain());
assertEquals(discoveryProviderEntry.getInterfaceName(), discoveryEntriesPassed[0].getInterfaceName());
assertEquals(discoveryProviderEntry.getParticipantId(), discoveryEntriesPassed[0].getParticipantId());
assertEquals(discoveryProviderEntry.getQos(), discoveryEntriesPassed[0].getQos());
assertEquals(discoveryProviderEntry.getProviderVersion(), discoveryEntriesPassed[0].getProviderVersion());
verify(discoveryProxyMock, never()).lookup(any(Callback.class), any(String[].class), anyString(), any(DiscoveryQos.class));
}
Aggregations