提交 0d6f7a26 编写于 作者: K kohsuke

Added a new extension point to listen to slave connection/disconnection activity.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11339 71c3de6d-444a-0410-be80-ed276b4c234a
上级 42316859
......@@ -16,6 +16,7 @@ import static hudson.Util.fixEmpty;
import hudson.XmlFile;
import hudson.ProxyConfiguration;
import hudson.slaves.RetentionStrategy;
import hudson.slaves.ComputerListener;
import hudson.model.Descriptor.FormException;
import hudson.model.listeners.ItemListener;
import hudson.model.listeners.JobListener;
......@@ -271,6 +272,11 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
*/
private transient final CopyOnWriteList<SCMListener> scmListeners = new CopyOnWriteList<SCMListener>();
/**
* List of registered {@link ComputerListener}s.
*/
private transient final CopyOnWriteList<ComputerListener> computerListeners = new CopyOnWriteList<ComputerListener>();
/**
* TCP slave agent port.
* 0 for random, -1 to disable.
......@@ -542,6 +548,13 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
return scmListeners;
}
/**
* Gets all the installed {@link ComputerListener}s.
*/
public CopyOnWriteList<ComputerListener> getComputerListeners() {
return computerListeners;
}
/**
* Gets the plugin object from its short name.
*
......
package hudson.slaves;
import hudson.model.Computer;
import hudson.model.Hudson;
import hudson.ExtensionPoint;
/**
* Receives notifications about status changes of {@link Computer}s.
*
* @author Kohsuke Kawaguchi
* @since 1.246
*/
public abstract class ComputerListener implements ExtensionPoint {
/**
* Called right after a {@link Computer} comes online.
*/
public void onOnline(Computer c) {}
/**
* Called right after a {@link Computer} went offline.
*/
public void onOffline(Computer c) {}
/**
* Registers this {@link ComputerListener} so that it will start receiving events.
*/
public final void register() {
Hudson.getInstance().getComputerListeners().add(this);
}
/**
* Unregisters this {@link ComputerListener} so that it will never receive further events.
*
* <p>
* Unless {@link ComputerListener} is unregistered, it will never be a subject of GC.
*/
public final boolean unregister() {
return Hudson.getInstance().getComputerListeners().remove(this);
}
}
......@@ -229,6 +229,8 @@ public final class SlaveComputer extends Computer {
numRetryAttempt = 0;
this.channel = channel;
}
for (ComputerListener cl : Hudson.getInstance().getComputerListeners())
cl.onOnline(this);
Hudson.getInstance().getQueue().scheduleMaintenance();
}
......@@ -336,6 +338,8 @@ public final class SlaveComputer extends Computer {
logger.log(Level.SEVERE, "Failed to terminate channel to " + getDisplayName(), e);
}
}
for (ComputerListener cl : Hudson.getInstance().getComputerListeners())
cl.onOffline(this);
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册