use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ServerConsumerImpl method individualCancel.
@Override
public synchronized void individualCancel(final long messageID, boolean failed) throws Exception {
if (browseOnly) {
return;
}
MessageReference ref = removeReferenceByID(messageID);
if (ref == null) {
throw new IllegalStateException("Cannot find ref to ack " + messageID);
}
if (!failed) {
ref.decrementDeliveryCount();
}
ref.getQueue().cancel(ref, System.currentTimeMillis());
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ServerConsumerImpl method individualAcknowledge.
@Override
public synchronized void individualAcknowledge(Transaction tx, final long messageID) throws Exception {
if (browseOnly) {
return;
}
boolean startedTransaction = false;
if (logger.isTraceEnabled()) {
logger.trace("individualACK messageID=" + messageID);
}
if (tx == null) {
if (logger.isTraceEnabled()) {
logger.trace("individualACK starting new TX");
}
startedTransaction = true;
tx = new TransactionImpl(storageManager);
}
try {
MessageReference ref;
ref = removeReferenceByID(messageID);
if (logger.isTraceEnabled()) {
logger.trace("ACKing ref " + ref + " on tx= " + tx + ", consumer=" + this);
}
if (ref == null) {
ActiveMQIllegalStateException ils = new ActiveMQIllegalStateException("Cannot find ref to ack " + messageID);
tx.markAsRollbackOnly(ils);
throw ils;
}
ref.acknowledge(tx);
acks++;
if (startedTransaction) {
tx.commit();
}
} catch (ActiveMQException e) {
if (startedTransaction) {
tx.rollback();
} else {
tx.markAsRollbackOnly(e);
}
throw e;
} catch (Throwable e) {
ActiveMQServerLogger.LOGGER.errorAckingMessage((Exception) e);
ActiveMQIllegalStateException hqex = new ActiveMQIllegalStateException(e.getMessage());
if (startedTransaction) {
tx.rollback();
} else {
tx.markAsRollbackOnly(hqex);
}
throw hqex;
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class ServerConsumerImpl method getDeliveringReferencesBasedOnProtocol.
/**
* Remove references based on the protocolData.
* there will be an interval defined between protocolDataStart and protocolDataEnd.
* This method will fetch the delivering references, remove them from the delivering list and return a list.
*
* This will be useful for other protocols that will need this such as openWire or MQTT.
*/
@Override
public synchronized List<MessageReference> getDeliveringReferencesBasedOnProtocol(boolean remove, Object protocolDataStart, Object protocolDataEnd) {
LinkedList<MessageReference> retReferences = new LinkedList<>();
boolean hit = false;
synchronized (lock) {
Iterator<MessageReference> referenceIterator = deliveringRefs.iterator();
while (referenceIterator.hasNext()) {
MessageReference reference = referenceIterator.next();
if (!hit) {
hit = reference.getProtocolData() != null && reference.getProtocolData().equals(protocolDataStart);
}
// notice: this is not an else clause, this is also valid for the first hit
if (hit) {
if (remove) {
referenceIterator.remove();
}
retReferences.add(reference);
// even on the first hit
if (reference.getProtocolData() != null && reference.getProtocolData().equals(protocolDataEnd)) {
break;
}
}
}
}
return retReferences;
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class RefsOperation method afterRollback.
@Override
public void afterRollback(final Transaction tx) {
Map<QueueImpl, LinkedList<MessageReference>> queueMap = new HashMap<>();
long timeBase = System.currentTimeMillis();
// add any already acked refs, this means that they have been transferred via a producer.send() and have no
// previous state persisted.
List<MessageReference> ackedRefs = new ArrayList<>();
for (MessageReference ref : refsToAck) {
ref.emptyConsumerID();
if (logger.isTraceEnabled()) {
logger.trace("rolling back " + ref);
}
try {
if (ref.isAlreadyAcked()) {
ackedRefs.add(ref);
}
rollbackRedelivery(tx, ref, timeBase, queueMap);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorCheckingDLQ(e);
}
}
for (Map.Entry<QueueImpl, LinkedList<MessageReference>> entry : queueMap.entrySet()) {
LinkedList<MessageReference> refs = entry.getValue();
QueueImpl queue = entry.getKey();
synchronized (queue) {
queue.postRollback(refs);
}
}
if (!ackedRefs.isEmpty()) {
// message references
try {
Transaction ackedTX = new TransactionImpl(storageManager);
for (MessageReference ref : ackedRefs) {
Message message = ref.getMessage();
if (message.isDurable()) {
int durableRefCount = message.incrementDurableRefCount();
if (durableRefCount == 1) {
storageManager.storeMessageTransactional(ackedTX.getID(), message);
}
Queue queue = ref.getQueue();
storageManager.storeReferenceTransactional(ackedTX.getID(), queue.getID(), message.getMessageID());
ackedTX.setContainsPersistent();
}
message.incrementRefCount();
}
ackedTX.commit(true);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToProcessMessageReferenceAfterRollback(e);
}
}
}
use of org.apache.activemq.artemis.core.server.MessageReference in project activemq-artemis by apache.
the class LastValueQueue method replaceLVQMessage.
private void replaceLVQMessage(MessageReference ref, HolderReference hr) {
MessageReference oldRef = hr.getReference();
referenceHandled(ref);
try {
oldRef.acknowledge();
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorAckingOldReference(e);
}
hr.setReference(ref);
}
Aggregations