java - Curator transaction runtime construction -


the apache curator library zookeeper uses nice "fluent" syntax. example, modify several nodes in transaction, code looks like:

client.intransaction().     .setdata().fornode(node1path, data1)     .and()     .setdata().fornode(node2path, data2)     .and()     .commit(); 

this works great and, imho, produces readable code. however, have situation have modify set of znodes in transaction. don't know until runtime how many nodes, or nodes, need modified. thus, don't think can use fluent syntax easily. looking @ docs, can manually manage proxy objects each of fluent method calls return, code requires explicit use of curatortransaction, transactionsetdatabuilder, curatortransactionbridge, etc. it's do-able, code starts ugly.

i don't see non-fluent way transactions curator. know if there 1 and/or if there "nice" way build transaction @ runtime? specifically, given map<string, string> mapping znode paths data needs end in znode, how set nodes transactionally?

one way skin cat?:

curatortransaction curatortransaction = client.intransaction();  (map.entry<string, string> entry : transactioninfo.entryset()) {     curatortransaction = curatortransaction         .setdata().fornode(entry.getkey(), entry.getvalue()).and(); }  // if there @ least 1 entry in transactioninfo, and() makes curatortransactionfinal if (curatortransaction instanceof curatortransactionfinal) {     ((curatortransactionfinal)curatortransaction).commit(); } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -