Solution_
- the solution type, the class with the PlanningSolution
annotationProblemId_
- the ID type of a submitted problem, such as Long
or UUID
.public final class DefaultSolverJob<Solution_,ProblemId_> extends Object implements SolverJob<Solution_,ProblemId_>, Callable<Solution_>
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
DefaultSolverJob(DefaultSolverManager<Solution_,ProblemId_> solverManager,
Solver<Solution_> solver,
ProblemId_ problemId,
Function<? super ProblemId_,? extends Solution_> problemFinder,
Consumer<? super Solution_> finalBestSolutionConsumer,
BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler) |
Modifier and Type | Method and Description |
---|---|
Solution_ |
call() |
Solution_ |
getFinalBestSolution()
Waits if necessary for the solver to complete and then returns the final best
PlanningSolution . |
ProblemId_ |
getProblemId() |
SolverStatus |
getSolverStatus()
Returns whether the
Solver is scheduled to solve, actively solving or not. |
Duration |
getSolvingDuration()
Returns the
Duration spent solving since the last start. |
void |
setFuture(Future<Solution_> future) |
void |
terminateEarly()
Terminates the solver or cancels the solver job if it hasn't (re)started yet.
|
public DefaultSolverJob(DefaultSolverManager<Solution_,ProblemId_> solverManager, Solver<Solution_> solver, ProblemId_ problemId, Function<? super ProblemId_,? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,? super Throwable> exceptionHandler)
public ProblemId_ getProblemId()
getProblemId
in interface SolverJob<Solution_,ProblemId_>
SolverManager.solve(Object, Function, Consumer)
or SolverManager.solveAndListen(Object, Function, Consumer)
public SolverStatus getSolverStatus()
SolverJob
Solver
is scheduled to solve, actively solving or not.
Returns SolverStatus.NOT_SOLVING
if the solver already terminated.
getSolverStatus
in interface SolverJob<Solution_,ProblemId_>
public void terminateEarly()
SolverJob
Does nothing if the solver already terminated.
Waits for the termination or cancellation to complete before returning.
During termination, a bestSolutionConsumer
could still be called (on a consumer thread),
before this method returns.
terminateEarly
in interface SolverJob<Solution_,ProblemId_>
public Solution_ getFinalBestSolution() throws InterruptedException, ExecutionException
SolverJob
PlanningSolution
.getFinalBestSolution
in interface SolverJob<Solution_,ProblemId_>
InterruptedException
- if the current thread was interrupted while waitingExecutionException
- if the computation threw an exceptionpublic Duration getSolvingDuration()
SolverJob
Duration
spent solving since the last start.
If it hasn't started it yet, it returns Duration.ZERO
.
If it hasn't ended yet, it returns the time between the last start and now.
If it has ended already, it returns the time between the last start and the ending.getSolvingDuration
in interface SolverJob<Solution_,ProblemId_>
Duration
spent solving since the last (re)start, at least 0Copyright © 2006–2021 JBoss by Red Hat. All rights reserved.