001/**
002 * Copyright The Apache Software Foundation
003 *
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with this
006 * work for additional information regarding copyright ownership. The ASF
007 * licenses this file to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
015 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
016 * License for the specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.hadoop.hbase.client;
020
021import static org.apache.hadoop.hbase.client.ConnectionUtils.noMoreResultsForReverseScan;
022
023import java.io.IOException;
024import java.util.concurrent.ExecutorService;
025
026import org.apache.hadoop.conf.Configuration;
027import org.apache.hadoop.hbase.TableName;
028import org.apache.yetus.audience.InterfaceAudience;
029import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
030
031/**
032 * A reversed client scanner which support backward scanning
033 */
034@InterfaceAudience.Private
035public class ReversedClientScanner extends ClientScanner {
036
037  /**
038   * Create a new ReversibleClientScanner for the specified table Note that the passed
039   * {@link Scan}'s start row maybe changed.
040   * @param conf
041   * @param scan
042   * @param tableName
043   * @param connection
044   * @param pool
045   * @param primaryOperationTimeout
046   * @throws IOException
047   */
048  public ReversedClientScanner(Configuration conf, Scan scan, TableName tableName,
049      ClusterConnection connection, RpcRetryingCallerFactory rpcFactory,
050      RpcControllerFactory controllerFactory, ExecutorService pool, int primaryOperationTimeout)
051      throws IOException {
052    super(conf, scan, tableName, connection, rpcFactory, controllerFactory, pool,
053        primaryOperationTimeout);
054  }
055
056  @Override
057  protected boolean setNewStartKey() {
058    if (noMoreResultsForReverseScan(scan, currentRegion)) {
059      return false;
060    }
061    scan.withStartRow(currentRegion.getStartKey(), false);
062    return true;
063  }
064
065  @Override
066  protected ReversedScannerCallable createScannerCallable() {
067    return new ReversedScannerCallable(getConnection(), getTable(), scan, this.scanMetrics,
068        this.rpcControllerFactory);
069  }
070}