use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class DiscoveryEntryStoreInMemory method add.
/*
* (non-Javadoc)
* @see io.joynr.capabilities.CapabilitiesStore#add(io.joynr.
* capabilities .DiscoveryEntry)
*/
@Override
public synchronized void add(DiscoveryEntry discoveryEntry) {
if (discoveryEntry.getDomain() == null || discoveryEntry.getInterfaceName() == null || discoveryEntry.getParticipantId() == null) {
String message = "discoveryEntry being registered is not complete: " + discoveryEntry;
logger.error(message);
throw new JoynrCommunicationException(message);
}
synchronized (storeLock) {
String discoveryEntryId = domainInterfaceParticipantIdKey(discoveryEntry.getDomain(), discoveryEntry.getInterfaceName(), discoveryEntry.getParticipantId());
DiscoveryEntry entry = capabilityKeyToCapabilityMapping.get(discoveryEntryId);
// check if a DiscoveryEntry with the same Id already exists
if (entry != null) {
remove(discoveryEntry.getParticipantId());
}
// update participantId to capability mapping
capabilityKeyToCapabilityMapping.put(discoveryEntryId, discoveryEntry);
// update time mapping
registeredCapabilitiesTime.put(discoveryEntryId, System.currentTimeMillis());
// update interfaceDomain to capability mapping
String domainInterfaceId = domainInterfaceKey(discoveryEntry.getDomain(), discoveryEntry.getInterfaceName());
// if domainInterfaceId not in the mapping, map it to an empty map,
// otherwise use the mapping that is already there
List<String> newMapping = new ArrayList<String>();
List<String> mapping = interfaceAddressToCapabilityMapping.putIfAbsent(domainInterfaceId, newMapping);
if (mapping == null) {
mapping = newMapping;
}
mapping.add(discoveryEntryId);
// update participantId to capability mapping
String participantId = discoveryEntry.getParticipantId();
participantIdToCapabilityMapping.put(participantId, discoveryEntryId);
}
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class DiscoveryEntryStorePersisted method lookup.
@Override
@CheckForNull
public DiscoveryEntry lookup(String participantId, long cacheMaxAge) {
DiscoveryEntry result = entityManager.find(GlobalDiscoveryEntryPersisted.class, participantId);
logger.debug("looked up {}, {} and found {}", participantId, cacheMaxAge, result);
return result;
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class CapabilitiesDirectoryImpl method lookup.
@Override
public Promise<Lookup1Deferred> lookup(final String[] domains, final String interfaceName) {
Lookup1Deferred deferred = new Lookup1Deferred();
logger.debug("Searching channels for domains: {} interfaceName: {}", domains, interfaceName);
Collection<DiscoveryEntry> discoveryEntries = discoveryEntryStore.lookup(domains, interfaceName);
GlobalDiscoveryEntry[] globalDiscoveryEntries = new GlobalDiscoveryEntry[discoveryEntries.size()];
int index = 0;
for (DiscoveryEntry discoveryEntry : discoveryEntries) {
// entries from persisted store are of type GlobalDiscoveryEntryPersisted.
// Copy required or else _typeName will be incorrect
globalDiscoveryEntries[index] = new GlobalDiscoveryEntry((GlobalDiscoveryEntry) discoveryEntry);
index++;
}
deferred.resolve(globalDiscoveryEntries);
return new Promise<Lookup1Deferred>(deferred);
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method addGlobalCapFails_NextAddShallAddGlobalAgain.
@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void addGlobalCapFails_NextAddShallAddGlobalAgain() throws InterruptedException {
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.GLOBAL);
String participantId = LocalCapabilitiesDirectoryTest.class.getName() + ".addLocalAndThanGlobalShallWork";
String domain = "testDomain";
final DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, participantId, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddressSerialized);
Mockito.doAnswer(createAddAnswerWithError()).when(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
Promise<DeferredVoid> promise = localCapabilitiesDirectory.add(discoveryEntry);
promise.then(new PromiseListener() {
@Override
public void onFulfillment(Object... values) {
verify(globalDiscoveryEntryCacheMock, never()).add(eq(globalDiscoveryEntry));
verify(globalCapabilitiesClient).add(any(Callback.class), eq(globalDiscoveryEntry));
reset(globalCapabilitiesClient);
localCapabilitiesDirectory.add(discoveryEntry);
verify(globalCapabilitiesClient, timeout(200)).add(any(Callback.class), eq(globalDiscoveryEntry));
}
@Override
public void onRejection(JoynrException error) {
}
});
}
use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.
the class LocalCapabilitiesDirectoryTest method lookupByParticipantIdWithScopeLocalSync.
@Test(timeout = 1000)
public void lookupByParticipantIdWithScopeLocalSync() throws InterruptedException {
String domain1 = "domain1";
String interfaceName1 = "interfaceName1";
String participantId1 = "participantId1";
DiscoveryQos discoveryQos = new DiscoveryQos(30000, ArbitrationStrategy.HighestPriority, 10000, DiscoveryScope.LOCAL_ONLY);
// add local entry
ProviderQos providerQos = new ProviderQos();
providerQos.setScope(ProviderScope.LOCAL);
DiscoveryEntry discoveryEntry = new DiscoveryEntry(new Version(47, 11), domain1, interfaceName1, participantId1, providerQos, System.currentTimeMillis(), expiryDateMs, publicKeyId);
DiscoveryEntryWithMetaInfo expectedDiscoveryEntry = CapabilityUtils.convertToDiscoveryEntryWithMetaInfo(true, discoveryEntry);
when(localDiscoveryEntryStoreMock.lookup(eq(participantId1), eq(discoveryQos.getCacheMaxAgeMs()))).thenReturn(discoveryEntry);
DiscoveryEntry retrievedCapabilityEntry = localCapabilitiesDirectory.lookup(participantId1, discoveryQos);
assertEquals(expectedDiscoveryEntry, retrievedCapabilityEntry);
}
Aggregations