提交 5f8c81e7 编写于 作者: K kohsuke

added a convenience method.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20756 71c3de6d-444a-0410-be80-ed276b4c234a
上级 691e4994
......@@ -29,6 +29,7 @@ import hudson.FileSystemProvisioner;
import hudson.Launcher;
import hudson.node_monitors.NodeMonitor;
import hudson.remoting.VirtualChannel;
import hudson.remoting.Channel;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.security.Permission;
......@@ -140,6 +141,16 @@ public abstract class Node extends AbstractModelObject implements Describable<No
return Hudson.getInstance().getComputer(this);
}
/**
* Gets the current channel, if the node is connected and online, or null.
*
* This is just a convenience method for {@link Computer#getChannel()} with null check.
*/
public final VirtualChannel getChannel() {
Computer c = toComputer();
return c==null ? null : c.getChannel();
}
/**
* Creates a new {@link Computer} object that acts as the UI peer of this {@link Node}.
* Nobody but {@link Hudson#updateComputerList()} should call this method.
......@@ -202,9 +213,7 @@ public abstract class Node extends AbstractModelObject implements Describable<No
* Gets the {@link FilePath} on this node.
*/
public FilePath createPath(String absolutePath) {
Computer computer = toComputer();
if (computer==null) return null; // offline
VirtualChannel ch = computer.getChannel();
VirtualChannel ch = getChannel();
if(ch==null) return null; // offline
return new FilePath(ch,absolutePath);
}
......
......@@ -291,7 +291,7 @@ public abstract class Slave extends Node implements Serializable {
}
public ClockDifference getClockDifference() throws IOException, InterruptedException {
VirtualChannel channel = getComputer().getChannel();
VirtualChannel channel = getChannel();
if(channel==null)
throw new IOException(getNodeName()+" is offline");
......
......@@ -344,7 +344,7 @@ public class JDKInstaller extends ToolInstaller {
* Determines the platform of the given node.
*/
public static Platform of(Node n) throws IOException,InterruptedException,DetectionFailedException {
return n.toComputer().getChannel().call(new Callable<Platform,DetectionFailedException>() {
return n.getChannel().call(new Callable<Platform,DetectionFailedException>() {
public Platform call() throws DetectionFailedException {
return current();
}
......@@ -396,7 +396,7 @@ public class JDKInstaller extends ToolInstaller {
* Determines the CPU of the given node.
*/
public static CPU of(Node n) throws IOException,InterruptedException, DetectionFailedException {
return n.toComputer().getChannel().call(new Callable<CPU,DetectionFailedException>() {
return n.getChannel().call(new Callable<CPU,DetectionFailedException>() {
public CPU call() throws DetectionFailedException {
return current();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册