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;
}
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;
}
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();
}
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());
}
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);
}
Aggregations