use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class DispatcherImpl method handle.
private void handle(final SubscriptionPublication publication) {
try {
String subscriptionId = publication.getSubscriptionId();
if (subscriptionManager.isBroadcast(subscriptionId)) {
Class<?>[] broadcastOutParameterTypes = subscriptionManager.getUnicastPublicationOutParameterTypes(subscriptionId);
List<?> broadcastOutParamterValues = (List<?>) publication.getResponse();
Object[] broadcastValues = getPublicationValues(broadcastOutParameterTypes, broadcastOutParamterValues);
subscriptionManager.handleBroadcastPublication(subscriptionId, broadcastValues);
} else {
JoynrRuntimeException error = publication.getError();
if (error != null) {
subscriptionManager.handleAttributePublicationError(subscriptionId, error);
} else {
Class<?> receivedType = subscriptionManager.getAttributeType(subscriptionId);
Object attributeValue;
if (TypeReference.class.isAssignableFrom(receivedType)) {
TypeReference<?> typeRef = (TypeReference<?>) receivedType.newInstance();
attributeValue = objectMapper.convertValue(((List<?>) publication.getResponse()).get(0), typeRef);
} else {
attributeValue = objectMapper.convertValue(((List<?>) publication.getResponse()).get(0), receivedType);
}
subscriptionManager.handleAttributePublication(subscriptionId, attributeValue);
}
}
} catch (Exception e) {
logger.error("Error delivering publication: {} : {}", e.getClass(), e.getMessage());
}
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class ReplyCallerDirectory method addReplyCaller.
public void addReplyCaller(final String requestReplyId, final ReplyCaller replyCaller, final ExpiryDate roundTripTtlExpirationDate) {
logger.trace("putReplyCaller: " + requestReplyId + " expiryDate: " + roundTripTtlExpirationDate);
super.add(requestReplyId, replyCaller);
try {
cleanupScheduler.schedule(new Runnable() {
@Override
public void run() {
removeExpiredReplyCaller(requestReplyId);
}
}, roundTripTtlExpirationDate.getRelativeTtl(), TimeUnit.MILLISECONDS);
} catch (RejectedExecutionException e) {
if (shutdown) {
throw new JoynrShutdownException("shutdown in ReplyCallerDirectory");
}
throw new JoynrRuntimeException(e);
}
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class JoynrMessagingConnectorFactory method ensureMethodMetaInformationPresent.
public static MethodMetaInformation ensureMethodMetaInformationPresent(Method method) {
if (metaInformationMap.containsKey(method)) {
return metaInformationMap.get(method);
}
MethodMetaInformation metaInformation;
try {
metaInformation = new MethodMetaInformation(method);
} catch (JsonMappingException e) {
throw new JoynrRuntimeException(e);
}
MethodMetaInformation existingMetaInformation = metaInformationMap.putIfAbsent(method, metaInformation);
if (existingMetaInformation != null) {
// we only use putIfAbsent instead of .put, because putIfAbsent is threadsafe
logger.debug("There was already a metaInformation object for that method in the map.");
}
return metaInformation;
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class CapabilitiesRegistrarImpl method registerProvider.
/*
* (non-Javadoc)
*
* @see io.joynr.capabilities.CapabilitiesRegistrar# registerProvider(java.lang.String,
* io.joynr.provider.JoynrProvider, java.lang.Class)
*/
@Override
public Future<Void> registerProvider(final String domain, Object provider, ProviderQos providerQos) {
if (providerQos == null) {
throw new JoynrRuntimeException("providerQos == null. It must not be null");
}
ProviderContainer providerContainer = providerContainerFactory.create(provider);
String participantId = participantIdStorage.getProviderParticipantId(domain, providerContainer.getInterfaceName());
String defaultPublicKeyId = "";
DiscoveryEntry discoveryEntry = new DiscoveryEntry(getVersionFromAnnotation(provider.getClass()), domain, providerContainer.getInterfaceName(), participantId, providerQos, System.currentTimeMillis(), System.currentTimeMillis() + defaultExpiryTimeMs, defaultPublicKeyId);
final boolean isGloballyVisible = (discoveryEntry.getQos().getScope() == ProviderScope.GLOBAL);
messageRouter.addNextHop(participantId, libjoynrMessagingAddress, isGloballyVisible);
providerDirectory.add(participantId, providerContainer);
Callback<Void> callback = new Callback<Void>() {
@Override
public void onSuccess(@CheckForNull Void result) {
}
@Override
public void onFailure(JoynrRuntimeException runtimeException) {
logger.error("Unexpected Error while registering Provider:", runtimeException);
}
};
return localDiscoveryAggregator.add(callback, discoveryEntry);
}
use of io.joynr.exceptions.JoynrRuntimeException in project joynr by bmwcarit.
the class IltConsumerAsyncMethodTest method callMethodWithSingleByteBufferParameterAsync.
@Test
public void callMethodWithSingleByteBufferParameterAsync() {
LOG.info(name.getMethodName());
final Semaphore resultAvailable = new Semaphore(0);
try {
// setup input parameter
final Byte[] byteBufferArg = { -128, 0, 127 };
Callback<Byte[]> callback = new Callback<Byte[]>() {
@Override
public void onSuccess(Byte[] byteBufferOut) {
// check result
if (!java.util.Objects.deepEquals(byteBufferOut, byteBufferArg)) {
LOG.info(name.getMethodName() + " - invalid byteBufferOut from callback");
LOG.info(name.getMethodName() + " - FAILED");
methodWithSingleByteBufferParameterAsyncCallbackResult = false;
resultAvailable.release();
return;
}
methodWithSingleByteBufferParameterAsyncCallbackResult = true;
resultAvailable.release();
}
@Override
public void onFailure(JoynrRuntimeException error) {
methodWithSingleByteBufferParameterAsyncCallbackResult = 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.methodWithSingleByteBufferParameter(callback, byteBufferArg);
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", methodWithSingleByteBufferParameterAsyncCallbackResult);
} 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");
}
Aggregations