protected void createLiveConfig(NodeManager nodeManager, int liveNode, int... otherLiveNodes)
      throws Exception {
    TransportConfiguration liveConnector =
        createTransportConfiguration(isNetty(), false, generateParams(liveNode, isNetty()));
    Configuration config0 = super.createDefaultConfig();
    config0.getAcceptorConfigurations().clear();
    config0
        .getAcceptorConfigurations()
        .add(createTransportConfiguration(isNetty(), true, generateParams(liveNode, isNetty())));
    config0.setSecurityEnabled(false);
    config0.setSharedStore(true);
    List<String> pairs = new ArrayList<String>();
    for (int node : otherLiveNodes) {
      TransportConfiguration otherLiveConnector =
          createTransportConfiguration(isNetty(), false, generateParams(node, isNetty()));
      config0.getConnectorConfigurations().put(otherLiveConnector.getName(), otherLiveConnector);
      pairs.add(otherLiveConnector.getName());
    }
    basicClusterConnectionConfig(config0, liveConnector.getName(), pairs);
    config0.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);

    config0.setBindingsDirectory(config0.getBindingsDirectory() + "_" + liveNode);
    config0.setJournalDirectory(config0.getJournalDirectory() + "_" + liveNode);
    config0.setPagingDirectory(config0.getPagingDirectory() + "_" + liveNode);
    config0.setLargeMessagesDirectory(config0.getLargeMessagesDirectory() + "_" + liveNode);

    servers.put(
        liveNode,
        new SameProcessHornetQServer(
            createInVMFailoverServer(true, config0, nodeManager, liveNode)));
  }
  protected void createConfigs() throws Exception {
    nodeManager = new InVMNodeManager();

    backupConfig = super.createDefaultConfig();
    backupConfig.getAcceptorConfigurations().clear();
    backupConfig.getAcceptorConfigurations().add(getAcceptorTransportConfiguration(false));
    backupConfig.setSharedStore(true);
    backupConfig.setBackup(true);
    backupConfig.setClustered(true);
    TransportConfiguration liveConnector = getConnectorTransportConfiguration(true);
    TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
    backupConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
    backupConfig.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
    ReplicatedBackupUtils.createClusterConnectionConf(
        backupConfig, backupConnector.getName(), liveConnector.getName());
    backupServer = createTestableServer(backupConfig);

    liveConfig = super.createDefaultConfig();
    liveConfig.getAcceptorConfigurations().clear();
    liveConfig.getAcceptorConfigurations().add(getAcceptorTransportConfiguration(true));
    liveConfig.setSharedStore(true);
    liveConfig.setClustered(true);
    ReplicatedBackupUtils.createClusterConnectionConf(liveConfig, liveConnector.getName());
    liveConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
    liveServer = createTestableServer(liveConfig);
  }
  private HornetQServer createServer2() throws Exception {
    // Server1 with two acceptors, each acceptor on a different cluster connection
    // talking to a different connector.
    // i.e. two cluster connections isolated on the same node
    Configuration config1 = createBasicConfig(3);

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc1");
    params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "3");

    TransportConfiguration acceptor1VM1 =
        new TransportConfiguration(UnitTestCase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc1");
    config1.getAcceptorConfigurations().add(acceptor1VM1);

    config1
        .getConnectorConfigurations()
        .put("local-cc1", createInVMTransportConnectorConfig(3, "local-cc1"));
    config1
        .getConnectorConfigurations()
        .put("local-cc2", createInVMTransportConnectorConfig(4, "local-cc2"));

    config1
        .getConnectorConfigurations()
        .put("other-cc1", createInVMTransportConnectorConfig(1, "other-cc1"));
    config1
        .getConnectorConfigurations()
        .put("other-cc2", createInVMTransportConnectorConfig(2, "other-cc2"));

    params = new HashMap<String, Object>();
    params.put(TransportConstants.CLUSTER_CONNECTION, "cc2");
    params.put(org.hornetq.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "4");

    TransportConfiguration acceptor2VM1 =
        new TransportConfiguration(UnitTestCase.INVM_ACCEPTOR_FACTORY, params, "acceptor-cc2");
    config1.getAcceptorConfigurations().add(acceptor2VM1);

    List<String> connectTo = new ArrayList<String>();
    connectTo.add("other-cc1");

    ClusterConnectionConfiguration server1CC1 =
        new ClusterConnectionConfiguration(
            "cc1", "jms", "local-cc1", 250, true, false, 1, 1024, connectTo, false);

    config1.getClusterConfigurations().add(server1CC1);

    ArrayList<String> connectTo2 = new ArrayList<String>();
    connectTo2.add("other-cc2");

    ClusterConnectionConfiguration server1CC2 =
        new ClusterConnectionConfiguration(
            "cc2", "jms", "local-cc2", 250, true, false, 1, 1024, connectTo2, false);

    config1.getClusterConfigurations().add(server1CC2);

    return createServer(false, config1);
  }
  /**
   * @param toOtherServerPair
   * @throws Exception
   */
  private void setupServer1() throws Exception {
    List<String> toOtherServerPair = new ArrayList<String>();
    toOtherServerPair.add("toServer2");

    Configuration conf1 =
        createDefaultConfig(0, generateInVMParams(0), InVMAcceptorFactory.class.getCanonicalName());

    conf1.setSecurityEnabled(false);
    conf1.setJMXManagementEnabled(true);
    conf1.setPersistenceEnabled(false);

    conf1
        .getConnectorConfigurations()
        .put(
            "toServer2",
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(1)));
    conf1
        .getConnectorConfigurations()
        .put(
            "server1",
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(0)));

    conf1.setClustered(true);

    conf1
        .getClusterConfigurations()
        .add(
            new ClusterConnectionConfiguration(
                "to-server2",
                "jms",
                "server1",
                1000,
                true,
                true,
                MAX_HOPS,
                1024,
                toOtherServerPair,
                false));

    JMSConfigurationImpl jmsconfig = new JMSConfigurationImpl();
    // jmsconfig.getTopicConfigurations().add(new TopicConfigurationImpl("t1", "topic/t1"));

    server1 = HornetQServers.newHornetQServer(conf1, false);
    jmsServer1 = new JMSServerManagerImpl(server1, jmsconfig);
    context1 = new InVMContext();
    jmsServer1.setContext(context1);
  }
  // XXX HORNETQ-720 + cluster fixes: needs review
  @Override
  public void announceReplicatingBackup(Channel liveChannel) {
    List<ClusterConnectionConfiguration> configs = this.configuration.getClusterConfigurations();
    if (!configs.isEmpty()) {
      ClusterConnectionConfiguration config = configs.get(0);

      TransportConfiguration connector =
          configuration.getConnectorConfigurations().get(config.getConnectorName());

      if (connector == null) {
        log.warn(
            "No connector with name '"
                + config.getConnectorName()
                + "'. backup cannot be announced.");
        return;
      }
      liveChannel.send(
          new BackupRegistrationMessage(
              nodeUUID.toString(),
              connector,
              configuration.getClusterUser(),
              configuration.getClusterPassword()));
    } else {
      log.warn("no cluster connections defined, unable to announce backup");
    }
  }
  @Override
  protected void createConfigs() throws Exception {
    Configuration config1 = super.createDefaultConfig();
    config1.setBindingsDirectory(config1.getBindingsDirectory() + "_backup");
    config1.setJournalDirectory(config1.getJournalDirectory() + "_backup");
    config1.getAcceptorConfigurations().clear();
    config1.getAcceptorConfigurations().add(getAcceptorTransportConfiguration(false));
    config1.setSecurityEnabled(false);
    config1.setSharedStore(false);
    config1.setBackup(true);
    server1Service = super.createServer(true, config1);

    Configuration config0 = super.createDefaultConfig();
    config0.getAcceptorConfigurations().clear();
    config0.getAcceptorConfigurations().add(getAcceptorTransportConfiguration(true));

    config0.getConnectorConfigurations().put("toBackup", getConnectorTransportConfiguration(false));
    config0.setBackupConnectorName("toBackup");
    config0.setSecurityEnabled(false);
    config0.setSharedStore(false);
    server0Service = super.createServer(true, config0);

    server1Service.start();
    server0Service.start();
  }
