use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class PostOfficeImpl method schedulePageDelivery.
/**
* This will kick a delivery async on the queue, so the queue may have a chance to depage messages
*
* @param tx
* @param entry
*/
private void schedulePageDelivery(Transaction tx, Map.Entry<SimpleString, RouteContextList> entry) {
if (tx != null) {
PageDelivery delivery = (PageDelivery) tx.getProperty(TransactionPropertyIndexes.PAGE_DELIVERY);
if (delivery == null) {
delivery = new PageDelivery();
tx.putProperty(TransactionPropertyIndexes.PAGE_DELIVERY, delivery);
tx.addOperation(delivery);
}
delivery.addQueues(entry.getValue().getDurableQueues());
delivery.addQueues(entry.getValue().getNonDurableQueues());
} else {
List<Queue> durableQueues = entry.getValue().getDurableQueues();
List<Queue> nonDurableQueues = entry.getValue().getNonDurableQueues();
final List<Queue> queues = new ArrayList<>(durableQueues.size() + nonDurableQueues.size());
queues.addAll(durableQueues);
queues.addAll(nonDurableQueues);
storageManager.afterCompleteOperations(new IOCallback() {
@Override
public void onError(int errorCode, String errorMessage) {
}
@Override
public void done() {
for (Queue queue : queues) {
// in case of paging, we need to kick asynchronous delivery to try delivering
queue.deliverAsync();
}
}
});
}
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class Redistributor method ackRedistribution.
private void ackRedistribution(final MessageReference reference, final Transaction tx) throws Exception {
reference.handled();
queue.acknowledge(tx, reference);
tx.commit();
storageManager.afterCompleteOperations(new IOCallback() {
@Override
public void onError(final int errorCode, final String errorMessage) {
ActiveMQServerLogger.LOGGER.ioErrorRedistributing(errorCode, errorMessage);
}
@Override
public void done() {
execPrompter();
}
});
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class AMQPSessionCallback method rejectMessage.
private void rejectMessage(Delivery delivery, Symbol errorCondition, String errorMessage) {
ErrorCondition condition = new ErrorCondition();
condition.setCondition(errorCondition);
condition.setDescription(errorMessage);
Rejected rejected = new Rejected();
rejected.setError(condition);
afterIO(new IOCallback() {
@Override
public void done() {
connection.lock();
try {
delivery.disposition(rejected);
delivery.settle();
} finally {
connection.unlock();
}
connection.flush();
}
@Override
public void onError(int errorCode, String errorMessage) {
}
});
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class AMQPSessionCallback method serverSend.
private void serverSend(final Transaction transaction, final Message message, final Delivery delivery, final Receiver receiver) throws Exception {
message.setConnectionID(receiver.getSession().getConnection().getRemoteContainer());
invokeIncoming((AMQPMessage) message, (ActiveMQProtonRemotingConnection) transportConnection.getProtocolConnection());
serverSession.send(transaction, message, false, false);
afterIO(new IOCallback() {
@Override
public void done() {
connection.lock();
try {
if (delivery.getRemoteState() instanceof TransactionalState) {
TransactionalState txAccepted = new TransactionalState();
txAccepted.setOutcome(Accepted.getInstance());
txAccepted.setTxnId(((TransactionalState) delivery.getRemoteState()).getTxnId());
delivery.disposition(txAccepted);
} else {
delivery.disposition(Accepted.getInstance());
}
delivery.settle();
} finally {
connection.unlock();
}
connection.flush();
}
@Override
public void onError(int errorCode, String errorMessage) {
connection.lock();
try {
receiver.setCondition(new ErrorCondition(AmqpError.ILLEGAL_STATE, errorCode + ":" + errorMessage));
connection.flush();
} finally {
connection.unlock();
}
}
});
}
use of org.apache.activemq.artemis.core.io.IOCallback in project activemq-artemis by apache.
the class ProtonTransactionHandler method onMessage.
@Override
public void onMessage(Delivery delivery) throws ActiveMQAMQPException {
final Receiver receiver;
try {
receiver = ((Receiver) delivery.getLink());
if (!delivery.isReadable()) {
return;
}
ByteBuffer buffer;
MessageImpl msg;
connection.lock();
try {
// transaction declare and discahrge operations.
if (receiver.getCredit() < amqpLowMark) {
receiver.flow(amqpCredit);
}
// the incoming request is to big just use a scratch buffer.
if (delivery.available() > DECODE_BUFFER.capacity()) {
buffer = ByteBuffer.allocate(delivery.available());
} else {
buffer = (ByteBuffer) DECODE_BUFFER.clear();
}
// Update Buffer for the next incoming command.
buffer.limit(receiver.recv(buffer.array(), buffer.arrayOffset(), buffer.capacity()));
receiver.advance();
msg = decodeMessage(buffer);
} finally {
connection.unlock();
}
Object action = ((AmqpValue) msg.getBody()).getValue();
if (action instanceof Declare) {
Binary txID = sessionSPI.newTransaction();
Declared declared = new Declared();
declared.setTxnId(txID);
IOCallback ioAction = new IOCallback() {
@Override
public void done() {
connection.lock();
try {
delivery.settle();
delivery.disposition(declared);
} finally {
connection.unlock();
connection.flush();
}
}
@Override
public void onError(int errorCode, String errorMessage) {
}
};
sessionSPI.afterIO(ioAction);
} else if (action instanceof Discharge) {
Discharge discharge = (Discharge) action;
Binary txID = discharge.getTxnId();
ProtonTransactionImpl tx = (ProtonTransactionImpl) sessionSPI.getTransaction(txID, true);
tx.discharge();
IOCallback ioAction = new IOCallback() {
@Override
public void done() {
connection.lock();
try {
delivery.settle();
delivery.disposition(new Accepted());
} finally {
connection.unlock();
connection.flush();
}
}
@Override
public void onError(int errorCode, String errorMessage) {
}
};
if (discharge.getFail()) {
sessionSPI.withinContext(() -> tx.rollback());
sessionSPI.afterIO(ioAction);
} else {
sessionSPI.withinContext(() -> tx.commit());
sessionSPI.afterIO(ioAction);
}
}
} catch (ActiveMQAMQPException amqpE) {
log.warn(amqpE.getMessage(), amqpE);
connection.lock();
try {
delivery.settle();
delivery.disposition(createRejected(amqpE.getAmqpError(), amqpE.getMessage()));
} finally {
connection.unlock();
}
connection.flush();
} catch (Throwable e) {
log.warn(e.getMessage(), e);
connection.lock();
try {
delivery.settle();
delivery.disposition(createRejected(Symbol.getSymbol("failed"), e.getMessage()));
} finally {
connection.unlock();
}
connection.flush();
}
}
Aggregations