File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\slaves\DelegatingComputerLauncher.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 package hudson.slaves;
25
26 import hudson.Functions;
27 import hudson.model.Descriptor;
28 import hudson.model.TaskListener;
29
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 /**
35 * Convenient base implementation of {@link ComputerLauncher} that allows
36 * subtypes to perform some initialization (typically something cloud/v12n related
37 * to power up the machine), then to delegate to another {@link ComputerLauncher}
38 * to connect.
39 *
40 * @author Kohsuke Kawaguchi
41 * @since 1.382
42 */
43 public abstract class DelegatingComputerLauncher extends ComputerLauncher {
44 protected ComputerLauncher launcher;
45
46 protected DelegatingComputerLauncher(ComputerLauncher launcher) {
47 this.launcher = launcher;
48 }
49
50 public ComputerLauncher getLauncher() {
51 return launcher;
52 }
53
54 @Override
55 public void launch(SlaveComputer computer, TaskListener listener) throws IOException, InterruptedException {
56 getLauncher().launch(computer, listener);
57 }
58
59 @Override
60 public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
61 getLauncher().afterDisconnect(computer, listener);
62 }
63
64 @Override
65 public void beforeDisconnect(SlaveComputer computer, TaskListener listener) {
66 getLauncher().beforeDisconnect(computer, listener);
67 }
68
69 public static abstract class DescriptorImpl extends Descriptor<ComputerLauncher> {
70 /**
71 * Returns the applicable nested computer launcher types.
72 * The default implementation avoids all delegating descriptors, as that creates infinite recursion.
73 */
74 public List<Descriptor<ComputerLauncher>> getApplicableDescriptors() {
75 List<Descriptor<ComputerLauncher>> r = new ArrayList<Descriptor<ComputerLauncher>>();
76 for (Descriptor<ComputerLauncher> d : Functions.getComputerLauncherDescriptors()) {
77 if (DelegatingComputerLauncher.class.isInstance(d)) continue;
78 r.add(d);
79 }
80 return r;
81 }
82 }
83
84 }
85