/** Performs all monitoring concurrently. */
  @Override
  protected Map<Computer, T> monitor() throws InterruptedException {
    Map<Computer, Future<T>> futures = new HashMap<Computer, Future<T>>();

    for (Computer c : Jenkins.getInstance().getComputers()) {
      try {
        VirtualChannel ch = c.getChannel();
        futures.put(c, null); // sentinel value
        if (ch != null) {
          Callable<T, ?> cc = createCallable(c);
          if (cc != null) futures.put(c, ch.callAsync(cc));
        }
      } catch (RuntimeException e) {
        LOGGER.log(
            WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), e);
      } catch (IOException e) {
        LOGGER.log(
            WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), e);
      }
    }

    final long now = System.currentTimeMillis();
    final long end = now + getMonitoringTimeOut();

    final Map<Computer, T> data = new HashMap<Computer, T>();

    for (Entry<Computer, Future<T>> e : futures.entrySet()) {
      Computer c = e.getKey();
      Future<T> f = futures.get(c);
      data.put(c, null); // sentinel value

      if (f != null) {
        try {
          data.put(c, f.get(Math.max(0, end - System.currentTimeMillis()), MILLISECONDS));
        } catch (RuntimeException x) {
          LOGGER.log(
              WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), x);
        } catch (ExecutionException x) {
          LOGGER.log(
              WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), x);
        } catch (TimeoutException x) {
          LOGGER.log(
              WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), x);
        }
      }
    }

    return data;
  }
示例#2
0
 public static Future<Map<String, String>> getThreadDumpAsync(VirtualChannel channel)
     throws IOException, InterruptedException {
   if (channel == null)
     return new AsyncFutureImpl<Map<String, String>>(Collections.singletonMap("N/A", "offline"));
   return channel.callAsync(new GetThreadDump());
 }