Infinispan HotRod C++ Client  8.3.1.Final
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TransactionManager.h
Go to the documentation of this file.
1 /*
2  * TransactionManager.h
3  *
4  * Created on: Jul 3, 2018
5  * Author: rigazilla
6  */
7 
8 #ifndef INCLUDE_INFINISPAN_HOTROD_TRANSACTIONMANAGER_H_
9 #define INCLUDE_INFINISPAN_HOTROD_TRANSACTIONMANAGER_H_
10 
12 #include <vector>
13 #include <memory>
14 #include <thread>
15 #include <map>
16 namespace infinispan {
17 namespace hotrod {
18 
19 class Transaction;
20 enum class TransactionRemoteStatus : unsigned int;
25 public:
26  HR_EXTERN TransactionManager() : UUID(generateV4UUID()) {}
27  /***
28  * Start a transaction on this thread. All the caches of all RemoteCacheManager
29  * will be involved
30  */
31  HR_EXTERN void begin();
32  /***
33  * Commit this transaction on the remote server
34  */
35  HR_EXTERN void commit();
36  /***
37  * Rollback this transaction on the remote server
38  */
39  HR_EXTERN void rollback();
40  /***
41  * Suspend the current transaction. Not Implemented
42  */
43  // HR_EXTERN void suspend();
44  /***
45  * Resume the suspended current transaction. Not Implemented
46  */
47  // HR_EXTERN void resume();
48  /***
49  * Get the UUID of this transaction manager
50  */
51  const std::vector<char>& getUuid() const { return UUID; }
52  HR_EXTERN std::shared_ptr<Transaction> getCurrentTransaction();
53 private:
54  std::map<std::thread::id, std::shared_ptr<Transaction> > currentTransactions;
55  std::vector<char> UUID;
56 
57  std::vector<char> generateV4UUID();
58  void throwExceptionOnIllegalState(const std::string& state, const std::string& action);
59  HR_EXTERN TransactionRemoteStatus remotePrepareCommit(Transaction& t);
60  HR_EXTERN void cleanUpCurrentTransaction();
61  HR_EXTERN void remoteCommit(Transaction& t);
62  HR_EXTERN void remoteRollback(Transaction& t);
63  HR_EXTERN void setRollbackOnly();
64 };
65 
70 public:
71  /***
72  * This provides the default instance of the transaction manager.
73  * Used only internally for now
74  */
76  static TransactionManager the_transaction_manager;
77  return the_transaction_manager;
78  }
79 };
80 
81 }
82 }
83 
84 #endif /* INCLUDE_INFINISPAN_HOTROD_TRANSACTIONMANAGER_H_ */
#define HR_EXTERN
Definition: ImportExport.h:35
HR_EXTERN TransactionManager()
Definition: TransactionManager.h:26
Definition: TransactionManager.h:24
TransactionRemoteStatus
Definition: Transactions.h:58
static TransactionManager & lookup()
Definition: TransactionManager.h:75
const std::vector< char > & getUuid() const
Definition: TransactionManager.h:51
Definition: Transactions.h:130
Definition: TransactionManager.h:69