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   */
041  public ReversedClientScanner(Configuration conf, Scan scan, TableName tableName,
042      ClusterConnection connection, RpcRetryingCallerFactory rpcFactory,
043      RpcControllerFactory controllerFactory, ExecutorService pool, int primaryOperationTimeout)
044      throws IOException {
045    super(conf, scan, tableName, connection, rpcFactory, controllerFactory, pool,
046        primaryOperationTimeout);
047  }
048
049  @Override
050  protected boolean setNewStartKey() {
051    if (noMoreResultsForReverseScan(scan, currentRegion)) {
052      return false;
053    }
054    scan.withStartRow(currentRegion.getStartKey(), false);
055    return true;
056  }
057
058  @Override
059  protected ReversedScannerCallable createScannerCallable() {
060    return new ReversedScannerCallable(getConnection(), getTable(), scan, this.scanMetrics,
061        this.rpcControllerFactory, getScanReplicaId());
062  }
063}