com.hazelcast.transaction
Class TransactionOptions

java.lang.Object
  extended by com.hazelcast.transaction.TransactionOptions
All Implemented Interfaces:
DataSerializable

public final class TransactionOptions
extends Object
implements DataSerializable

Contains the configuration for a Hazelcast transaction.


Nested Class Summary
static class TransactionOptions.TransactionType
          The type of transaction.
 
Field Summary
static long DEFAULT_TIMEOUT_MILLIS
          2 minutes as default timeout value
 
Constructor Summary
TransactionOptions()
          Creates a new default configured TransactionsOptions.
 
Method Summary
static TransactionOptions getDefault()
          Creates a new TransactionOptions configured with default settings.
 int getDurability()
          Gets the transaction durability.
 long getTimeoutMillis()
          Gets the timeout in milliseconds.
 TransactionOptions.TransactionType getTransactionType()
          Gets the TransactionOptions.TransactionType.
 void readData(ObjectDataInput in)
          Reads fields from the input stream
 TransactionOptions setDurability(int durability)
          Sets the transaction durability.
 TransactionOptions setTimeout(long timeout, TimeUnit timeUnit)
          Sets the timeout.
 TransactionOptions setTransactionType(TransactionOptions.TransactionType transactionType)
          Sets the TransactionOptions.TransactionType.
 String toString()
           
 void writeData(ObjectDataOutput out)
          Writes object fields to output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_TIMEOUT_MILLIS

public static final long DEFAULT_TIMEOUT_MILLIS
2 minutes as default timeout value

Constructor Detail

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 Detail

getTransactionType

public TransactionOptions.TransactionType getTransactionType()
Gets the TransactionOptions.TransactionType.

Returns:
the TransactionType.

setTransactionType

public TransactionOptions setTransactionType(TransactionOptions.TransactionType transactionType)
Sets the TransactionOptions.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:
getTransactionType(), setDurability(int)

getTimeoutMillis

public long getTimeoutMillis()
Gets the timeout in milliseconds.

Returns:
the timeout in milliseconds.
See Also:
setTimeout(long, java.util.concurrent.TimeUnit)

setTimeout

public TransactionOptions setTimeout(long timeout,
                                     TimeUnit timeUnit)
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 rollback 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:
getTimeoutMillis()

getDurability

public int getDurability()
Gets the transaction durability.

Returns:
the transaction durability.
See Also:
setDurability(int)

setDurability

public TransactionOptions setDurability(int durability)
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_PHASE is selected.

Parameters:
durability - the durability
Returns:
the updated TransactionOptions.
Throws:
IllegalArgumentException - if durability smaller than 0.

getDefault

public static TransactionOptions getDefault()
Creates a new TransactionOptions configured with default settings.

Returns:
the created default TransactionOptions.
See Also:
TransactionOptions()

writeData

public void writeData(ObjectDataOutput out)
               throws IOException
Description copied from interface: DataSerializable
Writes object fields to output stream

Specified by:
writeData in interface DataSerializable
Parameters:
out - output
Throws:
IOException

readData

public void readData(ObjectDataInput in)
              throws IOException
Description copied from interface: DataSerializable
Reads fields from the input stream

Specified by:
readData in interface DataSerializable
Parameters:
in - input
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.