Search in sources :

Example 11 with ClientFuture

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

the class AmqpSession method createSender.

/**
 * Create a sender instance using the given Target
 *
 * @param target the caller created and configured Target used to create the sender link.
 * @param senderId the sender ID to assign to the newly created Sender.
 * @param desiredCapabilities the capabilities that the caller wants the remote to support.
 * @param offeredCapabilities the capabilities that the caller wants the advertise support for.
 * @param properties the properties to send as part of the sender open.
 * @return a newly created sender that is ready for use.
 * @throws Exception if an error occurs while creating the receiver.
 */
public AmqpSender createSender(Target target, String senderId, Symbol[] desiredCapabilities, Symbol[] offeredCapabilities, Map<Symbol, Object> properties) throws Exception {
    checkClosed();
    final AmqpSender sender = new AmqpSender(AmqpSession.this, target, senderId);
    sender.setDesiredCapabilities(desiredCapabilities);
    sender.setOfferedCapabilities(offeredCapabilities);
    sender.setProperties(properties);
    final ClientFuture request = new ClientFuture();
    connection.getScheduler().execute(new Runnable() {

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

Example 12 with ClientFuture

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

the class AmqpSession method createReceiver.

/**
 * Create a receiver instance using the given address
 *
 * @param address
 *        the address to which the receiver will subscribe for its messages.
 * @param senderSettlementMode
 *        controls the desired settlement mode used by the remote Sender
 * @param receiverSettlementMode
 *        controls the settlement mode used by the created Receiver
 *
 * @return a newly created receiver that is ready for use.
 *
 * @throws Exception if an error occurs while creating the receiver.
 */
public AmqpReceiver createReceiver(String address, SenderSettleMode senderMode, ReceiverSettleMode receiverMode) throws Exception {
    checkClosed();
    final ClientFuture request = new ClientFuture();
    final AmqpReceiver receiver = new AmqpReceiver(AmqpSession.this, address, getNextReceiverId(), senderMode, receiverMode);
    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)

Example 13 with ClientFuture

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

the class AmqpReceiver method modified.

/**
 * Mark a message that was dispatched under the given Delivery instance as Modified.
 *
 * @param delivery
 *        the Delivery instance to mark modified.
 * @param deliveryFailed
 *        indicates that the delivery failed for some reason.
 * @param undeliverableHere
 *        marks the delivery as not being able to be process by link it was sent to.
 * @throws IOException
 *         if an error occurs while sending the reject.
 */
public void modified(final Delivery delivery, final Boolean deliveryFailed, final Boolean undeliverableHere) throws IOException {
    checkClosed();
    if (delivery == null) {
        throw new IllegalArgumentException("Delivery to reject cannot be null");
    }
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

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

Example 14 with ClientFuture

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

the class AmqpReceiver method detach.

/**
 * Detach 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 detach() throws IOException {
    if (closed.compareAndSet(false, true)) {
        final ClientFuture request = new ClientFuture();
        session.getScheduler().execute(new Runnable() {

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

Example 15 with ClientFuture

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

the class AmqpReceiver method pull.

/**
 * Request a remote peer send a Message to this client.
 *
 * {@literal timeout < 0} then it should remain open until a message is received.
 * {@literal timeout = 0} then it returns a message or null if none available
 * {@literal timeout > 0} then it should remain open for timeout amount of time.
 *
 * The timeout value when positive is given in milliseconds.
 *
 * @param timeout
 *        the amount of time to tell the remote peer to keep this pull request valid.
 * @param unit
 *        the unit of measure that the timeout represents.
 * @return the pulled AmqpMessage or null if none was pulled from the remote.
 * @throws IOException
 *         if an error occurs
 */
public AmqpMessage pull(final long timeout, final TimeUnit unit) throws IOException {
    checkClosed();
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            long timeoutMills = unit.toMillis(timeout);
            try {
                LOG.trace("Pull on Receiver {} with timeout = {}", getSubscriptionName(), timeoutMills);
                if (timeoutMills < 0) {
                    // Wait until message arrives. Just give credit if needed.
                    if (getEndpoint().getCredit() == 0) {
                        LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName());
                        getEndpoint().flow(1);
                    }
                    // Await the message arrival
                    pullRequest = request;
                } else if (timeoutMills == 0) {
                    // ensure we consume what is available and remove all credit.
                    if (getEndpoint().getCredit() == 0) {
                        LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName());
                        getEndpoint().flow(1);
                    }
                    // Drain immediately and wait for the message(s) to arrive,
                    // or a flow indicating removal of the remaining credit.
                    stop(request);
                } else if (timeoutMills > 0) {
                    // ensure we consume what is available and remove all credit.
                    if (getEndpoint().getCredit() == 0) {
                        LOG.trace("Receiver {} granting 1 additional credit for pull.", getSubscriptionName());
                        getEndpoint().flow(1);
                    }
                    // Wait for the timeout for the message(s) to arrive, then drain if required
                    // and wait for remaining message(s) to arrive or a flow indicating
                    // removal of the remaining credit.
                    stopOnSchedule(timeoutMills, request);
                }
                session.pumpToProtonTransport(request);
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
    return prefetch.poll();
}
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)

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