Exemple #7
0
  private BroadcastGroup createBroadcastGroup(BroadcastGroupConfiguration config) throws Exception {
    BroadcastGroup group = broadcastGroups.get(config.getName());

    if (group == null) {
      group =
          new BroadcastGroupImpl(
              nodeManager,
              config.getName(),
              config.getBroadcastPeriod(),
              scheduledExecutor,
              config.getEndpointFactoryConfiguration().createBroadcastEndpointFactory());

      for (String connectorInfo : config.getConnectorInfos()) {
        TransportConfiguration connector =
            configuration.getConnectorConfigurations().get(connectorInfo);

        if (connector == null) {
          logWarnNoConnector(config.getName(), connectorInfo);

          return null;
        }

        group.addConnector(connector);
      }
    }

    if (group.size() == 0) {
      logWarnNoConnector(config.getConnectorInfos().toString(), group.getName());
      return null;
    }

    broadcastGroups.put(config.getName(), group);

    return group;
  }
 @Override
 /*
  * for this test the 2 live connect to each other
  * */
 public void createLiveClusterConfiguration(int server, Configuration configuration, int servers) {
   TransportConfiguration livetc = getConnectorTransportConfiguration(true, server);
   configuration.getConnectorConfigurations().put(livetc.getName(), livetc);
   List<String> connectors = new ArrayList<String>();
   for (int i = 0; i < servers; i++) {
     if (i != server) {
       TransportConfiguration staticTc = getConnectorTransportConfiguration(true, i);
       configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
       connectors.add(staticTc.getName());
     }
   }
   basicClusterConnectionConfig(configuration, livetc.getName(), connectors);
 }
  protected void createBackupConfig(
      NodeManager nodeManager,
      int liveNode,
      int nodeid,
      boolean createClusterConnections,
      int[] otherBackupNodes,
      int... otherClusterNodes)
      throws Exception {
    Configuration config1 = super.createDefaultConfig();
    config1.getAcceptorConfigurations().clear();
    config1
        .getAcceptorConfigurations()
        .add(createTransportConfiguration(isNetty(), true, generateParams(nodeid, isNetty())));
    config1.setSecurityEnabled(false);
    config1.setSharedStore(true);
    config1.setBackup(true);

    List<String> staticConnectors = new ArrayList<String>();
    for (int node : otherBackupNodes) {
      TransportConfiguration liveConnector =
          createTransportConfiguration(isNetty(), false, generateParams(node, isNetty()));
      config1.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
      staticConnectors.add(liveConnector.getName());
    }
    TransportConfiguration backupConnector =
        createTransportConfiguration(isNetty(), false, generateParams(nodeid, isNetty()));
    config1.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);

    List<String> clusterNodes = new ArrayList<String>();
    for (int node : otherClusterNodes) {
      TransportConfiguration connector =
          createTransportConfiguration(isNetty(), false, generateParams(node, isNetty()));
      config1.getConnectorConfigurations().put(connector.getName(), connector);
      clusterNodes.add(connector.getName());
    }
    basicClusterConnectionConfig(config1, backupConnector.getName(), clusterNodes);
    config1.setBindingsDirectory(config1.getBindingsDirectory() + "_" + liveNode);
    config1.setJournalDirectory(config1.getJournalDirectory() + "_" + liveNode);
    config1.setPagingDirectory(config1.getPagingDirectory() + "_" + liveNode);
    config1.setLargeMessagesDirectory(config1.getLargeMessagesDirectory() + "_" + liveNode);

    servers.put(
        nodeid,
        new SameProcessHornetQServer(
            createInVMFailoverServer(true, config1, nodeManager, liveNode)));
  }
  public void testParsing() throws Exception {
    Configuration config = createDefaultConfig();

    // anything so the parsing will work
    config.getConnectorConfigurations().put("netty", new TransportConfiguration());

    JMSServerConfigParser parser = new JMSServerConfigParserImpl();

    String conf = "hornetq-jms-for-JMSServerDeployerTest.xml";
    URL confURL = Thread.currentThread().getContextClassLoader().getResource(conf);

    InputStream stream = confURL.openStream();

    JMSConfiguration jmsconfig = parser.parseConfiguration(stream);
    stream.close();

    ConnectionFactoryConfiguration cfConfig = jmsconfig.getConnectionFactoryConfigurations().get(0);

    assertEquals(1234, cfConfig.getClientFailureCheckPeriod());
    assertEquals(5678, cfConfig.getCallTimeout());
    assertEquals(12345, cfConfig.getConsumerWindowSize());
    assertEquals(6789, cfConfig.getConsumerMaxRate());
    assertEquals(123456, cfConfig.getConfirmationWindowSize());
    assertEquals(7712652, cfConfig.getProducerWindowSize());
    assertEquals(789, cfConfig.getProducerMaxRate());
    assertEquals(12, cfConfig.getMinLargeMessageSize());
    assertEquals(true, cfConfig.isCompressLargeMessages());
    assertEquals("TestClientID", cfConfig.getClientID());
    assertEquals(3456, cfConfig.getDupsOKBatchSize());
    assertEquals(4567, cfConfig.getTransactionBatchSize());
    assertEquals(true, cfConfig.isBlockOnAcknowledge());
    assertEquals(false, cfConfig.isBlockOnNonDurableSend());
    assertEquals(true, cfConfig.isBlockOnDurableSend());
    assertEquals(false, cfConfig.isAutoGroup());
    assertEquals(true, cfConfig.isPreAcknowledge());
    assertEquals(2345, cfConfig.getConnectionTTL());
    assertEquals("FooClass", cfConfig.getLoadBalancingPolicyClassName());
    assertEquals(34, cfConfig.getReconnectAttempts());
    assertEquals(5, cfConfig.getRetryInterval());
    assertEquals(6.0, cfConfig.getRetryIntervalMultiplier());
    assertEquals(300, cfConfig.getMaxRetryInterval());
    assertEquals(true, cfConfig.isCacheLargeMessagesClient());

    assertEquals(1, jmsconfig.getQueueConfigurations().size());

    JMSQueueConfiguration queueConfig = jmsconfig.getQueueConfigurations().get(0);
    assertEquals("fullConfigurationQueue", queueConfig.getName());
    assertEquals(2, queueConfig.getBindings().length);
    assertEquals("/fullConfigurationQueue", queueConfig.getBindings()[0]);
    assertEquals("/queue/fullConfigurationQueue", queueConfig.getBindings()[1]);

    assertEquals(1, jmsconfig.getTopicConfigurations().size());
    TopicConfiguration topicConfig = jmsconfig.getTopicConfigurations().get(0);
    assertEquals("fullConfigurationTopic", topicConfig.getName());
    assertEquals(2, topicConfig.getBindings().length);
    assertEquals("/fullConfigurationTopic", topicConfig.getBindings()[0]);
    assertEquals("/topic/fullConfigurationTopic", topicConfig.getBindings()[1]);
  }
Exemple #11
0
 private void configureAcceptor() {
   config.setPersistenceEnabled(true);
   config.setSecurityEnabled(false);
   config
       .getAcceptorConfigurations()
       .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
   config
       .getConnectorConfigurations()
       .put("connector", new TransportConfiguration(InVMConnectorFactory.class.getName()));
 }
  private Configuration getConfiguration(
      String identity,
      BackupStrategy backupStrategy,
      TransportConfiguration liveConnector,
      TransportConfiguration liveAcceptor,
      TransportConfiguration... otherLiveNodes)
      throws Exception {
    Configuration configuration = createDefaultConfig();
    configuration.getAcceptorConfigurations().clear();
    configuration.getAcceptorConfigurations().add(liveAcceptor);
    configuration.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
    configuration.setJournalDirectory(configuration.getJournalDirectory() + identity);
    configuration.setBindingsDirectory(configuration.getBindingsDirectory() + identity);
    configuration.setLargeMessagesDirectory(configuration.getLargeMessagesDirectory() + identity);
    configuration.setPagingDirectory(configuration.getPagingDirectory() + identity);
    List<String> transportConfigurationList = new ArrayList<>();
    final HAPolicy haPolicy = new HAPolicy();
    for (TransportConfiguration otherLiveNode : otherLiveNodes) {
      configuration.getConnectorConfigurations().put(otherLiveNode.getName(), otherLiveNode);
      transportConfigurationList.add(otherLiveNode.getName());
      haPolicy.getRemoteConnectors().add(otherLiveNode.getName());
    }
    basicClusterConnectionConfig(
        configuration, liveConnector.getName(), transportConfigurationList);
    configuration
        .getQueueConfigurations()
        .add(new CoreQueueConfiguration("jms.queue.testQueue", "jms.queue.testQueue", null, true));

    haPolicy.setPolicyType(policyType);
    haPolicy.setBackupStrategy(backupStrategy);
    haPolicy.setBackupPortOffset(100);
    haPolicy.setBackupRequestRetries(-1);
    haPolicy.setBackupRequestRetryInterval(500);
    haPolicy.setMaxBackups(1);
    haPolicy.setRequestBackup(true);
    configuration.setHAPolicy(haPolicy);

    return configuration;
  }
