From 64667af499e878f67b09e60bdf6ed0c2a549d545 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 28 Aug 2024 09:54:25 +0200 Subject: [PATCH] Implement ComputerListener#onIdle Introduces a new computer listener fired whenever a Computer becomes idle. --- core/src/main/java/hudson/model/Computer.java | 2 ++ core/src/main/java/hudson/slaves/ComputerListener.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 14a311381a37..903751b90c13 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -1102,6 +1102,8 @@ protected void removeExecutor(final Executor e) { if (ciBase != null) { // TODO confirm safe to assume non-null and use getInstance() ciBase.removeComputer(Computer.this); } + } else if (isIdle()) { + Listeners.notify(ComputerListener.class, false, l -> l.onIdle(this)); } } }; diff --git a/core/src/main/java/hudson/slaves/ComputerListener.java b/core/src/main/java/hudson/slaves/ComputerListener.java index bd794c456c50..f5d220c1104e 100644 --- a/core/src/main/java/hudson/slaves/ComputerListener.java +++ b/core/src/main/java/hudson/slaves/ComputerListener.java @@ -211,6 +211,13 @@ public void onTemporarilyOffline(Computer c, OfflineCause cause) {} */ public void onConfigurationChange() {} + /** + * Indicates that the computer has become idle. + * + * @since TODO + */ + public void onIdle(Computer c) {} + /** * Registers this {@link ComputerListener} so that it will start receiving events. *