Пример #1
0
  @Override
  public HandleStatus handle(final MessageReference ref) throws Exception {
    if (filter != null && !filter.match(ref.getMessage())) {
      return HandleStatus.NO_MATCH;
    }

    synchronized (this) {
      if (!active || !session.isWritable(this)) {
        if (logger.isDebugEnabled()) {
          logger.debug(this + "::Ignoring reference on bridge as it is set to inactive ref=" + ref);
        }
        return HandleStatus.BUSY;
      }

      if (deliveringLargeMessage) {
        return HandleStatus.BUSY;
      }

      if (logger.isTraceEnabled()) {
        logger.trace("Bridge " + this + " is handling reference=" + ref);
      }

      ref.handled();

      synchronized (refs) {
        refs.put(ref.getMessage().getMessageID(), ref);
      }

      final ServerMessage message = beforeForward(ref.getMessage());

      final SimpleString dest;

      if (forwardingAddress != null) {
        dest = forwardingAddress;
      } else {
        // Preserve the original address
        dest = message.getAddress();
      }

      pendingAcks.countUp();

      try {
        if (message.isLargeMessage()) {
          deliveringLargeMessage = true;
          deliverLargeMessage(dest, ref, (LargeServerMessage) message);
          return HandleStatus.HANDLED;
        } else {
          return deliverStandardMessage(dest, ref, message);
        }
      } catch (Exception e) {
        // If an exception happened, we must count down immediately
        pendingAcks.countDown();
        throw e;
      }
    }
  }
Пример #2
0
  @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);
      }
    }
  }