001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import java.util.Map; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.hadoop.hbase.ipc.HBaseRpcController; 023import org.apache.yetus.audience.InterfaceAudience; 024 025/** 026 * Implementations make an rpc call against a RegionService via a protobuf Service. Implement 027 * #rpcCall(RpcController) and then call {@link #call(int)} to trigger the rpc. The 028 * {@link #call(int)} eventually invokes your #rpcCall(RpcController) meanwhile saving you having to 029 * write a bunch of boilerplate. The {@link #call(int)} implementation is from 030 * {@link RpcRetryingCaller} so rpcs are retried on fail. 031 * <p> 032 * TODO: this class is actually tied to one region, because most of the paths make use of the 033 * regioninfo part of location when building requests. The only reason it works for multi-region 034 * requests (e.g. batch) is that they happen to not use the region parts. This could be done cleaner 035 * (e.g. having a generic parameter and 2 derived classes, RegionCallable and actual 036 * RegionServerCallable with ServerName. 037 * @param <T> the class that the ServerCallable handles 038 */ 039@InterfaceAudience.Private 040public abstract class NoncedRegionServerCallable<T> extends ClientServiceCallable<T> { 041 private final long nonce; 042 043 /** 044 * @param connection Connection to use. 045 * @param tableName Table name to which <code>row</code> belongs. 046 * @param row The row we want in <code>tableName</code>. 047 */ 048 public NoncedRegionServerCallable(Connection connection, TableName tableName, byte[] row, 049 HBaseRpcController rpcController, int priority, Map<String, byte[]> requestAttributes) { 050 super(connection, tableName, row, rpcController, priority, requestAttributes); 051 this.nonce = getConnection().getNonceGenerator().newNonce(); 052 } 053 054 long getNonceGroup() { 055 return getConnection().getNonceGenerator().getNonceGroup(); 056 } 057 058 long getNonce() { 059 return this.nonce; 060 } 061}