Curator: committing transaction
-
04-07-2021 - |
Question
Instances of Apache Curator's CuratorFramework class allow mutation operations to be run inTransaction()
. I'm currently using these calls, but can't figure out how to commit them.
Looking at the CuratorTransaction JavaDoc, it clearly states:
Important:
the operations are not submitted untilCuratorTransactionFinal.commit()
is called.
However, CuratorTransactionFinal
is an interface with no implementing classes (that I can find).
Am I expected to implement it and define the functionality of commit()
?
Or am I missing some larger concept?
Solution
Found it in the source code:
Assuming your instance of CuratorFramework is called "client".
if you perform an operation like...
client.create().forPath("/foo");
...it is not transactional. If you perform...
client.inTransaction().create.forPath("/foo");
...it is, but the operation will not actually be completed until you commit the transaction. This much I already knew. To commit the transaction, you do:
client.inTransaction().create().forPath("/foo")
.and().create().forPath("/bar")
.and().commit();