This repository has been archived by the owner on May 7, 2020. It is now read-only.
/
CompositeJob.java
58 lines (50 loc) · 1.67 KB
/
CompositeJob.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright (c) 2014-2017 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.smarthome.binding.astro.internal.job;
import java.util.List;
/**
* {@link CompositeJob} comprises multiple {@link Job}s to be executed in order
*
* @author Markus Rathgeb - Initial contribution
* @author Amit Kumar Mondal - Minor modifications
*/
public final class CompositeJob extends AbstractJob {
private final String thingUID;
private final List<Job> jobs;
/**
* Constructor
*
* @param thingUID thing UID
* @param jobs the jobs to execute
* @throws IllegalArgumentException
* if {@code jobs} is {@code null} or empty
*/
public CompositeJob(String thingUID, List<Job> jobs) {
super(thingUID);
checkArgument(jobs != null, "Jobs must not be null");
checkArgument(!jobs.isEmpty(), "Jobs must not be empty");
this.thingUID = thingUID;
this.jobs = jobs;
boolean notMatched = jobs.stream().anyMatch(j -> !j.getThingUID().equals(thingUID));
checkArgument(!notMatched, "The jobs must associate the same thing UID");
}
@Override
public String getThingUID() {
return thingUID;
}
@Override
public void run() {
jobs.forEach(j -> {
try {
j.run();
} catch (RuntimeException ex) {
logger.warn("Job execution failed.", ex);
}
});
}
}