Ejemplo n.º 1
0
 protected void removeAllMessages(final String queueName, final int index) throws Exception {
   ManagementService managementService = server0.getManagementService();
   if (index == 1) {
     managementService = server1.getManagementService();
   }
   JMSQueueControl queueControl =
       (JMSQueueControl) managementService.getResource(ResourceNames.JMS_QUEUE + queueName);
   queueControl.removeMessages(null);
 }
Ejemplo n.º 2
0
 protected void checkNoSubscriptions(final Topic topic, final int index) throws Exception {
   ManagementService managementService = server0.getManagementService();
   if (index == 1) {
     managementService = server1.getManagementService();
   }
   TopicControl topicControl =
       (TopicControl)
           managementService.getResource(ResourceNames.JMS_TOPIC + topic.getTopicName());
   Assert.assertEquals(0, topicControl.getSubscriptionCount());
 }
Ejemplo n.º 3
0
  public boolean checkEmpty(final Queue queue, final int index) throws Exception {
    ManagementService managementService = server0.getManagementService();
    if (index == 1) {
      managementService = server1.getManagementService();
    }
    JMSQueueControl queueControl =
        (JMSQueueControl)
            managementService.getResource(ResourceNames.JMS_QUEUE + queue.getQueueName());

    Long messageCount = queueControl.getMessageCount();

    if (messageCount > 0) {
      queueControl.removeMessages(null);
    }
    return true;
  }
Ejemplo n.º 4
0
  public void stop(final boolean criticalError) throws Exception {
    if (!started) {
      return;
    }

    failureCheckAndFlushThread.close(criticalError);

    // We need to stop them accepting first so no new connections are accepted after we send the
    // disconnect message
    for (Acceptor acceptor : acceptors) {
      if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
        HornetQServerLogger.LOGGER.debug("Pausing acceptor " + acceptor);
      }
      acceptor.pause();
    }

    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug("Sending disconnect on live connections");
    }

    HashSet<ConnectionEntry> connectionEntries = new HashSet<ConnectionEntry>(connections.values());

    // Now we ensure that no connections will process any more packets after this method is complete
    // then send a disconnect packet
    for (ConnectionEntry entry : connectionEntries) {
      RemotingConnection conn = entry.connection;

      if (HornetQServerLogger.LOGGER.isTraceEnabled()) {
        HornetQServerLogger.LOGGER.trace("Sending connection.disconnection packet to " + conn);
      }

      conn.disconnect(criticalError);
    }

    for (Acceptor acceptor : acceptors) {
      acceptor.stop();
    }

    acceptors.clear();

    connections.clear();

    if (managementService != null) {
      managementService.unregisterAcceptors();
    }

    threadPool.shutdown();

    if (!criticalError) {
      boolean ok = threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS);

      if (!ok) {
        HornetQServerLogger.LOGGER.timeoutRemotingThreadPool();
      }
    }

    started = false;
  }
Ejemplo n.º 5
0
  public void createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly)
      throws Exception {
    Binding binding = postOffice.getBinding(queueName);

    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
      throw HornetQMessageBundle.BUNDLE.noSuchQueue(queueName);
    }

    securityStore.check(binding.getAddress(), CheckType.CONSUME, this);

    Filter filter = FilterImpl.createFilter(filterString);

    ServerConsumer consumer =
        new ServerConsumerImpl(
            consumerID,
            this,
            (QueueBinding) binding,
            filter,
            started,
            browseOnly,
            storageManager,
            callback,
            preAcknowledge,
            strictUpdateDeliveryCount,
            managementService);

    consumers.put(consumer.getID(), consumer);

    if (!browseOnly) {
      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

      props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

      Queue theQueue = (Queue) binding.getBindable();

      props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

      if (filterString != null) {
        props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
      }

      Notification notification = new Notification(null, CONSUMER_CREATED, props);

      managementService.sendNotification(notification);
    }
  }
Ejemplo n.º 6
0
 public Response receive(final Proposal proposal, final int distance) throws Exception {
   TypedProperties props = new TypedProperties();
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());
   props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());
   props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);
   props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
   props.putIntProperty(ManagementHelper.HDR_DISTANCE, distance);
   Notification notification = new Notification(null, NotificationType.PROPOSAL, props);
   managementService.sendNotification(notification);
   return null;
 }
Ejemplo n.º 7
0
  public void stop() throws Exception {
    synchronized (this) {
      if (!started) {
        return;
      }

      if (clustered) {
        for (BroadcastGroup group : broadcastGroups.values()) {
          group.stop();
          managementService.unregisterBroadcastGroup(group.getName());
        }

        broadcastGroups.clear();

        for (ClusterConnection clusterConnection : clusterConnections.values()) {
          clusterConnection.stop();
          managementService.unregisterCluster(clusterConnection.getName().toString());
        }
      }

      for (Bridge bridge : bridges.values()) {
        bridge.stop();
        managementService.unregisterBridge(bridge.getName().toString());
      }

      bridges.clear();
    }

    for (ServerLocatorInternal clusterLocator : clusterLocators) {
      try {
        clusterLocator.close();
      } catch (Exception e) {
        log.warn(
            "Error closing serverLocator=" + clusterLocator + ", message=" + e.getMessage(), e);
      }
    }
    clusterLocators.clear();
    started = false;

    clearClusterConnections();
  }
Ejemplo n.º 8
0
  private synchronized void deployBroadcastGroup(final BroadcastGroupConfiguration config)
      throws Exception {
    if (broadcastGroups.containsKey(config.getName())) {
      HornetQServerLogger.LOGGER.broadcastGroupAlreadyExists(config.getName());

      return;
    }

    BroadcastGroup group = createBroadcastGroup(config);

    managementService.registerBroadcastGroup(group, config);
  }
Ejemplo n.º 9
0
  public void stop() throws Exception {
    if (!started) {
      return;
    }
    stopping = true;
    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(this + "::stopping ClusterConnection");
    }

    if (serverLocator != null) {
      serverLocator.removeClusterTopologyListener(this);
    }

    HornetQServerLogger.LOGGER.debug(
        "Cluster connection being stopped for node"
            + nodeManager.getNodeId()
            + ", server = "
            + this.server
            + " serverLocator = "
            + serverLocator);

    synchronized (this) {
      for (MessageFlowRecord record : records.values()) {
        try {
          record.close();
        } catch (Exception ignore) {
        }
      }
    }

    if (managementService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(new SimpleString("name"), name);
      Notification notification =
          new Notification(
              nodeManager.getNodeId().toString(),
              NotificationType.CLUSTER_CONNECTION_STOPPED,
              props);
      managementService.sendNotification(notification);
    }
    executor.execute(
        new Runnable() {
          public void run() {
            synchronized (ClusterConnectionImpl.this) {
              closeLocator(serverLocator);
              serverLocator = null;
            }
          }
        });

    started = false;
  }
Ejemplo n.º 10
0
  public void stop() throws Exception {
    synchronized (this) {
      if (state == State.STOPPED || state == State.STOPPING) {
        return;
      }
      state = State.STOPPING;

      for (BroadcastGroup group : broadcastGroups.values()) {
        group.stop();
        managementService.unregisterBroadcastGroup(group.getName());
      }

      broadcastGroups.clear();

      for (ClusterConnection clusterConnection : clusterConnections.values()) {
        clusterConnection.stop();
        managementService.unregisterCluster(clusterConnection.getName().toString());
      }

      for (Bridge bridge : bridges.values()) {
        bridge.stop();
        managementService.unregisterBridge(bridge.getName().toString());
      }

      bridges.clear();
    }

    for (ServerLocatorInternal clusterLocator : clusterLocators) {
      try {
        clusterLocator.close();
      } catch (Exception e) {
        HornetQServerLogger.LOGGER.errorClosingServerLocator(e, clusterLocator);
      }
    }
    clusterLocators.clear();
    state = State.STOPPED;

    clearClusterConnections();
  }
Ejemplo n.º 11
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);
  }
Ejemplo n.º 12
0
  public void destroyBridge(final String name) throws Exception {
    Bridge bridge;

    synchronized (this) {
      bridge = bridges.remove(name);
      if (bridge != null) {
        bridge.stop();
        managementService.unregisterBridge(name);
      }
    }
    if (bridge != null) {
      bridge.flushExecutor();
    }
  }
Ejemplo n.º 13
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);
    }
  }
