Skip to content

Commit c363e4c

Browse files
authored
docs: migrate to new event consumers (#1919)
1 parent 298d4ed commit c363e4c

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

docs/src/modules/ROOT/pages/enterprise-edition/enterprise-edition.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -982,12 +982,12 @@ It is not available in the Community Edition.
982982
This feature helps you avoid overloading your system with best solution events,
983983
especially in the early phase of the solving process when the solver is typically improving the solution very rapidly.
984984

985-
To enable event throttling, use `ThrottlingBestSolutionConsumer` when starting a new `SolverJob` using `SolverManager`:
985+
To enable event throttling, use `ThrottlingBestSolutionEventConsumer` when starting a new `SolverJob` using `SolverManager`:
986986

987987
[source,java,options="nowrap"]
988988
----
989989
...
990-
import ai.timefold.solver.enterprise.core.api.ThrottlingBestSolutionConsumer;
990+
import ai.timefold.solver.enterprise.core.api.ThrottlingBestSolutionEventConsumer;
991991
import java.time.Duration;
992992
...
993993
@@ -996,8 +996,8 @@ public class TimetableService {
996996
private SolverManager<Timetable, Long> solverManager;
997997
998998
public String solve(Timetable problem) {
999-
Consumer<Timetable> bestSolutionConsumer = ThrottlingBestSolutionConsumer.of(
1000-
solution -> {
999+
var bestSolutionEventConsumer = ThrottlingBestSolutionEventConsumer.of(
1000+
event -> {
10011001
// Your custom event handling code goes here.
10021002
},
10031003
Duration.ofSeconds(1)); // Throttle to 1 event per second.
@@ -1006,7 +1006,7 @@ public class TimetableService {
10061006
solverManager.solveBuilder()
10071007
.withProblemId(jobId)
10081008
.withProblem(problem)
1009-
.withBestSolutionConsumer(bestSolutionConsumer)
1009+
.withBestSolutionEventConsumer(bestSolutionEventConsumer)
10101010
.run(); // Start the solver job and listen to best solutions, with throttling.
10111011
return jobId;
10121012
}
@@ -1026,7 +1026,7 @@ event delivery will be delayed until a thread can be started.
10261026

10271027
[NOTE]
10281028
====
1029-
If you are using the `ThrottlingBestSolutionConsumer` for intermediate best solutions
1029+
If you are using the `ThrottlingBestSolutionEventConsumer` for intermediate best solutions
10301030
together with a final best solution consumer,
10311031
both these consumers will receive the final best solution.
10321032
====

docs/src/modules/ROOT/pages/upgrading-timefold-solver/upgrade-to-latest-version.adoc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,26 @@ We kindly ask Kotlin users to translate the changes accordingly.
6464
.icon:exclamation-triangle[role=red] `SolverJobBuilder` `with...SolutionConsumer` methods deprecated.
6565
[%collapsible%open]
6666
====
67-
The `SolverJobBuilder` 's `withBestSolutionConsumer`, `withFinalBestSolutionConsumer`, `withFirstInitializedSolutionConsumer` and `withSolverJobStartedConsumer` methods have been deprecated in favor of the new methods `withBestSolutionEventConsumer`, `withFinalBestSolutionEventConsumer`, `withFirstInitializedSolutionEventConsumer`, and `withSolverJobStartedEventConsumer` respectively.
68-
The new `with...EventConsumer` methods accept their own `...Event` object, with methods to access the best solution and different additional properties depending on the event.
67+
Some `SolverJobBuilder` 's methods for consuming solution-related events have been deprecated in favor of new methods that provide more context through event objects:
68+
69+
70+
|===
71+
|1.27.0 and older |1.28.0 and newer
72+
73+
|`withBestSolutionConsumer`
74+
|`withBestSolutionEventConsumer`
75+
76+
|`withFinalBestSolutionConsumer`
77+
|`withFinalBestSolutionEventConsumer`
78+
79+
|`withFirstInitializedSolutionConsumer`
80+
|`withFirstInitializedSolutionEventConsumer`
81+
82+
|`withSolverJobStartedConsumer`
83+
|`withSolverJobStartedEventConsumer`
84+
|===
85+
86+
6987
To migrate, change your `Consumer` to accept the event instead of the solution:
7088
7189
Before in `*.java`:
@@ -139,8 +157,13 @@ void onFinalBestSolution(FinalBestSolutionEvent<Timetable> event) {
139157
// ...
140158
}
141159
----
160+
161+
Users of xref:enterprise-edition/enterprise-edition.adoc#throttlingBestSolutionEvents[solution throttling] should also update their code
162+
to use `ThrottlingBestSolutionEventConsumer` instead of the now deprecated `ThrottlingBestSolutionConsumer`.
142163
====
143164

165+
'''
166+
144167
.icon:info-circle[role=yellow] `SelectionSorterWeightFactory` deprecated for removal
145168
[%collapsible%open]
146169
====
@@ -150,6 +173,8 @@ ensuring all related settings are consistent and simpler.
150173
The old class remains valid and can be easily converted to use the `ComparatorFactory` instead.
151174
====
152175

176+
'''
177+
153178
.icon:info-circle[role=yellow] `flattenLast` behaviour on `equals` objects
154179
[%collapsible%open]
155180
====

docs/src/modules/ROOT/pages/using-timefold-solver/running-the-solver.adoc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,29 +720,30 @@ Java::
720720
solverManager.solveBuilder()
721721
.withProblemId(problemId)
722722
.withProblem(problem)
723-
.withFirstInitializedSolutionConsumer(firstInitializedSolutionConsumer)
724-
.withBestSolutionConsumer(bestSolutionConsumer)
725-
.withFinalBestSolutionConsumer(finalBestSolutionConsumer)
723+
.withFirstInitializedSolutionEventConsumer(firstInitializedSolutionEventConsumer)
724+
.withBestSolutionEventConsumer(bestSolutionEventConsumer)
725+
.withFinalBestSolutionEventConsumer(finalBestSolutionEventConsumer)
726726
.withExceptionHandler(exceptionHandler)
727727
.withConfigOverride(configOverride)
728728
...
729729
----
730730
====
731731
732-
A consumer for the first initialized solution can be configured with `withFirstInitializedSolutionConsumer(...)`.
732+
A consumer for the first initialized solution can be configured with `withFirstInitializedSolutionEventConsumer(...)`.
733733
The solution is returned by the last phase that immediately precedes the first local search phase.
734734
735735
Whenever a new best solution is generated by the solver,
736-
it can be consumed by configuring it with `withBestSolutionConsumer(...)`.
736+
it can be consumed by configuring it with `withBestSolutionEventConsumer(...)`.
737737
The final best solution consumer,
738738
which is called at the end of the solving process,
739-
can be set using `withFinalBestSolutionConsumer(...)`.
739+
can be set using `withFinalBestSolutionEventConsumer(...)`.
740740
Additionally,
741741
an improved solution consumer capable of throttling events is available in the xref:enterprise-edition/enterprise-edition.adoc#throttlingBestSolutionEvents[Enterprise Edition].
742742
743743
[WARNING]
744744
====
745-
Do not modify the solutions returned by the events in `withFirstInitializedSolutionConsumer(...)` and `withBestSolutionConsumer(...)`. These instances are still utilized during the solving process, and any modifications may lead to solver corruption.
745+
Do not modify the solutions returned by the events in `withFirstInitializedSolutionEventConsumer(...)` and `withBestSolutionEventConsumer(...)`.
746+
These instances are still utilized during the solving process, and any modifications may lead to solver corruption.
746747
====
747748
748749
To handle errors that may arise during the solving process,

0 commit comments

Comments
 (0)