final void acknowledge(
      ConnectionContext context,
      final TopicMessageStore destination,
      final String clientId,
      final String subscriptionName,
      final MessageId messageId,
      final MessageAck ack)
      throws IOException {

    if (ack.isInTransaction()) {
      if (ack.getTransactionId().isXATransaction()
          || theStore.isConcurrentStoreAndDispatchTransactions() == false) {
        destination.acknowledge(context, clientId, subscriptionName, messageId, ack);
      } else {
        Tx tx = getTx(ack.getTransactionId());
        tx.add(
            new RemoveMessageCommand(context) {
              public MessageAck getMessageAck() {
                return ack;
              }

              public Future<Object> run(ConnectionContext ctx) throws IOException {
                destination.acknowledge(ctx, clientId, subscriptionName, messageId, ack);
                return AbstractMessageStore.FUTURE;
              }
            });
      }
    } else {
      destination.acknowledge(context, clientId, subscriptionName, messageId, ack);
    }
  }
  final void removeAsyncMessage(
      ConnectionContext context, final MessageStore destination, final MessageAck ack)
      throws IOException {

    if (ack.isInTransaction()) {
      if (ack.getTransactionId().isXATransaction()
          || theStore.isConcurrentStoreAndDispatchTransactions() == false) {
        destination.removeAsyncMessage(context, ack);
      } else {
        Tx tx = getTx(ack.getTransactionId());
        tx.add(
            new RemoveMessageCommand(context) {
              @Override
              public MessageAck getMessageAck() {
                return ack;
              }

              @Override
              public Future<Object> run(ConnectionContext ctx) throws IOException {
                destination.removeMessage(ctx, ack);
                return AbstractMessageStore.FUTURE;
              }
            });
      }
    } else {
      destination.removeAsyncMessage(context, ack);
    }
  }
Exemplo n.º 3
0
  public void removeMessage(ConnectionContext context, final MessageAck ack) throws IOException {
    final boolean debug = LOG.isDebugEnabled();
    JournalQueueAck remove = new JournalQueueAck();
    remove.setDestination(destination);
    remove.setMessageAck(ack);

    final RecordLocation location =
        peristenceAdapter.writeCommand(remove, ack.isResponseRequired());
    if (!context.isInTransaction()) {
      if (debug) {
        LOG.debug("Journalled message remove for: " + ack.getLastMessageId() + ", at: " + location);
      }
      removeMessage(ack, location);
    } else {
      if (debug) {
        LOG.debug(
            "Journalled transacted message remove for: "
                + ack.getLastMessageId()
                + ", at: "
                + location);
      }
      synchronized (this) {
        inFlightTxLocations.add(location);
      }
      transactionStore.removeMessage(this, ack, location);
      context
          .getTransaction()
          .addSynchronization(
              new Synchronization() {
                public void afterCommit() throws Exception {
                  if (debug) {
                    LOG.debug(
                        "Transacted message remove commit for: "
                            + ack.getLastMessageId()
                            + ", at: "
                            + location);
                  }
                  synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                    removeMessage(ack, location);
                  }
                }

                public void afterRollback() throws Exception {
                  if (debug) {
                    LOG.debug(
                        "Transacted message remove rollback for: "
                            + ack.getLastMessageId()
                            + ", at: "
                            + location);
                  }
                  synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                  }
                }
              });
    }
  }
Exemplo n.º 4
0
 public void replayRemoveMessage(ConnectionContext context, MessageAck messageAck) {
   try {
     // Only remove the message if it has not already been removed.
     Message t = longTermStore.getMessage(messageAck.getLastMessageId());
     if (t != null) {
       longTermStore.removeMessage(context, messageAck);
     }
   } catch (Throwable e) {
     LOG.warn(
         "Could not replay acknowledge for message '"
             + messageAck.getLastMessageId()
             + "'.  Message may have already been acknowledged. reason: "
             + e);
   }
 }
 @Override
 public void acknowledge(MessageAck ack) throws Exception {
   AMQConsumer amqConsumer = consumerMap.get(ack.getDestination());
   if (amqConsumer != null) {
     amqConsumer.acknowledge(ack);
   }
 }
