I'm in the process of writing a client for Apache Mesos' new HTTP Scheduler API using RxJava and RxNetty.
I've managed to successfully create the connection with RxNetty and create an Observable<Event>
from the resulting chunked stream.
Now I'm at the point of trying to model a sink that can be used to send calls back to Mesos in order to claim/decline resource offers, acknowledge task status updates, etc.
The message that will be sent to sent to Mesos is a Call
, I need to be able to provide an onCompleted
or onError
for every Call
that comes into the Sink. This is due to Mesos performing synchronous validation on the Call
being sent to it.
I'm essentially trying to allow for the following:
final MesosSchedulerClient client = new MesosSchedulerClient();
final Observable<Event> events = client.openEventStream(subscribeCall);
final Observable<Observable<Call>> ackCalls = events
.filter(event -> event.getType() == Event.Type.UPDATE && event.getUpdate().getStatus().hasUuid())
.zipWith(frameworkIDObservable, (Event e, AtomicReference<FrameworkID>> fwId) -> {
final TaskStatus status = e.getUpdate().getStatus();
final Call ackCall = ackUpdate(fwId.get(), status.getUuid(), status.getAgentId(), status.getTaskId());
return Observable.just(ackCall)
.doOnComplete(() -> { ... })
.doOnError((e) -> { ... });
});
client.sink(ackCalls);
Right now I've come up with a custom object[1] that extends Subject and specifies the Call
and Action0
for onCompleted
and Action1<Throwable>
for onError
. Though, I would prefer to use the existing constructs from RxJava if possible. Sample usage of what I've come up with[2].
Any guidance would be greatly appreciated.