Ejemplo n.º 14
0
  public Response propose(final Proposal proposal) throws Exception {
    // sanity check in case it is already selected
    Response response = responses.get(proposal.getGroupId());
    if (response != null) {
      return response;
    }

    try {
      lock.lock();

      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_GROUP_ID, proposal.getGroupId());

      props.putSimpleStringProperty(ManagementHelper.HDR_PROPOSAL_VALUE, proposal.getClusterName());

      props.putIntProperty(ManagementHelper.HDR_BINDING_TYPE, BindingType.LOCAL_QUEUE_INDEX);

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, 0);

      Notification notification = new Notification(null, NotificationType.PROPOSAL, props);

      managementService.sendNotification(notification);

      if (!sendCondition.await(timeout, TimeUnit.MILLISECONDS))
        HornetQLogger.LOGGER.groupHandlerSendTimeout();
      response = responses.get(proposal.getGroupId());

    } finally {
      lock.unlock();
    }
    if (response == null) {
      throw new IllegalStateException(
          "no response received from group handler for " + proposal.getGroupId());
    }
    return response;
  }
Ejemplo n.º 15
0
  private void createNewRecord(
      final long eventUID,
      final String targetNodeID,
      final TransportConfiguration connector,
      final SimpleString queueName,
      final Queue queue,
      final boolean start)
      throws Exception {
    String nodeId;

    synchronized (this) {
      if (!started) {
        return;
      }

      if (serverLocator == null) {
        return;
      }

      nodeId = serverLocator.getNodeID();
    }

    final ServerLocatorInternal targetLocator = new ServerLocatorImpl(topology, true, connector);

    targetLocator.setReconnectAttempts(0);

    targetLocator.setInitialConnectAttempts(0);
    targetLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    targetLocator.setConnectionTTL(connectionTTL);
    targetLocator.setInitialConnectAttempts(0);

    targetLocator.setConfirmationWindowSize(confirmationWindowSize);
    targetLocator.setBlockOnDurableSend(!useDuplicateDetection);
    targetLocator.setBlockOnNonDurableSend(!useDuplicateDetection);

    targetLocator.setRetryInterval(retryInterval);
    targetLocator.setMaxRetryInterval(maxRetryInterval);
    targetLocator.setRetryIntervalMultiplier(retryIntervalMultiplier);
    targetLocator.setMinLargeMessageSize(minLargeMessageSize);

    // No producer flow control on the bridges, as we don't want to lock the queues
    targetLocator.setProducerWindowSize(-1);

    targetLocator.setAfterConnectionInternalListener(this);

    targetLocator.setNodeID(nodeId);

    targetLocator.setClusterTransportConfiguration(
        serverLocator.getClusterTransportConfiguration());

    if (retryInterval > 0) {
      targetLocator.setRetryInterval(retryInterval);
    }

    targetLocator.disableFinalizeCheck();
    targetLocator.addIncomingInterceptor(
        new IncomingInterceptorLookingForExceptionMessage(manager, executorFactory.getExecutor()));
    MessageFlowRecordImpl record =
        new MessageFlowRecordImpl(
            targetLocator, eventUID, targetNodeID, connector, queueName, queue);

    ClusterConnectionBridge bridge =
        new ClusterConnectionBridge(
            this,
            manager,
            targetLocator,
            serverLocator,
            reconnectAttempts,
            retryInterval,
            retryIntervalMultiplier,
            maxRetryInterval,
            nodeManager.getUUID(),
            record.getEventUID(),
            record.getTargetNodeID(),
            record.getQueueName(),
            record.getQueue(),
            executorFactory.getExecutor(),
            null,
            null,
            scheduledExecutor,
            null,
            useDuplicateDetection,
            clusterUser,
            clusterPassword,
            server.getStorageManager(),
            managementService.getManagementAddress(),
            managementService.getManagementNotificationAddress(),
            record,
            record.getConnector());

    targetLocator.setIdentity(
        "(Cluster-connection-bridge::" + bridge.toString() + "::" + this.toString() + ")");

    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(
          "creating record between " + this.connector + " and " + connector + bridge);
    }

    record.setBridge(bridge);

    records.put(targetNodeID, record);

    if (start) {
      bridge.start();
    }
  }
