List<DaemonState> () { List<DaemonState> daemons = new ArrayList<>(); for (DaemonInfo daemon : this.daemonRegistry.getAll()) { DaemonClientConnection connection = this.connector.maybeConnect(daemon); if (connection != null) { DaemonInfo connectionDaemon = connection.getDaemon() instanceof DaemonInfo ? (DaemonInfo)connection.getDaemon() : daemon; try { List<String> daemonOpts = connectionDaemon.getContext().getDaemonOpts(); File javaHome = connectionDaemon.getContext().getJavaHome(); Integer idleTimeout = connectionDaemon.getContext().getIdleTimeout(); File registryDir = connectionDaemon.getContext().getDaemonRegistryDir(); Object id = this.idGenerator.generateId(); byte[] token = daemon.getToken(); ReportStatus statusCommand = createCommand(ReportStatus.class, id, token); Status status = this.reportStatusDispatcher.dispatch(connection, statusCommand); if (status != null) { daemons.add(new DaemonState(connectionDaemon.getPid(), connectionDaemon.getToken(), status.getVersion(), status.getStatus(), null, connectionDaemon.getLastBusy().getTime(), null, daemonOpts, javaHome, idleTimeout, registryDir)); } else { daemons.add(new DaemonState(connectionDaemon.getPid(), connectionDaemon.getToken(), "UNKNOWN", "UNKNOWN", null, connectionDaemon.getLastBusy().getTime(), null, daemonOpts, javaHome, idleTimeout, registryDir)); } } finally { connection.stop(); } } } List<DaemonStopEvent> stopEvents = DaemonStopEvents.uniqueRecentDaemonStopEvents(this.daemonRegistry.getStopEvents()); for (DaemonStopEvent stopEvent : stopEvents) { DaemonExpirationStatus expirationStatus = stopEvent.getStatus(); String daemonExpirationStatus = expirationStatus != null ? expirationStatus.name().replace("_", " ").toLowerCase(DynamicBundle.getLocale()) : ""; Long stopEventPid; if (GradleVersion.current().compareTo(GradleVersion.version("3.0")) <= 0) { try { Field pidField = stopEvent.getClass().getDeclaredField("pid"); pidField.setAccessible(true); stopEventPid = pidField.getLong(stopEvent); } catch (Exception ignore) { stopEventPid = -1L; } } else { stopEventPid = stopEvent.getPid(); } daemons.add(new DaemonState(stopEventPid, null, null, "Stopped", stopEvent.getReason(), stopEvent.getTimestamp().getTime(), daemonExpirationStatus, null, null, null, null)); } return daemons; }