SolverManager implements SolverEventListener<VehicleRoutingSolution> { void startSolver(VehicleRoutingSolution solution) { if (solverFuture != null) { throw new IllegalStateException("Solver start has already been requested"); } solverFuture = executor.submitListenable((SolvingTask) () -> solver.solve(solution)); solverFuture.addCallback( result -> { if (!solver.isTerminateEarly()) { logger.error("Solver stopped solving but that shouldn't happen in daemon mode."); eventPublisher.publishEvent(new ErrorEvent(this, "Solver stopped solving unexpectedly.")); } }, exception -> { logger.error("Solver failed", exception); eventPublisher.publishEvent(new ErrorEvent(this, exception.toString())); }); } @Autowired  SolverManager(
            Solver<VehicleRoutingSolution> solver,
            AsyncListenableTaskExecutor executor,
            RouteChangedEventPublisher routeChangedEventPublisher,
            ApplicationEventPublisher eventPublisher); @Override void bestSolutionChanged(BestSolutionChangedEvent<VehicleRoutingSolution> bestSolutionChangedEvent);  }
@Test void startSolver_should_start_solver() { returnSolverFutureWhenSolverIsStarted(); solverManager.startSolver(solution); verify(solver).solve(solution); assertThatIllegalStateException() .isThrownBy(() -> solverManager.startSolver(solution)); }