Ejemplo n.º 16
0
  public synchronized void deployBridge(final BridgeConfiguration config, final boolean start)
      throws Exception {
    if (config.getName() == null) {
      ClusterManagerImpl.log.warn(
          "Must specify a unique name for each bridge. This one will not be deployed.");

      return;
    }

    if (config.getQueueName() == null) {
      ClusterManagerImpl.log.warn(
          "Must specify a queue name for each bridge. This one will not be deployed.");

      return;
    }

    if (config.getForwardingAddress() == null) {
      ClusterManagerImpl.log.debug(
          "Forward address is not specified. Will use original message address instead");
    }

    if (bridges.containsKey(config.getName())) {
      ClusterManagerImpl.log.warn(
          "There is already a bridge with name "
              + config.getName()
              + " deployed. This one will not be deployed.");

      return;
    }

    Transformer transformer = instantiateTransformer(config.getTransformerClassName());

    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));

    if (binding == null) {
      ClusterManagerImpl.log.warn(
          "No queue found with name " + config.getQueueName() + " bridge will not be deployed.");

      return;
    }

    Queue queue = (Queue) binding.getBindable();

    ServerLocatorInternal serverLocator;

    if (config.getDiscoveryGroupName() != null) {
      DiscoveryGroupConfiguration discoveryGroupConfiguration =
          configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
      if (discoveryGroupConfiguration == null) {
        ClusterManagerImpl.log.warn(
            "No discovery group configured with name '"
                + config.getDiscoveryGroupName()
                + "'. The bridge will not be deployed.");

        return;
      }

      if (config.isHA()) {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
      } else {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
      }

    } else {
      TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors());

      if (tcConfigs == null) {
        return;
      }

      if (config.isHA()) {
        serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs);
      } else {
        serverLocator =
            (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs);
      }
    }

    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());

    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(-1);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    // disable flow control
    serverLocator.setProducerWindowSize(-1);

    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    if (!config.isUseDuplicateDetection()) {
      log.debug(
          "Bridge "
              + config.getName()
              + " is configured to not use duplicate detecion, it will send messages synchronously");
    }

    clusterLocators.add(serverLocator);

    Bridge bridge =
        new BridgeImpl(
            serverLocator,
            config.getReconnectAttempts(),
            config.getRetryInterval(),
            config.getRetryIntervalMultiplier(),
            config.getMaxRetryInterval(),
            nodeUUID,
            new SimpleString(config.getName()),
            queue,
            executorFactory.getExecutor(),
            SimpleString.toSimpleString(config.getFilterString()),
            SimpleString.toSimpleString(config.getForwardingAddress()),
            scheduledExecutor,
            transformer,
            config.isUseDuplicateDetection(),
            config.getUser(),
            config.getPassword(),
            !backup,
            server.getStorageManager());

    bridges.put(config.getName(), bridge);

    managementService.registerBridge(bridge, config);

    if (start) {
      bridge.start();
    }
  }
Ejemplo n.º 17
0
  private synchronized void activate() throws Exception {
    if (!started) {
      return;
    }

    if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
      HornetQServerLogger.LOGGER.debug(
          "Activating cluster connection nodeID="
              + nodeManager.getNodeId()
              + " for server="
              + this.server);
    }

    liveNotifier = new LiveNotifier();
    liveNotifier.updateAsLive();
    liveNotifier.schedule();

    serverLocator = clusterConnector.createServerLocator();

    if (serverLocator != null) {

      if (!useDuplicateDetection) {
        HornetQServerLogger.LOGGER.debug(
            "DuplicateDetection is disabled, sending clustered messages blocked");
      }

      final TopologyMember currentMember = topology.getMember(manager.getNodeId());

      if (currentMember == null) {
        // sanity check only
        throw new IllegalStateException(
            "InternalError! The ClusterConnection doesn't know about its own node = " + this);
      }

      serverLocator.setNodeID(nodeManager.getNodeId().toString());
      serverLocator.setIdentity("(main-ClusterConnection::" + server.toString() + ")");
      serverLocator.setReconnectAttempts(0);
      serverLocator.setClusterConnection(true);
      serverLocator.setClusterTransportConfiguration(connector);
      serverLocator.setInitialConnectAttempts(-1);
      serverLocator.setClientFailureCheckPeriod(clientFailureCheckPeriod);
      serverLocator.setConnectionTTL(connectionTTL);
      serverLocator.setConfirmationWindowSize(confirmationWindowSize);
      // if not using duplicate detection, we will send blocked
      serverLocator.setBlockOnDurableSend(!useDuplicateDetection);
      serverLocator.setBlockOnNonDurableSend(!useDuplicateDetection);
      serverLocator.setCallTimeout(callTimeout);
      serverLocator.setCallFailoverTimeout(callFailoverTimeout);
      // No producer flow control on the bridges, as we don't want to lock the queues
      serverLocator.setProducerWindowSize(-1);

      if (retryInterval > 0) {
        this.serverLocator.setRetryInterval(retryInterval);
      }

      addClusterTopologyListener(this);

      serverLocator.setAfterConnectionInternalListener(this);

      serverLocator.start(server.getExecutorFactory().getExecutor());
    }

    if (managementService != null) {
      TypedProperties props = new TypedProperties();
      props.putSimpleStringProperty(new SimpleString("name"), name);
      Notification notification =
          new Notification(
              nodeManager.getNodeId().toString(),
              NotificationType.CLUSTER_CONNECTION_STARTED,
              props);
      HornetQServerLogger.LOGGER.debug("sending notification: " + notification);
      managementService.sendNotification(notification);
    }
  }
