Interface JobExecutionAsyncApi


public interface JobExecutionAsyncApi
This interfaces exposes an event source, JobEventSource, that emits events to which a client application can subscribe to.

It differs from JobExecutionSharedAsyncApi as it allows multiple clients to get all events of jobs (events are not balanced).

Below an example that shows how to get a JobEventSource for a particular job:

   String jobId = "theJobToListen";
   CompletableFuture<Void> onComplete = new CompletableFuture<>();
   onComplete.whenComplete((v, e) ->
      LOGGER.info("The flow of events for this job is finished"));

   JobEventSource eventSource = jobExecutionAsyncApi.getJobEventSource(
     new JobSubscriptionFilter(jobId)
   );
 
Then, you can use the JobEventSource's methods.
See Also:
  • Method Details

    • getJobSolution

      default CompletionStage<com.decisionbrain.optimserver.master.model.JobSolution> getJobSolution(String jobId, Duration timeout)
      Waits for the job identified by jobId to terminate and return the computed solution.

      This method is a shortcut for {JobEventSource.jobSolution()}

      Parameters:
      jobId - The job identifier to get the solution from.
      timeout - The maximum amount of time to wait before completing the CompletionStage with a TimeoutException
      Returns:
      A CompletionStage with either the computed job solution or a TimeoutException
    • getJobEventSource

      JobEventSource getJobEventSource(JobSubscriptionFilter filter)
      Returns a connectable job event source the client can subscribe to.

      If the filter parameter field 'jobId' is set, only the events of the corresponding job are emitted as the source is connected. If the 'jobId' is not set, the events of all the jobs are emitted.

      All clients that use the same job id receive all events of the job. For instance, if two applications listen the job solution for the same job id, both will receive the JobSolution of the job.

      Parameters:
      filter - To filter the events emitted by this source.
      Returns:
      A connectable job event source the client can subscribe to.