Search in sources :

Example 1 with ArbitrationResult

use of io.joynr.arbitration.ArbitrationResult in project joynr by bmwcarit.

the class ProxyBuilderDefaultImpl method createProxyInvocationHandler.

// Method called by both synchronous and asynchronous build() to create a ProxyInvocationHandler
private ProxyInvocationHandler createProxyInvocationHandler(final ProxyCreatedCallback<T> callback) {
    if (buildCalled) {
        throw new JoynrIllegalStateException("Proxy builder was already used to build a proxy. Please create a new proxy builder for each proxy.");
    }
    buildCalled = true;
    final ProxyInvocationHandler proxyInvocationHandler = proxyInvocationHandlerFactory.create(domains, interfaceName, proxyParticipantId, discoveryQos, messagingQos);
    // This order is necessary because the Arbitrator might return early
    // But if the listener is set after the ProxyInvocationHandler the
    // Arbitrator cannot return early
    arbitrator.setArbitrationListener(new ArbitrationCallback() {

        @Override
        public void onSuccess(ArbitrationResult arbitrationResult) {
            logger.debug("DISCOVERY proxy created for:{}", arbitrationResult.getDiscoveryEntries());
            proxyInvocationHandler.createConnector(arbitrationResult);
            callback.onProxyCreationFinished(proxy);
        }

        @Override
        public void onError(Throwable throwable) {
            JoynrRuntimeException reason;
            if (throwable instanceof JoynrRuntimeException) {
                reason = (JoynrRuntimeException) throwable;
            } else {
                reason = new JoynrRuntimeException(throwable);
            }
            proxyInvocationHandler.abort(reason);
            callback.onProxyCreationError(reason);
        }
    });
    return proxyInvocationHandler;
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) ArbitrationCallback(io.joynr.arbitration.ArbitrationCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 2 with ArbitrationResult

use of io.joynr.arbitration.ArbitrationResult in project joynr by bmwcarit.

the class ConnectorTest method createConnector.

private ConnectorInvocationHandler createConnector() {
    ArbitrationResult arbitrationResult = new ArbitrationResult();
    arbitrationResult.setDiscoveryEntries(toDiscoveryEntries);
    JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
    ConnectorFactory connectorFactory = new ConnectorFactory(joynrMessagingConnectorFactory, messageRouter, libJoynrMessagingAddress);
    ConnectorInvocationHandler connector = connectorFactory.create(fromParticipantId, arbitrationResult, qosSettings);
    return connector;
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult)

Example 3 with ArbitrationResult

use of io.joynr.arbitration.ArbitrationResult in project joynr by bmwcarit.

the class ProxyInvocationHandlerTest method callProxyInvocationHandlerSyncFromMultipleThreadsTest.

@Test(timeout = 3000)
public void callProxyInvocationHandlerSyncFromMultipleThreadsTest() throws Throwable {
    Future<?> call1 = threadPool.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            Object result = null;
            try {
                result = proxyInvocationHandler.invoke(TestSyncInterface.class.getDeclaredMethod("testMethod", new Class<?>[] {}), new Object[] {});
            } catch (Exception e) {
            }
            return result;
        }
    });
    Future<?> call2 = threadPool.submit(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            Object result = null;
            try {
                result = proxyInvocationHandler.invoke(TestSyncInterface.class.getDeclaredMethod("testMethod", new Class<?>[] {}), new Object[] {});
            } catch (Exception e) {
            }
            return result;
        }
    });
    ArbitrationResult arbitrationResult = new ArbitrationResult();
    DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
    discoveryEntry.setParticipantId("participantId");
    arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
    proxyInvocationHandler.createConnector(arbitrationResult);
    // if the bug that causes one thread to hang in arbitration exists, one
    // of these calls will never return, causing the test to timeout and fail
    call1.get();
    call2.get();
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) ApplicationException(joynr.exceptions.ApplicationException) Test(org.junit.Test)

Example 4 with ArbitrationResult

use of io.joynr.arbitration.ArbitrationResult in project joynr by bmwcarit.

the class ProxyInvocationHandlerTest method testPartitionsPassedToMulticastSubscription.

@Test
public void testPartitionsPassedToMulticastSubscription() throws NoSuchMethodException, ApplicationException {
    ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
    when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
    MyBroadcastSubscriptionListener broadcastSubscriptionListener = mock(MyBroadcastSubscriptionListener.class);
    SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
    Method subscribeMethod = MyBroadcastInterface.class.getMethod("subscribeToMyMulticast", MyBroadcastSubscriptionListener.class, SubscriptionQos.class, String[].class);
    Object[] args = new Object[] { broadcastSubscriptionListener, subscriptionQos, new String[] { "one", "two", "three" } };
    ArbitrationResult arbitrationResult = new ArbitrationResult();
    DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
    discoveryEntry.setParticipantId("participantId");
    arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
    proxyInvocationHandler.createConnector(arbitrationResult);
    proxyInvocationHandler.invoke(subscribeMethod, args);
    ArgumentCaptor<MulticastSubscribeInvocation> captor = ArgumentCaptor.forClass(MulticastSubscribeInvocation.class);
    verify(connectorInvocationHandler).executeSubscriptionMethod(captor.capture());
    MulticastSubscribeInvocation multicastSubscribeInvocation = captor.getValue();
    assertNotNull(multicastSubscribeInvocation);
    assertArrayEquals(new String[] { "one", "two", "three" }, multicastSubscribeInvocation.getPartitions());
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Example 5 with ArbitrationResult

use of io.joynr.arbitration.ArbitrationResult in project joynr by bmwcarit.

the class ProxyInvocationHandlerTest method testCallFireAndForgetMethod.

@Test
public void testCallFireAndForgetMethod() throws Throwable {
    ConnectorInvocationHandler connectorInvocationHandler = mock(ConnectorInvocationHandler.class);
    when(connectorFactory.create(Mockito.anyString(), Mockito.<ArbitrationResult>any(), Mockito.eq(messagingQos))).thenReturn(connectorInvocationHandler);
    Method fireAndForgetMethod = TestServiceSync.class.getMethod("callMe", new Class<?>[] { String.class });
    Object[] args = new Object[] { "test" };
    ArbitrationResult arbitrationResult = new ArbitrationResult();
    DiscoveryEntryWithMetaInfo discoveryEntry = new DiscoveryEntryWithMetaInfo();
    discoveryEntry.setParticipantId("participantId");
    arbitrationResult.setDiscoveryEntries(Sets.newHashSet(discoveryEntry));
    proxyInvocationHandler.createConnector(arbitrationResult);
    proxyInvocationHandler.invoke(fireAndForgetMethod, args);
    verify(connectorInvocationHandler).executeOneWayMethod(fireAndForgetMethod, args);
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) Method(java.lang.reflect.Method) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) Test(org.junit.Test)

Aggregations

ArbitrationResult (io.joynr.arbitration.ArbitrationResult)5 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)3 Test (org.junit.Test)3 Method (java.lang.reflect.Method)2 ArbitrationCallback (io.joynr.arbitration.ArbitrationCallback)1 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)1 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)1 ApplicationException (joynr.exceptions.ApplicationException)1