forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-62006] Move getChannelToMaster to a separate class
This should avoid classloading issues I've seen, such as Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletException at hudson.util.ProcessTree.get(ProcessTree.java:432) ...
- Loading branch information
Showing
3 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hudson.slaves; | ||
|
||
import hudson.FilePath; | ||
import hudson.remoting.Channel; | ||
import hudson.remoting.VirtualChannel; | ||
import jenkins.model.Jenkins; | ||
|
||
public final class SlaveComputerUtil { | ||
private SlaveComputerUtil() {} | ||
/** | ||
* Obtains a {@link VirtualChannel} that allows some computation to be performed on the master. | ||
* This method can be called from any thread on the master, or from agent (more precisely, | ||
* it only works from the remoting request-handling thread in agents, which means if you've started | ||
* separate thread on agents, that'll fail.) | ||
* | ||
* @return null if the calling thread doesn't have any trace of where its master is. | ||
* @since XXX | ||
*/ | ||
public static VirtualChannel getChannelToMaster() { | ||
if (Jenkins.getInstanceOrNull()!=null) // check if calling thread is on master or on slave | ||
return FilePath.localChannel; | ||
|
||
// if this method is called from within the agent computation thread, this should work | ||
Channel c = Channel.current(); | ||
if (c!=null && Boolean.TRUE.equals(c.getProperty("slave"))) | ||
return c; | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters