Hazelcast C++ Client
Hazelcast C++ Client Library
hazelcast::client::transaction_options Class Reference

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

#include <transaction_options.h>

Public Types

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

Public Member Functions

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

Detailed Description

Contains the configuration for a Hazelcast transaction.

Definition at line 31 of file transaction_options.h.

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 586 of file transactions.cpp.

586  : timeout_(std::chrono::minutes(2)), durability_(1),
587  transaction_type_(transaction_type::TWO_PHASE) {}

Member Function Documentation

◆ get_durability()

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

Definition at line 611 of file transactions.cpp.

611  {
612  return durability_;
613  }

◆ get_timeout()

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

Definition at line 598 of file transactions.cpp.

598  {
599  return timeout_;
600  }

◆ get_transaction_type()

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

Definition at line 589 of file transactions.cpp.

589  {
590  return transaction_type_;
591  }

◆ 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 615 of file transactions.cpp.

615  {
616  if (num_machines < 0) {
617  BOOST_THROW_EXCEPTION(exception::illegal_state("TransactionOptions::setDurability",
618  "Durability cannot be negative!"));
619  }
620  this->durability_ = num_machines;
621  return *this;
622  }

◆ 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 602 of file transactions.cpp.

602  {
603  if (duration.count() <= 0) {
604  BOOST_THROW_EXCEPTION(exception::illegal_state("TransactionOptions::setTimeout",
605  "Timeout must be positive!"));
606  }
607  timeout_ = duration;
608  return *this;
609  }

◆ 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 593 of file transactions.cpp.

593  {
594  transaction_type_ = type;
595  return *this;
596  }

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