NSF Handler

The CORE database handlers can be found in the package com.hcl.domino.keep.dbrequests or sub-packages of it.

Handlers extend the AbstractAsyncDomino (or a subclass) that contains most of the boilerplate code required.

The only function to implement is processPayload

protected void processPayload(@NonNull final KeepSession s,
                              @NonNull final NotesDatabase db,
                              @NonNull final JsonObject payload) {
      // Your code goes here
}

Inside the function 2 methods send back results to the EventBus and the incoming request:

  • With data: this.onNext(resultData) - can be called repeatedly
  • On error this.onError(error) - one time only

We don’t need to call this.onComplete(), this is handled in the abstract class already.

Cross handler calling

For some of the calls (e.g Inbox, Drafts, All Documents) an existing handler does all the work already. Instead of copy & paste we can use KeepSubrequest to marshall the request after updating the payload JsonObject to match what the target handler needs

try {

    final JsonObject localPayload = this.convertPayload(payload);
    final GetDocument getDocument = new GetDocument(localPayload, this.vertx);
    final KeepSubrequest subrequest = new KeepSubrequest(getDocument, this)
        .execute(s, db, localPayload);

} catch (final Throwable t) {
    this.onError(t);
}

Not pictured above: convertPayload() that takes care of providing the matching payload.

The subrequest call can be modified. It is possible to process results before they go back onto the EventBus by providing a Consumer<JsonObject> for onNext and a Runnable for on complete. You can provide none, either or both.

When not provided, the parent onNext and/or onComplete are called

Sample:

@Override
public void processPayload(@NonNull final KeepSession s, @NonNull final NotesDatabase db,
    @NonNull final JsonObject payload) {

    Consumer < JsonObject > calOnNext = response - > {
        response.put("Demo", "This went through a consumer");
        this.onNext(response);
    };

    Runnable whenDone = () -> {
      System.out.println("I'm done, horray!");
      this.onComplete();
    };

    final JsonObject localPayload = this.prepareLocalPayload(payload);
    final GetDocument getDocument = new GetDocument(localPayload, this.vertx);
    
    new KeepSubrequest(getDocument, this)
      .setOnNext(calOnNext)
      .setOnComplete(whenDone)
      .execute(s, db, localPayload);
}