Search in sources :

Example 26 with ClientFuture

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

the class AmqpSession method lookupSubscription.

/**
 * Create a receiver instance using the given address that creates a durable subscription.
 *
 * @param subscriptionName the name of the subscription that should be queried for on the remote..
 * @return a newly created receiver that is ready for use if the subscription exists.
 * @throws Exception if an error occurs while creating the receiver.
 */
public AmqpReceiver lookupSubscription(String subscriptionName) 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, (String) null, getNextReceiverId());
    receiver.setSubscriptionName(subscriptionName);
    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 27 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 presettle controls if the created sender produces message that have already been marked settled.
 * @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 sender.
 */
public AmqpSender createSender(final String address, boolean presettle, Symbol[] desiredCapabilities, Symbol[] offeredCapabilities, Map<Symbol, Object> properties) throws Exception {
    checkClosed();
    final AmqpSender sender = new AmqpSender(AmqpSession.this, address, getNextSenderId());
    sender.setPresettle(presettle);
    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 28 with ClientFuture

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

the class AmqpTransactionContext method rollback.

/**
 * Rollback any transacted work performed under the current transaction.
 *
 * @throws Exception if an error occurs during the rollback operation.
 */
public void rollback() throws Exception {
    if (transactionId == null) {
        throw new IllegalStateException("Rollback called with no active Transaction.");
    }
    preRollback();
    final ClientFuture request = new ClientFuture(new ClientFutureSynchronization() {

        @Override
        public void onPendingSuccess() {
            transactionId = null;
            postRollback();
        }

        @Override
        public void onPendingFailure(Throwable cause) {
            transactionId = null;
            postRollback();
        }
    });
    LOG.debug("Rollback on TX[{}] initiated", transactionId);
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            try {
                LOG.info("Attempting to roll back TX:[{}]", transactionId);
                coordinator.discharge(transactionId, request, false);
                session.pumpToProtonTransport(request);
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
}
Also used : ClientFutureSynchronization(org.apache.activemq.transport.amqp.client.util.ClientFutureSynchronization) ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) IOException(java.io.IOException)

Example 29 with ClientFuture

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

the class AmqpTransactionContext method commit.

/**
 * Commit this transaction which then ends the lifetime of the transacted operation.
 *
 * @throws Exception if an error occurs while performing the commit
 */
public void commit() throws Exception {
    if (transactionId == null) {
        throw new IllegalStateException("Commit called with no active Transaction.");
    }
    preCommit();
    final ClientFuture request = new ClientFuture(new ClientFutureSynchronization() {

        @Override
        public void onPendingSuccess() {
            transactionId = null;
            postCommit();
        }

        @Override
        public void onPendingFailure(Throwable cause) {
            transactionId = null;
            postCommit();
        }
    });
    LOG.debug("Commit on TX[{}] initiated", transactionId);
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            try {
                LOG.info("Attempting to commit TX:[{}]", transactionId);
                coordinator.discharge(transactionId, request, true);
                session.pumpToProtonTransport(request);
            } catch (Exception e) {
                request.onFailure(e);
            }
        }
    });
    request.sync();
}
Also used : ClientFutureSynchronization(org.apache.activemq.transport.amqp.client.util.ClientFutureSynchronization) ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) IOException(java.io.IOException)

Example 30 with ClientFuture

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

the class AmqpTransactionContext method begin.

/**
 * Begins a new transaction scoped to the target session.
 *
 * @throws Exception if an error occurs while starting the transaction.
 */
public void begin() throws Exception {
    if (transactionId != null) {
        throw new IOException("Begin called while a TX is still Active.");
    }
    final AmqpTransactionId txId = session.getConnection().getNextTransactionId();
    final ClientFuture request = new ClientFuture(new ClientFutureSynchronization() {

        @Override
        public void onPendingSuccess() {
            transactionId = txId;
        }

        @Override
        public void onPendingFailure(Throwable cause) {
            transactionId = null;
        }
    });
    LOG.info("Attempting to Begin TX:[{}]", txId);
    session.getScheduler().execute(new Runnable() {

        @Override
        public void run() {
            if (coordinator == null || coordinator.isClosed()) {
                LOG.info("Creating new Coordinator for TX:[{}]", txId);
                coordinator = new AmqpTransactionCoordinator(session);
                coordinator.open(new AsyncResult() {

                    @Override
                    public void onSuccess() {
                        try {
                            LOG.info("Attempting to declare TX:[{}]", txId);
                            coordinator.declare(txId, request);
                        } catch (Exception e) {
                            request.onFailure(e);
                        }
                    }

                    @Override
                    public void onFailure(Throwable result) {
                        request.onFailure(result);
                    }

                    @Override
                    public boolean isComplete() {
                        return request.isComplete();
                    }
                });
            } else {
                try {
                    LOG.info("Attempting to declare TX:[{}]", txId);
                    coordinator.declare(txId, request);
                } catch (Exception e) {
                    request.onFailure(e);
                }
            }
            session.pumpToProtonTransport(request);
        }
    });
    request.sync();
}
Also used : ClientFutureSynchronization(org.apache.activemq.transport.amqp.client.util.ClientFutureSynchronization) ClientFuture(org.apache.activemq.transport.amqp.client.util.ClientFuture) IOException(java.io.IOException) AsyncResult(org.apache.activemq.transport.amqp.client.util.AsyncResult) 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