Пример #1
0
  /**
   * This is directly called when the connection to the node is gone, or when the node sends a
   * disconnection. Look for callers of this method!
   */
  public void notifyNodeDown(final long eventTime, final String nodeID) {

    if (!ha) {
      // there's no topology here
      return;
    }

    if (HornetQLogger.LOGGER.isDebugEnabled()) {
      HornetQLogger.LOGGER.debug(
          "nodeDown " + this + " nodeID=" + nodeID + " as being down", new Exception("trace"));
    }

    topology.removeMember(eventTime, nodeID);

    if (clusterConnection) {
      updateArraysAndPairs();
    } else {
      synchronized (this) {
        if (topology.isEmpty()) {
          // Resetting the topology to its original condition as it was brand new
          receivedTopology = false;
          topologyArray = null;
        } else {
          updateArraysAndPairs();

          if (topology.nodes() == 1 && topology.getMember(this.nodeID) != null) {
            // Resetting the topology to its original condition as it was brand new
            receivedTopology = false;
          }
        }
      }
    }
  }
Пример #2
0
  public void receiveConsumerCredits(final long consumerID, final int credits) throws Exception {
    ServerConsumer consumer = consumers.get(consumerID);

    if (consumer == null) {
      HornetQLogger.LOGGER.debug("There is no consumer with id " + consumerID);

      return;
    }

    consumer.receiveCredits(credits);
  }
Пример #3
0
      public ClientSessionFactory tryConnect() throws HornetQException {
        if (HornetQLogger.LOGGER.isDebugEnabled()) {
          HornetQLogger.LOGGER.debug(this + "::Trying to connect to " + factory);
        }
        try {
          ClientSessionFactoryInternal factoryToUse = factory;
          if (factoryToUse != null) {
            addToConnecting(factoryToUse);

            try {
              factoryToUse.connect(1, false);
            } finally {
              removeFromConnecting(factoryToUse);
            }
          }
          return factoryToUse;
        } catch (HornetQException e) {
          HornetQLogger.LOGGER.debug(
              this + "::Exception on establish connector initial connection", e);
          return null;
        }
      }
Пример #4
0
    private void run() {
      try {
        if (HornetQLogger.LOGGER.isDebugEnabled()) {
          HornetQLogger.LOGGER.debug("deleting temporary queue " + bindingName);
        }
        if (postOffice.getBinding(bindingName) != null) {
          postOffice.removeBinding(bindingName);
        }

        queue.deleteAllReferences();
      } catch (Exception e) {
        HornetQLogger.LOGGER.errorRemovingTempQueue(e, bindingName);
      }
    }
Пример #5
0
  public void notifyNodeUp(
      long uniqueEventID,
      final String nodeID,
      final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
      final boolean last) {
    if (!ha) {
      // there's no topology
      return;
    }

    if (HornetQLogger.LOGGER.isDebugEnabled()) {
      HornetQLogger.LOGGER.debug(
          "NodeUp " + this + "::nodeID=" + nodeID + ", connectorPair=" + connectorPair,
          new Exception("trace"));
    }

    TopologyMember member = new TopologyMember(connectorPair.getA(), connectorPair.getB());

    topology.updateMember(uniqueEventID, nodeID, member);

    TopologyMember actMember = topology.getMember(nodeID);

    if (actMember != null
        && actMember.getConnector().getA() != null
        && actMember.getConnector().getB() != null) {
      HashSet<ClientSessionFactory> clonedFactories = new HashSet<ClientSessionFactory>();
      synchronized (factories) {
        clonedFactories.addAll(factories);
      }

      for (ClientSessionFactory factory : clonedFactories) {
        ((ClientSessionFactoryInternal) factory)
            .setBackupConnector(actMember.getConnector().getA(), actMember.getConnector().getB());
      }
    }

    updateArraysAndPairs();

    if (last) {
      synchronized (this) {
        receivedTopology = true;
        // Notify if waiting on getting topology
        notifyAll();
      }
    }
  }
Пример #6
0
    public void run() {
      while (true) {
        try {
          if (thread.isInterrupted() && !started) {
            break;
          }

          Thread.sleep(measureInterval);
        } catch (InterruptedException ignore) {
          if (!started) {
            break;
          }
        }

        long maxMemory = runtime.maxMemory();

        long totalMemory = runtime.totalMemory();

        long freeMemory = runtime.freeMemory();

        long availableMemory = freeMemory + maxMemory - totalMemory;

        double availableMemoryPercent = 100.0 * availableMemory / maxMemory;

        StringBuilder info = new StringBuilder();
        info.append(String.format("free memory:      %s%n", SizeFormatterUtil.sizeof(freeMemory)));
        info.append(String.format("max memory:       %s%n", SizeFormatterUtil.sizeof(maxMemory)));
        info.append(String.format("total memory:     %s%n", SizeFormatterUtil.sizeof(totalMemory)));
        info.append(String.format("available memory: %.2f%%%n", availableMemoryPercent));

        if (HornetQLogger.LOGGER.isDebugEnabled()) {
          HornetQLogger.LOGGER.debug(info);
        }

        if (availableMemoryPercent <= memoryWarningThreshold) {
          HornetQLogger.LOGGER.memoryError(memoryWarningThreshold, info.toString());

          low = true;
        } else {
          low = false;
        }
      }
    }
