Search in sources :

Example 1 with JoynrVersion

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;
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) Nonnull(javax.annotation.Nonnull)

Example 2 with JoynrVersion

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));
}
Also used : RequestCaller(io.joynr.dispatching.RequestCaller) DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Test(org.junit.Test)

Example 3 with JoynrVersion

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());
}
Also used : JoynrVersion(io.joynr.JoynrVersion) Test(org.junit.Test)

Example 4 with JoynrVersion

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());
}
Also used : JoynrVersion(io.joynr.JoynrVersion) Test(org.junit.Test)

Example 5 with JoynrVersion

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();
    }
}
Also used : MethodSignature(io.joynr.proxy.MethodSignature) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Method(java.lang.reflect.Method) MethodInvocationException(joynr.exceptions.MethodInvocationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Aggregations

JoynrVersion (io.joynr.JoynrVersion)10 Version (joynr.types.Version)6 Test (org.junit.Test)5 MethodInvocationException (joynr.exceptions.MethodInvocationException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)3 Method (java.lang.reflect.Method)2 RequestCaller (io.joynr.dispatching.RequestCaller)1 JoynrException (io.joynr.exceptions.JoynrException)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 PromiseListener (io.joynr.provider.PromiseListener)1 Callback (io.joynr.proxy.Callback)1 MethodSignature (io.joynr.proxy.MethodSignature)1 Nonnull (javax.annotation.Nonnull)1 DiscoveryEntry (joynr.types.DiscoveryEntry)1