/**
 * When a slave is connected, redo the node monitoring.
 *
 * @author Kohsuke Kawaguchi
 */
@Extension
public class NodeMonitorUpdater extends ComputerListener {

  private static final Runnable MONITOR_UPDATER =
      new Runnable() {
        @Override
        public void run() {
          for (NodeMonitor nm : Jenkins.getInstance().getComputer().getMonitors()) {
            nm.triggerUpdate();
          }
        }
      };

  private Future<?> future = Futures.precomputed(null);

  /**
   * Triggers the update with 5 seconds quiet period, to avoid triggering data check too often when
   * multiple slaves become online at about the same time.
   */
  @Override
  public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
    synchronized (this) {
      future.cancel(false);
      future = Timer.get().schedule(MONITOR_UPDATER, 5, TimeUnit.SECONDS);
    }
  }
}
Example #2
0
  /**
   * Equivalent to {@code disconnect(null)}
   *
   * @deprecated as of 1.320. Use {@link #disconnect(OfflineCause)} and specify the cause.
   */
  public Future<?> disconnect() {
    if (Util.isOverridden(Computer.class, getClass(), "disconnect", OfflineCause.class))
      // if the subtype already derives disconnect(OfflineCause), delegate to it
      return disconnect(null);

    connectTime = 0;
    return Futures.precomputed(null);
  }
Example #3
0
  /**
   * Disconnect this computer.
   *
   * <p>If this is the master, no-op. This method may return immediately while the launch operation
   * happens asynchronously.
   *
   * @param cause Object that identifies the reason the node was disconnected.
   * @return {@link Future} to track the asynchronous disconnect operation.
   * @see #connect(boolean)
   * @since 1.320
   */
  public Future<?> disconnect(OfflineCause cause) {
    offlineCause = cause;
    if (Util.isOverridden(Computer.class, getClass(), "disconnect"))
      return disconnect(); // legacy subtypes that extend disconnect().

    connectTime = 0;
    return Futures.precomputed(null);
  }