View Javadoc

1   /**
2    * Copyright The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements. See the NOTICE file distributed with this
6    * work for additional information regarding copyright ownership. The ASF
7    * licenses this file to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   * http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16   * License for the specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.hadoop.hbase.client;
20  
21  import static org.apache.hadoop.hbase.client.ConnectionUtils.noMoreResultsForReverseScan;
22  
23  import java.io.IOException;
24  import java.util.concurrent.ExecutorService;
25  
26  import org.apache.hadoop.conf.Configuration;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.classification.InterfaceAudience;
29  import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
30  
31  /**
32   * A reversed client scanner which support backward scanning
33   */
34  @InterfaceAudience.Private
35  public class ReversedClientScanner extends ClientScanner {
36  
37    /**
38     * Create a new ReversibleClientScanner for the specified table Note that the passed
39     * {@link Scan}'s start row maybe changed.
40     * @param conf
41     * @param scan
42     * @param tableName
43     * @param connection
44     * @param pool
45     * @param primaryOperationTimeout
46     * @throws IOException
47     */
48    public ReversedClientScanner(Configuration conf, Scan scan, TableName tableName,
49        ClusterConnection connection, RpcRetryingCallerFactory rpcFactory,
50        RpcControllerFactory controllerFactory, ExecutorService pool, int primaryOperationTimeout)
51        throws IOException {
52      super(conf, scan, tableName, connection, rpcFactory, controllerFactory, pool,
53          primaryOperationTimeout);
54    }
55  
56    @Override
57    protected boolean setNewStartKey() {
58      if (noMoreResultsForReverseScan(scan, currentRegion)) {
59        return false;
60      }
61      scan.withStartRow(currentRegion.getStartKey(), false);
62      return true;
63    }
64  
65    @Override
66    protected ReversedScannerCallable createScannerCallable() {
67      return new ReversedScannerCallable(getConnection(), getTable(), scan, this.scanMetrics,
68          this.rpcControllerFactory);
69    }
70  }