Interface JobEventSource
- All Superinterfaces:
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 :
- 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 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
Modifier and TypeMethodDescriptionCompletionStage<com.decisionbrain.optimserver.master.model.JobSolution>
Waits for the job identified by theJobSubscriptionFilter
to terminate and return the computed solution.Flow.Publisher<com.decisionbrain.optimserver.master.model.JobSolution>
Returns a Flow.Publisher that emits the computed solutions of the successful jobs.Flow.Publisher<com.decisionbrain.optimserver.master.model.KpiEvent>
Returns a Flow.Publisher that emits the job KPI events of the job(s).Flow.Publisher<com.decisionbrain.optimserver.master.model.LogEvent>
Returns a Flow.Publisher that emits the job log events of the job(s).Flow.Publisher<com.decisionbrain.optimserver.master.model.ProgressEvent>
Returns a Flow.Publisher that emits the job progress events of the job(s).Flow.Publisher<com.decisionbrain.optimserver.master.model.JobStatusEvent>
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 Details
-
jobSolution
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
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
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
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
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
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).
-