Beispiel #1
0
  /**
   * Registers the monitor with the group so that it can be kept informed about the outcome of
   * elections and group membership changes. The monitor, just like a replication node, is
   * identified by its nodeName. The Monitor uses the helper nodes to locate a master with which it
   * can register itself. If the helper nodes are not available the registration will fail.
   *
   * <p>A monitor must be registered at least once, if it needs to be kept up to date about ongoing
   * election results and group changes. Attempts to re-register the same monitor are ignored.
   * Registration, once it has been completed successfully persists beyond the lifetime of the
   * Monitor instance and does not need to be repeated. Repeated registrations are benign and merely
   * confirm that the current monitor configuration is consistent with earlier registrations of this
   * monitor.
   *
   * @return the node that is the current master
   * @throws EnvironmentFailureException if an unexpected, internal or environment-wide failure
   *     occurs.
   * @throws IllegalStateException if the monitor has been shutdown, or no helper sockets were
   *     specified at Monitor initialization.
   */
  public ReplicationNode register() throws EnvironmentFailureException {

    if (shutdown.get()) {
      throw new IllegalStateException("The monitor has been shutdown");
    }

    if (repGroupAdmin.getHelperSockets().size() == 0) {
      throw new IllegalStateException("No helper sockets were specified at Monitor initialization");
    }
    RepNodeImpl monitorNode =
        new RepNodeImpl(
            nameIdPair,
            NodeType.MONITOR,
            monitorConfig.getNodeHostname(),
            monitorConfig.getNodePort());
    /* Ensure that the monitor is part of the group. */
    return repGroupAdmin.ensureMonitor(monitorNode);
  }