Ejemplo n.º 18
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"));
    }
  }
Ejemplo n.º 19
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"));
    }
  }
Ejemplo n.º 20
0
  public synchronized void deployBridge(final BridgeConfiguration config) throws Exception {
    if (config.getName() == null) {
      HornetQServerLogger.LOGGER.bridgeNotUnique();

      return;
    }

    if (config.getQueueName() == null) {
      HornetQServerLogger.LOGGER.bridgeNoQueue(config.getName());

      return;
    }

    if (config.getForwardingAddress() == null) {
      HornetQServerLogger.LOGGER.bridgeNoForwardAddress(config.getName());
    }

    if (bridges.containsKey(config.getName())) {
      HornetQServerLogger.LOGGER.bridgeAlreadyDeployed(config.getName());

      return;
    }

    Transformer transformer = instantiateTransformer(config.getTransformerClassName());

    Binding binding = postOffice.getBinding(new SimpleString(config.getQueueName()));

    if (binding == null) {
      HornetQServerLogger.LOGGER.bridgeQueueNotFound(config.getQueueName(), config.getName());

      return;
    }

    Queue queue = (Queue) binding.getBindable();

    ServerLocatorInternal serverLocator;

    if (config.getDiscoveryGroupName() != null) {
      DiscoveryGroupConfiguration discoveryGroupConfiguration =
          configuration.getDiscoveryGroupConfigurations().get(config.getDiscoveryGroupName());
      if (discoveryGroupConfiguration == null) {
        HornetQServerLogger.LOGGER.bridgeNoDiscoveryGroup(config.getDiscoveryGroupName());

        return;
      }

      if (config.isHA()) {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithHA(discoveryGroupConfiguration);
      } else {
        serverLocator =
            (ServerLocatorInternal)
                HornetQClient.createServerLocatorWithoutHA(discoveryGroupConfiguration);
      }

    } else {
      TransportConfiguration[] tcConfigs = connectorNameListToArray(config.getStaticConnectors());

      if (tcConfigs == null) {
        HornetQServerLogger.LOGGER.bridgeCantFindConnectors(config.getName());
        return;
      }

      if (config.isHA()) {
        serverLocator = (ServerLocatorInternal) HornetQClient.createServerLocatorWithHA(tcConfigs);
      } else {
        serverLocator =
            (ServerLocatorInternal) HornetQClient.createServerLocatorWithoutHA(tcConfigs);
      }
    }

    if (config.getForwardingAddress() != null) {
      AddressSettings addressConfig =
          configuration.getAddressesSettings().get(config.getForwardingAddress());

      // The address config could be null on certain test cases or some Embedded environment
      if (addressConfig == null) {
        // We will certainly have this warning on testcases which is ok
        HornetQServerLogger.LOGGER.bridgeCantFindAddressConfig(
            config.getName(), config.getForwardingAddress());
      } else {
        final int windowSize = config.getConfirmationWindowSize();
        final long maxBytes = addressConfig.getMaxSizeBytes();

        if (maxBytes != -1 && maxBytes < windowSize) {
          HornetQServerLogger.LOGGER.bridgeConfirmationWindowTooSmall(
              config.getName(), config.getForwardingAddress(), windowSize, maxBytes);
        }
      }
    }

    serverLocator.setIdentity("Bridge " + config.getName());
    serverLocator.setConfirmationWindowSize(config.getConfirmationWindowSize());

    // We are going to manually retry on the bridge in case of failure
    serverLocator.setReconnectAttempts(0);
    serverLocator.setInitialConnectAttempts(0);
    serverLocator.setRetryInterval(config.getRetryInterval());
    serverLocator.setMaxRetryInterval(config.getMaxRetryInterval());
    serverLocator.setRetryIntervalMultiplier(config.getRetryIntervalMultiplier());
    serverLocator.setClientFailureCheckPeriod(config.getClientFailureCheckPeriod());
    serverLocator.setConnectionTTL(config.getConnectionTTL());
    serverLocator.setBlockOnDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setBlockOnNonDurableSend(!config.isUseDuplicateDetection());
    serverLocator.setMinLargeMessageSize(config.getMinLargeMessageSize());
    // disable flow control
    serverLocator.setProducerWindowSize(-1);

    // This will be set to 30s unless it's changed from embedded / testing
    // there is no reason to exception the config for this timeout
    // since the Bridge is supposed to be non-blocking and fast
    // We may expose this if we find a good use case
    serverLocator.setCallTimeout(config.getCallTimeout());
    if (!config.isUseDuplicateDetection()) {
      HornetQServerLogger.LOGGER.debug(
          "Bridge "
              + config.getName()
              + " is configured to not use duplicate detecion, it will send messages synchronously");
    }

    clusterLocators.add(serverLocator);

    Bridge bridge =
        new BridgeImpl(
            serverLocator,
            config.getReconnectAttempts(),
            config.getReconnectAttemptsOnSameNode(),
            config.getRetryInterval(),
            config.getRetryIntervalMultiplier(),
            config.getMaxRetryInterval(),
            nodeManager.getUUID(),
            new SimpleString(config.getName()),
            queue,
            executorFactory.getExecutor(),
            FilterImpl.createFilter(config.getFilterString()),
            SimpleString.toSimpleString(config.getForwardingAddress()),
            scheduledExecutor,
            transformer,
            config.isUseDuplicateDetection(),
            config.getUser(),
            config.getPassword(),
            !backup,
            server.getStorageManager());

    bridges.put(config.getName(), bridge);

    managementService.registerBridge(bridge, config);

    bridge.start();
  }
