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.createClosestRowAfter;
021import static org.apache.hadoop.hbase.client.ConnectionUtils.isEmptyStartRow;
022import static org.apache.hadoop.hbase.client.ConnectionUtils.noMoreResultsForScan;
023
024import java.io.IOException;
025import java.util.concurrent.ExecutorService;
026
027import org.apache.hadoop.conf.Configuration;
028import org.apache.hadoop.hbase.TableName;
029import org.apache.yetus.audience.InterfaceAudience;
030import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
031
032/**
033 * ClientSimpleScanner implements a sync scanner behaviour.
034 * The cache is a simple list.
035 * The prefetch is invoked only when the application finished processing the entire cache.
036 */
037@InterfaceAudience.Private
038public class ClientSimpleScanner extends ClientScanner {
039  public ClientSimpleScanner(Configuration configuration, Scan scan, TableName name,
040      ClusterConnection connection, RpcRetryingCallerFactory rpcCallerFactory,
041      RpcControllerFactory rpcControllerFactory, ExecutorService pool,
042      int replicaCallTimeoutMicroSecondScan) throws IOException {
043    super(configuration, scan, name, connection, rpcCallerFactory, rpcControllerFactory, pool,
044        replicaCallTimeoutMicroSecondScan);
045  }
046
047  @Override
048  protected boolean setNewStartKey() {
049    if (noMoreResultsForScan(scan, currentRegion)) {
050      return false;
051    }
052    scan.withStartRow(currentRegion.getEndKey(), true);
053    return true;
054  }
055
056  @Override
057  protected ScannerCallable createScannerCallable() {
058    if (!scan.includeStartRow() && !isEmptyStartRow(scan.getStartRow())) {
059      // we have not implemented locate to next row for sync client yet, so here we change the
060      // inclusive of start row to true.
061      scan.withStartRow(createClosestRowAfter(scan.getStartRow()), true);
062    }
063    return new ScannerCallable(getConnection(), getTable(), scan, this.scanMetrics,
064        this.rpcControllerFactory);
065  }
066}