@ SuppressWarnings ( "WeakerAccess" ) public ApiFuture < List < String > > listTablesAsync ( ) { ListTablesRequest request = ListTablesRequest . newBuilder ( ) . setParent ( NameUtil . formatInstanceName ( projectId , instanceId ) ) . build ( ) ; // TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the // paginated responses while maintaining the wrapper facade. // Fetch the first page. ApiFuture < ListTablesPage > firstPageFuture = ApiFutures . transform ( stub . listTablesPagedCallable ( ) . futureCall ( request ) , new ApiFunction < ListTablesPagedResponse , ListTablesPage > ( ) { @ Override public ListTablesPage apply ( ListTablesPagedResponse response ) { return response . getPage ( ) ; } } , MoreExecutors . directExecutor ( ) ) ; // Fetch the rest of the pages by chaining the futures. ApiFuture < List < com . google . bigtable . admin . v2 . Table > > allProtos = ApiFutures . transformAsync ( firstPageFuture , new ApiAsyncFunction < ListTablesPage , List < com . google . bigtable . admin . v2 . Table > > ( ) { List < com . google . bigtable . admin . v2 . Table > responseAccumulator = Lists . newArrayList ( ) ; @ Override public ApiFuture < List < com . google . bigtable . admin . v2 . Table > > apply ( ListTablesPage page ) { // Add all entries from the page responseAccumulator . addAll ( Lists . newArrayList ( page . getValues ( ) ) ) ; // If this is the last page, just return the accumulated responses. if ( ! page . hasNextPage ( ) ) { return ApiFutures . immediateFuture ( responseAccumulator ) ; } // Otherwise fetch the next page. return ApiFutures . transformAsync ( page . getNextPageAsync ( ) , this , MoreExecutors . directExecutor ( ) ) ; } } , MoreExecutors . directExecutor ( ) ) ; // Wrap all of the accumulated protos. return ApiFutures . transform ( allProtos , new ApiFunction < List < com . google . bigtable . admin . v2 . Table > , List < String > > ( ) { @ Override public List < String > apply ( List < com . google . bigtable . admin . v2 . Table > protos ) { List < String > results = Lists . newArrayListWithCapacity ( protos . size ( ) ) ; for ( com . google . bigtable . admin . v2 . Table proto : protos ) { results . add ( NameUtil . extractTableIdFromTableName ( proto . getName ( ) ) ) ; } return results ; } } , MoreExecutors . directExecutor ( ) ) ; }
Asynchronously lists all table ids in the instance .