List of usage examples for java.util.concurrent CompletableFuture complete
public boolean complete(T value)
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Boolean> isTableDisabled(TableName tableName) { if (TableName.isMetaTableName(tableName)) { return CompletableFuture.completedFuture(false); }//w ww .j av a 2 s . com CompletableFuture<Boolean> future = new CompletableFuture<>(); addListener(AsyncMetaTableAccessor.getTableState(metaTable, tableName), (state, error) -> { if (error != null) { future.completeExceptionally(error); return; } if (state.isPresent()) { future.complete(state.get().inStates(TableState.State.DISABLED)); } else { future.completeExceptionally(new TableNotFoundException(tableName)); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker, ServiceCaller<S, R> callable) { MasterCoprocessorRpcChannelImpl channel = new MasterCoprocessorRpcChannelImpl( this.<Message>newMasterCaller()); S stub = stubMaker.apply(channel);//from ww w .ja va2 s .c o m CompletableFuture<R> future = new CompletableFuture<>(); ClientCoprocessorRpcController controller = new ClientCoprocessorRpcController(); callable.call(stub, controller, resp -> { if (controller.failed()) { future.completeExceptionally(controller.getFailed()); } else { future.complete(resp); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public <S, R> CompletableFuture<R> coprocessorService(Function<RpcChannel, S> stubMaker, ServiceCaller<S, R> callable, ServerName serverName) { RegionServerCoprocessorRpcChannelImpl channel = new RegionServerCoprocessorRpcChannelImpl( this.<Message>newServerCaller().serverName(serverName)); S stub = stubMaker.apply(channel);/*from w ww. ja v a 2s. c o m*/ CompletableFuture<R> future = new CompletableFuture<>(); ClientCoprocessorRpcController controller = new ClientCoprocessorRpcController(); callable.call(stub, controller, resp -> { if (controller.failed()) { future.completeExceptionally(controller.getFailed()); } else { future.complete(resp); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private CompletableFuture<Void> internalDeleteSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) { CompletableFuture<List<SnapshotDescription>> listSnapshotsFuture; if (tableNamePattern == null) { listSnapshotsFuture = getCompletedSnapshots(snapshotNamePattern); } else {//ww w . ja v a 2 s . c o m listSnapshotsFuture = getCompletedSnapshots(tableNamePattern, snapshotNamePattern); } CompletableFuture<Void> future = new CompletableFuture<>(); addListener(listSnapshotsFuture, ((snapshotDescriptions, err) -> { if (err != null) { future.completeExceptionally(err); return; } if (snapshotDescriptions == null || snapshotDescriptions.isEmpty()) { future.complete(null); return; } addListener(CompletableFuture.allOf(snapshotDescriptions.stream().map(this::internalDeleteSnapshot) .toArray(CompletableFuture[]::new)), (v, e) -> { if (e != null) { future.completeExceptionally(e); } else { future.complete(v); } }); })); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private CompletableFuture<List<SnapshotDescription>> getCompletedSnapshots(Pattern tableNamePattern, Pattern snapshotNamePattern) { CompletableFuture<List<SnapshotDescription>> future = new CompletableFuture<>(); addListener(listTableNames(tableNamePattern, false), (tableNames, err) -> { if (err != null) { future.completeExceptionally(err); return; }//www . j av a 2s.com if (tableNames == null || tableNames.size() <= 0) { future.complete(Collections.emptyList()); return; } addListener(getCompletedSnapshots(snapshotNamePattern), (snapshotDescList, err2) -> { if (err2 != null) { future.completeExceptionally(err2); return; } if (snapshotDescList == null || snapshotDescList.isEmpty()) { future.complete(Collections.emptyList()); return; } future.complete(snapshotDescList.stream() .filter(snap -> (snap != null && tableNames.contains(snap.getTableName()))) .collect(Collectors.toList())); }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private <PREQ, PRESP, RESP> CompletableFuture<RESP> adminCall(HBaseRpcController controller, AdminService.Interface stub, PREQ preq, AdminRpcCall<PRESP, PREQ> rpcCall, Converter<RESP, PRESP> respConverter) { CompletableFuture<RESP> future = new CompletableFuture<>(); rpcCall.call(stub, controller, preq, new RpcCallback<PRESP>() { @Override/*from w w w . ja v a 2 s.co m*/ public void run(PRESP resp) { if (controller.failed()) { future.completeExceptionally(controller.getFailed()); } else { try { future.complete(respConverter.convert(resp)); } catch (IOException e) { future.completeExceptionally(e); } } } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private CompletableFuture<List<ServerName>> getRegionServerList(List<String> serverNamesList) { CompletableFuture<List<ServerName>> future = new CompletableFuture<>(); if (serverNamesList.isEmpty()) { CompletableFuture<ClusterMetrics> clusterMetricsCompletableFuture = getClusterMetrics( EnumSet.of(Option.LIVE_SERVERS)); addListener(clusterMetricsCompletableFuture, (clusterMetrics, err) -> { if (err != null) { future.completeExceptionally(err); } else { future.complete(new ArrayList<>(clusterMetrics.getLiveServerMetrics().keySet())); }/* w w w . j av a2s . co m*/ }); return future; } else { List<ServerName> serverList = new ArrayList<>(); for (String regionServerName : serverNamesList) { ServerName serverName = null; try { serverName = ServerName.valueOf(regionServerName); } catch (Exception e) { future.completeExceptionally( new IllegalArgumentException(String.format("ServerName format: %s", regionServerName))); } if (serverName == null) { future.completeExceptionally( new IllegalArgumentException(String.format("Null ServerName: %s", regionServerName))); } } future.complete(serverList); } return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private CompletableFuture<byte[][]> getTableSplits(TableName tableName) { CompletableFuture<byte[][]> future = new CompletableFuture<>(); addListener(/*from ww w .ja v a2 s . co m*/ getRegions(tableName).thenApply(regions -> regions.stream() .filter(RegionReplicaUtil::isDefaultReplica).collect(Collectors.toList())), (regions, err2) -> { if (err2 != null) { future.completeExceptionally(err2); return; } if (regions.size() == 1) { future.complete(null); } else { byte[][] splits = new byte[regions.size() - 1][]; for (int i = 1; i < regions.size(); i++) { splits[i - 1] = regions.get(i).getStartKey(); } future.complete(splits); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> appendReplicationPeerTableCFs(String id, Map<TableName, List<String>> tableCfs) { if (tableCfs == null) { return failedFuture(new ReplicationException("tableCfs is null")); }//ww w . j a va 2 s .co m CompletableFuture<Void> future = new CompletableFuture<Void>(); addListener(getReplicationPeerConfig(id), (peerConfig, error) -> { if (!completeExceptionally(future, error)) { ReplicationPeerConfig newPeerConfig = ReplicationPeerConfigUtil .appendTableCFsToReplicationPeerConfig(tableCfs, peerConfig); addListener(updateReplicationPeerConfig(id, newPeerConfig), (result, err) -> { if (!completeExceptionally(future, error)) { future.complete(result); } }); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> move(byte[] regionName) { CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionInfo(regionName), (regionInfo, err) -> { if (err != null) { future.completeExceptionally(err); return; }//from ww w . j a v a 2 s. c om addListener( moveRegion(regionInfo, RequestConverter.buildMoveRegionRequest(regionInfo.getEncodedNameAsBytes(), null)), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }