-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the capacity to stop realtime after a defined duration
- Loading branch information
Showing
7 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...nator/repairnator-core/src/main/java/fr/inria/spirals/repairnator/PeriodStringParser.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,31 @@ | ||
package fr.inria.spirals.repairnator; | ||
|
||
import com.martiansoftware.jsap.ParseException; | ||
import com.martiansoftware.jsap.StringParser; | ||
|
||
import java.time.Duration; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class PeriodStringParser extends StringParser { | ||
private static PeriodStringParser instance; | ||
|
||
private PeriodStringParser() {} | ||
|
||
public static PeriodStringParser getParser() { | ||
if (instance == null) { | ||
instance = new PeriodStringParser(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public Object parse(String s) throws ParseException { | ||
try { | ||
return Duration.parse(s); | ||
} catch (DateTimeParseException e) { | ||
throw new ParseException(e); | ||
} catch (NullPointerException e) { | ||
throw new ParseException("No period given to parse"); | ||
} | ||
} | ||
} |
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
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
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
55 changes: 55 additions & 0 deletions
55
...-realtime/src/main/java/fr/inria/spirals/repairnator/realtime/InspectProcessDuration.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,55 @@ | ||
package fr.inria.spirals.repairnator.realtime; | ||
|
||
import fr.inria.spirals.repairnator.notifier.EndProcessNotifier; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
public class InspectProcessDuration implements Runnable { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(InspectProcessDuration.class); | ||
private static final int SLEEP_TIME = 10; // seconds | ||
|
||
private Duration duration; | ||
private EndProcessNotifier endProcessNotifier; | ||
private InspectBuilds inspectBuilds; | ||
private InspectJobs inspectJobs; | ||
private BuildRunner buildRunner; | ||
|
||
public InspectProcessDuration(Duration duration, InspectBuilds inspectBuilds, InspectJobs inspectJobs, BuildRunner buildRunner, EndProcessNotifier endProcessNotifier) { | ||
this(duration, inspectBuilds, inspectJobs, buildRunner); | ||
this.endProcessNotifier = endProcessNotifier; | ||
} | ||
|
||
public InspectProcessDuration(Duration duration, InspectBuilds inspectBuilds, InspectJobs inspectJobs, BuildRunner buildRunner) { | ||
this.duration = duration; | ||
this.inspectBuilds = inspectBuilds; | ||
this.inspectJobs = inspectJobs; | ||
this.buildRunner = buildRunner; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
Instant endOfProcessDate = new Date().toInstant().plus(duration); | ||
LOGGER.info("The process will finish at: " + endOfProcessDate); | ||
|
||
while (!new Date().toInstant().isAfter(endOfProcessDate)) { | ||
try { | ||
Thread.sleep(SLEEP_TIME * 1000); | ||
} catch (InterruptedException e) { | ||
LOGGER.warn("Sleep interrupted: premature stop will occured."); | ||
} | ||
} | ||
|
||
LOGGER.info("The process will now stop."); | ||
this.inspectBuilds.switchOff(); | ||
this.inspectJobs.switchOff(); | ||
this.buildRunner.switchOff(); | ||
|
||
if (this.endProcessNotifier != null) { | ||
this.endProcessNotifier.notifyEnd(); | ||
} | ||
} | ||
} |
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
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