use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class JoynrMessagingConnectorInvocationHandler method executeAsyncMethod.
@SuppressWarnings("unchecked")
@Override
public Future<?> executeAsyncMethod(Method method, Object[] params, Future<?> future) {
if (method == null) {
throw new IllegalArgumentException("Method cannot be null");
}
if (toDiscoveryEntries.size() > 1) {
throw new JoynrIllegalStateException("You can't execute async methods for multiple participants.");
}
if (toDiscoveryEntries.isEmpty()) {
throw new JoynrIllegalStateException("You must have exactly one participant to be able to execute an async method.");
}
MethodMetaInformation methodMetaInformation = JoynrMessagingConnectorFactory.ensureMethodMetaInformationPresent(method);
if (methodMetaInformation.getCallbackAnnotation() == null) {
throw new JoynrIllegalStateException("All async methods need to have a annotated callback parameter.");
}
int callbackIndex = methodMetaInformation.getCallbackIndex();
ICallback callback = (ICallback) params[callbackIndex];
Object[] paramsWithoutCallback = new Object[params.length - 1];
copyArrayWithoutElement(params, paramsWithoutCallback, callbackIndex);
Class<?>[] paramDatatypes = method.getParameterTypes();
Class<?>[] paramDatatypesWithoutCallback = new Class<?>[paramDatatypes.length - 1];
copyArrayWithoutElement(paramDatatypes, paramDatatypesWithoutCallback, callbackIndex);
Request request = new Request(method.getName(), paramsWithoutCallback, paramDatatypesWithoutCallback);
String requestReplyId = request.getRequestReplyId();
@SuppressWarnings("rawtypes") RpcAsyncRequestReplyCaller<?> callbackWrappingReplyCaller = new RpcAsyncRequestReplyCaller(requestReplyId, callback, future, method, methodMetaInformation);
ExpiryDate expiryDate = DispatcherUtils.convertTtlToExpirationDate(qosSettings.getRoundTripTtl_ms());
replyCallerDirectory.addReplyCaller(requestReplyId, callbackWrappingReplyCaller, expiryDate);
requestReplyManager.sendRequest(fromParticipantId, toDiscoveryEntries.iterator().next(), request, qosSettings);
return future;
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class ParticipantIdKeyUtil method getProviderParticipantIdKey.
public static String getProviderParticipantIdKey(String domain, Class interfaceClass) {
Class annotatedInterface;
if (interfaceClass.getAnnotation(ProvidedBy.class) != null) {
annotatedInterface = ((ProvidedBy) interfaceClass.getAnnotation(ProvidedBy.class)).value();
} else {
annotatedInterface = interfaceClass;
}
JoynrInterface joynrInterface = (JoynrInterface) annotatedInterface.getAnnotation(JoynrInterface.class);
if (joynrInterface == null) {
throw new JoynrIllegalStateException("Class " + annotatedInterface + " not annotated with @JoynrInterface. Can't get interface name.");
}
String interfaceName = joynrInterface.name();
return getProviderParticipantIdKey(domain, interfaceName);
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class SubscriptionPublisherInjectionWrapper method createInvocationHandler.
public static SubscriptionPublisherInjectionWrapper createInvocationHandler(Bean<?> bean, BeanManager beanManager) {
logger.trace("Called with {} and {}", bean, beanManager);
SubscriptionPublisherProducer subscriptionPublisherProducer = getSubscriptionPublisherProducerReference(beanManager);
Class proxiedInterface = SubscriptionPublisherInjection.class;
Class subscriptionPublisherClass = null;
Class beanClass = bean.getBeanClass();
for (InjectionPoint injectionPoint : bean.getInjectionPoints()) {
if (!injectionPoint.getQualifiers().contains(SUBSCRIPTION_PUBLISHER_ANNOTATION_LITERAL)) {
continue;
}
Type baseType = injectionPoint.getAnnotated().getBaseType();
if (baseType instanceof Class && SubscriptionPublisher.class.isAssignableFrom((Class) baseType)) {
subscriptionPublisherClass = (Class) baseType;
break;
}
}
logger.debug("Found injector {} and publisher {} classes.", proxiedInterface, subscriptionPublisherClass);
if (subscriptionPublisherClass == null || proxiedInterface == null) {
throw new JoynrIllegalStateException("Cannot create subscription publisher injection wrapper proxy for bean which doesn't inject a concrete SubscriptionPublisher.");
}
return new SubscriptionPublisherInjectionWrapper(proxiedInterface, subscriptionPublisherClass, subscriptionPublisherProducer, beanClass);
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class WebSocketJettyServer method writeBytes.
@Override
public synchronized void writeBytes(Address toAddress, byte[] message, long timeout, TimeUnit unit, final SuccessAction successAction, final FailureAction failureAction) {
if (!(toAddress instanceof WebSocketClientAddress)) {
throw new JoynrIllegalStateException("Web Socket Server can only send to WebSocketClientAddresses");
}
WebSocketClientAddress toClientAddress = (WebSocketClientAddress) toAddress;
Session session = sessionMap.get(toClientAddress.getId());
if (session == null) {
// TODO We need a delay with invalidation of the stub
throw new JoynrDelayMessageException("no active session for WebSocketClientAddress: " + toClientAddress.getId());
}
try {
session.getRemote().sendBytes(ByteBuffer.wrap(message), new WriteCallback() {
@Override
public void writeSuccess() {
successAction.execute();
}
@Override
public void writeFailed(Throwable error) {
if (shutdown) {
return;
}
failureAction.execute(error);
}
});
} catch (WebSocketException e) {
// Jetty throws WebSocketException when expecting [OPEN or CONNECTED] but found a different state
// The client must reconnect, but the message can be queued in the mean time.
sessionMap.remove(toClientAddress.getId());
// TODO We need a delay with invalidation of the stub
throw new JoynrDelayMessageException(e.getMessage(), e);
}
}
use of io.joynr.exceptions.JoynrIllegalStateException in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method testSubscribeToNonExistentDomain.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH_EXCEPTION", justification = "NPE in test would fail test")
@SuppressWarnings("unchecked")
@Ignore
@Test
public void testSubscribeToNonExistentDomain() throws InterruptedException {
AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
testProxy proxyToNonexistentDomain = null;
try {
ProxyBuilder<testProxy> proxyBuilder;
String nonExistentDomain = UUID.randomUUID().toString() + "-domaindoesnotexist-end2end";
MessagingQos messagingQos = new MessagingQos(20000);
DiscoveryQos discoveryQos = new DiscoveryQos(50000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
proxyBuilder = consumerRuntime.getProxyBuilder(nonExistentDomain, testProxy.class);
proxyToNonexistentDomain = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
} catch (DiscoveryException e) {
logger.error(e.getMessage(), e);
} catch (JoynrIllegalStateException e) {
logger.error(e.getMessage(), e);
}
// This should not cause an exception
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(30000);
subscriptionQos.setAlertAfterIntervalMs(0);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxyToNonexistentDomain.subscribeToTestAttribute(integerListener, subscriptionQos);
Thread.sleep(4000);
try {
proxyToNonexistentDomain.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
} catch (JoynrRuntimeException | ApplicationException e) {
assertTrue(e.getMessage(), e != null);
}
getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Aggregations