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.regionserver;
019
020import org.apache.hadoop.hbase.HBaseInterfaceAudience;
021import org.apache.yetus.audience.InterfaceAudience;
022import org.apache.yetus.audience.InterfaceStability;
023
024/**
025 * This is a special {@link ScannerContext} subclass that is designed to be used globally when
026 * limits should not be enforced during invocations of {@link InternalScanner#next(java.util.List)}
027 * or {@link RegionScanner#next(java.util.List)}.
028 * <p>
029 * Instances of {@link NoLimitScannerContext} are immutable after construction. Any attempt to
030 * change the limits or progress of a {@link NoLimitScannerContext} will fail silently. The net
031 * effect is that all limit checks will return false, thus indicating that a limit has not been
032 * reached.
033 */
034@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
035@InterfaceStability.Evolving
036public class NoLimitScannerContext extends ScannerContext {
037
038  public NoLimitScannerContext() {
039    super(false, null, false);
040  }
041
042  /**
043   * Use this instance whenever limits do not need to be enforced.
044   */
045  private static final ScannerContext NO_LIMIT = new NoLimitScannerContext();
046
047  /**
048   * Returns the static, immutable instance of {@link NoLimitScannerContext} to be used whenever
049   * limits should not be enforced
050   */
051  @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
052      justification = "singleton pattern")
053  public static final ScannerContext getInstance() {
054    return NO_LIMIT;
055  }
056
057  @Override
058  void setKeepProgress(boolean keepProgress) {
059    // Do nothing. NoLimitScannerContext instances are immutable post-construction
060  }
061
062  @Override
063  void setBatchProgress(int batchProgress) {
064    // Do nothing. NoLimitScannerContext instances are immutable post-construction
065  }
066
067  @Override
068  void setSizeProgress(long sizeProgress, long heapSizeProgress) {
069    // Do nothing. NoLimitScannerContext instances are immutable post-construction
070  }
071
072  @Override
073  void setProgress(int batchProgress, long sizeProgress, long heapSizeProgress) {
074    // Do nothing. NoLimitScannerContext instances are immutable post-construction
075  }
076
077  @Override
078  void clearProgress() {
079    // Do nothing. NoLimitScannerContext instances are immutable post-construction
080  }
081
082  @Override
083  void setSizeLimitScope(LimitScope scope) {
084    // Do nothing. NoLimitScannerContext instances are immutable post-construction
085  }
086
087  @Override
088  void setTimeLimitScope(LimitScope scope) {
089    // Do nothing. NoLimitScannerContext instances are immutable post-construction
090  }
091
092  @Override
093  NextState setScannerState(NextState state) {
094    // Do nothing. NoLimitScannerContext instances are immutable post-construction
095    return state;
096  }
097
098  @Override
099  boolean checkBatchLimit(LimitScope checkerScope) {
100    // No limits can be specified, thus return false to indicate no limit has been reached.
101    return false;
102  }
103
104  @Override
105  boolean checkSizeLimit(LimitScope checkerScope) {
106    // No limits can be specified, thus return false to indicate no limit has been reached.
107    return false;
108  }
109
110  @Override
111  boolean checkTimeLimit(LimitScope checkerScope) {
112    // No limits can be specified, thus return false to indicate no limit has been reached.
113    return false;
114  }
115
116  @Override
117  boolean checkAnyLimitReached(LimitScope checkerScope) {
118    return false;
119  }
120}