Class OptimizationEvents

java.lang.Object
com.dna.jopt.framework.body.event.OptimizationEvents

public class OptimizationEvents extends Object
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
  • Field Details

    • result

      public final CompletableFuture<IOptimizationResult> result
      The result CompletableFuture.
    • requestedresult

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> requestedresult
      The requestedresult ReplaySubject.
    • beforeNodeFilteringResult

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> beforeNodeFilteringResult
      The requestedresult ReplaySubject.
    • afterNodeFilteringResult

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> afterNodeFilteringResult
      The requestedresult ReplaySubject.
    • progress

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationProgress> progress
      The progress ReplaySubject.
    • error

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IErrorEvent> error
      The error ReplaySubject.
    • warning

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IWarningEvent> warning
      The warning ReplaySubject.
    • status

      public final io.reactivex.rxjava3.subjects.ReplaySubject<IStatusEvent> status
      The status ReplaySubject.
    • nodeFiltering

      public final io.reactivex.rxjava3.subjects.ReplaySubject<NodeFilteringEvent> nodeFiltering
      The node filtering ReplaySubject.
    • requestCodeExecutionDone

      public final io.reactivex.rxjava3.subjects.ReplaySubject<String> requestCodeExecutionDone
  • Constructor Details

    • OptimizationEvents

      public OptimizationEvents()
      Instantiates new optimization events, by completing all these event subscriptions.
  • Method Details

    • completeExternalEvents

      public void completeExternalEvents()
      Complete external like events like Injection andTestInjection.
    • resultFuture

      public CompletableFuture<IOptimizationResult> resultFuture()
      Gets CompletableFuture of the result.

      Please refer to OptimizationEvents for an implementation example.

      Returns:
      the result as soon as the Optimization is finished
    • requestedResultSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationResult> requestedResultSubject()
      Gets the ReplaySubject which can be used to subscribe to the results.
      Returns:
      the results so far as the Optimization 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

      public io.reactivex.rxjava3.subjects.ReplaySubject<IOptimizationProgress> progressSubject()
      Gets the ReplaySubject which can be used to subscribe to the progress
      Returns:
      the Progress during the running Optimization
    • errorSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<IErrorEvent> errorSubject()
      Gets the Error ReplaySubject which can be used to subscribe to any upcoming Errors.
      Returns:
      the Errors during the running Optimization
    • warningSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<IWarningEvent> warningSubject()
      Gets the Warnings ReplaySubject which can be used to subscribe to any upcoming Warnings
      Returns:
      the pushed Warnings
    • statusSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<IStatusEvent> statusSubject()
      Gets the status ReplaySubject which can be used to subscribe to the current status.
      Returns:
      the pushed status of the Optimization
    • nodeFilteringSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<NodeFilteringEvent> nodeFilteringSubject()
      Gets the ReplaySubject of filtered Nodes.
      Returns:
      the filtered Nodes
    • requestCodeExecutionDoneSubject

      public io.reactivex.rxjava3.subjects.ReplaySubject<String> 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 the subject pushes against the boundingPredicate and returns those subjects that do not conform with it.
      Type Parameters:
      T - variable dependent on the subject to test
      Parameters:
      subject - the replaySubject of the subject to test
      boundingPredicate - the predicate to which the subject is tested
      maxSize - the maximum number of buffered items
      Returns:
      subjects not conforming with the boundingPredicate
    • 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)