Search in sources :

Example 1 with ClientException

use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.

the class ClientLinkType method handleEngineShutdown.

protected final void handleEngineShutdown(Engine engine) {
    if (!isDynamic() && !session.getConnection().getEngine().isShutdown()) {
        recreateLinkForReconnect();
        open();
    } else {
        final Connection connection = engine.connection();
        final ClientException failureCause;
        if (connection.getRemoteCondition() != null) {
            failureCause = ClientExceptionSupport.convertToConnectionClosedException(connection.getRemoteCondition());
        } else if (engine.failureCause() != null) {
            failureCause = ClientExceptionSupport.convertToConnectionClosedException(engine.failureCause());
        } else if (!isClosed()) {
            failureCause = new ClientConnectionRemotelyClosedException("Remote closed without a specific error condition");
        } else {
            failureCause = null;
        }
        immediateLinkShutdown(failureCause);
    }
}
Also used : ClientConnectionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException) Connection(org.apache.qpid.protonj2.engine.Connection) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException)

Example 2 with ClientException

use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.

the class ClientLocalTransactionContext method handleTransactionDischargeFailed.

private void handleTransactionDischargeFailed(Transaction<TransactionController> transaction) {
    ClientFuture<Session> future = transaction.getAttachments().get(DISCHARGE_FUTURE_NAME);
    LOG.trace("Discharge of transaction:{} failed", transaction);
    ClientException cause = ClientExceptionSupport.convertToNonFatalException(transaction.getCondition());
    future.failed(new ClientTransactionRolledBackException(cause.getMessage(), cause));
}
Also used : ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Session(org.apache.qpid.protonj2.client.Session)

Example 3 with ClientException

use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.

the class ClientMessageSupport method convertFromOutsideMessage.

// ----- Internal Implementation
private static <E> ClientMessage<E> convertFromOutsideMessage(Message<E> source) throws ClientException {
    Header header = new Header();
    header.setDurable(source.durable());
    header.setPriority(source.priority());
    header.setTimeToLive(source.timeToLive());
    header.setFirstAcquirer(source.firstAcquirer());
    header.setDeliveryCount(source.deliveryCount());
    Properties properties = new Properties();
    properties.setMessageId(source.messageId());
    properties.setUserId(source.userId() != null ? new Binary(source.userId()) : null);
    properties.setTo(source.to());
    properties.setSubject(source.subject());
    properties.setReplyTo(source.replyTo());
    properties.setCorrelationId(source.correlationId());
    properties.setContentType(source.contentType());
    properties.setContentEncoding(source.contentEncoding());
    properties.setAbsoluteExpiryTime(source.absoluteExpiryTime());
    properties.setCreationTime(source.creationTime());
    properties.setGroupId(source.groupId());
    properties.setGroupSequence(source.groupSequence());
    properties.setReplyToGroupId(source.replyToGroupId());
    final MessageAnnotations messageAnnotations;
    if (source.hasAnnotations()) {
        messageAnnotations = new MessageAnnotations(new LinkedHashMap<>());
        source.forEachAnnotation((key, value) -> {
            messageAnnotations.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        messageAnnotations = null;
    }
    final ApplicationProperties applicationProperties;
    if (source.hasProperties()) {
        applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
        source.forEachProperty((key, value) -> {
            applicationProperties.getValue().put(key, value);
        });
    } else {
        applicationProperties = null;
    }
    final Footer footer;
    if (source.hasFooters()) {
        footer = new Footer(new LinkedHashMap<>());
        source.forEachFooter((key, value) -> {
            footer.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        footer = null;
    }
    ClientMessage<E> message = new ClientMessage<>(createSectionFromValue(source.body()));
    message.header(header);
    message.properties(properties);
    message.annotations(messageAnnotations);
    message.applicationProperties(applicationProperties);
    message.footer(footer);
    return message;
}
Also used : Header(org.apache.qpid.protonj2.types.messaging.Header) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) Footer(org.apache.qpid.protonj2.types.messaging.Footer) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Binary(org.apache.qpid.protonj2.types.Binary) Properties(org.apache.qpid.protonj2.types.messaging.Properties) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ClientException

use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.

the class ClientReceiver method drain.

@Override
public Future<Receiver> drain() throws ClientException {
    checkClosedOrFailed();
    final ClientFuture<Receiver> drainComplete = session.getFutureFactory().createFuture();
    executor.execute(() -> {
        if (notClosedOrFailed(drainComplete)) {
            if (protonReceiver.isDraining()) {
                drainComplete.failed(new ClientIllegalStateException("Receiver is already draining"));
                return;
            }
            try {
                if (protonReceiver.drain()) {
                    drainingFuture = drainComplete;
                    drainingTimeout = session.scheduleRequestTimeout(drainingFuture, options.drainTimeout(), () -> new ClientOperationTimedOutException("Timed out waiting for remote to respond to drain request"));
                } else {
                    drainComplete.complete(this);
                }
            } catch (Exception ex) {
                drainComplete.failed(ClientExceptionSupport.createNonFatalOrPassthrough(ex));
            }
        }
    });
    return drainComplete;
}
Also used : ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) Receiver(org.apache.qpid.protonj2.client.Receiver) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientResourceRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)

Example 5 with ClientException

use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.

the class ClientReceiver method tryReceive.

@Override
public Delivery tryReceive() throws ClientException {
    checkClosedOrFailed();
    Delivery delivery = messageQueue.dequeueNoWait();
    if (delivery != null) {
        if (options.autoAccept()) {
            delivery.disposition(org.apache.qpid.protonj2.client.DeliveryState.accepted(), options.autoSettle());
        } else {
            asyncReplenishCreditIfNeeded();
        }
    } else {
        checkClosedOrFailed();
    }
    return delivery;
}
Also used : Delivery(org.apache.qpid.protonj2.client.Delivery) IncomingDelivery(org.apache.qpid.protonj2.engine.IncomingDelivery)

Aggregations

ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)73 Client (org.apache.qpid.protonj2.client.Client)44 URI (java.net.URI)43 Connection (org.apache.qpid.protonj2.client.Connection)43 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)43 ExecutionException (java.util.concurrent.ExecutionException)33 Session (org.apache.qpid.protonj2.client.Session)27 Test (org.junit.jupiter.api.Test)24 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)18 Receiver (org.apache.qpid.protonj2.client.Receiver)13 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)12 ClientResourceRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientResourceRemotelyClosedException)10 TimeoutException (java.util.concurrent.TimeoutException)9 StreamReceiver (org.apache.qpid.protonj2.client.StreamReceiver)9 ClientConnectionRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException)9 StreamReceiverOptions (org.apache.qpid.protonj2.client.StreamReceiverOptions)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 ValueSource (org.junit.jupiter.params.provider.ValueSource)8 IOException (java.io.IOException)7 SessionOptions (org.apache.qpid.protonj2.client.SessionOptions)7