Package io.pravega.client.stream.impl
Class EventStreamWriterImpl<Type>
- java.lang.Object
-
- io.pravega.client.stream.impl.EventStreamWriterImpl<Type>
-
- Type Parameters:
Type- The type of event that is sent
- All Implemented Interfaces:
EventStreamWriter<Type>,java.lang.AutoCloseable
public class EventStreamWriterImpl<Type> extends java.lang.Object implements EventStreamWriter<Type>
This class takes in events, finds out which segment they belong to and then calls write on the appropriate segment. It deals with segments that are sealed by re-sending the unacked events to the new correct segment.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Calls flush and then closes the writer.voidflush()Block until all events that have been passed to writeEvent's corresponding futures have completed.EventWriterConfiggetConfig()Returns the configuration that this writer was create with.voidnoteTime(long timestamp)Notes a time that can be seen by readers which read from this stream byEventStreamReader.getCurrentTimeWindow(Stream).java.lang.StringtoString()java.util.concurrent.CompletableFuture<java.lang.Void>writeEvent(java.lang.String routingKey, Type event)Write an event to the stream.java.util.concurrent.CompletableFuture<java.lang.Void>writeEvent(Type event)Send an event to the stream.java.util.concurrent.CompletableFuture<java.lang.Void>writeEvents(java.lang.String routingKey, java.util.List<Type> events)Write an ordered list of events to the stream atomically for a given routing key.
-
-
-
Method Detail
-
writeEvent
public java.util.concurrent.CompletableFuture<java.lang.Void> writeEvent(Type event)
Description copied from interface:EventStreamWriterSend an event to the stream. Events that are written should appear in the stream exactly once. The maximum size of the serialized event supported is defined atSerializer.MAX_EVENT_SIZE. Note that the implementation provides retry logic to handle connection failures and service host failures. Internal retries will not violate the exactly once semantic so it is better to rely on them than to wrap this with custom retry logic.- Specified by:
writeEventin interfaceEventStreamWriter<Type>- Parameters:
event- The event to be written to the stream (Null is disallowed)- Returns:
- A completableFuture that will complete when the event has been durably stored on the configured number of replicas, and is available for readers to see. This future may complete exceptionally if this cannot happen, however these exceptions are not transient failures. Failures that occur as a result of connection drops or host death are handled internally with multiple retires and exponential backoff. So there is no need to attempt to retry in the event of an exception.
-
writeEvent
public java.util.concurrent.CompletableFuture<java.lang.Void> writeEvent(java.lang.String routingKey, Type event)Description copied from interface:EventStreamWriterWrite an event to the stream. Similar toEventStreamWriter.writeEvent(Object)but provides a routingKey which is used to specify ordering. Events written with the same routing key will be read by readers in exactly the same order they were written. The maximum size of the serialized event supported is defined atSerializer.MAX_EVENT_SIZE. Note that the implementation provides retry logic to handle connection failures and service host failures. Internal retries will not violate the exactly once semantic so it is better to rely on this than to wrap this method with custom retry logic.- Specified by:
writeEventin interfaceEventStreamWriter<Type>- Parameters:
routingKey- A free form string that is used to route messages to readers. Two events written with the same routingKey are guaranteed to be read in order. Two events with different routing keys may be read in parallel.event- The event to be written to the stream (Null is disallowed)- Returns:
- A completableFuture that will complete when the event has been durably stored on the configured number of replicas, and is available for readers to see. This future may complete exceptionally if this cannot happen, however these exceptions are not transient failures. Failures that occur as a result of connection drops or host death are handled internally with multiple retires and exponential backoff. So there is no need to attempt to retry in the event of an exception.
-
writeEvents
public java.util.concurrent.CompletableFuture<java.lang.Void> writeEvents(java.lang.String routingKey, java.util.List<Type> events)Description copied from interface:EventStreamWriterWrite an ordered list of events to the stream atomically for a given routing key. Events written with the same routing key will be read by readers in exactly the same order they were written. The maximum size of the serialized event individually should beSerializer.MAX_EVENT_SIZEand the collective batch should be less than twice theSerializer.MAX_EVENT_SIZE. Note that the implementation provides retry logic to handle connection failures and service host failures. Internal retries will not violate the exactly once semantic so it is better to rely on this than to wrap this method with custom retry logic.- Specified by:
writeEventsin interfaceEventStreamWriter<Type>- Parameters:
routingKey- A free form string that is used to route messages to readers. Two events written with the same routingKey are guaranteed to be read in order. Two events with different routing keys may be read in parallel.events- The batch of events to be written to the stream (Null is disallowed)- Returns:
- A completableFuture that will complete when the event has been durably stored on the configured number of replicas, and is available for readers to see. This future may complete exceptionally if this cannot happen, however these exceptions are not transient failures. Failures that occur as a result of connection drops or host death are handled internally with multiple retires and exponential backoff. So there is no need to attempt to retry in the event of an exception.
-
flush
public void flush()
Description copied from interface:EventStreamWriterBlock until all events that have been passed to writeEvent's corresponding futures have completed.- Specified by:
flushin interfaceEventStreamWriter<Type>
-
close
public void close()
Description copied from interface:EventStreamWriterCalls flush and then closes the writer. (No further methods may be called)- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceEventStreamWriter<Type>
-
getConfig
public EventWriterConfig getConfig()
Description copied from interface:EventStreamWriterReturns the configuration that this writer was create with.- Specified by:
getConfigin interfaceEventStreamWriter<Type>- Returns:
- Writer configuration
-
noteTime
public void noteTime(long timestamp)
Description copied from interface:EventStreamWriterNotes a time that can be seen by readers which read from this stream byEventStreamReader.getCurrentTimeWindow(Stream). The semantics or meaning of the timestamp is left to the application. Readers might expect timestamps to be monotonic. So this is recommended but not enforced. There is no requirement to call this method. Never doing so will result in readers invokingEventStreamReader.getCurrentTimeWindow(Stream)receiving a null for both upper and lower times. Calling this method can be automated by settingEventWriterConfig.EventWriterConfigBuilder.automaticallyNoteTime(boolean)to true when creating a writer.- Specified by:
noteTimein interfaceEventStreamWriter<Type>- Parameters:
timestamp- a timestamp that represents the current location in the stream.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-