List of usage examples for java.util.concurrent CompletableFuture completeExceptionally
public boolean completeExceptionally(Throwable ex)
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> split(TableName tableName, byte[] splitPoint) { CompletableFuture<Void> result = new CompletableFuture<>(); if (splitPoint == null) { return failedFuture(new IllegalArgumentException("splitPoint can not be null.")); }//from w ww . j a v a 2 s. c o m addListener(connection.getRegionLocator(tableName).getRegionLocation(splitPoint, true), (loc, err) -> { if (err != null) { result.completeExceptionally(err); } else if (loc == null || loc.getRegion() == null) { result.completeExceptionally(new IllegalArgumentException( "Region does not found: rowKey=" + Bytes.toStringBinary(splitPoint))); } else { addListener(splitRegion(loc.getRegion().getRegionName(), splitPoint), (ret, err2) -> { if (err2 != null) { result.completeExceptionally(err2); } else { result.complete(ret); } }); } }); return result; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> splitRegion(byte[] regionName) { CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionLocation(regionName), (location, err) -> { if (err != null) { future.completeExceptionally(err); return; }/*from w ww . j a v a 2 s . c o m*/ RegionInfo regionInfo = location.getRegion(); if (regionInfo.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) { future.completeExceptionally(new IllegalArgumentException("Can't split replicas directly. " + "Replicas are auto-split when their primary is split.")); return; } ServerName serverName = location.getServerName(); if (serverName == null) { future.completeExceptionally(new NoServerForRegionException(Bytes.toStringBinary(regionName))); return; } addListener(split(regionInfo, null), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> splitRegion(byte[] regionName, byte[] splitPoint) { Preconditions.checkNotNull(splitPoint, "splitPoint is null. If you don't specify a splitPoint, use splitRegion(byte[]) instead"); CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionLocation(regionName), (location, err) -> { if (err != null) { future.completeExceptionally(err); return; }//from w w w . j a v a 2s .co m RegionInfo regionInfo = location.getRegion(); if (regionInfo.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) { future.completeExceptionally(new IllegalArgumentException("Can't split replicas directly. " + "Replicas are auto-split when their primary is split.")); return; } ServerName serverName = location.getServerName(); if (serverName == null) { future.completeExceptionally(new NoServerForRegionException(Bytes.toStringBinary(regionName))); return; } if (regionInfo.getStartKey() != null && Bytes.compareTo(regionInfo.getStartKey(), splitPoint) == 0) { future.completeExceptionally( new IllegalArgumentException("should not give a splitkey which equals to startkey!")); return; } addListener(split(regionInfo, splitPoint), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
private CompletableFuture<Void> split(final RegionInfo hri, byte[] splitPoint) { CompletableFuture<Void> future = new CompletableFuture<>(); TableName tableName = hri.getTable(); SplitTableRegionRequest request = null; try {//from w w w. j a v a 2 s .c om request = RequestConverter.buildSplitTableRegionRequest(hri, splitPoint, ng.getNonceGroup(), ng.newNonce()); } catch (DeserializationException e) { future.completeExceptionally(e); return future; } addListener(this.<SplitTableRegionRequest, SplitTableRegionResponse>procedureCall(tableName, request, (s, c, req, done) -> s.splitRegion(c, req, done), (resp) -> resp.getProcId(), new SplitTableRegionProcedureBiConsumer(tableName)), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> assign(byte[] regionName) { CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionInfo(regionName), (regionInfo, err) -> { if (err != null) { future.completeExceptionally(err); return; }/*from w w w . j ava2 s . c o m*/ addListener(this.<Void>newMasterCaller().priority(regionInfo.getTable()) .action(((controller, stub) -> this.<AssignRegionRequest, AssignRegionResponse, Void>call( controller, stub, RequestConverter.buildAssignRegionRequest(regionInfo.getRegionName()), (s, c, req, done) -> s.assignRegion(c, req, done), resp -> null))) .call(), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> unassign(byte[] regionName, boolean forcible) { CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionInfo(regionName), (regionInfo, err) -> { if (err != null) { future.completeExceptionally(err); return; }/*from w ww . j a v a 2 s . c o m*/ addListener(this.<Void>newMasterCaller().priority(regionInfo.getTable()) .action(((controller, stub) -> this.<UnassignRegionRequest, UnassignRegionResponse, Void>call( controller, stub, RequestConverter.buildUnassignRegionRequest(regionInfo.getRegionName(), forcible), (s, c, req, done) -> s.unassignRegion(c, req, done), resp -> null))) .call(), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> offline(byte[] regionName) { CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionInfo(regionName), (regionInfo, err) -> { if (err != null) { future.completeExceptionally(err); return; }/* w ww.j av a2 s . c o m*/ addListener(this.<Void>newMasterCaller().priority(regionInfo.getTable()) .action(((controller, stub) -> this.<OfflineRegionRequest, OfflineRegionResponse, Void>call( controller, stub, RequestConverter.buildOfflineRegionRequest(regionInfo.getRegionName()), (s, c, req, done) -> s.offlineRegion(c, req, done), resp -> null))) .call(), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); 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 w w w.jav a2 s . c o m addListener( moveRegion(regionInfo, RequestConverter.buildMoveRegionRequest(regionInfo.getEncodedNameAsBytes(), null)), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<Void> move(byte[] regionName, ServerName destServerName) { Preconditions.checkNotNull(destServerName, "destServerName is null. If you don't specify a destServerName, use move(byte[]) instead"); CompletableFuture<Void> future = new CompletableFuture<>(); addListener(getRegionInfo(regionName), (regionInfo, err) -> { if (err != null) { future.completeExceptionally(err); return; }/*w w w .j a v a 2 s .c o m*/ addListener( moveRegion(regionInfo, RequestConverter .buildMoveRegionRequest(regionInfo.getEncodedNameAsBytes(), destServerName)), (ret, err2) -> { if (err2 != null) { future.completeExceptionally(err2); } else { future.complete(ret); } }); }); return future; }
From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java
@Override public CompletableFuture<List<QuotaSettings>> getQuota(QuotaFilter filter) { CompletableFuture<List<QuotaSettings>> future = new CompletableFuture<>(); Scan scan = QuotaTableUtil.makeScan(filter); this.connection.getTableBuilder(QuotaTableUtil.QUOTA_TABLE_NAME).build().scan(scan, new AdvancedScanResultConsumer() { List<QuotaSettings> settings = new ArrayList<>(); @Override//from w ww.jav a 2s . c o m public void onNext(Result[] results, ScanController controller) { for (Result result : results) { try { QuotaTableUtil.parseResultToCollection(result, settings); } catch (IOException e) { controller.terminate(); future.completeExceptionally(e); } } } @Override public void onError(Throwable error) { future.completeExceptionally(error); } @Override public void onComplete() { future.complete(settings); } }); return future; }