Interface JobEventSource

  • All Superinterfaces:
    ConnectableEventSource

    public interface JobEventSource
    extends ConnectableEventSource

    Exposes publishers that emit events the client application can subscribe to. These publishers start emitting as ConnectableEventSource.connect() bas been called.
    These events are:

    • A solution computed by a worker.
    • A job status emitted by the master that monitors the worker.
    • A KPI emitted by the worker that is carrying out the job.
    • A progress status emitted by the worker that is executing the job.
    • A log emitted by the worker that is executing the job.

    The connectable aspect is directly inspired by the Rx Connectable Observable

    If the source emits events relative to one job only, All the publishers stop emitting when a terminal job status event has been received, regardless the statusEvents publisher has been subscribed or not. All the subscribers are then notified with the Flow.Subscriber.onComplete() method. The source disconnects itself.

    If the source emits events of all jobs, ConnectableEventSource.disconnect() must be called explicitly.

    The client program has to :


    Below an example that shows how to use a JobEventSource:
    
       eventSource.statusEvents().subscribe(new ConsumerSubscriber<>(
         onComplete,
         jobStatusEvent ->
          LOGGER.info(String.format("[STATUS]: %s", jobStatusEvent.getStatus().name()))
       ));
    
       jobExecutionAsyncApi.getJobSolution(jobDefinition.getId(), Duration.ofSeconds(3))
         .whenComplete((jobSolution, throwable) -> {
              if (jobSolution != null) {
                  LOGGER.info("Solution retrieved before timeout");
              }
              if (throwable != null) {
                  LOGGER.error("Exception while waiting for solution", throwable);
              }
         });
    
       eventSource.connect();
     
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletionStage<com.decisionbrain.optimserver.master.model.JobSolution> jobSolution()
      Waits for the job identified by the JobSubscriptionFilter to terminate and return the computed solution.
      java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.JobSolution> jobSolutions()
      Returns a Flow.Publisher that emits the computed solutions of the successful jobs.
      java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.KpiEvent> kpiEvents()
      Returns a Flow.Publisher that emits the job KPI events of the job(s).
      java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.LogEvent> logEvents()
      Returns a Flow.Publisher that emits the job log events of the job(s).
      java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.ProgressEvent> progressEvents()
      Returns a Flow.Publisher that emits the job progress events of the job(s).
      java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.JobStatusEvent> statusEvents()
      Returns a Flow.Publisher that emits the status events of the job(s).
    • Method Detail

      • jobSolution

        java.util.concurrent.CompletionStage<com.decisionbrain.optimserver.master.model.JobSolution> jobSolution()

        Waits for the job identified by the JobSubscriptionFilter to terminate and return the computed solution.

        If no job identifier is supplied in the JobSubscriptionFilter, the CompletionStage completes with the solution of the first successful job.

        This method should be called when a job identifier has been supplied in the JobSubscriptionFilter
        Returns:
        A Flow.Publisher with the computed job solution.
      • jobSolutions

        java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.JobSolution> jobSolutions()

        Returns a Flow.Publisher that emits the computed solutions of the successful jobs.

        If a job identifier is supplied in the JobSubscriptionFilter, the publisher emits one event only.

        This method should be called when no job identifier has been supplied in the JobSubscriptionFilter
        Returns:
        a Flow.Publisher that emits the computed solutions of the successful jobs.
      • statusEvents

        java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.JobStatusEvent> statusEvents()
        Returns a Flow.Publisher that emits the status events of the job(s).
        Returns:
        a Flow.Publisher that emits the status events of the job(s).
      • kpiEvents

        java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.KpiEvent> kpiEvents()
        Returns a Flow.Publisher that emits the job KPI events of the job(s).
        Returns:
        a Flow.Publisher that emits the job KPI events of the job(s).
      • progressEvents

        java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.ProgressEvent> progressEvents()
        Returns a Flow.Publisher that emits the job progress events of the job(s).
        Returns:
        a Flow.Publisher that emits the job progress events of the job(s).
      • logEvents

        java.util.concurrent.Flow.Publisher<com.decisionbrain.optimserver.master.model.LogEvent> logEvents()
        Returns a Flow.Publisher that emits the job log events of the job(s).
        Returns:
        a Flow.Publisher that emits the job log events of the job(s).