Interface ProducerBase
- All Superinterfaces:
AutoCloseable
- All Known Subinterfaces:
ExactlyOnceProducer, Producer
Common producer offsets, acknowledgement, flushing, and lifecycle operations.
Producer futures can complete inline on a transport callback. A synchronous continuation must
not invoke an operation that would block, such as flush(); offload the continuation to
an executor instead. A reentrant call that would block is rejected with IllegalStateException rather than deadlocking the transport callback lane.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Immediately closes the producer and shuts down its stream without flushing.longflush()Blocks until every invocation accepted before this call is durably acknowledged.Asynchronously awaits durable acknowledgement of every invocation accepted before this call.longReturns the highest offset durably acknowledged by Restate.longReturns the highest offset successfully accepted bysendortrySendso far.waitAcknowledged(long offset) Awaits durable acknowledgement of all invocations up to and includingoffset.
-
Method Details
-
lastSentOffset
long lastSentOffset()Returns the highest offset successfully accepted bysendortrySendso far.- Returns:
- the highest offset accepted, or
-1if nothing has been accepted yet - Throws:
ConcurrentModificationException- if the producer is used concurrently from another thread
-
lastAcknowledgedOffset
long lastAcknowledgedOffset()Returns the highest offset durably acknowledged by Restate.This value remains available after the producer closes or fails, so an exactly-once producer can use it to determine where to resume.
- Returns:
- the highest durably acknowledged offset, or
-1if nothing has been acknowledged yet - Throws:
ConcurrentModificationException- if the producer is used concurrently from another thread
-
waitAcknowledged
Awaits durable acknowledgement of all invocations up to and includingoffset.- Parameters:
offset- the offset to wait for- Returns:
- a future completing, once every invocation up to and including
offsetis durably acknowledged by Restate, with the highest acknowledged offset - Throws:
ConcurrentModificationException- if the producer is used concurrently from another thread
-
flush
long flush()Blocks until every invocation accepted before this call is durably acknowledged.- Returns:
- the highest durably committed offset
- Throws:
IntegrationClientException- if the producer fails before all invocations are acknowledgedIllegalStateException- if a reentrant producer callback invokes this method when it would blockConcurrentModificationException- if the producer is used concurrently from another thread
-
flushAsync
CompletableFuture<Long> flushAsync()Asynchronously awaits durable acknowledgement of every invocation accepted before this call.- Returns:
- a future completing with the highest durably committed offset once all invocations sent so far are acknowledged
- Throws:
ConcurrentModificationException- if the producer is used concurrently from another thread
-
close
void close()Immediately closes the producer and shuts down its stream without flushing. Any not-yet-acknowledged invocation completes its future exceptionally with anIntegrationClientException.Call
flush()before closing, or awaitflushAsync(), when accepted invocations must be durably committed.- Specified by:
closein interfaceAutoCloseable- Throws:
ConcurrentModificationException- if the producer is used concurrently from another thread
-