Exemple #13
0
  private synchronized void deployBroadcastGroup(final BroadcastGroupConfiguration config)
      throws Exception {
    if (broadcastGroups.containsKey(config.getName())) {
      ClusterManagerImpl.log.warn(
          "There is already a broadcast-group with name "
              + config.getName()
              + " deployed. This one will not be deployed.");

      return;
    }

    InetAddress localAddress = null;
    if (config.getLocalBindAddress() != null) {
      localAddress = InetAddress.getByName(config.getLocalBindAddress());
    }

    InetAddress groupAddress = InetAddress.getByName(config.getGroupAddress());

    BroadcastGroupImpl group =
        new BroadcastGroupImpl(
            nodeUUID.toString(),
            config.getName(),
            localAddress,
            config.getLocalBindPort(),
            groupAddress,
            config.getGroupPort(),
            !backup);

    for (String connectorInfo : config.getConnectorInfos()) {
      TransportConfiguration connector =
          configuration.getConnectorConfigurations().get(connectorInfo);

      if (connector == null) {
        logWarnNoConnector(config.getName(), connectorInfo);

        return;
      }

      group.addConnector(connector);
    }

    ScheduledFuture<?> future =
        scheduledExecutor.scheduleWithFixedDelay(
            group, 0L, config.getBroadcastPeriod(), MILLISECONDS);

    group.setScheduledFuture(future);

    broadcastGroups.put(config.getName(), group);

    managementService.registerBroadcastGroup(group, config);
  }
 @Override
 /*
  * for this test the backups will connect to their own live server
  * */
 public void createBackupClusterConfiguration(
     int server, Configuration configuration, int servers) {
   TransportConfiguration backuptc = getConnectorTransportConfiguration(false, server);
   configuration.getConnectorConfigurations().put(backuptc.getName(), backuptc);
   List<String> connectors = new ArrayList<String>();
   for (int i = 0; i < servers; i++) {
     TransportConfiguration staticTc = getConnectorTransportConfiguration(true, i);
     configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
     connectors.add(staticTc.getName());
   }
   for (int i = 0; i < servers; i++) {
     if (i != server) {
       TransportConfiguration staticTc = getConnectorTransportConfiguration(false, i);
       configuration.getConnectorConfigurations().put(staticTc.getName(), staticTc);
       connectors.add(staticTc.getName());
     }
   }
   basicClusterConnectionConfig(configuration, backuptc.getName(), connectors);
 }
  /** @throws Exception */
  protected void startServer() throws Exception {
    Configuration conf = createDefaultConfig(false);
    conf.getConnectorConfigurations()
        .put("invm", new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    conf.setSecurityEnabled(false);
    conf.setJMXManagementEnabled(true);
    conf.getAcceptorConfigurations().add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY));
    server = HornetQServers.newHornetQServer(conf, mbeanServer, true);
    server.start();

    serverManager = new JMSServerManagerImpl(server);
    serverManager.start();

    ctx = new InVMNamingContext();

    serverManager.setContext(ctx);
    serverManager.activated();
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    Map<String, Object> params = new HashMap<String, Object>();
    // params.put(RandomUtil.randomString(), RandomUtil.randomBoolean());
    connectorConfig =
        new TransportConfiguration(
            InVMConnectorFactory.class.getName(), params, RandomUtil.randomString());

    conf = createDefaultConfig(false);
    conf.setSecurityEnabled(false);
    conf.setJMXManagementEnabled(true);
    conf.getAcceptorConfigurations().clear();
    conf.getAcceptorConfigurations()
        .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    server = HornetQServers.newHornetQServer(conf, mbeanServer, true);
    conf.getConnectorConfigurations().put(connectorConfig.getName(), connectorConfig);
    server.start();
  }
Exemple #17
0
  private TransportConfiguration[] connectorNameListToArray(final List<String> connectorNames) {
    TransportConfiguration[] tcConfigs =
        (TransportConfiguration[])
            Array.newInstance(TransportConfiguration.class, connectorNames.size());
    int count = 0;
    for (String connectorName : connectorNames) {
      TransportConfiguration connector =
          configuration.getConnectorConfigurations().get(connectorName);

      if (connector == null) {
        HornetQServerLogger.LOGGER.bridgeNoConnector(connectorName);

        return null;
      }

      tcConfigs[count++] = connector;
    }

    return tcConfigs;
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    config = createBasicConfig();
    config
        .getConnectorConfigurations()
        .put("netty", new TransportConfiguration(NettyConnectorFactory.class.getName()));

    DiscoveryGroupConfiguration dcg =
        new DiscoveryGroupConfiguration("mygroup", "172.16.8.10", "243.7.7.7", 12345, 5432, 5432);
    config.getDiscoveryGroupConfigurations().put("mygroup", dcg);
    HornetQServer server = createServer(false, config);

    deploymentManager = new FileDeploymentManager(config.getFileDeployerScanPeriod());

    jmsServer = new JMSServerManagerImpl(server);
    context = new InVMContext();
    jmsServer.setContext(context);
    jmsServer.start();
  }
Exemple #19
0
  /**
   * XXX HORNETQ-720
   *
   * @param liveChannel channel for opening connection with live
   * @param attemptingFailBack if {@code true} then this server wants to trigger a fail-back when
   *     up-to-date, that is it wants to take over the role of 'live' from the current 'live'
   *     server.
   * @throws HornetQException
   */
  public void announceReplicatingBackupToLive(
      final Channel liveChannel, final boolean attemptingFailBack) throws HornetQException {
    ClusterConnectionConfiguration config =
        ConfigurationUtils.getReplicationClusterConfiguration(configuration);
    if (config == null) {
      HornetQServerLogger.LOGGER.announceBackupNoClusterConnections();
      throw new HornetQException("lacking cluster connection");
    }
    TransportConfiguration connector =
        configuration.getConnectorConfigurations().get(config.getConnectorName());

    if (connector == null) {
      HornetQServerLogger.LOGGER.announceBackupNoConnector(config.getConnectorName());
      throw new HornetQException("lacking cluster connection");
    }
    liveChannel.send(
        new BackupRegistrationMessage(
            connector,
            configuration.getClusterUser(),
            configuration.getClusterPassword(),
            attemptingFailBack));
  }
Exemple #20
0
  private TransportConfiguration[] connectorNameListToArray(final List<String> connectorNames) {
    TransportConfiguration[] tcConfigs =
        (TransportConfiguration[])
            Array.newInstance(TransportConfiguration.class, connectorNames.size());
    int count = 0;
    for (String connectorName : connectorNames) {
      TransportConfiguration connector =
          configuration.getConnectorConfigurations().get(connectorName);

      if (connector == null) {
        ClusterManagerImpl.log.warn(
            "No connector defined with name '"
                + connectorName
                + "'. The bridge will not be deployed.");

        return null;
      }

      tcConfigs[count++] = connector;
    }

    return tcConfigs;
  }
  /** @throws Exception */
  protected void startServers() throws Exception {
    NodeManager nodeManager = new InVMNodeManager(false);
    backuptc = new TransportConfiguration(INVM_CONNECTOR_FACTORY, backupParams);
    livetc = new TransportConfiguration(INVM_CONNECTOR_FACTORY);

    liveAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY);

    backupAcceptortc = new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams);

    backupConf = createBasicConfig(0);

    backupConf.getAcceptorConfigurations().add(backupAcceptortc);
    backupConf.getConnectorConfigurations().put(livetc.getName(), livetc);
    backupConf.getConnectorConfigurations().put(backuptc.getName(), backuptc);
    basicClusterConnectionConfig(backupConf, backuptc.getName(), livetc.getName());

    backupConf.setSecurityEnabled(false);
    backupConf.setJournalType(getDefaultJournalType());
    backupParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    backupConf
        .getAcceptorConfigurations()
        .add(new TransportConfiguration(INVM_ACCEPTOR_FACTORY, backupParams));
    backupConf.setBackup(true);
    backupConf.setSharedStore(true);
    backupConf.setBindingsDirectory(getBindingsDir());
    backupConf.setJournalMinFiles(2);
    backupConf.setJournalDirectory(getJournalDir());
    backupConf.setPagingDirectory(getPageDir());
    backupConf.setLargeMessagesDirectory(getLargeMessagesDir());
    backupConf.setPersistenceEnabled(true);
    backupService = new InVMNodeManagerServer(backupConf, nodeManager);

    backupJMSService = new JMSServerManagerImpl(backupService);

    backupJMSService.setContext(ctx2);

    backupJMSService.getHornetQServer().setIdentity("JMSBackup");
    log.info("Starting backup");
    backupJMSService.start();

    liveConf = createBasicConfig(0);

    liveConf.setJournalDirectory(getJournalDir());
    liveConf.setBindingsDirectory(getBindingsDir());

    liveConf.setSecurityEnabled(false);
    liveConf.getAcceptorConfigurations().add(liveAcceptortc);
    basicClusterConnectionConfig(liveConf, livetc.getName());
    liveConf.setSharedStore(true);
    liveConf.setJournalType(getDefaultJournalType());
    liveConf.setBindingsDirectory(getBindingsDir());
    liveConf.setJournalMinFiles(2);
    liveConf.setJournalDirectory(getJournalDir());
    liveConf.setPagingDirectory(getPageDir());
    liveConf.setLargeMessagesDirectory(getLargeMessagesDir());
    liveConf.getConnectorConfigurations().put(livetc.getName(), livetc);
    liveConf.setPersistenceEnabled(true);
    liveService = new InVMNodeManagerServer(liveConf, nodeManager);

    liveJMSService = new JMSServerManagerImpl(liveService);

    liveJMSService.setContext(ctx1);

    liveJMSService.getHornetQServer().setIdentity("JMSLive");
    log.info("Starting life");

    liveJMSService.start();

    JMSUtil.waitForServer(backupService);
  }
Exemple #22
0
  private void deployClusterConnection(final ClusterConnectionConfiguration config)
      throws Exception {
    if (config.getName() == null) {
      ClusterManagerImpl.log.warn(
          "Must specify a unique name for each cluster connection. This one will not be deployed.");

      return;
    }

    if (config.getAddress() == null) {
      ClusterManagerImpl.log.warn(
          "Must specify an address for each cluster connection. This one will not be deployed.");

      return;
    }

    TransportConfiguration connector =
        configuration.getConnectorConfigurations().get(config.getConnectorName());

    if (connector == null) {
      log.warn(
          "No connector with name '"
              + config.getConnectorName()
              + "'. The cluster connection will not be deployed.");
      return;
    }

    if (clusterConnections.containsKey(config.getName())) {
      log.warn(
          "Cluster Configuration  '"
              + config.getConnectorName()
              + "' already exists. The cluster connection will not be deployed.",
          new Exception("trace"));
      return;
    }

    ClusterConnectionImpl clusterConnection;

    if (config.getDiscoveryGroupName() != null) {
      DiscoveryGroupConfiguration dg =
          configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());

      if (dg == null) {
        ClusterManagerImpl.log.warn(
            "No discovery group with name '"
                + config.getDiscoveryGroupName()
                + "'. The cluster connection will not be deployed.");
        return;
      }

      if (log.isDebugEnabled()) {
        log.debug(
            this
                + " Starting a Discovery Group Cluster Connection, name="
                + config.getDiscoveryGroupName()
                + ", dg="
                + dg);
      }

      clusterConnection =
          new ClusterConnectionImpl(
              this,
              dg,
              connector,
              new SimpleString(config.getName()),
              new SimpleString(config.getAddress()),
              config.getMinLargeMessageSize(),
              config.getClientFailureCheckPeriod(),
              config.getConnectionTTL(),
              config.getRetryInterval(),
              config.getRetryIntervalMultiplier(),
              config.getMaxRetryInterval(),
              config.getReconnectAttempts(),
              config.getCallTimeout(),
              config.getCallFailoverTimeout(),
              config.isDuplicateDetection(),
              config.isForwardWhenNoConsumers(),
              config.getConfirmationWindowSize(),
              executorFactory,
              server,
              postOffice,
              managementService,
              scheduledExecutor,
              config.getMaxHops(),
              nodeUUID,
              backup,
              server.getConfiguration().getClusterUser(),
              server.getConfiguration().getClusterPassword(),
              config.isAllowDirectConnectionsOnly());
    } else {
      TransportConfiguration[] tcConfigs =
          config.getStaticConnectors() != null
              ? connectorNameListToArray(config.getStaticConnectors())
              : null;

      if (log.isDebugEnabled()) {
        log.debug(this + " defining cluster connection towards " + Arrays.toString(tcConfigs));
      }

      clusterConnection =
          new ClusterConnectionImpl(
              this,
              tcConfigs,
              connector,
              new SimpleString(config.getName()),
              new SimpleString(config.getAddress()),
              config.getMinLargeMessageSize(),
              config.getClientFailureCheckPeriod(),
              config.getConnectionTTL(),
              config.getRetryInterval(),
              config.getRetryIntervalMultiplier(),
              config.getMaxRetryInterval(),
              config.getReconnectAttempts(),
              config.getCallTimeout(),
              config.getCallFailoverTimeout(),
              config.isDuplicateDetection(),
              config.isForwardWhenNoConsumers(),
              config.getConfirmationWindowSize(),
              executorFactory,
              server,
              postOffice,
              managementService,
              scheduledExecutor,
              config.getMaxHops(),
              nodeUUID,
              backup,
              server.getConfiguration().getClusterUser(),
              server.getConfiguration().getClusterPassword(),
              config.isAllowDirectConnectionsOnly());
    }

    if (defaultClusterConnection == null) {
      defaultClusterConnection = clusterConnection;
    }

    managementService.registerCluster(clusterConnection, config);

    clusterConnections.put(config.getName(), clusterConnection);

    if (log.isDebugEnabled()) {
      log.debug("ClusterConnection.start at " + clusterConnection, new Exception("trace"));
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    Map<String, Object> acceptorParams = new HashMap<String, Object>();
    acceptorParams.put(TransportConstants.SERVER_ID_PROP_NAME, 1);
    TransportConfiguration acceptorConfig =
        new TransportConfiguration(
            InVMAcceptorFactory.class.getName(), acceptorParams, RandomUtil.randomString());

    TransportConfiguration connectorConfig =
        new TransportConfiguration(
            InVMConnectorFactory.class.getName(), acceptorParams, RandomUtil.randomString());

    CoreQueueConfiguration sourceQueueConfig =
        new CoreQueueConfiguration(
            RandomUtil.randomString(), RandomUtil.randomString(), null, false);
    CoreQueueConfiguration targetQueueConfig =
        new CoreQueueConfiguration(
            RandomUtil.randomString(), RandomUtil.randomString(), null, false);
    List<String> connectors = new ArrayList<String>();
    connectors.add(connectorConfig.getName());
    bridgeConfig =
        new BridgeConfiguration(
            RandomUtil.randomString(),
            sourceQueueConfig.getName(),
            targetQueueConfig.getAddress(),
            null,
            null,
            HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
            HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
            HornetQClient.DEFAULT_CONNECTION_TTL,
            RandomUtil.randomPositiveLong(),
            HornetQClient.DEFAULT_MAX_RETRY_INTERVAL,
            RandomUtil.randomDouble(),
            RandomUtil.randomPositiveInt(),
            RandomUtil.randomBoolean(),
            RandomUtil.randomPositiveInt(),
            connectors,
            false,
            ConfigurationImpl.DEFAULT_CLUSTER_USER,
            ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD);

    Configuration conf_1 = createBasicConfig();
    conf_1.setSecurityEnabled(false);
    conf_1.setJMXManagementEnabled(true);
    conf_1.setClustered(true);
    conf_1.getAcceptorConfigurations().add(acceptorConfig);
    conf_1.getQueueConfigurations().add(targetQueueConfig);

    Configuration conf_0 = createBasicConfig();
    conf_0.setSecurityEnabled(false);
    conf_0.setJMXManagementEnabled(true);
    conf_0.setClustered(true);
    conf_0
        .getAcceptorConfigurations()
        .add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
    conf_0.getConnectorConfigurations().put(connectorConfig.getName(), connectorConfig);
    conf_0.getQueueConfigurations().add(sourceQueueConfig);
    conf_0.getBridgeConfigurations().add(bridgeConfig);

    server_1 =
        HornetQServers.newHornetQServer(conf_1, MBeanServerFactory.createMBeanServer(), false);
    addServer(server_1);
    server_1.start();

    server_0 = HornetQServers.newHornetQServer(conf_0, mbeanServer, false);
    addServer(server_0);
    server_0.start();
  }
Exemple #24
0
  private void deployClusterConnection(final ClusterConnectionConfiguration config)
      throws Exception {
    if (config.getName() == null) {
      HornetQServerLogger.LOGGER.clusterConnectionNotUnique();

      return;
    }

    if (config.getAddress() == null) {
      HornetQServerLogger.LOGGER.clusterConnectionNoForwardAddress();

      return;
    }

    TransportConfiguration connector =
        configuration.getConnectorConfigurations().get(config.getConnectorName());

    if (connector == null) {
      HornetQServerLogger.LOGGER.clusterConnectionNoConnector(config.getConnectorName());
      return;
    }

    if (clusterConnections.containsKey(config.getName())) {
      HornetQServerLogger.LOGGER.clusterConnectionAlreadyExists(config.getConnectorName());
      return;
    }

    ClusterConnectionImpl clusterConnection;
    DiscoveryGroupConfiguration dg;

    if (config.getDiscoveryGroupName() != null) {
      dg = configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());

      if (dg == null) {
        HornetQServerLogger.LOGGER.clusterConnectionNoDiscoveryGroup(
            config.getDiscoveryGroupName());
        return;
      }

      if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
        HornetQServerLogger.LOGGER.debug(
            this
                + " Starting a Discovery Group Cluster Connection, name="
                + config.getDiscoveryGroupName()
                + ", dg="
                + dg);
      }

      clusterConnection =
          new ClusterConnectionImpl(
              this,
              dg,
              connector,
              new SimpleString(config.getName()),
              new SimpleString(config.getAddress()),
              config.getMinLargeMessageSize(),
              config.getClientFailureCheckPeriod(),
              config.getConnectionTTL(),
              config.getRetryInterval(),
              config.getRetryIntervalMultiplier(),
              config.getMaxRetryInterval(),
              config.getReconnectAttempts(),
              config.getCallTimeout(),
              config.getCallFailoverTimeout(),
              config.isDuplicateDetection(),
              config.isForwardWhenNoConsumers(),
              config.getConfirmationWindowSize(),
              executorFactory,
              threadPool,
              server,
              postOffice,
              managementService,
              scheduledExecutor,
              config.getMaxHops(),
              nodeManager,
              backup,
              server.getConfiguration().getClusterUser(),
              server.getConfiguration().getClusterPassword(),
              config.isAllowDirectConnectionsOnly(),
              config.getClusterNotificationInterval(),
              config.getClusterNotificationAttempts());
    } else {
      TransportConfiguration[] tcConfigs =
          config.getStaticConnectors() != null
              ? connectorNameListToArray(config.getStaticConnectors())
              : null;

      if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
        HornetQServerLogger.LOGGER.debug(
            this + " defining cluster connection towards " + Arrays.toString(tcConfigs));
      }

      clusterConnection =
          new ClusterConnectionImpl(
              this,
              tcConfigs,
              connector,
              new SimpleString(config.getName()),
              new SimpleString(config.getAddress()),
              config.getMinLargeMessageSize(),
              config.getClientFailureCheckPeriod(),
              config.getConnectionTTL(),
              config.getRetryInterval(),
              config.getRetryIntervalMultiplier(),
              config.getMaxRetryInterval(),
              config.getReconnectAttempts(),
              config.getCallTimeout(),
              config.getCallFailoverTimeout(),
              config.isDuplicateDetection(),
              config.isForwardWhenNoConsumers(),
              config.getConfirmationWindowSize(),
              executorFactory,
              threadPool,
              server,
              postOffice,
              managementService,
              scheduledExecutor,
              config.getMaxHops(),
              nodeManager,
              backup,
              server.getConfiguration().getClusterUser(),
              server.getConfiguration().getClusterPassword(),
              config.isAllowDirectConnectionsOnly(),
              config.getClusterNotificationInterval(),
              config.getClusterNotificationAttempts());
    }

    if (defaultClusterConnection == null) {
      defaultClusterConnection = clusterConnection;
    }

    managementService.registerCluster(clusterConnection, config);

    clusterConnections.put(config.getName(), clusterConnection);

    if (HornetQServerLogger.LOGGER.isTraceEnabled()) {
      HornetQServerLogger.LOGGER.trace(
          "ClusterConnection.start at " + clusterConnection, new Exception("trace"));
    }
  }