Exemplo n.º 6
0
 final void removeMessage(final MessageAck ack, final RecordLocation location) {
   synchronized (this) {
     lastLocation = location;
     MessageId id = ack.getLastMessageId();
     Message message = messages.remove(id);
     if (message == null) {
       messageAcks.add(ack);
     } else {
       message.decrementReferenceCount();
     }
   }
 }
Exemplo n.º 7
0
 @Override
 public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack)
     throws Exception {
   if (isLogAll() || isLogConsumerEvents()) {
     LOG.info(
         "Acknowledging message for client ID: {}{}",
         consumerExchange.getConnectionContext().getClientId(),
         (ack.getMessageCount() == 1 ? ", " + ack.getLastMessageId() : ""));
     if (ack.getMessageCount() > 1) {
       LOG.trace(
           "Message count: {}, First Message Id: {}, Last Message Id: {}",
           new Object[] {ack.getMessageCount(), ack.getFirstMessageId(), ack.getLastMessageId()});
     }
   }
   super.acknowledge(consumerExchange, ack);
 }
 @Override
 public Response processMessageAck(MessageAck ack) throws Exception {
   AMQConsumerBrokerExchange consumerBrokerExchange = consumerExchanges.get(ack.getConsumerId());
   consumerBrokerExchange.acknowledge(ack);
   return null;
 }
  public void acknowledge(MessageAck ack) throws Exception {
    MessageId first = ack.getFirstMessageId();
    MessageId lastm = ack.getLastMessageId();
    TransactionId tid = ack.getTransactionId();
    boolean isLocalTx = (tid != null) && tid.isLocalTransaction();
    boolean single = lastm.equals(first);

    MessageInfo mi = null;
    int n = 0;

    if (ack.isIndividualAck()) {
      Iterator<MessageInfo> iter = deliveringRefs.iterator();
      while (iter.hasNext()) {
        mi = iter.next();
        if (mi.amqId.equals(lastm)) {
          n++;
          iter.remove();
          session.getCoreSession().individualAcknowledge(nativeId, mi.nativeId);
          session.getCoreSession().commit();
          break;
        }
      }
    } else if (ack.isRedeliveredAck()) {
      // client tells that this message is for redlivery.
      // do nothing until poisoned.
      n = 1;
    } else if (ack.isPoisonAck()) {
      // send to dlq
      Iterator<MessageInfo> iter = deliveringRefs.iterator();
      boolean firstFound = false;
      while (iter.hasNext()) {
        mi = iter.next();
        if (mi.amqId.equals(first)) {
          n++;
          iter.remove();
          session
              .getCoreSession()
              .moveToDeadLetterAddress(nativeId, mi.nativeId, ack.getPoisonCause());
          session.getCoreSession().commit();
          if (single) {
            break;
          }
          firstFound = true;
        } else if (firstFound || first == null) {
          n++;
          iter.remove();
          session
              .getCoreSession()
              .moveToDeadLetterAddress(nativeId, mi.nativeId, ack.getPoisonCause());
          session.getCoreSession().commit();
          if (mi.amqId.equals(lastm)) {
            break;
          }
        }
      }
    } else if (ack.isDeliveredAck() || ack.isExpiredAck()) {
      // ToDo: implement with tests
      n = 1;
    } else {
      Iterator<MessageInfo> iter = deliveringRefs.iterator();
      boolean firstFound = false;
      while (iter.hasNext()) {
        MessageInfo ami = iter.next();
        if (ami.amqId.equals(first)) {
          n++;
          if (!isLocalTx) {
            iter.remove();
          } else {
            ami.setLocalAcked(true);
          }
          if (single) {
            mi = ami;
            break;
          }
          firstFound = true;
        } else if (firstFound || first == null) {
          n++;
          if (!isLocalTx) {
            iter.remove();
          } else {
            ami.setLocalAcked(true);
          }
          if (ami.amqId.equals(lastm)) {
            mi = ami;
            break;
          }
        }
      }
      if (mi != null && !isLocalTx) {
        session.getCoreSession().acknowledge(nativeId, mi.nativeId);
      }
    }

    acquireCredit(n);
  }
Exemplo n.º 10
0
 public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException {
   removeMessage(ack.getLastMessageId());
 }