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 static org.apache.hadoop.hbase.client.ConnectionUtils.noMoreResultsForReverseScan; 021 022import java.io.IOException; 023import java.util.concurrent.ExecutorService; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.ipc.RpcControllerFactory; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * A reversed client scanner which support backward scanning 031 */ 032@InterfaceAudience.Private 033public class ReversedClientScanner extends ClientScanner { 034 035 /** 036 * Create a new ReversibleClientScanner for the specified table Note that the passed 037 * {@link Scan}'s start row maybe changed. 038 */ 039 public ReversedClientScanner(Configuration conf, Scan scan, TableName tableName, 040 ClusterConnection connection, RpcRetryingCallerFactory rpcFactory, 041 RpcControllerFactory controllerFactory, ExecutorService pool, int scanReadRpcTimeout, 042 int scannerTimeout, int primaryOperationTimeout) throws IOException { 043 super(conf, scan, tableName, connection, rpcFactory, controllerFactory, pool, 044 scanReadRpcTimeout, scannerTimeout, primaryOperationTimeout); 045 } 046 047 @Override 048 protected boolean setNewStartKey() { 049 if (noMoreResultsForReverseScan(scan, currentRegion)) { 050 return false; 051 } 052 scan.withStartRow(currentRegion.getStartKey(), false); 053 return true; 054 } 055 056 @Override 057 protected ReversedScannerCallable createScannerCallable() { 058 return new ReversedScannerCallable(getConnection(), getTable(), scan, this.scanMetrics, 059 this.rpcControllerFactory, getScanReplicaId()); 060 } 061}