6.10. SolverEventListener

Each time a new best solution is found, the Solver fires a BestSolutionChangedEvent, in the solver's thread.
To listen to such events, add a SolverEventListener to the Solver:
public interface Solver {

    // ...

    void addEventListener(SolverEventListener<? extends Solution> eventListener);
    void removeEventListener(SolverEventListener<? extends Solution> eventListener);

}
The BestSolutionChangedEvent's newBestSolution might not be initialized or feasible. Use the methods on BestSolutionChangedEvent to detect such cases:
    solver.addEventListener(new SolverEventListener<CloudBalance>() {
        public void bestSolutionChanged(BestSolutionChangedEvent<CloudBalance> event) {
            // Ignore invalid solutions
            if (event.isNewBestSolutionInitialized()
                    && event.getNewBestSolution().getScore().isFeasible()) {
                ...
            }
        }
    });
Warning
The bestSolutionChanged() method is called in the solver's thread, as part of Solver.solve(). So it should return quickly to avoid slowing down the solving.