use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.
the class IltProvider method setAttributeBaseStruct.
@Override
public Promise<DeferredVoid> setAttributeBaseStruct(BaseStruct attributeBaseStruct) {
DeferredVoid deferred = new DeferredVoid();
this.attributeBaseStruct = attributeBaseStruct;
attributeBaseStructChanged(attributeBaseStruct);
deferred.resolve();
return new Promise<DeferredVoid>(deferred);
}
use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.
the class IltProvider method methodWithoutParameters.
/*
* methodWithoutParameters
*
* no output possible, but may reject instead
*/
@Override
public Promise<DeferredVoid> methodWithoutParameters() {
logger.warn("*******************************************");
logger.warn("* IltProvider.methodWithoutParameters called");
logger.warn("*******************************************");
DeferredVoid deferred = new DeferredVoid();
deferred.resolve();
return new Promise<DeferredVoid>(deferred);
}
use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.
the class ProviderWrapper method createAndResolveOrRejectDeferred.
@SuppressWarnings("unchecked")
private AbstractDeferred createAndResolveOrRejectDeferred(Method method, Object result, JoynrException joynrException) {
AbstractDeferred deferred;
if (result == null && method.getReturnType().equals(Void.class)) {
deferred = new DeferredVoid();
if (joynrException == null) {
((DeferredVoid) deferred).resolve();
}
} else {
if (result instanceof MultiReturnValuesContainer) {
deferred = new MultiValueDeferred();
if (joynrException == null) {
((MultiValueDeferred) deferred).resolve(((MultiReturnValuesContainer) result).getValues());
}
} else {
deferred = new Deferred<Object>();
if (joynrException == null) {
((Deferred<Object>) deferred).resolve(result);
}
}
}
if (joynrException != null) {
LOG.debug("Provider method invocation resulted in provider runtime exception - rejecting the deferred {} with {}", deferred, joynrException);
if (joynrException instanceof ApplicationException) {
try {
Method rejectMethod = AbstractDeferred.class.getDeclaredMethod("reject", new Class[] { JoynrException.class });
rejectMethod.setAccessible(true);
rejectMethod.invoke(deferred, new Object[] { joynrException });
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
LOG.warn("Unable to set {} as rejection reason on {}. Wrapping in ProviderRuntimeException instead.", joynrException, deferred);
deferred.reject(new ProviderRuntimeException(((ApplicationException) joynrException).getMessage()));
}
} else if (joynrException instanceof ProviderRuntimeException) {
deferred.reject((ProviderRuntimeException) joynrException);
}
}
return deferred;
}
use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.
the class RoutingProviderImpl method resolvedDeferred.
private Promise<DeferredVoid> resolvedDeferred() {
final DeferredVoid deferred = new DeferredVoid();
deferred.resolve();
return new Promise<>(deferred);
}
use of io.joynr.provider.DeferredVoid in project joynr by bmwcarit.
the class RpcStubbingTest method setUp.
@Before
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "NPE in test would fail test")
public void setUp() throws JoynrCommunicationException, JoynrSendBufferFullException, JsonGenerationException, JsonMappingException, IOException, JoynrMessageNotSentException {
Deferred<GpsLocation> deferredGpsLocation = new Deferred<GpsLocation>();
deferredGpsLocation.resolve(gpsValue);
when(testMock.returnsGpsLocation()).thenReturn(new Promise<Deferred<GpsLocation>>(deferredGpsLocation));
Deferred<List<GpsLocation>> deferredGpsLocationList = new Deferred<List<GpsLocation>>();
deferredGpsLocationList.resolve(gpsList);
when(testMock.returnsGpsLocationList()).thenReturn(new Promise<Deferred<List<GpsLocation>>>(deferredGpsLocationList));
DeferredVoid deferredVoid = new DeferredVoid();
deferredVoid.resolve();
when(testMock.noParamsNoReturnValue()).thenReturn(new Promise<DeferredVoid>(deferredVoid));
when(testMock.takesTwoSimpleParams(any(Integer.class), any(String.class))).thenReturn(new Promise<DeferredVoid>(deferredVoid));
fromParticipantId = UUID.randomUUID().toString();
toParticipantId = UUID.randomUUID().toString();
toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
toDiscoveryEntry.setParticipantId(toParticipantId);
// required to inject static members of JoynMessagingConnectorFactory
injector = Guice.createInjector(new JoynrPropertiesModule(PropertyLoader.loadProperties(MessagingPropertyKeys.DEFAULT_MESSAGING_PROPERTIES_FILE)), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
requestStaticInjection(RpcUtils.class);
install(new JoynrMessageScopeModule());
MapBinder<Class<? extends Address>, AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>> messagingStubFactory;
messagingStubFactory = MapBinder.newMapBinder(binder(), new TypeLiteral<Class<? extends Address>>() {
}, new TypeLiteral<AbstractMiddlewareMessagingStubFactory<? extends IMessagingStub, ? extends Address>>() {
}, Names.named(MessagingStubFactory.MIDDLEWARE_MESSAGING_STUB_FACTORIES));
messagingStubFactory.addBinding(InProcessAddress.class).to(InProcessMessagingStubFactory.class);
}
});
final RequestInterpreter requestInterpreter = injector.getInstance(RequestInterpreter.class);
final RequestCallerFactory requestCallerFactory = injector.getInstance(RequestCallerFactory.class);
when(requestReplyManager.sendSyncRequest(eq(fromParticipantId), eq(toDiscoveryEntry), any(Request.class), any(SynchronizedReplyCaller.class), eq(messagingQos))).thenAnswer(new Answer<Reply>() {
@Override
public Reply answer(InvocationOnMock invocation) throws Throwable {
RequestCaller requestCaller = requestCallerFactory.create(testMock);
Object[] args = invocation.getArguments();
Request request = null;
for (Object arg : args) {
if (arg instanceof Request) {
request = (Request) arg;
break;
}
}
final Future<Reply> future = new Future<Reply>();
ProviderCallback<Reply> callback = new ProviderCallback<Reply>() {
@Override
public void onSuccess(Reply result) {
future.onSuccess(result);
}
@Override
public void onFailure(JoynrException error) {
future.onFailure(error);
}
};
requestInterpreter.execute(callback, requestCaller, request);
return future.get();
}
});
JoynrMessagingConnectorFactory joynrMessagingConnectorFactory = new JoynrMessagingConnectorFactory(requestReplyManager, replyCallerDirectory, subscriptionManager);
connector = joynrMessagingConnectorFactory.create(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), messagingQos);
}
Aggregations