public void handlePacket(final Packet packet) {
    byte type = packet.getType();

    try {
      switch (type) {
        case SESS_RECEIVETOKENS:
          {
            SessionProducerFlowCreditMessage message = (SessionProducerFlowCreditMessage) packet;

            clientSession.receiveProducerCredits(message.getProducerID(), message.getTokens());

            break;
          }
        case SESS_RECEIVE_MSG:
          {
            SessionReceiveMessage message = (SessionReceiveMessage) packet;

            clientSession.handleReceiveMessage(message.getConsumerID(), message.getClientMessage());

            break;
          }
        case EXCEPTION:
          {
            // TODO - we can provide a means for async exceptions to get back to to client
            // For now we just log it
            MessagingExceptionMessage mem = (MessagingExceptionMessage) packet;

            log.error("Received exception asynchronously from server", mem.getException());

            break;
          }
        default:
          {
            throw new IllegalStateException("Invalid packet: " + type);
          }
      }
    } catch (Exception e) {
      log.error("Failed to handle packet", e);
    }
  }
Пример #2
0
    public void run() {
      try {
        for (int i = 0; i < numMessages; i++) {
          TextMessage tm = sess.createTextMessage("message" + i);

          prod.send(tm);

          log.trace("Sent message " + i);
        }
      } catch (Exception e) {
        log.error("Failed to send", e);
        ex = e;
      }
    }
Пример #3
0
  public void testStartBridgeWithJTATransactionAlreadyRunning() throws Exception {
    BridgeImpl bridge = null;

    Transaction toResume = null;

    Transaction started = null;

    TransactionManager mgr = TransactionManagerLocator.getInstance().locate();

    try {

      toResume = mgr.suspend();

      mgr.begin();

      started = mgr.getTransaction();

      final int NUM_MESSAGES = 10;

      bridge =
          new BridgeImpl(
              cff0,
              cff1,
              sourceTopicFactory,
              targetQueueFactory,
              null,
              null,
              null,
              null,
              null,
              5000,
              10,
              QualityOfServiceMode.AT_MOST_ONCE,
              1,
              -1,
              null,
              null,
              false);

      bridge.start();

      this.sendMessages(cf0, sourceTopic, 0, NUM_MESSAGES, false);

      this.checkAllMessageReceivedInOrder(cf1, targetQueue, 0, NUM_MESSAGES);
    } finally {
      if (started != null) {
        try {
          started.rollback();
        } catch (Exception e) {
          log.error("Failed to rollback", e);
        }
      }

      if (toResume != null) {
        try {
          mgr.resume(toResume);
        } catch (Exception e) {
          log.error("Failed to resume", e);
        }
      }
      if (bridge != null) {
        bridge.stop();
      }
    }
  }
Пример #4
0
  // Both source and destination on same rm
  private void testStressSameServer(QualityOfServiceMode qosMode, boolean persistent, int batchSize)
      throws Exception {
    Connection connSource = null;

    BridgeImpl bridge = null;

    Thread t = null;

    try {
      bridge =
          new BridgeImpl(
              cff0,
              cff0,
              sourceQueueFactory,
              localTargetQueueFactory,
              null,
              null,
              null,
              null,
              null,
              5000,
              10,
              qosMode,
              batchSize,
              -1,
              null,
              null,
              false);

      bridge.start();

      connSource = cf0.createConnection();

      Session sessSend = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer prod = sessSend.createProducer(sourceQueue);

      final int NUM_MESSAGES = 2000;

      StressSender sender = new StressSender();
      sender.sess = sessSend;
      sender.prod = prod;
      sender.numMessages = NUM_MESSAGES;
      prod.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);

      t = new Thread(sender);

      t.start();

      this.checkAllMessageReceivedInOrder(cf0, localTargetQueue, 0, NUM_MESSAGES);

      t.join();

      if (sender.ex != null) {
        // An error occurred during the send
        throw sender.ex;
      }

    } finally {
      if (t != null) {
        t.join(10000);
      }

      if (connSource != null) {
        try {
          connSource.close();
        } catch (Exception e) {
          log.error("Failed to close connection", e);
        }
      }

      if (bridge != null) {
        bridge.stop();
      }
    }
  }