public Deferred < ArrayList < Boolean > > storeBranch ( final TSDB tsdb , final Tree tree , final boolean store_leaves ) { if ( tree_id < 1 || tree_id > 65535 ) { throw new IllegalArgumentException ( "Missing or invalid tree ID" ) ; } final ArrayList < Deferred < Boolean > > storage_results = new ArrayList < Deferred < Boolean > > ( leaves != null ? leaves . size ( ) + 1 : 1 ) ; // compile the row key by making sure the display_name is in the path set // row ID = <treeID>[<parent.display_name.hashCode()>...] final byte [ ] row = this . compileBranchId ( ) ; // compile the object for storage, this will toss exceptions if we are // missing anything important final byte [ ] storage_data = toStorageJson ( ) ; final PutRequest put = new PutRequest ( tsdb . treeTable ( ) , row , Tree . TREE_FAMILY ( ) , BRANCH_QUALIFIER , storage_data ) ; put . setBufferable ( true ) ; storage_results . add ( tsdb . getClient ( ) . compareAndSet ( put , new byte [ 0 ] ) ) ; // store leaves if told to and put the storage calls in our deferred group if ( store_leaves && leaves != null && ! leaves . isEmpty ( ) ) { for ( final Leaf leaf : leaves . values ( ) ) { storage_results . add ( leaf . storeLeaf ( tsdb , row , tree ) ) ; } } return Deferred . group ( storage_results ) ; }
Attempts to write the branch definition and optionally child leaves to storage via CompareAndSets . Each returned deferred will be a boolean regarding whether the CAS call was successful or not . This will be a mix of the branch call and leaves . Some of these may be false which is OK because if the branch definition already exists we don t need to re - write it . Leaves will return false if there was a collision .