Package io.confluent.ksql.api.client
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>
Aorg.reactivestreams.Publisher
suitable for use with theClient.streamInserts(String, Publisher)
method. Rows for insertion are passed to the publisher via theaccept(KsqlObject)
method, and buffered for delivery once theClient.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
Fields Modifier and Type Field Description static int
DEFAULT_BUFFER_MAX_SIZE
The buffer max size indicator value used by the default constructor.
-
Constructor Summary
Constructors Constructor Description InsertsPublisher()
Creates anInsertsPublisher
.InsertsPublisher(int bufferMaxSize)
Creates anInsertsPublisher
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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 Detail
-
DEFAULT_BUFFER_MAX_SIZE
public static final int DEFAULT_BUFFER_MAX_SIZE
The buffer max size indicator value used by the default constructor. SeeInsertsPublisher(int)
for how this value is used.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
accept
public boolean accept(KsqlObject row)
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
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 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
public void subscribe(org.reactivestreams.Subscriber<? super KsqlObject> subscriber)
- Specified by:
subscribe
in interfaceorg.reactivestreams.Publisher<KsqlObject>
-
-