Hazelcast C++ Client
Hazelcast C++ Client Library
Loading...
Searching...
No Matches
hazelcast::client::transaction_options Class Reference

Contains the configuration for a Hazelcast transaction. More...

#include <transaction_options.h>

Public Types

enum struct  transaction_type { TWO_PHASE = 1 , LOCAL = 2 }
 Transaction type. More...

Public Member Functions

 transaction_options ()
 Creates a new default configured TransactionsOptions.
transaction_type get_transaction_type () const
transaction_optionsset_transaction_type (transaction_type transaction_type)
 Sets the TransactionType.
std::chrono::milliseconds get_timeout () const
transaction_optionsset_timeout (std::chrono::milliseconds duration)
 The timeout determines the maximum lifespan of a transaction.
int get_durability () const
transaction_optionsset_durability (int num_machines)
 Sets the transaction durability.

Detailed Description

Contains the configuration for a Hazelcast transaction.

Definition at line 31 of file transaction_options.h.

Member Enumeration Documentation

◆ transaction_type

Transaction type.

Definition at line 37 of file transaction_options.h.

38 {
39 TWO_PHASE = 1,
40 LOCAL = 2
41 };

Constructor & Destructor Documentation

◆ transaction_options()

hazelcast::client::transaction_options::transaction_options ( )

Creates a new default configured TransactionsOptions.

It will be configured with a timeout of 2 minutes, durability of 1 and a TransactionType.TWO_PHASE.

Definition at line 747 of file transactions.cpp.

748 : timeout_(std::chrono::minutes(2))
749 , durability_(1)
750 , transaction_type_(transaction_type::TWO_PHASE)
751{}

Member Function Documentation

◆ get_durability()

int hazelcast::client::transaction_options::get_durability ( ) const
Returns
the transaction durability.
See also
#setDurability(int)

Definition at line 784 of file transactions.cpp.

785{
786 return durability_;
787}

◆ get_timeout()

std::chrono::milliseconds hazelcast::client::transaction_options::get_timeout ( ) const
Returns
the timeout

Definition at line 767 of file transactions.cpp.

768{
769 return timeout_;
770}

◆ get_transaction_type()

transaction_options::transaction_type hazelcast::client::transaction_options::get_transaction_type ( ) const
Returns
the TransactionType.

Definition at line 754 of file transactions.cpp.

755{
756 return transaction_type_;
757}

◆ set_durability()

transaction_options & hazelcast::client::transaction_options::set_durability ( int num_machines)

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 TransactionType#TWO_PHASE is selected.

Parameters
durabilitythe durability
Returns
the updated TransactionOptions.
Exceptions
illegal_argumentif durability smaller than 0.

Definition at line 790 of file transactions.cpp.

791{
792 if (num_machines < 0) {
793 BOOST_THROW_EXCEPTION(
794 exception::illegal_state("TransactionOptions::setDurability",
795 "Durability cannot be negative!"));
796 }
797 this->durability_ = num_machines;
798 return *this;
799}

◆ set_timeout()

transaction_options & hazelcast::client::transaction_options::set_timeout ( std::chrono::milliseconds duration)

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
timeoutInSecondsthe timeout value.
Returns
the updated TransactionOptions
Exceptions
illegal_argumentif timeout smaller or equal than 0, or timeUnit is null.
See also
#getTimeout()

Definition at line 773 of file transactions.cpp.

774{
775 if (duration.count() <= 0) {
776 BOOST_THROW_EXCEPTION(exception::illegal_state(
777 "TransactionOptions::setTimeout", "Timeout must be positive!"));
778 }
779 timeout_ = duration;
780 return *this;
781}

◆ set_transaction_type()

transaction_options & hazelcast::client::transaction_options::set_transaction_type ( transaction_type transaction_type)

Sets the 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
transactionTypethe new TransactionType.
Returns
the updated TransactionOptions.
See also
#getTransactionType()
#setDurability(int)

Definition at line 760 of file transactions.cpp.

761{
762 transaction_type_ = type;
763 return *this;
764}

The documentation for this class was generated from the following files: