Interface ProducerBase

All Superinterfaces:
AutoCloseable
All Known Subinterfaces:
ExactlyOnceProducer, Producer

@Experimental public interface ProducerBase extends AutoCloseable
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 Type
    Method
    Description
    void
    Immediately closes the producer and shuts down its stream without flushing.
    long
    Blocks until every invocation accepted before this call is durably acknowledged.
    Asynchronously awaits durable acknowledgement of every invocation accepted before this call.
    long
    Returns the highest offset durably acknowledged by Restate.
    long
    Returns the highest offset successfully accepted by send or trySend so far.
    waitAcknowledged(long offset)
    Awaits durable acknowledgement of all invocations up to and including offset.
  • Method Details

    • lastSentOffset

      long lastSentOffset()
      Returns the highest offset successfully accepted by send or trySend so far.
      Returns:
      the highest offset accepted, or -1 if 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 -1 if nothing has been acknowledged yet
      Throws:
      ConcurrentModificationException - if the producer is used concurrently from another thread
    • waitAcknowledged

      CompletableFuture<Long> waitAcknowledged(long offset)
      Awaits durable acknowledgement of all invocations up to and including offset.
      Parameters:
      offset - the offset to wait for
      Returns:
      a future completing, once every invocation up to and including offset is 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 acknowledged
      IllegalStateException - if a reentrant producer callback invokes this method when it would block
      ConcurrentModificationException - 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 an IntegrationClientException.

      Call flush() before closing, or await flushAsync(), when accepted invocations must be durably committed.

      Specified by:
      close in interface AutoCloseable
      Throws:
      ConcurrentModificationException - if the producer is used concurrently from another thread