Interface JobEventSource
-
- All Superinterfaces:
ConnectableEventSource
public interface JobEventSource extends ConnectableEventSource
Exposes
publishers
that emit events the client application can subscribe to. Thesepublishers
start emitting asConnectableEventSource.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 thestatusEvents
publisher has been subscribed or not. All thesubscribers
are then notified with theFlow.Subscriber.onComplete()
method. The sourcedisconnects
itself.If the source emits events of all jobs,
ConnectableEventSource.disconnect()
must be called explicitly.The client program has to :
- Retrieve a JobEventSource using
JobExecutionAsyncApi
orJobExecutionSharedAsyncApi
- Subscribe to the Flow.Publisher that emits the events it wants to listen to.
- Call
ConnectableEventSource.connect()
to tell the source to start emitting.
Below an example that shows how to use aJobEventSource
: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 theJobSubscriptionFilter
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).-
Methods inherited from interface com.decisionbrain.optimserver.client.java.async.api.ConnectableEventSource
connect, disconnect
-
-
-
-
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
This method should be called when a job identifier has been supplied in theJobSubscriptionFilter
, the CompletionStage completes with the solution of the first successful job.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
This method should be called when no job identifier has been supplied in theJobSubscriptionFilter
, the publisher emits one event only.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).
-
-