1515 */
1616package com .google .cloud .bigtable .admin .v2 ;
1717
18+ import com .google .cloud .bigtable .admin .v2 .BaseBigtableTableAdminClient .ListTablesPagedResponse ;
19+ import com .google .common .util .concurrent .MoreExecutors ;
1820import java .io .IOException ;
1921import java .util .ArrayList ;
2022import java .util .List ;
@@ -144,9 +146,7 @@ public void close() {
144146 * @see CreateTableRequest for createTable configurations
145147 */
146148 public Table createTable (CreateTableRequest request ) {
147- com .google .bigtable .admin .v2 .Table table =
148- this .stub .createTableCallable ().call (request .toProto (instanceName ));
149- return Table .fromProto (table );
149+ return awaitFuture (createTableAsync (request ));
150150 }
151151
152152 /**
@@ -200,9 +200,7 @@ public ApiFuture<Table> createTableAsync(CreateTableRequest request) {
200200 * @see ModifyColumnFamiliesRequest for modifyFamily options
201201 */
202202 public Table modifyFamilies (ModifyColumnFamiliesRequest request ) {
203- com .google .bigtable .admin .v2 .Table table =
204- this .stub .modifyColumnFamiliesCallable ().call (request .toProto (instanceName ));
205- return Table .fromProto (table );
203+ return awaitFuture (modifyFamiliesAsync (request ));
206204 }
207205
208206 /**
@@ -252,7 +250,7 @@ public ApiFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request)
252250 * }</pre>
253251 */
254252 public void deleteTable (String tableId ) {
255- this . stub . deleteTableCallable (). call ( composeDeleteTableRequest (tableId ));
253+ awaitFuture ( deleteTableAsync (tableId ));
256254 }
257255
258256 /**
@@ -283,9 +281,7 @@ public ApiFuture<Void> deleteTableAsync(String tableId) {
283281 * }</pre>
284282 */
285283 public Table getTable (String tableId ) {
286- com .google .bigtable .admin .v2 .Table table =
287- this .stub .getTableCallable ().call (composeGetTableRequest (tableId ));
288- return Table .fromProto (table );
284+ return awaitFuture (getTableAsync (tableId ));
289285 }
290286
291287 /**
@@ -316,8 +312,7 @@ public ApiFuture<Table> getTableAsync(String tableId) {
316312 * }</pre>
317313 */
318314 public List <TableName > listTables () {
319- ListTablesResponse listResp = this .stub .listTablesCallable ().call (composeListTableRequest ());
320- return convertToTableNames (listResp );
315+ return awaitFuture (listTablesAsync ());
321316 }
322317
323318 /**
@@ -332,17 +327,18 @@ public List<TableName> listTables() {
332327 * }</pre>
333328 */
334329 public ApiFuture <List <TableName >> listTablesAsync () {
335- ApiFuture <ListTablesResponse > listResp =
336- this .stub .listTablesCallable ().futureCall (composeListTableRequest ());
330+ ApiFuture <ListTablesPagedResponse > listResp =
331+ this .stub .listTablesPagedCallable ().futureCall (composeListTableRequest ());
337332
338333 return ApiFutures .transform (
339334 listResp ,
340- new ApiFunction <ListTablesResponse , List <TableName >>() {
335+ new ApiFunction <ListTablesPagedResponse , List <TableName >>() {
341336 @ Override
342- public List <TableName > apply (ListTablesResponse input ) {
343- return convertToTableNames (input );
337+ public List <TableName > apply (ListTablesPagedResponse input ) {
338+ return convertToTableNames (input . iterateAll () );
344339 }
345- });
340+ },
341+ MoreExecutors .directExecutor ());
346342 }
347343
348344 /**
@@ -357,7 +353,7 @@ public List<TableName> apply(ListTablesResponse input) {
357353 * }</pre>
358354 */
359355 public void dropRowRange (String tableId , String rowKeyPrefix ) {
360- dropRowRange ( tableId , ByteString . copyFromUtf8 ( rowKeyPrefix ));
356+ awaitFuture ( dropRowRangeAsync ( tableId , rowKeyPrefix ));
361357 }
362358
363359 /**
@@ -387,7 +383,7 @@ public ApiFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix) {
387383 * }</pre>
388384 */
389385 public void dropRowRange (String tableId , ByteString rowKeyPrefix ) {
390- this . stub . dropRowRangeCallable (). call ( composeDropRowRangeRequest ( tableId , rowKeyPrefix , false ));
386+ awaitFuture ( dropRowRangeAsync ( tableId , rowKeyPrefix ));
391387 }
392388
393389 /**
@@ -420,7 +416,7 @@ public ApiFuture<Void> dropRowRangeAsync(String tableId, ByteString rowKeyPrefix
420416 * }</pre>
421417 */
422418 public void dropAllRows (String tableId ) {
423- this . stub . dropRowRangeCallable (). call ( composeDropRowRangeRequest ( tableId , null , true ));
419+ awaitFuture ( dropAllRowsAsync ( tableId ));
424420 }
425421
426422 /**
@@ -454,10 +450,7 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
454450 * }</pre>
455451 */
456452 public ConsistencyToken generateConsistencyToken (String tableId ) {
457- return ConsistencyToken .fromProto (
458- this .stub
459- .generateConsistencyTokenCallable ()
460- .call (composeGenerateConsistencyTokenRequest (tableId )));
453+ return awaitFuture (generateConsistencyTokenAsync (tableId ));
461454 }
462455
463456 /**
@@ -485,7 +478,8 @@ public ApiFuture<ConsistencyToken> generateConsistencyTokenAsync(String tableId)
485478 public ConsistencyToken apply (GenerateConsistencyTokenResponse input ) {
486479 return ConsistencyToken .fromProto (input );
487480 }
488- });
481+ },
482+ MoreExecutors .directExecutor ());
489483 }
490484
491485 /**
@@ -500,9 +494,7 @@ public ConsistencyToken apply(GenerateConsistencyTokenResponse input) {
500494 * }</pre>
501495 */
502496 public boolean isConsistent (String tableId , ConsistencyToken token ) {
503- return stub .checkConsistencyCallable ()
504- .call (token .toProto (getTableName (tableId )))
505- .getConsistent ();
497+ return awaitFuture (isConsistentAsync (tableId , token ));
506498 }
507499
508500 /**
@@ -527,7 +519,8 @@ public ApiFuture<Boolean> isConsistentAsync(String tableId, ConsistencyToken tok
527519 public Boolean apply (CheckConsistencyResponse input ) {
528520 return input .getConsistent ();
529521 }
530- });
522+ },
523+ MoreExecutors .directExecutor ());
531524 }
532525
533526 /**
@@ -591,10 +584,10 @@ GenerateConsistencyTokenRequest composeGenerateConsistencyTokenRequest(String ta
591584 * Helper method to convert ListTablesResponse to List<TableName>
592585 */
593586 @ VisibleForTesting
594- static List <TableName > convertToTableNames (ListTablesResponse listTablesResponse ) {
587+ static List <TableName > convertToTableNames (Iterable < com . google . bigtable . admin . v2 . Table > listTablesResponse ) {
595588 List <TableName > tableNames = new ArrayList <>();
596589
597- for (com .google .bigtable .admin .v2 .Table table : listTablesResponse . getTablesList () ) {
590+ for (com .google .bigtable .admin .v2 .Table table : listTablesResponse ) {
598591 tableNames .add (TableName .parse (table .getName ()));
599592 }
600593 return tableNames ;
@@ -604,8 +597,7 @@ static List<TableName> convertToTableNames(ListTablesResponse listTablesResponse
604597 /**
605598 * Helper method to transform ApiFuture<com.google.bigtable.admin.v2.Table> to ApiFuture<Table>
606599 */
607- @ VisibleForTesting
608- static ApiFuture <Table > transformToTableResponse (
600+ private static ApiFuture <Table > transformToTableResponse (
609601 ApiFuture <com .google .bigtable .admin .v2 .Table > future ) {
610602 return ApiFutures .transform (
611603 future ,
@@ -614,21 +606,31 @@ static ApiFuture<Table> transformToTableResponse(
614606 public Table apply (com .google .bigtable .admin .v2 .Table table ) {
615607 return Table .fromProto (table );
616608 }
617- });
609+ },
610+ MoreExecutors .directExecutor ());
618611 }
619612
620613 /**
621614 * Helper method to transform ApiFuture<Empty> to ApiFuture<Void>
622615 */
623- @ VisibleForTesting
624- static ApiFuture <Void > transformToVoid (ApiFuture <Empty > future ) {
616+ private static ApiFuture <Void > transformToVoid (ApiFuture <Empty > future ) {
625617 return ApiFutures .transform (
626618 future ,
627619 new ApiFunction <Empty , Void >() {
628620 @ Override
629621 public Void apply (Empty empty ) {
630622 return null ;
631623 }
632- });
624+ },
625+ MoreExecutors .directExecutor ());
626+ }
627+
628+ private <T > T awaitFuture (ApiFuture <T > future ) {
629+ try {
630+ return future .get ();
631+ } catch (Throwable t ) {
632+ // TODO(igorbernstein2): figure out a better wrapper exception.
633+ throw new RuntimeException (t );
634+ }
633635 }
634636}
0 commit comments