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

1 package hudson.model.queue;
2
3 import hudson.ExtensionList;
4 import hudson.ExtensionPoint;
5 import hudson.init.Initializer;
6 import jenkins.model.Jenkins;
7 import hudson.model.LoadBalancer;
8 import hudson.model.Queue;
9 import hudson.model.Queue.BuildableItem;
10
11 import java.util.List;
12 import java.util.logging.Logger;
13
14 import static hudson.init.InitMilestone.JOB_LOADED;
15
16 /**
17 * Singleton extension point for sorting buildable items
18 *
19 * @since 1.343
20 */
21 public abstract class QueueSorter implements ExtensionPoint {
22 /**
23 * Sorts the buildable items list. The items at the beginning will be executed
24 * before the items at the end of the list.
25 *
26 * @param buildables
27 * List of buildable items in the queue. Never null.
28 */
29 public abstract void sortBuildableItems(List<BuildableItem> buildables);
30
31 /**
32 * All registered {@link QueueSorter}s. Only the first one will be picked up,
33 * unless explicitly overridden by {@link Queue#setSorter(QueueSorter)}.
34 */
35 public static ExtensionList<QueueSorter> all() {
36 return Jenkins.getInstance().getExtensionList(QueueSorter.class);
37 }
38
39 /**
40 * Installs the default queue sorter.
41 *
42 * {@link Queue#Queue(LoadBalancer)} is too early to do this
43 */
44 @Initializer(after=JOB_LOADED)
45 public static void installDefaultQueueSorter() {
46 ExtensionList<QueueSorter> all = all();
47 if (all.isEmpty()) return;
48
49 Queue q = Jenkins.getInstance().getQueue();
50 if (q.getSorter()!=null) return; // someone has already installed something. leave that alone.
51
52 q.setSorter(all.get(0));
53 if (all.size()>1)
54 LOGGER.warning("Multiple QueueSorters are registered. Only the first one is used and the rest are ignored: "+all);
55 }
56
57 private static final Logger LOGGER = Logger.getLogger(QueueSorter.class.getName());
58 }
59