Search in sources :

Example 46 with DiscoveryEntry

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);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException)

Example 47 with DiscoveryEntry

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;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) CheckForNull(javax.annotation.CheckForNull)

Example 48 with DiscoveryEntry

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);
}
Also used : Promise(io.joynr.provider.Promise) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 49 with DiscoveryEntry

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) {
        }
    });
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) PromiseListener(io.joynr.provider.PromiseListener) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) JoynrException(io.joynr.exceptions.JoynrException) Matchers.anyString(org.mockito.Matchers.anyString) DeferredVoid(io.joynr.provider.DeferredVoid) Callback(io.joynr.proxy.Callback) Version(joynr.types.Version) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 50 with DiscoveryEntry

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);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Version(joynr.types.Version) Matchers.anyString(org.mockito.Matchers.anyString) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4