Example usage for java.util.concurrent CompletableFuture complete

List of usage examples for java.util.concurrent CompletableFuture complete

Introduction

In this page you can find the example usage for java.util.concurrent CompletableFuture complete.

Prototype

public boolean complete(T value) 

Source Link

Document

If not already completed, sets the value returned by #get() and related methods to the given value.

Usage

From source file:org.apache.hadoop.hbase.client.RawAsyncHBaseAdmin.java

private CompletableFuture<Void> compactRegion(byte[] regionName, byte[] columnFamily, boolean major) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    addListener(getRegionLocation(regionName), (location, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }//from  w  w w  .j  a  va  2s  .c  o  m
        ServerName serverName = location.getServerName();
        if (serverName == null) {
            future.completeExceptionally(new NoServerForRegionException(Bytes.toStringBinary(regionName)));
            return;
        }
        addListener(compact(location.getServerName(), location.getRegion(), major, columnFamily),
                (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> flushRegionServer(ServerName sn) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    addListener(getRegions(sn), (hRegionInfos, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }//from   w  w w .j  a  va 2  s  . c om
        List<CompletableFuture<Void>> compactFutures = new ArrayList<>();
        if (hRegionInfos != null) {
            hRegionInfos.forEach(region -> compactFutures.add(flush(sn, region)));
        }
        addListener(
                CompletableFuture
                        .allOf(compactFutures.toArray(new CompletableFuture<?>[compactFutures.size()])),
                (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> compactRegionServer(ServerName sn, boolean major) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    addListener(getRegions(sn), (hRegionInfos, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }// w  ww . ja va  2s  .  c  o m
        List<CompletableFuture<Void>> compactFutures = new ArrayList<>();
        if (hRegionInfos != null) {
            hRegionInfos.forEach(region -> compactFutures.add(compact(sn, region, major, null)));
        }
        addListener(
                CompletableFuture
                        .allOf(compactFutures.toArray(new CompletableFuture<?>[compactFutures.size()])),
                (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<TableDescriptor> getDescriptor(TableName tableName) {
    CompletableFuture<TableDescriptor> future = new CompletableFuture<>();
    addListener(this.<List<TableSchema>>newMasterCaller().priority(tableName)
            .action((controller, stub) -> this
                    .<GetTableDescriptorsRequest, GetTableDescriptorsResponse, List<TableSchema>>call(
                            controller, stub, RequestConverter.buildGetTableDescriptorsRequest(tableName),
                            (s, c, req, done) -> s.getTableDescriptors(c, req, done),
                            (resp) -> resp.getTableSchemaList()))
            .call(), (tableSchemas, error) -> {
                if (error != null) {
                    future.completeExceptionally(error);
                    return;
                }/*from  w w  w .j  a v  a  2 s  . c  om*/
                if (!tableSchemas.isEmpty()) {
                    future.complete(ProtobufUtil.toTableDescriptor(tableSchemas.get(0)));
                } else {
                    future.completeExceptionally(new TableNotFoundException(tableName.getNameAsString()));
                }
            });
    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  . ja v  a 2s.  c om
        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

private CompletableFuture<Void> split(final RegionInfo hri, byte[] splitPoint) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    TableName tableName = hri.getTable();
    SplitTableRegionRequest request = null;
    try {//from   w  ww.  ja  va  2s . 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<List<TableCFs>> listReplicatedTableCFs() {
    CompletableFuture<List<TableCFs>> future = new CompletableFuture<List<TableCFs>>();
    addListener(listTableDescriptors(), (tables, error) -> {
        if (!completeExceptionally(future, error)) {
            List<TableCFs> replicatedTableCFs = new ArrayList<>();
            tables.forEach(table -> {
                Map<String, Integer> cfs = new HashMap<>();
                Stream.of(table.getColumnFamilies())
                        .filter(column -> column.getScope() != HConstants.REPLICATION_SCOPE_LOCAL)
                        .forEach(column -> {
                            cfs.put(column.getNameAsString(), column.getScope());
                        });//from  w ww.j a  v a 2  s .  c om
                if (!cfs.isEmpty()) {
                    replicatedTableCFs.add(new TableCFs(table.getTableName(), cfs));
                }
            });
            future.complete(replicatedTableCFs);
        }
    });
    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;
        }//from  w w  w.j  a v 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> split(TableName tableName, byte[] splitPoint) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    if (splitPoint == null) {
        return failedFuture(new IllegalArgumentException("splitPoint can not be null."));
    }/*  w ww. j av  a  2  s.  c om*/
    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> unassign(byte[] regionName, boolean forcible) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    addListener(getRegionInfo(regionName), (regionInfo, err) -> {
        if (err != null) {
            future.completeExceptionally(err);
            return;
        }/*from  www.ja  v  a2  s  . co  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;
}