Пример #7
0
  public synchronized void start() {
    HornetQLogger.LOGGER.debug(
        "Starting MemoryManager with MEASURE_INTERVAL: "
            + measureInterval
            + " FREE_MEMORY_PERCENT: "
            + memoryWarningThreshold);

    if (started) {
      // Already started
      return;
    }

    started = true;

    thread = new Thread(new MemoryRunnable(), "hornetq-memory-manager-thread");

    thread.setDaemon(true);

    thread.start();
  }
Пример #8
0
    public void handlePacket(final Packet packet) {
      if (packet.getType() == PacketImpl.PING) {
        Ping ping = (Ping) packet;

        if (config.getConnectionTTLOverride() == -1) {
          // Allow clients to specify connection ttl
          entry.ttl = ping.getConnectionTTL();
        }

        // Just send a ping back
        channel0.send(packet);
      } else if (packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY
          || packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY_V2) {
        SubscribeClusterTopologyUpdatesMessage msg =
            (SubscribeClusterTopologyUpdatesMessage) packet;

        if (packet.getType() == PacketImpl.SUBSCRIBE_TOPOLOGY_V2) {
          channel0
              .getConnection()
              .setClientVersion(
                  ((SubscribeClusterTopologyUpdatesMessageV2) msg).getClientVersion());
        }

        final ClusterTopologyListener listener =
            new ClusterTopologyListener() {
              public void nodeUP(
                  final long uniqueEventID,
                  final String nodeID,
                  final Pair<TransportConfiguration, TransportConfiguration> connectorPair,
                  final boolean last) {
                // Using an executor as most of the notifications on the Topology
                // may come from a channel itself
                // What could cause deadlocks
                entry.connectionExecutor.execute(
                    new Runnable() {
                      public void run() {
                        if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                          channel0.send(
                              new ClusterTopologyChangeMessage_V2(
                                  uniqueEventID, nodeID, connectorPair, last));
                        } else {
                          channel0.send(
                              new ClusterTopologyChangeMessage(nodeID, connectorPair, last));
                        }
                      }
                    });
              }

              public void nodeDown(final long uniqueEventID, final String nodeID) {
                // Using an executor as most of the notifications on the Topology
                // may come from a channel itself
                // What could cause deadlocks
                entry.connectionExecutor.execute(
                    new Runnable() {
                      public void run() {
                        if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                          channel0.send(new ClusterTopologyChangeMessage_V2(uniqueEventID, nodeID));
                        } else {
                          channel0.send(new ClusterTopologyChangeMessage(nodeID));
                        }
                      }
                    });
              }

              @Override
              public String toString() {
                return "Remote Proxy on channel "
                    + Integer.toHexString(System.identityHashCode(this));
              }
            };

        if (acceptorUsed.getClusterConnection() != null) {
          acceptorUsed.getClusterConnection().addClusterTopologyListener(listener);

          rc.addCloseListener(
              new CloseListener() {
                public void connectionClosed() {
                  acceptorUsed.getClusterConnection().removeClusterTopologyListener(listener);
                }
              });
        } else {
          // if not clustered, we send a single notification to the client containing the node-id
          // where the server is connected to
          // This is done this way so Recovery discovery could also use the node-id for
          // non-clustered setups
          entry.connectionExecutor.execute(
              new Runnable() {
                public void run() {
                  String nodeId = server.getNodeID().toString();
                  Pair<TransportConfiguration, TransportConfiguration> emptyConfig =
                      new Pair<TransportConfiguration, TransportConfiguration>(null, null);
                  if (channel0.supports(PacketImpl.CLUSTER_TOPOLOGY_V2)) {
                    channel0.send(
                        new ClusterTopologyChangeMessage_V2(
                            System.currentTimeMillis(), nodeId, emptyConfig, true));
                  } else {
                    channel0.send(new ClusterTopologyChangeMessage(nodeId, emptyConfig, true));
                  }
                }
              });
        }
      } else if (packet.getType() == PacketImpl.NODE_ANNOUNCE) {
        NodeAnnounceMessage msg = (NodeAnnounceMessage) packet;

        Pair<TransportConfiguration, TransportConfiguration> pair;
        if (msg.isBackup()) {
          pair = new Pair<TransportConfiguration, TransportConfiguration>(null, msg.getConnector());
        } else {
          pair =
              new Pair<TransportConfiguration, TransportConfiguration>(
                  msg.getConnector(), msg.getBackupConnector());
        }
        if (isTrace) {
          HornetQLogger.LOGGER.trace(
              "Server "
                  + server
                  + " receiving nodeUp from NodeID="
                  + msg.getNodeID()
                  + ", pair="
                  + pair);
        }

        if (acceptorUsed != null) {
          ClusterConnection clusterConn = acceptorUsed.getClusterConnection();
          if (clusterConn != null) {
            clusterConn.nodeAnnounced(
                msg.getCurrentEventID(), msg.getNodeID(), pair, msg.isBackup());
          } else {
            HornetQLogger.LOGGER.debug("Cluster connection is null on acceptor = " + acceptorUsed);
          }
        } else {
          HornetQLogger.LOGGER.debug(
              "there is no acceptor used configured at the CoreProtocolManager " + this);
        }
      } else if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
        BackupRegistrationMessage msg = (BackupRegistrationMessage) packet;
        ClusterConnection clusterConnection = acceptorUsed.getClusterConnection();

        if (clusterConnection.verify(msg.getClusterUser(), msg.getClusterPassword())) {
          try {
            server.startReplication(
                rc, clusterConnection, getPair(msg.getConnector(), true), msg.isFailBackRequest());
          } catch (HornetQException e) {
            channel0.send(new BackupRegistrationFailedMessage(e));
          }
        } else {
          channel0.send(new BackupRegistrationFailedMessage(null));
        }
      }
    }
