use of io.joynr.JoynrVersion in project joynr by bmwcarit.
the class AttributePollInterpreter method execute.
@Nonnull
public Promise<?> execute(ProviderContainer providerContainer, Method method) {
String interfaceName = providerContainer.getInterfaceName();
Object returnValueFromProvider = null;
try {
returnValueFromProvider = method.invoke(providerContainer.getProviderProxy());
} catch (IllegalAccessException e) {
String message = String.format("Method \"%s\" is not accessible on \"%s\" provider (exception: \"%s\").", method.getName(), interfaceName, e.toString());
logger.error(message, e);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
} catch (IllegalArgumentException e) {
String message = String.format("Provider of interface \"%s\" does not declare method \"%s\" (exception: \"%s\")", interfaceName, method.getName(), e.toString());
logger.error(message, e);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
String message = String.format("Calling method \"%s\" on \"%s\" provider threw an exception: \"%s\"", method.getName(), interfaceName, cause == null ? e.toString() : cause.toString());
logger.error(message, e);
throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
} catch (Exception e) {
String message = String.format("Calling method \"%s\" on \"%s\" provider threw an unexpected exception: \"%s\"", method.getName(), interfaceName, e.toString());
logger.error(message, e);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(providerContainer.getProviderProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(message, new Version(joynrVersion.major(), joynrVersion.minor()));
}
if (returnValueFromProvider == null) {
String message = String.format("Calling method \"%s\" on \"%s\" provider returned \"null\".", method.getName(), interfaceName);
logger.error(message);
throw new JoynrRuntimeException(message);
}
Promise<?> returnedPromiseFromProvider = null;
try {
returnedPromiseFromProvider = (Promise<?>) returnValueFromProvider;
} catch (ClassCastException e) {
String message = String.format("Calling method \"%s\" on \"%s\" provider did not return a promise.", method.getName(), interfaceName);
logger.error(message, e);
throw new JoynrRuntimeException(message, e);
}
return returnedPromiseFromProvider;
}
use of io.joynr.JoynrVersion in project joynr by bmwcarit.
the class CapabilitiesRegistrarTest method registerWithCapRegistrar.
@SuppressWarnings("unchecked")
@Test
public void registerWithCapRegistrar() {
JoynrVersion currentJoynrVersion = (JoynrVersion) TestProvider.class.getAnnotation(JoynrVersion.class);
Version testVersion = new Version(currentJoynrVersion.major(), currentJoynrVersion.minor());
when(providerContainer.getInterfaceName()).thenReturn(TestProvider.INTERFACE_NAME);
RequestCaller requestCallerMock = mock(RequestCaller.class);
when(providerContainer.getRequestCaller()).thenReturn(requestCallerMock);
when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
when(participantIdStorage.getProviderParticipantId(eq(domain), eq(TestProvider.INTERFACE_NAME))).thenReturn(participantId);
when(providerContainerFactory.create(testProvider)).thenReturn(providerContainer);
ArgumentCaptor<DiscoveryEntry> discoveryEntryCaptor = ArgumentCaptor.forClass(DiscoveryEntry.class);
registrar.registerProvider(domain, testProvider, providerQos);
verify(localDiscoveryAggregator).add(any(Callback.class), discoveryEntryCaptor.capture());
DiscoveryEntry actual = discoveryEntryCaptor.getValue();
Assert.assertEquals(actual.getProviderVersion(), testVersion);
Assert.assertEquals(actual.getDomain(), domain);
Assert.assertEquals(actual.getInterfaceName(), TestProvider.INTERFACE_NAME);
Assert.assertEquals(actual.getParticipantId(), participantId);
Assert.assertEquals(actual.getQos(), providerQos);
Assert.assertTrue((System.currentTimeMillis() - actual.getLastSeenDateMs()) < 5000);
Assert.assertTrue((actual.getExpiryDateMs() - expiryDateMs) < 5000);
Assert.assertEquals(actual.getPublicKeyId(), publicKeyId);
verify(providerDirectory).add(eq(participantId), eq(providerContainer));
}
use of io.joynr.JoynrVersion in project joynr by bmwcarit.
the class ProxyVersionTest method versionIsSetCorrectly.
@Test
public void versionIsSetCorrectly() {
int expectedMajorVersion = 47;
int expectedMinorVersion = 11;
JoynrVersion versionAnnotation = getAnnotation(testProxy.class, JoynrVersion.class);
assertNotNull(versionAnnotation);
assertEquals(expectedMajorVersion, versionAnnotation.major());
assertEquals(expectedMinorVersion, versionAnnotation.minor());
}
use of io.joynr.JoynrVersion in project joynr by bmwcarit.
the class ProxyVersionTest method defaultVersionIsSetCorrectly.
@Test
public void defaultVersionIsSetCorrectly() {
int expectedMajorVersion = 0;
int expectedMinorVersion = 0;
JoynrVersion versionAnnotation = getAnnotation(TestWithoutVersionProxy.class, JoynrVersion.class);
assertEquals(expectedMajorVersion, versionAnnotation.major());
assertEquals(expectedMinorVersion, versionAnnotation.minor());
}
use of io.joynr.JoynrVersion in project joynr by bmwcarit.
the class RequestInterpreter method invokeMethod.
public Object invokeMethod(RequestCaller requestCaller, OneWayRequest request) {
// A method is identified by its defining request caller, its name and the types of its arguments
MethodSignature methodSignature = new MethodSignature(requestCaller, request.getMethodName(), request.getParamDatatypes());
ensureMethodMetaInformationPresent(requestCaller, request, methodSignature);
Method method = methodSignatureToMethodMap.get(methodSignature);
Object[] params = null;
try {
if (method.getParameterTypes().length > 0) {
// method with parameters
params = request.getParams();
}
joynrMessageScope.activate();
setContext(requestCaller, request);
logger.trace("invoke provider method {}({})", method.getName(), params == null ? "" : params);
return requestCaller.invoke(method, params);
} catch (IllegalAccessException e) {
logger.error("RequestInterpreter: Received an RPC invocation for a non public method {}", request);
JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
throw new MethodInvocationException(e, new Version(joynrVersion.major(), joynrVersion.minor()));
} catch (InvocationTargetException e) {
logger.debug("invokeMethod error", e);
Throwable cause = e.getCause();
logger.error("RequestInterpreter: Could not perform an RPC invocation: {}", cause == null ? e.toString() : cause.getMessage());
throw new ProviderRuntimeException(cause == null ? e.toString() : cause.toString());
} finally {
requestCaller.removeContext();
joynrMessageScope.deactivate();
}
}
Aggregations