Search in sources :

Example 6 with ClientFuture

use of org.apache.activemq.transport.amqp.client.util.ClientFuture in project activemq-artemis by apache.

the class AmqpReceiver method release.

/**
 * Release a message that was dispatched under the given Delivery instance.
 *
 * @param delivery
 *        the Delivery instance to release.
 * @throws IOException
 *         if an error occurs while sending the release.
 */
public void release(final Delivery delivery) throws IOException {
    checkClosed();
    if (delivery == null) {
        throw new IllegalArgumentException("Delivery to release cannot be null");
    }
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            try {
                if (!delivery.isSettled()) {
                    delivery.disposition(Released.getInstance());
                    delivery.settle();
                    session.pumpToProtonTransport(request);
                }
                request.onSuccess();
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) JmsOperationTimedOutException(org.apache.qpid.jms.JmsOperationTimedOutException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 7 with ClientFuture

use of org.apache.activemq.transport.amqp.client.util.ClientFuture in project activemq-artemis by apache.

the class AmqpReceiver method drain.

/**
 * Attempts to drain a given amount of credit from the link.
 *
 * @param credit
 *        the amount of credit to drain.
 * @throws IOException
 *         if an error occurs while sending the drain.
 */
public void drain(final int credit) throws IOException {
    checkClosed();
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            try {
                getEndpoint().drain(credit);
                session.pumpToProtonTransport(request);
                request.onSuccess();
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) JmsOperationTimedOutException(org.apache.qpid.jms.JmsOperationTimedOutException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 8 with ClientFuture

use of org.apache.activemq.transport.amqp.client.util.ClientFuture in project activemq-artemis by apache.

the class AmqpReceiver method close.

/**
 * Close the receiver, a closed receiver will throw exceptions if any further send calls are
 * made.
 *
 * @throws IOException
 *         if an error occurs while closing the receiver.
 */
public void close() throws IOException {
    if (closed.compareAndSet(false, true)) {
        final ClientFuture request = new ClientFuture();
        session.getScheduler().execute(new Runnable() {

            @Override
            public void run() {
                checkClosed();
                close(request);
                session.pumpToProtonTransport(request);
            }
        });
        request.sync();
    }
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture)

Example 9 with ClientFuture

use of org.apache.activemq.transport.amqp.client.util.ClientFuture in project activemq-artemis by apache.

the class AmqpReceiver method reject.

/**
 * Reject a message that was dispatched under the given Delivery instance.
 *
 * @param delivery
 *        the Delivery instance to reject.
 * @throws IOException
 *         if an error occurs while sending the release.
 */
public void reject(final Delivery delivery) throws IOException {
    checkClosed();
    if (delivery == null) {
        throw new IllegalArgumentException("Delivery to release cannot be null");
    }
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            try {
                if (!delivery.isSettled()) {
                    delivery.disposition(new Rejected());
                    delivery.settle();
                    session.pumpToProtonTransport(request);
                }
                request.onSuccess();
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) JmsOperationTimedOutException(org.apache.qpid.jms.JmsOperationTimedOutException) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 10 with ClientFuture

use of org.apache.activemq.transport.amqp.client.util.ClientFuture in project activemq-artemis by apache.

the class AmqpSession method createDurableReceiver.

/**
 * Create a receiver instance using the given address that creates a durable subscription.
 *
 * @param address          the address to which the receiver will subscribe for its messages.
 * @param subscriptionName the name of the subscription that is being created.
 * @param selector         the JMS selector to use for the subscription
 * @param noLocal          should the subscription have messages from its connection filtered.
 * @return a newly created receiver that is ready for use.
 * @throws Exception if an error occurs while creating the receiver.
 */
public AmqpReceiver createDurableReceiver(String address, String subscriptionName, String selector, boolean noLocal) throws Exception {
    checkClosed();
    if (subscriptionName == null || subscriptionName.isEmpty()) {
        throw new IllegalArgumentException("subscription name must not be null or empty.");
    }
    final ClientFuture request = new ClientFuture();
    final AmqpReceiver receiver = new AmqpReceiver(AmqpSession.this, address, getNextReceiverId());
    receiver.setSubscriptionName(subscriptionName);
    receiver.setNoLocal(noLocal);
    if (selector != null && !selector.isEmpty()) {
        receiver.setSelector(selector);
    }
    connection.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            receiver.setStateInspector(getStateInspector());
            receiver.open(request);
            pumpToProtonTransport(request);
        }
    });
    request.sync();
    return receiver;
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture)

Aggregations

ClientFuture (org.apache.activemq.transport.amqp.client.util.ClientFuture)30 IOException (java.io.IOException)15 InvalidDestinationException (javax.jms.InvalidDestinationException)9 JmsOperationTimedOutException (org.apache.qpid.jms.JmsOperationTimedOutException)8 InactivityIOException (org.apache.activemq.transport.InactivityIOException)3 ClientFutureSynchronization (org.apache.activemq.transport.amqp.client.util.ClientFutureSynchronization)3 SaslAuthenticator (org.apache.activemq.transport.amqp.client.sasl.SaslAuthenticator)1 AsyncResult (org.apache.activemq.transport.amqp.client.util.AsyncResult)1 Binary (org.apache.qpid.proton.amqp.Binary)1 Modified (org.apache.qpid.proton.amqp.messaging.Modified)1 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)1 TransactionalState (org.apache.qpid.proton.amqp.transaction.TransactionalState)1 Sasl (org.apache.qpid.proton.engine.Sasl)1