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