use of io.joynr.arbitration.ArbitrationCallback 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.ArbitrationCallback in project joynr by bmwcarit.
the class ProxyBuilderDefaultImplTest method testMultiDomainNoCompatibleProviderFoundSetOnInvocationHandler.
@Test
public void testMultiDomainNoCompatibleProviderFoundSetOnInvocationHandler() throws Exception {
final Set<String> domains = Sets.newHashSet("domain-1", "domain-2");
setup(domains);
final ExecutorService executor = Executors.newSingleThreadExecutor();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(10L);
verify(arbitrator).setArbitrationListener(arbitrationCallbackCaptor.capture());
ArbitrationCallback callback = arbitrationCallbackCaptor.getValue();
Map<String, Set<Version>> versionsByDomain = new HashMap<>();
HashSet<Version> discoveredVersions = Sets.newHashSet(new Version(100, 100));
Map<String, NoCompatibleProviderFoundException> exceptionsByDomain = Maps.newHashMap();
for (String domain : domains) {
versionsByDomain.put(domain, discoveredVersions);
exceptionsByDomain.put(domain, new NoCompatibleProviderFoundException("interfaceName", new Version(1, 1), domain, discoveredVersions));
}
callback.onError(new MultiDomainNoCompatibleProviderFoundException(exceptionsByDomain));
return null;
}
});
return null;
}
}).when(arbitrator).scheduleArbitration();
subject.build(proxyCreatedCallback);
executor.shutdown();
executor.awaitTermination(100L, TimeUnit.MILLISECONDS);
verify(proxyCreatedCallback).onProxyCreationError(exceptionCaptor.capture());
JoynrRuntimeException capturedException = exceptionCaptor.getValue();
assertTrue(capturedException instanceof MultiDomainNoCompatibleProviderFoundException);
}
use of io.joynr.arbitration.ArbitrationCallback in project joynr by bmwcarit.
the class ProxyBuilderDefaultImplTest method testNoCompatibleProviderPassedToOnError.
@Test
public void testNoCompatibleProviderPassedToOnError() throws Exception {
final String domain = "domain1";
final Set<String> domains = Sets.newHashSet(domain);
setup(domains);
final ExecutorService executor = Executors.newSingleThreadExecutor();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(10L);
verify(arbitrator).setArbitrationListener(arbitrationCallbackCaptor.capture());
ArbitrationCallback callback = arbitrationCallbackCaptor.getValue();
Set<Version> discoveredVersions = Sets.newHashSet(new Version(100, 100));
callback.onError(new NoCompatibleProviderFoundException(TestInterface.INTERFACE_NAME, new Version(1, 1), domain, discoveredVersions));
return null;
}
});
return null;
}
}).when(arbitrator).scheduleArbitration();
subject.build(proxyCreatedCallback);
executor.shutdown();
executor.awaitTermination(100L, TimeUnit.MILLISECONDS);
verify(proxyCreatedCallback).onProxyCreationError(exceptionCaptor.capture());
JoynrRuntimeException capturedException = exceptionCaptor.getValue();
assertTrue(capturedException instanceof NoCompatibleProviderFoundException);
}
Aggregations