Beispiel #1
0
  private void doSend(final ServerMessage msg, final boolean direct) throws Exception {
    // check the user has write access to this address.
    try {
      securityStore.check(msg.getAddress(), CheckType.SEND, this);
    } catch (HornetQException e) {
      if (!autoCommitSends) {
        tx.markAsRollbackOnly(e);
      }
      throw e;
    }

    if (tx == null || autoCommitSends) {
    } else {
      routingContext.setTransaction(tx);
    }

    postOffice.route(msg, routingContext, direct);

    Pair<UUID, AtomicLong> value = targetAddressInfos.get(msg.getAddress());

    if (value == null) {
      targetAddressInfos.put(
          msg.getAddress(), new Pair<UUID, AtomicLong>(msg.getUserID(), new AtomicLong(1)));
    } else {
      value.setA(msg.getUserID());
      value.getB().incrementAndGet();
    }

    routingContext.clear();
  }
  public synchronized void xaFailed(final Xid xid) throws Exception {
    if (tx != null) {
      final String msg =
          "Cannot start, session is already doing work in a transaction " + tx.getXid();

      throw new HornetQXAException(XAException.XAER_PROTO, msg);
    } else {

      tx = newTransaction(xid);
      tx.markAsRollbackOnly(
          new HornetQException("Can't commit as a Failover happened during the operation"));

      if (isTrace) {
        HornetQServerLogger.LOGGER.trace("xastart into tx= " + tx);
      }

      boolean added = resourceManager.putTransaction(xid, tx);

      if (!added) {
        final String msg = "Cannot start, there is already a xid " + tx.getXid();

        throw new HornetQXAException(XAException.XAER_DUPID, msg);
      }
    }
  }
Beispiel #3
0
  private void handleManagementMessage(final ServerMessage message, final boolean direct)
      throws Exception {
    try {
      securityStore.check(message.getAddress(), CheckType.MANAGE, this);
    } catch (HornetQException e) {
      if (!autoCommitSends) {
        tx.markAsRollbackOnly(e);
      }
      throw e;
    }

    ServerMessage reply = managementService.handleMessage(message);

    SimpleString replyTo = message.getSimpleStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME);

    if (replyTo != null) {
      reply.setAddress(replyTo);

      doSend(reply, direct);
    }
  }
  public void acknowledge(final boolean autoCommitAcks, Transaction tx, final long messageID)
      throws Exception {
    if (browseOnly) {
      return;
    }

    // Acknowledge acknowledges all refs delivered by the consumer up to and including the one
    // explicitly
    // acknowledged

    // We use a transaction here as if the message is not found, we should rollback anything done
    // This could eventually happen on retries during transactions, and we need to make sure we
    // don't ACK things we are not supposed to acknowledge

    boolean startedTransaction = false;

    if (tx == null || autoCommitAcks) {
      startedTransaction = true;
      tx = new TransactionImpl(storageManager);
    }

    try {

      MessageReference ref;
      do {
        ref = deliveringRefs.poll();

        if (HornetQServerLogger.LOGGER.isTraceEnabled()) {
          HornetQServerLogger.LOGGER.trace(
              "ACKing ref " + ref + " on tx= " + tx + ", consumer=" + this);
        }

        if (ref == null) {
          throw HornetQMessageBundle.BUNDLE.consumerNoReference(
              id, messageID, messageQueue.getName());
        }

        ref.getQueue().acknowledge(tx, ref);
      } while (ref.getMessage().getMessageID() != messageID);

      if (startedTransaction) {
        tx.commit();
      }
    } catch (HornetQException e) {
      if (startedTransaction) {
        tx.rollback();
      } else {
        tx.markAsRollbackOnly(e);
      }
      throw e;
    } catch (Throwable e) {
      HornetQServerLogger.LOGGER.errorAckingMessage((Exception) e);
      HornetQException hqex = new HornetQIllegalStateException(e.getMessage());
      if (startedTransaction) {
        tx.rollback();
      } else {
        tx.markAsRollbackOnly(hqex);
      }
      throw hqex;
    }
  }