Search in sources :

Example 11 with JoynrIllegalStateException

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;
}
Also used : RpcAsyncRequestReplyCaller(io.joynr.dispatching.rpc.RpcAsyncRequestReplyCaller) ExpiryDate(io.joynr.common.ExpiryDate) MethodMetaInformation(joynr.MethodMetaInformation) OneWayRequest(joynr.OneWayRequest) Request(joynr.Request) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 12 with JoynrIllegalStateException

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);
}
Also used : ProvidedBy(io.joynr.ProvidedBy) JoynrInterface(io.joynr.provider.JoynrInterface) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 13 with JoynrIllegalStateException

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);
}
Also used : Type(java.lang.reflect.Type) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) SubscriptionPublisher(io.joynr.provider.SubscriptionPublisher) SubscriptionPublisherInjection(io.joynr.provider.SubscriptionPublisherInjection) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 14 with JoynrIllegalStateException

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);
    }
}
Also used : WebSocketException(org.eclipse.jetty.websocket.api.WebSocketException) JoynrDelayMessageException(io.joynr.exceptions.JoynrDelayMessageException) WebSocketClientAddress(joynr.system.RoutingTypes.WebSocketClientAddress) WriteCallback(org.eclipse.jetty.websocket.api.WriteCallback) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Session(org.eclipse.jetty.websocket.api.Session)

Example 15 with JoynrIllegalStateException

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");
}
Also used : joynr.tests.testProxy(joynr.tests.testProxy) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) DiscoveryQos(io.joynr.arbitration.DiscoveryQos) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) ApplicationException(joynr.exceptions.ApplicationException) DiscoveryException(io.joynr.exceptions.DiscoveryException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)19 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)5 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)4 Query (javax.persistence.Query)4 OneWayRequest (joynr.OneWayRequest)3 ApplicationException (joynr.exceptions.ApplicationException)3 Test (org.junit.Test)3 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 ExpiryDate (io.joynr.common.ExpiryDate)2 DiscoveryException (io.joynr.exceptions.DiscoveryException)2 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)2 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Method (java.lang.reflect.Method)2 URISyntaxException (java.net.URISyntaxException)2 CheckForNull (javax.annotation.CheckForNull)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 MethodMetaInformation (joynr.MethodMetaInformation)2 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)2 Reply (joynr.Reply)2