mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
[FIXED HUDSON-5249] Made the ping behaviour customizable.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@35023 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
3f7e205734
commit
bb8bf3c498
2 files changed
+66
-1
No files matched your search
@@ -792,7 +792,7 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
|
||||
LOGGER.fine(address+" is not an IPv4 address");
|
||||
continue;
|
||||
}
|
||||
if(!ia.isReachable(3000)) {
|
||||
if(!ComputerPinger.checkIsReachable(ia, 3)) {
|
||||
LOGGER.fine(address+" didn't respond to ping");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package hudson.model;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.ExtensionList;
|
||||
import hudson.ExtensionPoint;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A way to see if a computer is reachable.
|
||||
*
|
||||
* @since 1.378
|
||||
*/
|
||||
public abstract class ComputerPinger implements ExtensionPoint {
|
||||
/**
|
||||
* Is the specified address reachable?
|
||||
*
|
||||
* @param ia The address to check.
|
||||
* @param timeout Timeout in seconds.
|
||||
*/
|
||||
public abstract boolean isReachable(InetAddress ia, int timeout) throws IOException;
|
||||
|
||||
/**
|
||||
* Get all registered instances.
|
||||
*/
|
||||
public static ExtensionList<ComputerPinger> all() {
|
||||
return Hudson.getInstance().getExtensionList(ComputerPinger.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this computer reachable via the given address?
|
||||
*
|
||||
* @param ia The address to check.
|
||||
* @param timeout Timeout in seconds.
|
||||
*/
|
||||
public static boolean checkIsReachable(InetAddress ia, int timeout) throws IOException {
|
||||
for (ComputerPinger pinger : ComputerPinger.all()) {
|
||||
try {
|
||||
if (pinger.isReachable(ia, timeout)) {
|
||||
return true;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.fine("Error checking reachability with " + pinger + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default pinger - use Java built-in functionality. This doesn't always work,
|
||||
* a host may be reachable even if this returns false.
|
||||
*/
|
||||
@Extension
|
||||
public static class BuiltInComputerPinger extends ComputerPinger {
|
||||
@Override
|
||||
public boolean isReachable(InetAddress ia, int timeout) throws IOException {
|
||||
return ia.isReachable(timeout * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ComputerPinger.class.getName());
|
||||
}
|
||||
Reference in new issue
Block a user