File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\ComputerPinger.java.html

1 package hudson.model;
2
3 import hudson.Extension;
4 import hudson.ExtensionList;
5 import hudson.ExtensionPoint;
6 import jenkins.model.Jenkins;
7
8 import java.io.IOException;
9 import java.net.InetAddress;
10 import java.util.logging.Logger;
11
12 /**
13 * A way to see if a computer is reachable.
14 *
15 * @since 1.378
16 */
17 public abstract class ComputerPinger implements ExtensionPoint {
18 /**
19 * Is the specified address reachable?
20 *
21 * @param ia The address to check.
22 * @param timeout Timeout in seconds.
23 */
24 public abstract boolean isReachable(InetAddress ia, int timeout) throws IOException;
25
26 /**
27 * Get all registered instances.
28 */
29 public static ExtensionList<ComputerPinger> all() {
30 return Jenkins.getInstance().getExtensionList(ComputerPinger.class);
31 }
32
33 /**
34 * Is this computer reachable via the given address?
35 *
36 * @param ia The address to check.
37 * @param timeout Timeout in seconds.
38 */
39 public static boolean checkIsReachable(InetAddress ia, int timeout) throws IOException {
40 for (ComputerPinger pinger : ComputerPinger.all()) {
41 try {
42 if (pinger.isReachable(ia, timeout)) {
43 return true;
44 }
45 } catch (IOException e) {
46 LOGGER.fine("Error checking reachability with " + pinger + ": " + e.getMessage());
47 }
48 }
49
50 return false;
51 }
52
53 /**
54 * Default pinger - use Java built-in functionality. This doesn't always work,
55 * a host may be reachable even if this returns false.
56 */
57 @Extension
58 public static class BuiltInComputerPinger extends ComputerPinger {
59 @Override
60 public boolean isReachable(InetAddress ia, int timeout) throws IOException {
61 return ia.isReachable(timeout * 1000);
62 }
63 }
64
65 private static final Logger LOGGER = Logger.getLogger(ComputerPinger.class.getName());
66 }
67