Search in sources :

Example 1 with Session

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

the class ClientExceptionSupport method convertToSessionClosedException.

/**
 * Given an ErrorCondition instance create a new Exception that best matches
 * the error type that indicates the session creation failed for some reason.
 *
 * @param errorCondition
 *      The ErrorCondition returned from the remote peer.
 *
 * @return a new Exception instance that best matches the ErrorCondition value.
 */
public static ClientSessionRemotelyClosedException convertToSessionClosedException(ErrorCondition errorCondition) {
    final ClientSessionRemotelyClosedException remoteError;
    if (errorCondition != null && errorCondition.getCondition() != null) {
        String message = extractErrorMessage(errorCondition);
        if (message == null) {
            message = "Session remotely closed without explanation";
        }
        remoteError = new ClientSessionRemotelyClosedException(message, new ClientErrorCondition(errorCondition));
    } else {
        remoteError = new ClientSessionRemotelyClosedException("Session remotely closed without explanation");
    }
    return remoteError;
}
Also used : ClientSessionRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientSessionRemotelyClosedException)

Example 2 with Session

use of org.apache.qpid.protonj2.client.Session 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 Session

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

the class ClientReceiverBuilder method receiver.

public ClientReceiver receiver(String address, ReceiverOptions receiverOptions) throws ClientException {
    final ReceiverOptions rcvOptions = receiverOptions != null ? receiverOptions : getDefaultReceiverOptions();
    final String receiverId = nextReceiverId();
    final Receiver protonReceiver = createReceiver(address, rcvOptions, receiverId);
    protonReceiver.setSource(createSource(address, rcvOptions));
    protonReceiver.setTarget(createTarget(address, rcvOptions));
    return new ClientReceiver(session, rcvOptions, receiverId, protonReceiver);
}
Also used : ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Receiver(org.apache.qpid.protonj2.engine.Receiver)

Example 4 with Session

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

the class ClientReceiverBuilder method durableReceiver.

public ClientReceiver durableReceiver(String address, String subscriptionName, ReceiverOptions receiverOptions) {
    final ReceiverOptions options = receiverOptions != null ? receiverOptions : getDefaultReceiverOptions();
    final String receiverId = nextReceiverId();
    options.linkName(subscriptionName);
    final Receiver protonReceiver = createReceiver(address, options, receiverId);
    protonReceiver.setSource(createDurableSource(address, options));
    protonReceiver.setTarget(createTarget(address, options));
    return new ClientReceiver(session, options, receiverId, protonReceiver);
}
Also used : ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Receiver(org.apache.qpid.protonj2.engine.Receiver)

Example 5 with Session

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

the class ClientReceiverBuilder method dynamicReceiver.

public ClientReceiver dynamicReceiver(Map<String, Object> dynamicNodeProperties, ReceiverOptions receiverOptions) throws ClientException {
    final ReceiverOptions options = receiverOptions != null ? receiverOptions : getDefaultReceiverOptions();
    final String receiverId = nextReceiverId();
    final Receiver protonReceiver = createReceiver(null, options, receiverId);
    protonReceiver.setSource(createSource(null, options));
    protonReceiver.setTarget(createTarget(null, options));
    // Configure the dynamic nature of the source now.
    protonReceiver.getSource().setDynamic(true);
    protonReceiver.getSource().setDynamicNodeProperties(ClientConversionSupport.toSymbolKeyedMap(dynamicNodeProperties));
    return new ClientReceiver(session, options, receiverId, protonReceiver);
}
Also used : ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Receiver(org.apache.qpid.protonj2.engine.Receiver)

Aggregations

Test (org.junit.jupiter.api.Test)306 Connection (org.apache.qpid.protonj2.engine.Connection)248 Engine (org.apache.qpid.protonj2.engine.Engine)247 ProtonTestConnector (org.apache.qpid.protonj2.test.driver.ProtonTestConnector)247 Session (org.apache.qpid.protonj2.engine.Session)241 Client (org.apache.qpid.protonj2.client.Client)180 Connection (org.apache.qpid.protonj2.client.Connection)180 URI (java.net.URI)178 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)178 Session (org.apache.qpid.protonj2.client.Session)167 Sender (org.apache.qpid.protonj2.engine.Sender)95 Receiver (org.apache.qpid.protonj2.engine.Receiver)88 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)85 AtomicReference (java.util.concurrent.atomic.AtomicReference)71 Sender (org.apache.qpid.protonj2.client.Sender)66 Receiver (org.apache.qpid.protonj2.client.Receiver)64 OutgoingDelivery (org.apache.qpid.protonj2.engine.OutgoingDelivery)52 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)45 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)37 ExecutionException (java.util.concurrent.ExecutionException)36