Exemplo n.º 1
0
  @Override
  public void connectionFailed(
      final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) {
    ActiveMQServerLogger.LOGGER.bridgeConnectionFailed(failedOver);

    synchronized (connectionGuard) {
      keepConnecting = true;
    }

    try {
      if (producer != null) {
        producer.close();
      }

      cleanUpSessionFactory(csf);
    } catch (Throwable dontCare) {
    }

    try {
      session.cleanUp(false);
    } catch (Throwable dontCare) {
    }

    if (scaleDownTargetNodeID != null && !scaleDownTargetNodeID.equals(nodeUUID.toString())) {
      synchronized (this) {
        try {
          logger.debug(
              "Moving "
                  + queue.getMessageCount()
                  + " messages from "
                  + queue.getName()
                  + " to "
                  + scaleDownTargetNodeID);
          ((QueueImpl) queue)
              .moveReferencesBetweenSnFQueues(SimpleString.toSimpleString(scaleDownTargetNodeID));

          // stop the bridge from trying to reconnect and clean up all the bindings
          fail(true);
        } catch (Exception e) {
          ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
        }
      }
    } else if (scaleDownTargetNodeID != null) {
      // the disconnected node is scaling down to me, no need to reconnect to it
      logger.debug(
          "Received scaleDownTargetNodeID: " + scaleDownTargetNodeID + "; cancelling reconnect.");
      fail(true);
    } else {
      logger.debug("Received invalid scaleDownTargetNodeID: " + scaleDownTargetNodeID);

      fail(me.getType() == ActiveMQExceptionType.DISCONNECTED);
    }

    tryScheduleRetryReconnect(me.getType());
  }
  protected void sendCrashReceive() throws Exception {
    ServerLocator[] locators = new ServerLocator[liveServers.size()];
    try {
      for (int i = 0; i < locators.length; i++) {
        locators[i] = getServerLocator(i);
      }

      ClientSessionFactory[] factories = new ClientSessionFactory[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        factories[i] = createSessionFactory(locators[i]);
      }

      ClientSession[] sessions = new ClientSession[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        sessions[i] = createSession(factories[i], true, true);
        sessions[i].createQueue(ADDRESS, ADDRESS, null, true);
      }

      // make sure bindings are ready before sending messages
      for (int i = 0; i < liveServers.size(); i++) {
        this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), true, 1, 0, 2000);
        this.waitForBindings(liveServers.get(i).getServer(), ADDRESS.toString(), false, 1, 0, 2000);
      }

      ClientProducer producer = sessions[0].createProducer(ADDRESS);

      for (int i = 0; i < liveServers.size() * 100; i++) {
        ClientMessage message = sessions[0].createMessage(true);

        setBody(i, message);

        message.putIntProperty("counter", i);

        producer.send(message);
      }

      producer.close();

      for (TestableServer liveServer : liveServers) {
        waitForDistribution(ADDRESS, liveServer.getServer(), 100);
      }

      for (TestableServer liveServer : liveServers) {
        liveServer.crash();
      }
      ClientConsumer[] consumers = new ClientConsumer[liveServers.size()];
      for (int i = 0; i < factories.length; i++) {
        consumers[i] = sessions[i].createConsumer(ADDRESS);
        sessions[i].start();
      }

      for (int i = 0; i < 100; i++) {
        for (ClientConsumer consumer : consumers) {
          ClientMessage message = consumer.receive(1000);
          assertNotNull("expecting durable msg " + i, message);
          message.acknowledge();
        }
      }
    } finally {
      for (ServerLocator locator : locators) {
        if (locator != null) {
          try {
            locator.close();
          } catch (Exception e) {
            // ignore
          }
        }
      }
    }
  }