Package io.confluent.ksql.api.client
Class InsertsPublisher
java.lang.Object
io.confluent.ksql.api.client.InsertsPublisher
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionstatic final int
The buffer max size indicator value used by the default constructor. -
Constructor Summary
ConstructorDescriptionCreates anInsertsPublisher
.InsertsPublisher
(int bufferMaxSize) Creates anInsertsPublisher
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
accept
(KsqlObject row) Provides a new row for insertion.void
complete()
Marks the incoming stream of elements as complete.void
drainHandler
(Runnable handler) Sets a drain handler on the publisher.void
subscribe
(org.reactivestreams.Subscriber<? super KsqlObject> subscriber)
-
Field Details
-
DEFAULT_BUFFER_MAX_SIZE
public static final int DEFAULT_BUFFER_MAX_SIZEThe buffer max size indicator value used by the default constructor. SeeInsertsPublisher(int)
for how this value is used.- See Also:
-
-
Constructor Details
-
InsertsPublisher
public InsertsPublisher()Creates anInsertsPublisher
. -
InsertsPublisher
public InsertsPublisher(int bufferMaxSize) Creates anInsertsPublisher
.- 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 theaccept(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
Provides a new row for insertion. The publisher will attempt to deliver it to server endpoint, once theClient.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 leastbufferMaxSize
, as thebufferMaxSize
value is not a hard limit. SeeInsertsPublisher(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
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 fromaccept(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 theClient.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
- Specified by:
subscribe
in interfaceorg.reactivestreams.Publisher<KsqlObject>
-