Class InsertsPublisher

java.lang.Object
io.confluent.ksql.api.client.InsertsPublisher
All Implemented Interfaces:
org.reactivestreams.Publisher<KsqlObject>

public class InsertsPublisher extends Object implements org.reactivestreams.Publisher<KsqlObject>
A org.reactivestreams.Publisher suitable for use with the Client.streamInserts(String, Publisher) method. Rows for insertion are passed to the publisher via the accept(KsqlObject) method, and buffered for delivery once the Client.streamInserts(java.lang.String, org.reactivestreams.Publisher<io.confluent.ksql.api.client.KsqlObject>) request is made and the server-side subscriber has been subscribed.
  • Field Details

    • DEFAULT_BUFFER_MAX_SIZE

      public static final int DEFAULT_BUFFER_MAX_SIZE
      The buffer max size indicator value used by the default constructor. See InsertsPublisher(int) for how this value is used.
      See Also:
  • Constructor Details

    • InsertsPublisher

      public InsertsPublisher()
      Creates an InsertsPublisher.
    • InsertsPublisher

      public InsertsPublisher(int bufferMaxSize)
      Creates an InsertsPublisher.
      Parameters:
      bufferMaxSize - Indicative max number of elements to store in the buffer. Note that this value is not enforced, but it used to determine what to return from the accept(KsqlObject) method so the caller can stop sending more rows and set a drainHandler to be notified when the buffer is cleared
  • Method Details

    • accept

      public boolean accept(KsqlObject row)
      Provides a new row for insertion. The publisher will attempt to deliver it to server endpoint, once the Client.streamInserts(java.lang.String, org.reactivestreams.Publisher<io.confluent.ksql.api.client.KsqlObject>) request has been made. The publisher will buffer the row internally if it can't deliver it immediately. Note that the row will be buffered even if the buffer is 'full', i.e., if number of elements is at least bufferMaxSize, as the bufferMaxSize value is not a hard limit. See InsertsPublisher(int) for more.
      Parameters:
      row - the row to insert
      Returns:
      whether the internal buffer is 'full', i.e., if number of elements is at least bufferMaxSize.
    • drainHandler

      public void drainHandler(Runnable handler)
      Sets a drain handler on the publisher. The drain handler will be called if after a row is delivered there are zero elements buffered internally and there is demand from the subscriber for more elements. Drain handlers may be used in combination with the return value from accept(KsqlObject) to ensure the publisher's buffer does not grow too large.

      Drain handlers are one shot handlers; after a drain handler is called it will never be called again. Instead, the caller should set a new drain handler for subsequent use.

      Parameters:
      handler - the drain handler
    • complete

      public void complete()
      Marks the incoming stream of elements as complete. This means no further rows will be accepted by the publisher and the Client.streamInserts(java.lang.String, org.reactivestreams.Publisher<io.confluent.ksql.api.client.KsqlObject>) connection will be closed once any buffered rows have been delivered for insertion.
    • subscribe

      public void subscribe(org.reactivestreams.Subscriber<? super KsqlObject> subscriber)
      Specified by:
      subscribe in interface org.reactivestreams.Publisher<KsqlObject>