Search in sources :

Example 1 with InProcessAddress

use of io.joynr.messaging.inprocess.InProcessAddress in project joynr by bmwcarit.

the class LibJoynrMessageRouter method addMulticastReceiver.

@Override
public void addMulticastReceiver(final String multicastId, final String subscriberParticipantId, final String providerParticipantId) {
    super.addMulticastReceiver(multicastId, subscriberParticipantId, providerParticipantId);
    DeferrableRegistration registerWithParent = new DeferrableRegistration() {

        @Override
        public void register() {
            Address providerAddress = routingTable.get(providerParticipantId);
            if (providerAddress == null || !(providerAddress instanceof InProcessAddress)) {
                parentRouter.addMulticastReceiver(multicastId, subscriberParticipantId, providerParticipantId);
            }
        }
    };
    if (parentRouter != null) {
        registerWithParent.register();
    } else {
        synchronized (deferredMulticastRegistrations) {
            deferredMulticastRegistrations.put(multicastId + subscriberParticipantId + providerParticipantId, registerWithParent);
        }
    }
}
Also used : WebSocketClientAddress(joynr.system.RoutingTypes.WebSocketClientAddress) BrowserAddress(joynr.system.RoutingTypes.BrowserAddress) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) WebSocketAddress(joynr.system.RoutingTypes.WebSocketAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress)

Example 2 with InProcessAddress

use of io.joynr.messaging.inprocess.InProcessAddress in project joynr by bmwcarit.

