Search in sources :

Example 36 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class Future method onSuccess.

/**
 * Resolves the future using the given result
 *
 * @param result
 *            the result of the asynchronous call
 */
public void onSuccess(T result) {
    try {
        statusLock.lock();
        value = result;
        status = new RequestStatus(RequestStatusCode.OK);
        statusLockChangedCondition.signalAll();
    } catch (Exception e) {
        status = new RequestStatus(RequestStatusCode.ERROR);
        exception = new JoynrRuntimeException(e);
    } finally {
        statusLock.unlock();
    }
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrException(io.joynr.exceptions.JoynrException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) JoynrWaitExpiredException(io.joynr.exceptions.JoynrWaitExpiredException) RequestStatus(io.joynr.dispatcher.rpc.RequestStatus)

Example 37 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class IltConsumerAsyncMethodTest method callMethodWithMultipleByteBufferParametersAsync.

@Test
public void callMethodWithMultipleByteBufferParametersAsync() {
    LOG.info(name.getMethodName());
    final Semaphore resultAvailable = new Semaphore(0);
    try {
        // setup input parameter
        final Byte[] byteBufferArg1 = { -5, 125 };
        final Byte[] byteBufferArg2 = { 78, 0 };
        Callback<Byte[]> callback = new Callback<Byte[]>() {

            @Override
            public void onSuccess(Byte[] byteBufferOut) {
                // check result
                if (!java.util.Objects.deepEquals(byteBufferOut, (Byte[]) ArrayUtils.addAll(byteBufferArg1, byteBufferArg2))) {
                    LOG.info(name.getMethodName() + " - invalid byteBufferOut from callback");
                    LOG.info(name.getMethodName() + " - FAILED");
                    methodWithMultipleByteBufferParametersAsyncCallbackResult = false;
                    resultAvailable.release();
                    return;
                }
                methodWithMultipleByteBufferParametersAsyncCallbackResult = true;
                resultAvailable.release();
            }

            @Override
            public void onFailure(JoynrRuntimeException error) {
                methodWithMultipleByteBufferParametersAsyncCallbackResult = false;
                if (error instanceof JoynrRuntimeException) {
                    LOG.info(name.getMethodName() + " - callback - caught exception " + ((JoynrRuntimeException) error).getMessage());
                } else {
                    LOG.info(name.getMethodName() + " - callback - caught exception");
                }
                LOG.info(name.getMethodName() + " - FAILED");
                resultAvailable.release();
            }
        };
        testInterfaceProxy.methodWithMultipleByteBufferParameters(callback, byteBufferArg1, byteBufferArg2);
        try {
            // wait for callback
            LOG.info(name.getMethodName() + " - about to wait for callback");
            Assert.assertTrue(name.getMethodName() + " - FAILED - callback not received in time", resultAvailable.tryAcquire(10, TimeUnit.SECONDS));
            // check result from callback
            LOG.info(name.getMethodName() + " - wait for callback is over");
            Assert.assertTrue(name.getMethodName() + " - FAILED - callback reported error", methodWithMultipleByteBufferParametersAsyncCallbackResult);
        } catch (InterruptedException | JoynrRuntimeException e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        }
    } catch (Exception e) {
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
    }
    LOG.info(name.getMethodName() + " - OK");
}
Also used : MethodWithMultipleStructParametersCallback(joynr.interlanguagetest.TestInterfaceAsync.MethodWithMultipleStructParametersCallback) Callback(io.joynr.proxy.Callback) Semaphore(java.util.concurrent.Semaphore) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ApplicationException(joynr.exceptions.ApplicationException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 38 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class IltConsumerAttributeSubscriptionTest method callSubscribeAttributeEnumeration.

@Test
public void callSubscribeAttributeEnumeration() {
    Future<String> subscriptionIdFuture;
    String subscriptionId;
    int minIntervalMs = 0;
    int maxIntervalMs = 10000;
    long validityMs = 60000;
    int alertAfterIntervalMs = 20000;
    int publicationTtlMs = 5000;
    OnChangeWithKeepAliveSubscriptionQos subscriptionQos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(minIntervalMs).setMaxIntervalMs(maxIntervalMs).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterIntervalMs).setPublicationTtlMs(publicationTtlMs);
    boolean result;
    LOG.info(name.getMethodName() + "");
    try {
        // must set the value before it can be retrieved again via subscription
        Enumeration enumerationArg = Enumeration.ENUM_0_VALUE_2;
        testInterfaceProxy.setAttributeEnumeration(enumerationArg);
        subscriptionIdFuture = testInterfaceProxy.subscribeToAttributeEnumeration(new AttributeSubscriptionAdapter<Enumeration>() {

            @Override
            public void onReceive(Enumeration value) {
                if (value == Enumeration.ENUM_0_VALUE_2) {
                    LOG.info(name.getMethodName() + " - callback - got publication with correct value");
                    subscribeAttributeEnumerationCallbackResult = true;
                } else {
                    subscribeAttributeEnumerationCallbackResult = false;
                    LOG.info(name.getMethodName() + " - callback - got publication with invalid value");
                }
                subscribeAttributeEnumerationCallbackDone = true;
            }

            @Override
            public void onError(JoynrRuntimeException error) {
                LOG.info(name.getMethodName() + " - callback - got unexpected exception");
                subscribeAttributeEnumerationCallbackResult = false;
                subscribeAttributeEnumerationCallbackDone = true;
            }
        }, subscriptionQos);
        subscriptionId = subscriptionIdFuture.get(10000);
        LOG.info(name.getMethodName() + " - subscription successful, subscriptionId = " + subscriptionId);
        // should have been called ahead anyway
        if (subscribeAttributeEnumerationCallbackDone == false) {
            LOG.info(name.getMethodName() + " - about to wait for a second for callback");
            Thread.sleep(1000);
            LOG.info(name.getMethodName() + " - wait for callback is over");
        } else {
            LOG.info(name.getMethodName() + " - callback already done");
        }
        if (subscribeAttributeEnumerationCallbackDone && subscribeAttributeEnumerationCallbackResult) {
            result = true;
        } else {
            fail(name.getMethodName() + " - FAILED - callback NOT done");
            result = false;
        }
        // try to unsubscribe in any case
        try {
            testInterfaceProxy.unsubscribeFromAttributeEnumeration(subscriptionId);
            LOG.info(name.getMethodName() + " - unsubscribe successful");
        } catch (Exception e) {
            fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
            result = false;
        }
        if (!result) {
            LOG.info(name.getMethodName() + " - FAILED");
        } else {
            LOG.info(name.getMethodName() + " - OK");
        }
        return;
    } catch (Exception e) {
        // also catches InterruptedException from Thread.sleep() call
        fail(name.getMethodName() + " - FAILED - caught unexpected exception: " + e.getMessage());
        return;
    }
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Enumeration(joynr.interlanguagetest.Enumeration) AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderRuntimeException(joynr.exceptions.ProviderRuntimeException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) Test(org.junit.Test)

Example 39 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class ConsumerApplication method run.

@SuppressWarnings("checkstyle:methodlength")
@Override
public void run() {
    DiscoveryQos discoveryQos = new DiscoveryQos();
    discoveryQos.setDiscoveryTimeoutMs(10000);
    discoveryQos.setCacheMaxAgeMs(Long.MAX_VALUE);
    discoveryQos.setArbitrationStrategy(ArbitrationStrategy.HighestPriority);
    ProxyBuilder<SystemIntegrationTestProxy> proxyBuilder = runtime.getProxyBuilder(providerDomain, SystemIntegrationTestProxy.class);
    boolean success = false;
    try {
        systemIntegrationTestProxy = proxyBuilder.setMessagingQos(new MessagingQos(10000)).setDiscoveryQos(discoveryQos).build(new ProxyCreatedCallback<SystemIntegrationTestProxy>() {

            @Override
            public void onProxyCreationFinished(SystemIntegrationTestProxy result) {
                LOG.info("proxy created");
                proxyCreated.release();
            }

            @Override
            public void onProxyCreationError(JoynrRuntimeException error) {
                LOG.error("error creating proxy");
            }
        });
        try {
            if (proxyCreated.tryAcquire(11000, TimeUnit.MILLISECONDS) == false) {
                throw new DiscoveryException("proxy not created in time");
            }
        } catch (InterruptedException e) {
            throw new DiscoveryException("proxy not created in time");
        }
        try {
            int addendA = 3333333;
            int addendB = 4444444;
            Integer sum = systemIntegrationTestProxy.add(addendA, addendB);
            if (sum != null && sum == (addendA + addendB)) {
                LOG.info("SIT RESULT success: Java consumer -> " + providerDomain + " (" + addendA + " + " + addendB + " =  " + sum + ")");
                success = true;
            }
        } catch (Exception e) {
        // fallthrough
        }
    } catch (DiscoveryException | JoynrCommunicationException e) {
    // fallthrough
    }
    if (!success) {
        LOG.info("SIT RESULT error: Java consumer -> " + providerDomain);
    }
    System.exit((success) ? 0 : 1);
}
Also used : SystemIntegrationTestProxy(joynr.test.SystemIntegrationTestProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) DiscoveryException(io.joynr.exceptions.DiscoveryException) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException) MessagingQos(io.joynr.messaging.MessagingQos) ProxyCreatedCallback(io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback) DiscoveryException(io.joynr.exceptions.DiscoveryException) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Example 40 with JoynrRuntimeException

use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.

the class ProviderApplication method run.

@Override
public void run() {
    provider = new Provider();
    ProviderQos providerQos = new ProviderQos();
    providerQos.setPriority(System.currentTimeMillis());
    // access to provider is needed inside the hook, so it must be added here
    Thread shutdownHook = new Thread() {

        @Override
        public void run() {
            LOG.info("executing shutdown hook");
            synchronized (this) {
                LOG.info("notifying any waiting thread from shutdown hook");
                notifyAll();
            }
            LOG.info("shutting down");
            if (provider != null) {
                try {
                    runtime.unregisterProvider(localDomain, provider);
                } catch (JoynrRuntimeException e) {
                    LOG.error("unable to unregister capabilities {}", e.getMessage());
                }
            }
            runtime.shutdown(false);
            LOG.info("shutdown completed");
        }
    };
    LOG.info("adding shutdown hook");
    Runtime.getRuntime().addShutdownHook(shutdownHook);
    runtime.registerProvider(localDomain, provider, providerQos);
    try {
        if (!runForever) {
            Thread.sleep(30000);
        } else {
            synchronized (shutdownHook) {
                shutdownHook.wait();
            }
        }
    } catch (Exception e) {
    // terminate execution by continuing
    }
}
Also used : JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) ProviderQos(joynr.types.ProviderQos) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException)

Aggregations

JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)76 Test (org.junit.Test)41 ApplicationException (joynr.exceptions.ApplicationException)18 joynr.tests.testProxy (joynr.tests.testProxy)16 MessagingQos (io.joynr.messaging.MessagingQos)14 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)13 Callback (io.joynr.proxy.Callback)9 Future (io.joynr.proxy.Future)9 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)9 IOException (java.io.IOException)8 Semaphore (java.util.concurrent.Semaphore)8 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 DiscoveryException (io.joynr.exceptions.DiscoveryException)7 JoynrException (io.joynr.exceptions.JoynrException)7 DeferredVoid (io.joynr.provider.DeferredVoid)7 HashSet (java.util.HashSet)7 ProviderQos (joynr.types.ProviderQos)7 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)5 ProxyCreatedCallback (io.joynr.proxy.ProxyBuilder.ProxyCreatedCallback)5