Interface QueryResponseSink

All Known Implementing Classes:
SseQueryResponseSink

public interface QueryResponseSink
Where a member writes the responses to a query it is answering for another member.

This is what keeps answering a query testable without a web stack: the endpoint adapts a response stream to this, and everything deciding what to write works against it rather than against the stream itself. Keeping an idle stream open is not among those decisions -- whether that takes writing anything at all, and what, is the transport's own business, so it lives on the implementation rather than here.

A sink is written to until it is terminated, which error(QueryDispatchFailure), complete(), subscriptionComplete(String) or leaving(String) does. Nothing is written after that.

Since:
5.4.0
Author:
Allard Buijze
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Ends the response stream, reporting that the query was answered in full.
    void
    Ends the response stream, reporting that the query failed.
    void
    leaving(String requestIdentifier)
    Ends the response stream, reporting that this member stops answering the subscription query because it is leaving the cluster.
    void
    Registers a listener to run once this sink can no longer be written to, for a reason other than the query having been answered — the member that asked stopped reading, or waited longer than it was given.
    void
    Writes one response to the query being answered.
    void
    subscriptionComplete(String requestIdentifier)
    Reports that the subscription query being answered is over: there will never be another update to it.
    void
    Writes one update to the subscription query being answered.
  • Method Details

    • onUnavailable

      void onUnavailable(Runnable listener)
      Registers a listener to run once this sink can no longer be written to, for a reason other than the query having been answered — the member that asked stopped reading, or waited longer than it was given.

      Only the sink knows how its transport reports that, which is why the listener is registered here rather than discovered by whatever writes to it. Answering a query that nothing is reading is wasted work, and the handler's response stream would otherwise be held until it happens to produce a response that fails to write — which a handler that has gone quiet never does.

      Parameters:
      listener - runs when this sink can no longer be written to
    • response

      void response(QueryDispatchResponse response)
      Writes one response to the query being answered.
      Parameters:
      response - the response to write
    • update

      void update(QueryDispatchResponse update)
      Writes one update to the subscription query being answered.

      Distinct from response(QueryDispatchResponse) because the subscriber acts on the two differently: a response belongs to the initial result, an update is a change after it.

      Parameters:
      update - the update to write
    • subscriptionComplete

      void subscriptionComplete(String requestIdentifier)
      Reports that the subscription query being answered is over: there will never be another update to it.

      Distinct from leaving(String), which says only that this member stops answering, and from the stream merely ending, which fails the subscription. This says the subscription itself has run its course, and the subscriber stops waiting on every other member too.

      Parameters:
      requestIdentifier - the identifier of the subscription query that is over
    • leaving

      void leaving(String requestIdentifier)
      Ends the response stream, reporting that this member stops answering the subscription query because it is leaving the cluster.

      Distinct from subscriptionComplete(String), which ends the subscription for every member, and from error(QueryDispatchFailure), which fails it. This ends only this member's part: it has stopped emitting updates, so the subscriber carries on with the members that remain. Also distinct from the stream merely ending, which the subscriber cannot tell apart from a lost connection and so treats as a failure.

      Parameters:
      requestIdentifier - the identifier of the subscription query this member stops answering
    • error

      void error(QueryDispatchFailure error)
      Ends the response stream, reporting that the query failed.
      Parameters:
      error - the failure that ended the response stream
    • complete

      void complete()
      Ends the response stream, reporting that the query was answered in full.