Class TransactionOptions
- All Implemented Interfaces:
DataSerializable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe type of transaction. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long2 minutes as default timeout value -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TransactionOptionsCreates a new TransactionOptions configured with default settings.intGets the transaction durability.longGets the timeout in milliseconds.Gets theTransactionOptions.TransactionType.voidReads fields from the input streamsetDurability(int durability) Sets the transaction durability.setTimeout(long timeout, TimeUnit timeUnit) Sets the timeout.setTransactionType(TransactionOptions.TransactionType transactionType) Sets theTransactionOptions.TransactionType.toString()voidWrites object fields to output stream
-
Field Details
-
DEFAULT_TIMEOUT_MILLIS
public static final long DEFAULT_TIMEOUT_MILLIS2 minutes as default timeout value
-
-
Constructor Details
-
TransactionOptions
public TransactionOptions()Creates a new default configured TransactionsOptions.It will be configured with a timeout of 2 minutes, durability of 1 and a TransactionType.TWO_PHASE.
-
-
Method Details
-
getTransactionType
Gets theTransactionOptions.TransactionType.- Returns:
- the TransactionType.
-
setTransactionType
Sets theTransactionOptions.TransactionType.A local transaction is less safe than a two phase transaction; when a member fails during the commit of a local transaction, it could be that some of the changes are committed, while others are not and this can leave your system in an inconsistent state.
- Parameters:
transactionType- the new TransactionType.- Returns:
- the updated TransactionOptions.
- See Also:
-
getTimeoutMillis
public long getTimeoutMillis()Gets the timeout in milliseconds.- Returns:
- the timeout in milliseconds.
- See Also:
-
setTimeout
Sets the timeout.The timeout determines the maximum lifespan of a transaction. So if a transaction is configured with a timeout of 2 minutes, then it will automatically roll back if it hasn't committed yet.
- Parameters:
timeout- the timeout.timeUnit- the TimeUnit of the timeout.- Returns:
- the updated TransactionOptions
- Throws:
IllegalArgumentException- if timeout smaller or equal than 0, or timeUnit is null.- See Also:
-
getDurability
public int getDurability()Gets the transaction durability.- Returns:
- the transaction durability.
- See Also:
-
setDurability
Sets the transaction durability.The durability is the number of machines that can take over if a member fails during a transaction commit or rollback. This value only has meaning when
TransactionOptions.TransactionType.TWO_PHASEis selected.- Parameters:
durability- the durability- Returns:
- the updated TransactionOptions.
- Throws:
IllegalArgumentException- if durability smaller than 0.
-
getDefault
Creates a new TransactionOptions configured with default settings.- Returns:
- the created default TransactionOptions.
- See Also:
-
writeData
Description copied from interface:DataSerializableWrites object fields to output stream- Specified by:
writeDatain interfaceDataSerializable- Parameters:
out- output- Throws:
IOException- if an I/O error occurs. In particular, anIOExceptionmay be thrown if the output stream has been closed.
-
readData
Description copied from interface:DataSerializableReads fields from the input stream- Specified by:
readDatain interfaceDataSerializable- Parameters:
in- input- Throws:
IOException- if an I/O error occurs. In particular, anIOExceptionmay be thrown if the input stream has been closed.
-
toString
-