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
-
Field Summary
Modifier 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
ConstructorDescriptionInstantiates 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.void
Complete external like events likeInjection
andTestInjection
.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 thesubject
pushes against theboundingPredicate
and returns those subjects that do not conform with it.io.reactivex.rxjava3.subjects.ReplaySubject<IErrorEvent>
Gets theError
ReplaySubject
which can be used to subscribe to any upcomingErrors
.io.reactivex.rxjava3.subjects.ReplaySubject<NodeFilteringEvent>
Gets theReplaySubject
of filteredNodes
.io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationProgress>
Gets theReplaySubject
which can be used to subscribe to the progressio.reactivex.rxjava3.subjects.ReplaySubject<String>
io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult>
Gets theReplaySubject
which can be used to subscribe to the results.GetsCompletableFuture
of 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 theWarnings
ReplaySubject
which 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 likeInjection
andTestInjection
. -
resultFuture
GetsCompletableFuture
of the result.Please refer to
OptimizationEvents
for an implementation example.- Returns:
- the
result
as soon as theOptimization
is finished
-
requestedResultSubject
Gets theReplaySubject
which can be used to subscribe to the results.- Returns:
- the
results
so far as theOptimization
is 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 theReplaySubject
which can be used to subscribe to the progress- Returns:
- the
Progress
during the runningOptimization
-
errorSubject
Gets theError
ReplaySubject
which can be used to subscribe to any upcomingErrors
.- Returns:
- the
Errors
during the runningOptimization
-
warningSubject
Gets theWarnings
ReplaySubject
which can be used to subscribe to any upcomingWarnings
- Returns:
- the pushed
Warnings
-
statusSubject
- Returns:
- the pushed
status
of theOptimization
-
nodeFilteringSubject
Gets theReplaySubject
of 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 thesubject
pushes against theboundingPredicate
and returns those subjects that do not conform with it.- Type Parameters:
T
- variable dependent on thesubject
to test- Parameters:
subject
- the replaySubject of thesubject
to testboundingPredicate
- the predicate to which thesubject
is testedmaxSize
- the maximum number of buffered items- Returns:
subjects
not 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)
-