Пример #9
0
    public ClientSessionFactory connect() throws HornetQException {
      assertOpen();

      initialise();

      ClientSessionFactory csf = null;

      createConnectors();

      try {

        int retryNumber = 0;
        while (csf == null && !isClosed()) {
          retryNumber++;
          for (Connector conn : connectors) {
            if (HornetQLogger.LOGGER.isDebugEnabled()) {
              HornetQLogger.LOGGER.debug(this + "::Submitting connect towards " + conn);
            }

            csf = conn.tryConnect();

            if (csf != null) {
              csf.getConnection()
                  .addFailureListener(
                      new FailureListener() {
                        // Case the node where the cluster connection was connected is gone, we need
                        // to restart the
                        // connection
                        public void connectionFailed(
                            HornetQException exception, boolean failedOver) {
                          if (clusterConnection
                              && exception.getType() == HornetQExceptionType.DISCONNECTED) {
                            try {
                              ServerLocatorImpl.this.start(startExecutor);
                            } catch (Exception e) {
                              // There isn't much to be done if this happens here
                              HornetQLogger.LOGGER.errorStartingLocator(e);
                            }
                          }
                        }

                        @Override
                        public String toString() {
                          return "FailureListener('restarts cluster connections')";
                        }
                      });

              if (HornetQLogger.LOGGER.isDebugEnabled()) {
                HornetQLogger.LOGGER.debug(
                    "Returning "
                        + csf
                        + " after "
                        + retryNumber
                        + " retries on StaticConnector "
                        + ServerLocatorImpl.this);
              }

              return csf;
            }
          }

          if (initialConnectAttempts >= 0 && retryNumber > initialConnectAttempts) {
            break;
          }

          if (!isClosed()) {
            Thread.sleep(retryInterval);
          }
        }

      } catch (RejectedExecutionException e) {
        HornetQLogger.LOGGER.debug("Rejected execution", e);
        throw e;
      } catch (Exception e) {
        HornetQLogger.LOGGER.errorConnectingToNodes(e);
        throw HornetQMessageBundle.BUNDLE.cannotConnectToStaticConnectors(e);
      }

      if (!isClosed()) {
        HornetQLogger.LOGGER.errorConnectingToNodes(e);
        throw HornetQMessageBundle.BUNDLE.cannotConnectToStaticConnectors2();
      }
      return null;
    }
Пример #10
0
  private void doClose(final boolean sendClose) {
    if (state == STATE.CLOSED) {
      if (HornetQLogger.LOGGER.isDebugEnabled()) {
        HornetQLogger.LOGGER.debug(this + " is already closed when calling closed");
      }
      return;
    }

    state = STATE.CLOSING;

    if (discoveryGroup != null) {
      synchronized (this) {
        try {
          discoveryGroup.stop();
        } catch (Exception e) {
          HornetQLogger.LOGGER.failedToStopDiscovery(e);
        }
      }
    } else {
      staticConnector.disconnect();
    }

    synchronized (connectingFactories) {
      for (ClientSessionFactoryInternal csf : connectingFactories) {
        csf.close();
      }
      connectingFactories.clear();
    }

    Set<ClientSessionFactoryInternal> clonedFactory;
    synchronized (factories) {
      clonedFactory = new HashSet<ClientSessionFactoryInternal>(factories);

      factories.clear();
    }

    for (ClientSessionFactory factory : clonedFactory) {
      if (sendClose) {
        factory.close();
      } else {
        factory.cleanup();
      }
    }

    if (shutdownPool) {
      if (threadPool != null) {
        threadPool.shutdown();

        try {
          if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
            HornetQLogger.LOGGER.timedOutWaitingForTermination();
          }
        } catch (InterruptedException ignore) {
        }
      }

      if (scheduledThreadPool != null) {
        scheduledThreadPool.shutdown();

        try {
          if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
            HornetQLogger.LOGGER.timedOutWaitingForScheduledPoolTermination();
          }
        } catch (InterruptedException ignore) {
        }
      }
    }
    readOnly = false;

    state = STATE.CLOSED;
  }