Search in sources :

Example 6 with JoynrIllegalStateException

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

the class ProxyBuilderDefaultImpl method createProxyInvocationHandler.

// Method called by both synchronous and asynchronous build() to create a ProxyInvocationHandler
private ProxyInvocationHandler createProxyInvocationHandler(final ProxyCreatedCallback<T> callback) {
    if (buildCalled) {
        throw new JoynrIllegalStateException("Proxy builder was already used to build a proxy. Please create a new proxy builder for each proxy.");
    }
    buildCalled = true;
    final ProxyInvocationHandler proxyInvocationHandler = proxyInvocationHandlerFactory.create(domains, interfaceName, proxyParticipantId, discoveryQos, messagingQos);
    // This order is necessary because the Arbitrator might return early
    // But if the listener is set after the ProxyInvocationHandler the
    // Arbitrator cannot return early
    arbitrator.setArbitrationListener(new ArbitrationCallback() {

        @Override
        public void onSuccess(ArbitrationResult arbitrationResult) {
            logger.debug("DISCOVERY proxy created for:{}", arbitrationResult.getDiscoveryEntries());
            proxyInvocationHandler.createConnector(arbitrationResult);
            callback.onProxyCreationFinished(proxy);
        }

        @Override
        public void onError(Throwable throwable) {
            JoynrRuntimeException reason;
            if (throwable instanceof JoynrRuntimeException) {
                reason = (JoynrRuntimeException) throwable;
            } else {
                reason = new JoynrRuntimeException(throwable);
            }
            proxyInvocationHandler.abort(reason);
            callback.onProxyCreationError(reason);
        }
    });
    return proxyInvocationHandler;
}
Also used : ArbitrationResult(io.joynr.arbitration.ArbitrationResult) ArbitrationCallback(io.joynr.arbitration.ArbitrationCallback) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 7 with JoynrIllegalStateException

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

the class ConnectorTest method subscriptionMethodCallWithNoExpiryDate.

@Test
public void subscriptionMethodCallWithNoExpiryDate() throws JoynrIllegalStateException {
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    try {
        Future<String> future = new Future<String>();
        String subscriptionId = "subscriptionId";
        PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
        subscriptionQos.setPeriodMs(1000).setExpiryDateMs(0).setAlertAfterIntervalMs(1000);
        AttributeSubscriptionListener<GpsPosition> listener = new AttributeSubscriptionAdapter<GpsPosition>();
        Object[] args = new Object[] { listener, subscriptionQos, subscriptionId };
        Method method = LocalisationSubscriptionInterface.class.getDeclaredMethod("subscribeToGPSPosition", String.class, AttributeSubscriptionListener.class, SubscriptionQos.class);
        AttributeSubscribeInvocation attributeSubscription = new AttributeSubscribeInvocation(method, args, future);
        connector.executeSubscriptionMethod(attributeSubscription);
        verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(attributeSubscription));
    } catch (Exception e) {
        // This is what is supposed to happen -> no error handling
        fail("Calling a subscription method with no expiry date throws an exception.");
    }
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) GpsPosition(joynr.types.Localisation.GpsPosition) Method(java.lang.reflect.Method) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 8 with JoynrIllegalStateException

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

the class OwnerAccessControlEntryManager method findByUserIdDomainInterfaceNameAndOperation.

private OwnerAccessControlEntryEntity findByUserIdDomainInterfaceNameAndOperation(String userId, String domain, String interfaceName, String operation) {
    OwnerAccessControlEntryEntity entity = null;
    Query query = entityManager.createQuery("select oace from OwnerAccessControlEntryEntity oace where " + "oace.userId = :userId and oace.domain = :domain and oace.interfaceName = :interfaceName " + "and oace.operation = :operation", OwnerAccessControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    query.setParameter("operation", operation);
    List<OwnerAccessControlEntryEntity> resultList = query.getResultList();
    if (resultList.size() == 1) {
        entity = resultList.get(0);
    } else if (resultList.size() > 1) {
        throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s / %s", OwnerAccessControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName, operation));
    }
    return entity;
}
Also used : OwnerAccessControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerAccessControlEntryEntity) Query(javax.persistence.Query) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 9 with JoynrIllegalStateException

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

the class OwnerRegistrationControlEntryManager method findByUserIdDomainAndInterfaceName.

private OwnerRegistrationControlEntryEntity findByUserIdDomainAndInterfaceName(String userId, String domain, String interfaceName) {
    Query query = entityManager.createQuery("select orce from OwnerRegistrationControlEntryEntity orce " + "where orce.userId = :userId and orce.domain = :domain and orce.interfaceName = :interfaceName", OwnerRegistrationControlEntryEntity.class);
    query.setParameter("userId", userId);
    query.setParameter("domain", domain);
    query.setParameter("interfaceName", interfaceName);
    List<OwnerRegistrationControlEntryEntity> resultList = query.getResultList();
    OwnerRegistrationControlEntryEntity entity = null;
    if (resultList.size() == 1) {
        entity = resultList.get(0);
    } else if (resultList.size() > 1) {
        throw new JoynrIllegalStateException(format("Too many results found for %s for userId / domain / interfaceName / operation: %s / %s / %s", OwnerRegistrationControlEntryEntity.class.getSimpleName(), userId, domain, interfaceName));
    }
    return entity;
}
Also used : OwnerRegistrationControlEntryEntity(io.joynr.accesscontrol.global.jee.persistence.OwnerRegistrationControlEntryEntity) Query(javax.persistence.Query) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

Example 10 with JoynrIllegalStateException

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

the class JoynrMessagingConnectorInvocationHandler method executeOneWayMethod.

@Override
public void executeOneWayMethod(Method method, Object[] args) {
    // TODO does a method with 0 args pass in an empty args array, or null for args?
    if (method == null) {
        throw new IllegalArgumentException("Method cannot be null");
    }
    if (toDiscoveryEntries.isEmpty()) {
        throw new JoynrIllegalStateException("You must have at least one participant to be able to execute an oneWayMethod.");
    }
    logger.debug("ONEWAYREQUEST call proxy: method: {}, params: {}, proxy participantId: {}," + " provider discovery entries: {}", method.getName(), args, fromParticipantId, toDiscoveryEntries);
    OneWayRequest request = new OneWayRequest(method.getName(), args, method.getParameterTypes());
    requestReplyManager.sendOneWayRequest(fromParticipantId, toDiscoveryEntries, request, qosSettings);
}
Also used : OneWayRequest(joynr.OneWayRequest) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException)

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