This repository has been archived by the owner on May 7, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added composite job for range events if scheduled at same time instant
Also-by: Markus Rathgeb <maggu2810@gmail.com> Signed-off-by: Amit Kumar Mondal <admin@amitinside.com>
- Loading branch information
Showing
2 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...ng.astro/src/main/java/org/eclipse/smarthome/binding/astro/internal/job/CompositeJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* 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 jobs the jobs to execute | ||
* @throws IllegalArgumentException | ||
* if {@code jobs} is {@code null} or empty | ||
*/ | ||
public CompositeJob(List<Job> jobs) { | ||
checkArgument(jobs != null, "Jobs must not be null"); | ||
checkArgument(!jobs.isEmpty(), "Jobs must not be empty"); | ||
|
||
this.jobs = jobs; | ||
this.thingUID = jobs.get(0).getThingUID(); | ||
|
||
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters