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();
}
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();
}
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();
}
}
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();
}
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;
}
Aggregations