1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.hbase.regionserver;
19
20 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceAudience;
22 import org.apache.hadoop.hbase.classification.InterfaceStability;
23
24 /**
25 * This is a special {@link ScannerContext} subclass that is designed to be used globally when
26 * limits should not be enforced during invocations of {@link InternalScanner#next(java.util.List)}
27 * or {@link RegionScanner#next(java.util.List)}.
28 * <p>
29 * Instances of {@link NoLimitScannerContext} are immutable after construction. Any attempt to
30 * change the limits or progress of a {@link NoLimitScannerContext} will fail silently. The net
31 * effect is that all limit checks will return false, thus indicating that a limit has not been
32 * reached.
33 */
34 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
35 @InterfaceStability.Evolving
36 public class NoLimitScannerContext extends ScannerContext {
37
38 public NoLimitScannerContext() {
39 super(false, null);
40 }
41
42 /**
43 * Use this instance whenever limits do not need to be enforced.
44 */
45 private static final ScannerContext NO_LIMIT = new NoLimitScannerContext();
46
47 /**
48 * @return The static, immutable instance of {@link NoLimitScannerContext} to be used whenever
49 * limits should not be enforced
50 */
51 public static final ScannerContext getInstance() {
52 return NO_LIMIT;
53 }
54
55 @Override
56 void setKeepProgress(boolean keepProgress) {
57 // Do nothing. NoLimitScannerContext instances are immutable post-construction
58 }
59
60 @Override
61 void setBatchProgress(int batchProgress) {
62 // Do nothing. NoLimitScannerContext instances are immutable post-construction
63 }
64
65 @Override
66 void setSizeProgress(long sizeProgress) {
67 // Do nothing. NoLimitScannerContext instances are immutable post-construction
68 }
69
70 @Override
71 void setTimeProgress(long timeProgress) {
72 // Do nothing. NoLimitScannerContext instances are immutable post-construction
73 }
74
75 @Override
76 void updateTimeProgress() {
77 // Do nothing. NoLimitScannerContext instances are immutable post-construction
78 }
79
80 @Override
81 void setProgress(int batchProgress, long sizeProgress, long timeProgress) {
82 // Do nothing. NoLimitScannerContext instances are immutable post-construction
83 }
84
85 @Override
86 void clearProgress() {
87 // Do nothing. NoLimitScannerContext instances are immutable post-construction
88 }
89
90 @Override
91 void setSizeLimitScope(LimitScope scope) {
92 // Do nothing. NoLimitScannerContext instances are immutable post-construction
93 }
94
95 @Override
96 void setTimeLimitScope(LimitScope scope) {
97 // Do nothing. NoLimitScannerContext instances are immutable post-construction
98 }
99
100 @Override
101 NextState setScannerState(NextState state) {
102 // Do nothing. NoLimitScannerContext instances are immutable post-construction
103 return state;
104 }
105
106 @Override
107 boolean checkBatchLimit(LimitScope checkerScope) {
108 // No limits can be specified, thus return false to indicate no limit has been reached.
109 return false;
110 }
111
112 @Override
113 boolean checkSizeLimit(LimitScope checkerScope) {
114 // No limits can be specified, thus return false to indicate no limit has been reached.
115 return false;
116 }
117
118 @Override
119 boolean checkTimeLimit(LimitScope checkerScope) {
120 // No limits can be specified, thus return false to indicate no limit has been reached.
121 return false;
122 }
123
124 @Override
125 boolean checkAnyLimitReached(LimitScope checkerScope) {
126 return false;
127 }
128 }