Ejemplo n.º 21
0
  public synchronized void start() throws Exception {
    if (started) {
      return;
    }

    ClassLoader tccl =
        AccessController.doPrivileged(
            new PrivilegedAction<ClassLoader>() {
              public ClassLoader run() {
                return Thread.currentThread().getContextClassLoader();
              }
            });

    // The remoting service maintains it's own thread pool for handling remoting traffic
    // If OIO each connection will have it's own thread
    // If NIO these are capped at nio-remoting-threads which defaults to num cores * 3
    // This needs to be a different thread pool to the main thread pool especially for OIO where we
    // may need
    // to support many hundreds of connections, but the main thread pool must be kept small for
    // better performance

    ThreadFactory tFactory =
        new HornetQThreadFactory(
            "HornetQ-remoting-threads-" + server.toString() + "-" + System.identityHashCode(this),
            false,
            tccl);

    threadPool = Executors.newCachedThreadPool(tFactory);

    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    for (TransportConfiguration info : acceptorsConfig) {
      try {
        Class<?> clazz = loader.loadClass(info.getFactoryClassName());

        AcceptorFactory factory = (AcceptorFactory) clazz.newInstance();

        // Check valid properties

        if (info.getParams() != null) {
          Set<String> invalid =
              ConfigurationHelper.checkKeys(
                  factory.getAllowableProperties(), info.getParams().keySet());

          if (!invalid.isEmpty()) {
            HornetQServerLogger.LOGGER.invalidAcceptorKeys(
                ConfigurationHelper.stringSetToCommaListString(invalid));

            continue;
          }
        }

        String protocol =
            ConfigurationHelper.getStringProperty(
                TransportConstants.PROTOCOL_PROP_NAME,
                TransportConstants.DEFAULT_PROTOCOL,
                info.getParams());

        ProtocolManager manager = protocolMap.get(protocol);
        if (manager == null) {
          throw HornetQMessageBundle.BUNDLE.noProtocolManagerFound(protocol);
        }
        ClusterConnection clusterConnection = lookupClusterConnection(info);

        Acceptor acceptor =
            factory.createAcceptor(
                clusterConnection,
                info.getParams(),
                new DelegatingBufferHandler(),
                manager,
                this,
                threadPool,
                scheduledThreadPool,
                manager);

        if (defaultInvmSecurityPrincipal != null && acceptor.isUnsecurable()) {
          acceptor.setDefaultHornetQPrincipal(defaultInvmSecurityPrincipal);
        }

        acceptors.add(acceptor);

        if (managementService != null) {
          acceptor.setNotificationService(managementService);

          managementService.registerAcceptor(acceptor, info);
        }
      } catch (Exception e) {
        HornetQServerLogger.LOGGER.errorCreatingAcceptor(e, info.getFactoryClassName());
      }
    }

    for (Acceptor a : acceptors) {
      a.start();
    }

    // This thread checks connections that need to be closed, and also flushes confirmations
    failureCheckAndFlushThread =
        new FailureCheckAndFlushThread(RemotingServiceImpl.CONNECTION_TTL_CHECK_INTERVAL);

    failureCheckAndFlushThread.start();

    started = true;
  }
Ejemplo n.º 22
0
  public void close(final boolean failed) throws Exception {
    callback.removeReadyListener(this);

    setStarted(false);

    LargeMessageDeliverer del = largeMessageDeliverer;

    if (del != null) {
      del.finish();
    }

    if (browseOnly) {
      browserDeliverer.close();
    } else {
      messageQueue.removeConsumer(this);
    }

    session.removeConsumer(id);

    LinkedList<MessageReference> refs = cancelRefs(failed, false, null);

    Iterator<MessageReference> iter = refs.iterator();

    Transaction tx = new TransactionImpl(storageManager);

    while (iter.hasNext()) {
      MessageReference ref = iter.next();

      ref.getQueue().cancel(tx, ref);
    }

    tx.rollback();

    if (!browseOnly) {
      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

      props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

      props.putSimpleStringProperty(
          ManagementHelper.HDR_FILTERSTRING, filter == null ? null : filter.getFilterString());

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

      props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, messageQueue.getConsumerCount());

      // HORNETQ-946
      props.putSimpleStringProperty(
          ManagementHelper.HDR_USER, SimpleString.toSimpleString(session.getUsername()));

      props.putSimpleStringProperty(
          ManagementHelper.HDR_REMOTE_ADDRESS,
          SimpleString.toSimpleString(
              ((ServerSessionImpl) session).getRemotingConnection().getRemoteAddress()));

      props.putSimpleStringProperty(
          ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(session.getName()));

      Notification notification = new Notification(null, NotificationType.CONSUMER_CLOSED, props);

      managementService.sendNotification(notification);
    }
  }
Ejemplo n.º 23
0
  public void createConsumer(
      final long consumerID,
      final SimpleString queueName,
      final SimpleString filterString,
      final boolean browseOnly,
      final boolean supportLargeMessage,
      final Integer credits)
      throws Exception {
    Binding binding = postOffice.getBinding(queueName);

    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
      throw HornetQMessageBundle.BUNDLE.noSuchQueue(queueName);
    }

    securityStore.check(binding.getAddress(), CheckType.CONSUME, this);

    Filter filter = FilterImpl.createFilter(filterString);

    ServerConsumer consumer =
        new ServerConsumerImpl(
            consumerID,
            this,
            (QueueBinding) binding,
            filter,
            started,
            browseOnly,
            storageManager,
            callback,
            preAcknowledge,
            strictUpdateDeliveryCount,
            managementService,
            supportLargeMessage,
            credits);
    consumers.put(consumer.getID(), consumer);

    if (!browseOnly) {
      TypedProperties props = new TypedProperties();

      props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());

      props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());

      props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());

      props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());

      Queue theQueue = (Queue) binding.getBindable();

      props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());

      // HORNETQ-946
      props.putSimpleStringProperty(
          ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));

      props.putSimpleStringProperty(
          ManagementHelper.HDR_REMOTE_ADDRESS,
          SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));

      props.putSimpleStringProperty(
          ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));

      if (filterString != null) {
        props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
      }

      Notification notification = new Notification(null, CONSUMER_CREATED, props);

      if (HornetQServerLogger.LOGGER.isDebugEnabled()) {
        HornetQServerLogger.LOGGER.debug(
            "Session with user="******", connection="
                + this.remotingConnection
                + " created a consumer on queue "
                + queueName
                + ", filter = "
                + filterString);
      }

      managementService.sendNotification(notification);
    }
  }