the class ProxyTest method setUp.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Before
public void setUp() throws Exception {
    navigationProxyCreatedSemaphore = new Semaphore(0);
    navigationProxyCreatedCallback = new ProxyCreatedCallback<NavigationProxy>() {

        @Override
        public void onProxyCreationFinished(NavigationProxy result) {
            navigationProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("Navigation proxy creation failed: " + error);
        }
    };
    testInterfaceProxyCreatedSemaphore = new Semaphore(0);
    testInterfaceProxyCreatedCallback = new ProxyCreatedCallback<TestInterface>() {

        @Override
        public void onProxyCreationFinished(TestInterface result) {
            testInterfaceProxyCreatedSemaphore.release();
        }

        @Override
        public void onProxyCreationError(JoynrRuntimeException error) {
            fail("TestInterface proxy creation failed: " + error);
        }
    };
    domain = "TestDomain";
    fromParticipantId = "ProxyTestFromParticipantId";
    toParticipantId = "ProxyTestToParticipantId";
    toDiscoveryEntry = new DiscoveryEntryWithMetaInfo(new Version(47, 11), domain, TestInterface.INTERFACE_NAME, toParticipantId, new ProviderQos(), System.currentTimeMillis(), System.currentTimeMillis() + ONE_MINUTE_IN_MS, "publicKeyId", true);
    toDiscoveryEntries = new HashSet<DiscoveryEntryWithMetaInfo>();
    toDiscoveryEntries.add(toDiscoveryEntry);
    MockitoAnnotations.initMocks(this);
    Injector injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            requestStaticInjection(RpcUtils.class);
            bind(ReplyCallerDirectory.class).toInstance(replyCallerDirectory);
            bind(RequestReplyManager.class).toInstance(requestReplyManager);
            bind(SubscriptionManager.class).toInstance(subscriptionManager);
            bind(MessageRouter.class).toInstance(messageRouter);
            bind(RoutingTable.class).toInstance(routingTable);
            install(new FactoryModuleBuilder().implement(ProxyInvocationHandler.class, ProxyInvocationHandlerImpl.class).build(ProxyInvocationHandlerFactory.class));
        }

        @Provides
        @Singleton
        @Named(SystemServicesSettings.PROPERTY_DISPATCHER_ADDRESS)
        Address getDispatcherAddress() {
            return new InProcessAddress();
        }
    });
    proxyBuilderFactory = new ProxyBuilderFactoryImpl(localDiscoveryAggregator, injector.getInstance(ProxyInvocationHandlerFactory.class), MAX_TTL_MS, DISCOVERY_TIMEOUT_MS, RETRY_INTERVAL_MS);
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            DiscoveryEntryWithMetaInfo[] fakeCapabilitiesResult = { toDiscoveryEntry };
            ((Callback) args[0]).resolve((Object) fakeCapabilitiesResult);
            return null;
        }
    }).when(localDiscoveryAggregator).lookup(Mockito.<Callback>any(), Mockito.<String[]>any(), Mockito.<String>any(), Mockito.<joynr.types.DiscoveryQos>any());
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            AttributeSubscribeInvocation request = (AttributeSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerAttributeSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(AttributeSubscribeInvocation.class));
    Mockito.doAnswer(new // TODO simulate resolve here ! subscription reply bastern ... handle subscriptionreply ausführen..
    Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            BroadcastSubscribeInvocation request = (BroadcastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerBroadcastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(BroadcastSubscribeInvocation.class));
    Mockito.doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            MulticastSubscribeInvocation request = (MulticastSubscribeInvocation) args[2];
            if (request.getSubscriptionId() == null) {
                request.setSubscriptionId(UUID.randomUUID().toString());
            }
            request.getFuture().resolve(request.getSubscriptionId());
            return null;
        }
    }).when(subscriptionManager).registerMulticastSubscription(any(String.class), eq(Sets.newHashSet(toDiscoveryEntry)), Mockito.any(MulticastSubscribeInvocation.class));
    discoveryQos = new DiscoveryQos(10000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
    messagingQos = new MessagingQos();
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field discoveryEntryVersionFilterField = ArbitratorFactory.class.getDeclaredField("discoveryEntryVersionFilter");
    discoveryEntryVersionFilterField.setAccessible(true);
    discoveryEntryVersionFilterField.set(ArbitratorFactory.class, discoveryEntryVersionFilter);
    doAnswer(new Answer<Set<DiscoveryEntryWithMetaInfo>>() {

        @Override
        public Set<DiscoveryEntryWithMetaInfo> answer(InvocationOnMock invocation) throws Throwable {
            return (Set<DiscoveryEntryWithMetaInfo>) invocation.getArguments()[1];
        }
    }).when(discoveryEntryVersionFilter).filter(Mockito.<Version>any(), Mockito.<Set<DiscoveryEntryWithMetaInfo>>any(), Mockito.<Map<String, Set<Version>>>any());
    Field schedulerField = ArbitratorFactory.class.getDeclaredField("scheduler");
    schedulerField.setAccessible(true);
    String name = "TEST.joynr.scheduler.arbitration.arbitratorRunnable";
    ThreadFactory joynrThreadFactory = new JoynrThreadFactory(name, true);
    scheduler = Executors.newSingleThreadScheduledExecutor(joynrThreadFactory);
    schedulerField.set(ArbitratorFactory.class, scheduler);
    Field shutdownNotifierField = ArbitratorFactory.class.getDeclaredField("shutdownNotifier");
    shutdownNotifierField.setAccessible(true);
    shutdownNotifierField.set(ArbitratorFactory.class, shutdownNotifier);
    ArbitratorFactory.start();
    verify(shutdownNotifier).registerForShutdown(any(ShutdownListener.class));
}
Also used : JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) ThreadFactory(java.util.concurrent.ThreadFactory) RpcUtils(io.joynr.dispatching.rpc.RpcUtils) Set(java.util.Set) HashSet(java.util.HashSet) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Semaphore(java.util.concurrent.Semaphore) Matchers.anyString(org.mockito.Matchers.anyString) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ShutdownListener(io.joynr.runtime.ShutdownListener) Field(java.lang.reflect.Field) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Injector(com.google.inject.Injector) JoynrThreadFactory(io.joynr.runtime.JoynrThreadFactory) NavigationProxy(joynr.vehicle.NavigationProxy) Named(com.google.inject.name.Named) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) Provides(com.google.inject.Provides) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) AbstractModule(com.google.inject.AbstractModule) Singleton(com.google.inject.Singleton) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ProviderQos(joynr.types.ProviderQos) Before(org.junit.Before)

