/**
   * @param ref
   * @param message
   * @return
   */
  private HandleStatus deliverStandardMessage(
      SimpleString dest, final MessageReference ref, ServerMessage message) {
    // if we failover during send then there is a chance that the
    // that this will throw a disconnect, we need to remove the message
    // from the acks so it will get resent, duplicate detection will cope
    // with any messages resent

    if (logger.isTraceEnabled()) {
      logger.trace("going to send message: " + message + " from " + this.getQueue());
    }

    try {
      producer.send(dest, message);
    } catch (final ActiveMQException e) {
      ActiveMQServerLogger.LOGGER.bridgeUnableToSendMessage(e, ref);

      synchronized (refs) {
        // We remove this reference as we are returning busy which means the reference will never
        // leave the Queue.
        // because of this we have to remove the reference here
        refs.remove(message.getMessageID());

        // The delivering count should also be decreased as to avoid inconsistencies
        ((QueueImpl) ref.getQueue()).decDelivering();
      }

      connectionFailed(e, false);

      return HandleStatus.BUSY;
    }

    return HandleStatus.HANDLED;
  }
  @Override
  public void sendAcknowledged(final Message message) {
    if (logger.isTraceEnabled()) {
      logger.trace("BridgeImpl::sendAcknowledged received confirmation for message " + message);
    }
    if (active) {
      try {

        final MessageReference ref;

        synchronized (refs) {
          ref = refs.remove(message.getMessageID());
        }

        if (ref != null) {
          if (logger.isTraceEnabled()) {
            logger.trace(
                "BridgeImpl::sendAcknowledged bridge "
                    + this
                    + " Acking "
                    + ref
                    + " on queue "
                    + ref.getQueue());
          }
          ref.getQueue().acknowledge(ref);
          pendingAcks.countDown();
        } else {
          if (logger.isTraceEnabled()) {
            logger.trace(
                "BridgeImpl::sendAcknowledged bridge "
                    + this
                    + " could not find reference for message "
                    + message);
          }
        }
      } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.bridgeFailedToAck(e);
      }
    }
  }
  @Override
  public void handlePreparedTransaction(
      Transaction tx,
      List<MessageReference> referencesToAck,
      Xid xid,
      ResourceManager resourceManager)
      throws Exception {
    for (MessageReference ack : referencesToAck) {
      ack.getQueue().reacknowledge(tx, ack);
    }

    tx.setState(Transaction.State.PREPARED);

    resourceManager.putTransaction(xid, tx);
  }
  private void cancelRefs() {
    LinkedList<MessageReference> list = new LinkedList<>();

    synchronized (refs) {
      list.addAll(refs.values());
      refs.clear();
    }

    if (logger.isTraceEnabled()) {
      logger.trace("BridgeImpl::cancelRefs cancelling " + list.size() + " references");
    }

    if (logger.isTraceEnabled() && list.isEmpty()) {
      logger.trace("didn't have any references to cancel on bridge " + this);
      return;
    }

    ListIterator<MessageReference> listIterator = list.listIterator(list.size());

    Queue refqueue;

    long timeBase = System.currentTimeMillis();

    while (listIterator.hasPrevious()) {
      MessageReference ref = listIterator.previous();

      if (logger.isTraceEnabled()) {
        logger.trace("BridgeImpl::cancelRefs Cancelling reference " + ref + " on bridge " + this);
      }

      refqueue = ref.getQueue();

      try {
        refqueue.cancel(ref, timeBase);
      } catch (Exception e) {
        // There isn't much we can do besides log an error
        ActiveMQServerLogger.LOGGER.errorCancellingRefOnBridge(e, ref);
      }
    }
  }
 /* (non-Javadoc)
  * @see org.apache.activemq.artemis.core.server.MessageReference#acknowledge(org.apache.activemq.artemis.core.server.MessageReference)
  */
 @Override
 public void acknowledge() throws Exception {
   ref.getQueue().acknowledge(this);
 }
 @Override
 public Queue getQueue() {
   return ref.getQueue();
 }