File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\queue\WorkUnit.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.model.queue;
25
26 import hudson.model.Executor;
27 import hudson.model.Queue;
28 import hudson.model.Queue.Executable;
29 import hudson.model.Queue.Task;
30 import org.kohsuke.stapler.export.ExportedBean;
31
32 /**
33 * Represents a unit of hand-over to {@link Executor} from {@link Queue}.
34 *
35 * @author Kohsuke Kawaguchi
36 * @since 1.377
37 */
38 @ExportedBean
39 public final class WorkUnit {
40 /**
41 * Task to be executed.
42 */
43 public final SubTask work;
44
45 /**
46 * Shared context among {@link WorkUnit}s.
47 */
48 public final WorkUnitContext context;
49
50 private volatile Executor executor;
51
52 WorkUnit(WorkUnitContext context, SubTask work) {
53 this.context = context;
54 this.work = work;
55 }
56
57 /**
58 * {@link Executor} running this work unit.
59 * <p>
60 * {@link Executor#getCurrentWorkUnit()} and {@link WorkUnit#getExecutor()}
61 * form a bi-directional reachability between them.
62 */
63 public Executor getExecutor() {
64 return executor;
65 }
66
67 public void setExecutor(Executor e) {
68 executor = e;
69 }
70
71 /**
72 * If the execution has already started, return the current executable.
73 */
74 public Executable getExecutable() {
75 return executor!=null ? executor.getCurrentExecutable() : null;
76 }
77
78 /**
79 * Is this work unit the "main work", which is the primary {@link SubTask}
80 * represented by {@link Task} itself.
81 */
82 public boolean isMainWork() {
83 return context.task==work;
84 }
85
86 @Override
87 public String toString() {
88 if (work==context.task)
89 return super.toString()+"[work="+context.task.getFullDisplayName()+"]";
90 else
91 return super.toString()+"[work="+work+",context.task="+context.task.getFullDisplayName()+"]";
92 }
93 }
94