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();
}
}
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");
}
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;
}
}
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);
}
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
}
}
Aggregations