Search in sources :

Example 31 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class RequestInterpreter method execute.

public void execute(final ProviderCallback<Reply> callback, RequestCaller requestCaller, final Request request) {
    Promise<? extends AbstractDeferred> promise;
    logger.debug("execute request on provider: {}", request);
    try {
        promise = (Promise<?>) invokeMethod(requestCaller, request);
    } catch (MethodInvocationException | ProviderRuntimeException e) {
        logger.warn("execute request on provider failed with exception: {}, request: {}", e, request);
        callback.onFailure(e);
        return;
    } catch (Exception e) {
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
        MethodInvocationException methodInvocationException = new MethodInvocationException(e, new Version(joynrVersion.major(), joynrVersion.minor()));
        logger.warn("execute request on provider failed with exception: {}, request: {}", methodInvocationException, request);
        callback.onFailure(methodInvocationException);
        return;
    }
    promise.then(new PromiseListener() {

        @Override
        public void onRejection(JoynrException error) {
            logger.debug("execute request on provider onRejection: {}, request: {}", error, request);
            callback.onFailure(error);
        }

        @Override
        public void onFulfillment(Object... values) {
            logger.debug("execute request on provider onFulfillment: {}, request: {}", values, request);
            callback.onSuccess(createReply(request, values));
        }
    });
}
Also used : JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) PromiseListener(io.joynr.provider.PromiseListener) JoynrException(io.joynr.exceptions.JoynrException) MethodInvocationException(joynr.exceptions.MethodInvocationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) MethodInvocationException(joynr.exceptions.MethodInvocationException) JoynrException(io.joynr.exceptions.JoynrException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException)

Example 32 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class RequestInterpreter method ensureMethodMetaInformationPresent.

private void ensureMethodMetaInformationPresent(RequestCaller requestCaller, OneWayRequest request, MethodSignature methodSignature) {
    try {
        if (!methodSignatureToMethodMap.containsKey(methodSignature)) {
            Method method;
            method = ReflectionUtils.findMethodByParamTypeNames(methodSignature.getRequestCaller().getProxy().getClass(), methodSignature.getMethodName(), methodSignature.getParameterTypeNames());
            methodSignatureToMethodMap.putIfAbsent(methodSignature, method);
        }
    } catch (NoSuchMethodException e) {
        logger.error("RequestInterpreter: Received an RPC invocation for a non existing method" + request, e);
        JoynrVersion joynrVersion = AnnotationUtil.getAnnotation(requestCaller.getProxy().getClass(), JoynrVersion.class);
        throw new MethodInvocationException(e.toString(), new Version(joynrVersion.major(), joynrVersion.minor()));
    }
}
Also used : JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Method(java.lang.reflect.Method) MethodInvocationException(joynr.exceptions.MethodInvocationException)

Example 33 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class VersionUtil method getVersionFromAnnotation.

public static Version getVersionFromAnnotation(Class<?> annotatedClass) {
    JoynrVersion versionAnnotation = AnnotationUtil.getAnnotation(annotatedClass, JoynrVersion.class);
    if (versionAnnotation == null) {
        throw new IllegalStateException("No @JoynrVersion found on " + annotatedClass);
    }
    Version version = new Version(versionAnnotation.major(), versionAnnotation.minor());
    logger.trace("Created version {} for interface class {}", version, annotatedClass);
    return version;
}
Also used : JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version)

Example 34 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class SerializationTest method serializeAndDeserializeGlobalDiscoveryEntryTest.

@Test
public void serializeAndDeserializeGlobalDiscoveryEntryTest() throws Exception {
    ProviderQos qos = new ProviderQos();
    String channelAddress = "channelId";
    final GlobalDiscoveryEntry[] capInfos = { new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", qos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddress) };
    String writeValueAsString = null;
    writeValueAsString = objectMapper.writeValueAsString(capInfos);
    System.err.println(writeValueAsString);
    assertTrue(writeValueAsString.startsWith("[{\"_typeName\":\"joynr.types.GlobalDiscoveryEntry\""));
    GlobalDiscoveryEntry[] readValue = objectMapper.readValue(writeValueAsString, GlobalDiscoveryEntry[].class);
    assertArrayEquals(capInfos, readValue);
    GlobalDiscoveryEntry globalDiscoveryEntry = new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", qos, System.currentTimeMillis(), expiryDateMs, publicKeyId, channelAddress);
    writeValueAsString = objectMapper.writeValueAsString(globalDiscoveryEntry);
    System.err.println(writeValueAsString);
    GlobalDiscoveryEntry readCapInfo = objectMapper.readValue(writeValueAsString, GlobalDiscoveryEntry.class);
    assertEquals(globalDiscoveryEntry, readCapInfo);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Example 35 with Version

use of joynr.types.Version in project joynr by bmwcarit.

the class SerializationTest method serializeReplyWithCapabilityInfoArray.

@Test
public void serializeReplyWithCapabilityInfoArray() throws JsonGenerationException, JsonMappingException, IOException {
    Object response = new GlobalDiscoveryEntry[] { new GlobalDiscoveryEntry(new Version(47, 11), "domain", "interface", "participantId", new ProviderQos(), System.currentTimeMillis(), expiryDateMs, publicKeyId, "channelId") };
    Reply reply = new Reply(UUID.randomUUID().toString(), response);
    String writeValueAsString = objectMapper.writeValueAsString(reply);
    Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
    GlobalDiscoveryEntry[] convertValue = objectMapper.convertValue(receivedReply.getResponse()[0], GlobalDiscoveryEntry[].class);
    Assert.assertArrayEquals((GlobalDiscoveryEntry[]) reply.getResponse()[0], convertValue);
    ComplexTestType2[] complexTestType2Array = { new ComplexTestType2(3, 4), new ComplexTestType2(5, 6) };
    ArrayList<ComplexTestType2> customListParam2List = new ArrayList<ComplexTestType2>();
    customListParam2List.add(new ComplexTestType2(3, 4));
    customListParam2List.add(new ComplexTestType2(5, 6));
    ComplexTestType2[] convertValue2 = objectMapper.convertValue(customListParam2List, ComplexTestType2[].class);
    Assert.assertArrayEquals(complexTestType2Array, convertValue2);
}
Also used : Version(joynr.types.Version) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ArrayList(java.util.ArrayList) Reply(joynr.Reply) ComplexTestType2(joynr.tests.testTypes.ComplexTestType2) ProviderQos(joynr.types.ProviderQos) Test(org.junit.Test)

Aggregations

Version (joynr.types.Version)65 Test (org.junit.Test)47 ProviderQos (joynr.types.ProviderQos)43 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)29 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)24 DiscoveryEntry (joynr.types.DiscoveryEntry)22 ArrayList (java.util.ArrayList)13 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)13 Matchers.anyString (org.mockito.Matchers.anyString)12 Callback (io.joynr.proxy.Callback)11 HashSet (java.util.HashSet)11 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 JoynrVersion (io.joynr.JoynrVersion)9 Address (joynr.system.RoutingTypes.Address)9 HashMap (java.util.HashMap)8 MqttAddress (joynr.system.RoutingTypes.MqttAddress)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 Set (java.util.Set)7 DeferredVoid (io.joynr.provider.DeferredVoid)6