public class StopCriterionChecker extends Object
add(StopCriterion)
, which usually only happens from within the search, which passes
all its stop criteria to its dedicated checker.
When startChecking()
is called, a task will be scheduled to periodically check the stop
criteria in the background, by default with a period of 1 second, while the search is running.
These tasks are executed by a dedicated thread which is shared among all stop criterion checker
instances, as checking stop criteria is not an intensive task. A manual check can be performed
with stopCriterionSatisfied()
.
As soon as some stop criterion is satisfied, the checker will cancel the scheduled task for further execution and will request the search to stop.
Constructor and Description |
---|
StopCriterionChecker(Search<?> search)
Create a stop criterion checker dedicated to checking the stop criteria of the given search.
|
Modifier and Type | Method and Description |
---|---|
void |
add(StopCriterion stopCriterion)
Add a stop criterion to check.
|
void |
clear()
Remove all stop criteria.
|
boolean |
remove(StopCriterion stopCriterion)
Remove a stop criterion.
|
void |
setPeriod(long period,
TimeUnit timeUnit)
Set the period between consecutive stop criterion checks.
|
void |
startChecking()
Start checking the stop criteria, in a separate background thread.
|
void |
stopChecking()
Instructs the stop criterion checker to stop checking.
|
boolean |
stopCriterionSatisfied()
Check whether at least one stop criterion is satisfied.
|
public StopCriterionChecker(Search<?> search)
setPeriod(long, TimeUnit)
.search
- search for which the stop criteria should be checked while runningpublic void add(StopCriterion stopCriterion)
stopCriterion
- stop criterion to addIncompatibleStopCriterionException
- if the given stop criterion is not compatible with the search
to which this checker belongspublic boolean remove(StopCriterion stopCriterion)
false
if the given stop criterion had never been added.stopCriterion
- stop criterion to removetrue
if the stop criterion has successfully been removedpublic void clear()
public void setPeriod(long period, TimeUnit timeUnit)
startChecking()
.period
- period between two checkstimeUnit
- time unit of this periodpublic void startChecking()
public void stopChecking()
public boolean stopCriterionSatisfied()
true
if a stop condition is satisfiedCopyright © 2016. All rights reserved.