Package io.pravega.client.stream
Interface Transaction<Type>
-
- Type Parameters:
Type
- The type of events in the associated stream.
public interface Transaction<Type>
Provides a mechanism for writing many events atomically. A Transaction is unbounded in size but is bounded in time. If it has not been committed within a time window specified at the time of its creation it will be automatically aborted. All methods on this class may block.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Transaction.PingStatus
static class
Transaction.Status
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
abort()
Drops the transaction, causing all events written to it to be deleted.Transaction.Status
checkStatus()
Gets the status of the transaction.void
commit()
Causes all messages previously written to the transaction to go into the stream contiguously.void
commit(long timestamp)
Commits the transaction similar tocommit()
, but also notes an associated timestamp.void
flush()
Blocks until all events passed towriteEvent(String, Object)
make it to durable storage.java.util.UUID
getTxnId()
Returns a unique ID that can be used to identify this transaction.void
writeEvent(java.lang.String routingKey, Type event)
Sends an event to the stream just likeEventStreamWriter.writeEvent(Type)
but with the caveat that the message will not be visible to anyone untilcommit()
is called.void
writeEvent(Type event)
Sends an event to the stream just likeEventStreamWriter.writeEvent(Type)
but with the caveat that the message will not be visible to anyone untilcommit()
is called.
-
-
-
Method Detail
-
getTxnId
java.util.UUID getTxnId()
Returns a unique ID that can be used to identify this transaction.- Returns:
- Unique identifier of the transaction
-
writeEvent
void writeEvent(Type event) throws TxnFailedException
Sends an event to the stream just likeEventStreamWriter.writeEvent(Type)
but with the caveat that the message will not be visible to anyone untilcommit()
is called. A routing key will automatically be inferred from the transactionID. So all events written this way will be fully ordered and contiguous when read.- Parameters:
event
- The Event to write. (Null is disallowed)- Throws:
TxnFailedException
- The Transaction is no longer in stateTransaction.Status.OPEN
-
writeEvent
void writeEvent(java.lang.String routingKey, Type event) throws TxnFailedException
Sends an event to the stream just likeEventStreamWriter.writeEvent(Type)
but with the caveat that the message will not be visible to anyone untilcommit()
is called.- Parameters:
routingKey
- The Routing Key to use for writing.event
- The Event to write. (Null is disallowed)- Throws:
TxnFailedException
- The Transaction is no longer in stateTransaction.Status.OPEN
-
flush
void flush() throws TxnFailedException
Blocks until all events passed towriteEvent(String, Object)
make it to durable storage. This is only needed if the transaction is going to be serialized.- Throws:
TxnFailedException
- The Transaction is no longer in stateTransaction.Status.OPEN
-
commit
void commit() throws TxnFailedException
Causes all messages previously written to the transaction to go into the stream contiguously. This operation will either fully succeed making all events consumable or fully fail such that none of them are. There may be some time delay before readers see the events after this call has returned.- Throws:
TxnFailedException
- The Transaction is no longer in stateTransaction.Status.OPEN
-
commit
void commit(long timestamp) throws TxnFailedException
Commits the transaction similar tocommit()
, but also notes an associated timestamp. Similar toEventStreamWriter.noteTime(long)
.- Parameters:
timestamp
- A timestamp associated with this transaction.- Throws:
TxnFailedException
- The Transaction is no longer in stateTransaction.Status.OPEN
-
abort
void abort()
Drops the transaction, causing all events written to it to be deleted.
-
checkStatus
Transaction.Status checkStatus()
Gets the status of the transaction.- Returns:
- Current status of the transaction
-
-