Class OptimizationEvents
java.lang.Object
com.dna.jopt.framework.body.event.OptimizationEvents
The Class OptimizationEvents provides access to events occurring during the optimization and are
backed by multiple
ReplaySubject and a CompletableFuture. OptimizationEvents can
be used to subscribe to different events of the optimization.
Subscriptions have to be done before get() is called on the CompletableFuture
returned by IOptimization.startRunSync(long, TimeUnit).
The following example shows how to subscribe to different evens and how to print the results:
// Use asynch run here - this is an optimization instance
CompletableFuture<IOptimizationResult> resultFuture = this.startRunAsync();
// Subscribe to events
this.getOptimizationEvents()
.progress
.subscribe(
p -> {
System.out.println(p.getProgressString());
});
this.getOptimizationEvents()
.error
.subscribe(
e -> {
System.out.println(e.getCause() + " " + e.getCode());
});
this.getOptimizationEvents()
.status
.subscribe(
s -> {
System.out.println(s.getDescription() + " " + s.getCode());
});
// Get result - This blocks the execution for statements after the get() call
IOptimizationResult result = resultFuture.get();
System.out.println(result);
- Since:
- 17/09/2019
- Version:
- 31/01/2020
- Author:
- Jens Richter
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>The requestedresult ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>The requestedresult ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<IErrorEvent>The error ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<NodeFilteringEvent>The node filtering ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationProgress>The progress ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<String>final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>The requestedresult ReplaySubject.The result CompletableFuture.final io.reactivex.rxjava3.subjects.ReplaySubject<IStatusEvent>The status ReplaySubject.final io.reactivex.rxjava3.subjects.ReplaySubject<IWarningEvent>The warning ReplaySubject. -
Constructor Summary
ConstructorsConstructorDescriptionInstantiates new optimizationevents, by completing all theseevent subscriptions. -
Method Summary
Modifier and TypeMethodDescriptionio.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>After node filtering result subject.io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>Before node filtering result subject.voidComplete external like events likeInjectionandTestInjection.static <T> io.reactivex.rxjava3.subjects.ReplaySubject<T>createBoundSubject(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, Predicate<T> boundingPredicate) static <T> io.reactivex.rxjava3.subjects.ReplaySubject<T>createBoundSubject(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, Predicate<T> boundingPredicate, int maxSize) Checks thesubjectpushes against theboundingPredicateand returns those subjects that do not conform with it.io.reactivex.rxjava3.subjects.ReplaySubject<IErrorEvent>Gets theErrorReplaySubjectwhich can be used to subscribe to any upcomingErrors.io.reactivex.rxjava3.subjects.ReplaySubject<NodeFilteringEvent>Gets theReplaySubjectof filteredNodes.io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationProgress>Gets theReplaySubjectwhich can be used to subscribe to the progressio.reactivex.rxjava3.subjects.ReplaySubject<String>io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>Gets theReplaySubjectwhich can be used to subscribe to the results.GetsCompletableFutureof the result.io.reactivex.rxjava3.subjects.ReplaySubject<IStatusEvent>static <T> io.reactivex.rxjava3.observers.TestObserver<OptimizationEvents.AssertionResult>subscribeSubjectWithTestObserver(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, io.reactivex.rxjava3.functions.Function<T, OptimizationEvents.AssertionResult> assertResultMapper) io.reactivex.rxjava3.subjects.ReplaySubject<IWarningEvent>Gets theWarningsReplaySubjectwhich can be used to subscribe to any upcomingWarnings
-
Field Details
-
result
The result CompletableFuture. -
requestedresult
The requestedresult ReplaySubject. -
beforeNodeFilteringResult
public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> beforeNodeFilteringResultThe requestedresult ReplaySubject. -
afterNodeFilteringResult
public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> afterNodeFilteringResultThe requestedresult ReplaySubject. -
progress
The progress ReplaySubject. -
error
The error ReplaySubject. -
warning
The warning ReplaySubject. -
status
The status ReplaySubject. -
nodeFiltering
The node filtering ReplaySubject. -
requestCodeExecutionDone
-
-
Constructor Details
-
OptimizationEvents
public OptimizationEvents()Instantiates new optimizationevents, by completing all theseevent subscriptions.
-
-
Method Details
-
completeExternalEvents
public void completeExternalEvents()Complete external like events likeInjectionandTestInjection. -
resultFuture
GetsCompletableFutureof the result.Please refer to
OptimizationEventsfor an implementation example.- Returns:
- the
resultas soon as theOptimizationis finished
-
requestedResultSubject
Gets theReplaySubjectwhich can be used to subscribe to the results.- Returns:
- the
resultsso far as theOptimizationis still running
-
beforeNodeFilteringResultSubject
public io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> beforeNodeFilteringResultSubject()Before node filtering result subject.- Returns:
- the replay subject
-
afterNodeFilteringResultSubject
public io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> afterNodeFilteringResultSubject()After node filtering result subject.- Returns:
- the replay subject
-
progressSubject
Gets theReplaySubjectwhich can be used to subscribe to the progress- Returns:
- the
Progressduring the runningOptimization
-
errorSubject
Gets theErrorReplaySubjectwhich can be used to subscribe to any upcomingErrors.- Returns:
- the
Errorsduring the runningOptimization
-
warningSubject
Gets theWarningsReplaySubjectwhich can be used to subscribe to any upcomingWarnings- Returns:
- the pushed
Warnings
-
statusSubject
- Returns:
- the pushed
statusof theOptimization
-
nodeFilteringSubject
Gets theReplaySubjectof filteredNodes.- Returns:
- the filtered
Nodes
-
requestCodeExecutionDoneSubject
-
createBoundSubject
public static <T> io.reactivex.rxjava3.subjects.ReplaySubject<T> createBoundSubject(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, Predicate<T> boundingPredicate, int maxSize) Checks thesubjectpushes against theboundingPredicateand returns those subjects that do not conform with it.- Type Parameters:
T- variable dependent on thesubjectto test- Parameters:
subject- the replaySubject of thesubjectto testboundingPredicate- the predicate to which thesubjectis testedmaxSize- the maximum number of buffered items- Returns:
subjectsnot conforming with theboundingPredicate
-
createBoundSubject
public static <T> io.reactivex.rxjava3.subjects.ReplaySubject<T> createBoundSubject(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, Predicate<T> boundingPredicate) -
subscribeSubjectWithTestObserver
public static <T> io.reactivex.rxjava3.observers.TestObserver<OptimizationEvents.AssertionResult> subscribeSubjectWithTestObserver(io.reactivex.rxjava3.subjects.ReplaySubject<T> subject, io.reactivex.rxjava3.functions.Function<T, OptimizationEvents.AssertionResult> assertResultMapper)
-