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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 package hudson.util;
26
27 import hudson.ExtensionList;
28 import hudson.ExtensionPoint;
29 import jenkins.model.Jenkins;
30 import hudson.util.ProcessTree.OSProcess;
31
32 import java.io.IOException;
33 import java.io.Serializable;
34
35 /**
36 * Extension point that defines more elaborate way of killing processes, such as
37 * sudo or pfexec, for {@link ProcessTree}.
38 *
39 * <h2>Lifecycle</h2>
40 * <p>
41 * Each implementation of {@link ProcessKiller} is instantiated once on the master.
42 * Whenever a process needs to be killed, those implementations are serialized and sent over
43 * to the appropriate slave, then the {@link #kill(OSProcess)} method is invoked
44 * to attempt to kill the process.
45 *
46 * <p>
47 * One of the consequences of this design is that the implementation should be stateless
48 * and concurrent-safe. That is, the {@link #kill(OSProcess)} method can be invoked by multiple threads
49 * concurrently on the single instance.
50 *
51 * <p>
52 * Another consequence of this design is that if your {@link ProcessKiller} requires configuration,
53 * it needs to be serializable, and configuration needs to be updated atomically, as another
54 * thread may be calling into {@link #kill(OSProcess)} just when you are updating your configuration.
55 *
56 * @author jpederzolli
57 * @author Kohsuke Kawaguchi
58 * @since 1.362
59 */
60 public abstract class ProcessKiller implements ExtensionPoint, Serializable {
61 /**
62 * Returns all the registered {@link ProcessKiller} descriptors.
63 */
64 public static ExtensionList<ProcessKiller> all() {
65 return Jenkins.getInstance().getExtensionList(ProcessKiller.class);
66 }
67
68 /**
69 * Attempts to kill the given process.
70 *
71 * @param process process to be killed. Always a {@linkplain ProcessTree.Local local process}.
72 * @return
73 * true if the killing was successful, and Hudson won't try to use other {@link ProcessKiller}
74 * implementations to kill the process. false if the killing failed or is unattempted, and Hudson will continue
75 * to use the rest of the {@link ProcessKiller} implementations to try to kill the process.
76 * @throws IOException
77 * The caller will log this exception and otherwise treat as if the method returned false, and moves on
78 * to the next killer.
79 * @throws InterruptedException
80 * if the callee performs a time consuming operation and if the thread is canceled, do not catch
81 * {@link InterruptedException} and just let it thrown from the method.
82 */
83 public abstract boolean kill(ProcessTree.OSProcess process) throws IOException, InterruptedException;
84
85 private static final long serialVersionUID = 1L;
86 }
87