Search in sources :

Example 16 with ClientFuture

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

the class AmqpReceiver method flow.

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

        @Override
        public void run() {
            checkClosed();
            try {
                getEndpoint().flow(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 17 with ClientFuture

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

the class AmqpReceiver method stop.

/**
 * Stops the receiver, using all link credit and waiting for in-flight messages to arrive.
 *
 * @throws IOException
 *         if an error occurs while sending the drain.
 */
public void stop() throws IOException {
    checkClosed();
    final ClientFuture request = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            checkClosed();
            try {
                stop(request);
                session.pumpToProtonTransport(request);
            } 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 18 with ClientFuture

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

the class AmqpSender method send.

/**
 * Sends the given message to this senders assigned address using the supplied transaction
 * ID.
 *
 * @param message
 *        the message to send.
 * @param txId
 *        the transaction ID to assign the outgoing send.
 * @throws IOException
 *         if an error occurs during the send.
 */
public void send(final AmqpMessage message, final AmqpTransactionId txId) throws IOException {
    checkClosed();
    final ClientFuture sendRequest = new ClientFuture();
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            try {
                doSend(message, sendRequest, txId);
                session.pumpToProtonTransport(sendRequest);
            } catch (Exception e) {
                sendRequest.onFailure(e);
                session.getConnection().fireClientException(e);
            }
        }
    });
    if (sendTimeout <= 0) {
        sendRequest.sync();
    } else {
        sendRequest.sync(sendTimeout, TimeUnit.MILLISECONDS);
    }
}
Also used : ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) InvalidDestinationException(javax.jms.InvalidDestinationException) IOException(java.io.IOException)

Example 19 with ClientFuture

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

the class AmqpSender method close.

/**
 * Close the sender, a closed sender will throw exceptions if any further send calls are
 * made.
 *
 * @throws IOException
 *         if an error occurs while closing the sender.
 */
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 20 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 address
 *
 * @param address
 *        the address to which the sender will produce its messages.
 * @param senderSettlementMode
 *        controls the settlement mode used by the created Sender
 * @param receiverSettlementMode
 *        controls the desired settlement mode used by the remote Receiver
 *
 * @return a newly created sender that is ready for use.
 *
 * @throws Exception if an error occurs while creating the sender.
 */
public AmqpSender createSender(final String address, final SenderSettleMode senderMode, ReceiverSettleMode receiverMode) throws Exception {
    checkClosed();
    final AmqpSender sender = new AmqpSender(AmqpSession.this, address, getNextSenderId(), senderMode, receiverMode);
    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)

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