Example 3 with InProcessAddress

use of io.joynr.messaging.inprocess.InProcessAddress 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);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProviderQos(joynr.types.ProviderQos)

Example 4 with InProcessAddress

use of io.joynr.messaging.inprocess.InProcessAddress in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioning method substituteInProcessAddressIfLocal.

private void substituteInProcessAddressIfLocal(ObjectMapper objectMapper, String localChannelId, GlobalDiscoveryEntry globalDiscoveryEntry, Address address) throws JsonProcessingException {
    if ((address instanceof ChannelAddress && localChannelId.equals(((ChannelAddress) address).getChannelId())) || (address instanceof MqttAddress && localChannelId.equals(((MqttAddress) address).getTopic()))) {
        Address localAddress = new InProcessAddress();
        globalDiscoveryEntry.setAddress(objectMapper.writeValueAsString(localAddress));
    }
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Example 5 with InProcessAddress

use of io.joynr.messaging.inprocess.InProcessAddress in project joynr by bmwcarit.

the class LegacyCapabilitiesProvisioning method createDiscoveryEntryFor.

private void createDiscoveryEntryFor(Class<?> interfaceClass, String interfaceName, String channelId, String participantId, String urlForAddress, String localChannelId, String domain) {
    boolean hasUrl = isPresent(urlForAddress);
    boolean hasParticipantId = isPresent(participantId);
    if (hasUrl && !hasParticipantId) {
        throw new IllegalArgumentException(format("When configuring the discovery directory or domain access controller " + "via properties, you must provide both a URL and a participant ID per service.%n" + "You provided the URL '%s' and the participant ID '%s' for the service %s.%n" + "Please complete the configuration and restart the application.", urlForAddress, participantId, interfaceName));
    }
    if (hasParticipantId && hasUrl && isPresent(channelId) && isPresent(domain)) {
        Address address;
        if (localChannelId.equals(channelId)) {
            address = new InProcessAddress();
        } else if (urlForAddress.startsWith("tcp") || urlForAddress.startsWith("mqtt")) {
            address = new MqttAddress(urlForAddress, channelId);
        } else {
            address = new ChannelAddress(urlForAddress, channelId);
        }
        DiscoveryEntry discoveryEntry = CapabilityUtils.newGlobalDiscoveryEntry(new Version(0, 1), domain, interfaceName, participantId, new ProviderQos(), System.currentTimeMillis(), Long.MAX_VALUE, "", address);
        logger.debug("Created legacy discovery entry: {}", discoveryEntry);
        legacyDiscoveryEntries.put(interfaceClass, discoveryEntry);
        legacyAddresses.put(interfaceClass, address);
    } else {
        logger.trace("Insufficient properties data to create entry for interface {}", interfaceName);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) InProcessAddress(io.joynr.messaging.inprocess.InProcessAddress) Version(joynr.types.Version) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) ProviderQos(joynr.types.ProviderQos) MqttAddress(joynr.system.RoutingTypes.MqttAddress)

Aggregations

InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)6 Address (joynr.system.RoutingTypes.Address)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4 ProviderQos (joynr.types.ProviderQos)3 Version (joynr.types.Version)3 MqttAddress (joynr.system.RoutingTypes.MqttAddress)2 DiscoveryEntry (joynr.types.DiscoveryEntry)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 Named (com.google.inject.name.Named)1 JoynrVersion (io.joynr.JoynrVersion)1 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)1 RpcUtils (io.joynr.dispatching.rpc.RpcUtils)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 MessagingQos (io.joynr.messaging.MessagingQos)1 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)1