Search in sources :

Example 26 with DiscoveryEntry

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);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) CheckForNull(javax.annotation.CheckForNull) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderContainer(io.joynr.provider.ProviderContainer)

Example 27 with 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;
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) ProviderQos(joynr.types.ProviderQos)

Example 28 with DiscoveryEntry

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);
    }
}
Also used : GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) HashSet(java.util.HashSet) MqttAddress(joynr.system.RoutingTypes.MqttAddress) DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Callback(io.joynr.proxy.Callback) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(io.joynr.proxy.Future) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 29 with DiscoveryEntry

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);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) joynr.tests.testProxy(joynr.tests.testProxy) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) MessagingQos(io.joynr.messaging.MessagingQos) Future(io.joynr.proxy.Future) ProviderQos(joynr.types.ProviderQos) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with DiscoveryEntry

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));
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) DiscoveryQos(joynr.types.DiscoveryQos) 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