All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hbase.client.AsyncAdminClientUtils Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta-1
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.hadoop.hbase.client;

import com.google.protobuf.RpcChannel;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.util.FutureUtils;
import org.apache.yetus.audience.InterfaceAudience;

/**
 * Additional Asynchronous Admin capabilities for clients.
 */
@InterfaceAudience.Public
public final class AsyncAdminClientUtils {

  private AsyncAdminClientUtils() {
  }

  /**
   * Execute the given coprocessor call on all region servers.
   * 

* The {@code stubMaker} is just a delegation to the {@code newStub} call. Usually it is only a * one line lambda expression, like: * *

   * channel -> xxxService.newStub(channel)
   * 
* * @param asyncAdmin the asynchronous administrative API for HBase. * @param stubMaker a delegation to the actual {@code newStub} call. * @param callable a delegation to the actual protobuf rpc call. See the comment of * {@link ServiceCaller} for more details. * @param the type of the asynchronous stub * @param the type of the return value * @return Map of each region server to its result of the protobuf rpc call, wrapped by a * {@link CompletableFuture}. * @see ServiceCaller */ public static CompletableFuture> coprocessorServiceOnAllRegionServers(AsyncAdmin asyncAdmin, Function stubMaker, ServiceCaller callable) { CompletableFuture> future = new CompletableFuture<>(); FutureUtils.addListener(asyncAdmin.getRegionServers(), (regionServers, error) -> { if (error != null) { future.completeExceptionally(error); return; } Map resultMap = new ConcurrentHashMap<>(); for (ServerName regionServer : regionServers) { FutureUtils.addListener(asyncAdmin.coprocessorService(stubMaker, callable, regionServer), (server, err) -> { if (err != null) { resultMap.put(regionServer, err); } else { resultMap.put(regionServer, server); } if (resultMap.size() == regionServers.size()) { future.complete(Collections.unmodifiableMap(resultMap)); } }); } }); return future; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy