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.ipc; 019 020import java.util.Collection; 021import java.util.Comparator; 022import java.util.Iterator; 023import java.util.concurrent.TimeUnit; 024import org.apache.hadoop.conf.Configuration; 025import org.apache.hadoop.hbase.conf.ConfigurationObserver; 026import org.apache.hadoop.hbase.util.BoundedPriorityBlockingQueue; 027 028/** 029 * Implementation of the PluggableBlockingQueue abstract class. Used to verify that the pluggable 030 * call queue type for the RpcExecutor can load correctly via the FQCN reflection semantics. 031 */ 032public class TestPluggableQueueImpl extends PluggableBlockingQueue 033 implements ConfigurationObserver { 034 035 private final BoundedPriorityBlockingQueue<CallRunner> inner; 036 private static boolean configurationRecentlyChanged = false; 037 038 public TestPluggableQueueImpl(int maxQueueLength, PriorityFunction priority, Configuration conf) { 039 super(maxQueueLength, priority, conf); 040 Comparator<CallRunner> comparator = Comparator.comparingInt(r -> r.getRpcCall().getPriority()); 041 inner = new BoundedPriorityBlockingQueue<>(maxQueueLength, comparator); 042 configurationRecentlyChanged = false; 043 } 044 045 @Override 046 public boolean add(CallRunner callRunner) { 047 return inner.add(callRunner); 048 } 049 050 @Override 051 public boolean offer(CallRunner callRunner) { 052 return inner.offer(callRunner); 053 } 054 055 @Override 056 public CallRunner remove() { 057 return inner.remove(); 058 } 059 060 @Override 061 public CallRunner poll() { 062 return inner.poll(); 063 } 064 065 @Override 066 public CallRunner element() { 067 return inner.element(); 068 } 069 070 @Override 071 public CallRunner peek() { 072 return inner.peek(); 073 } 074 075 @Override 076 public void put(CallRunner callRunner) throws InterruptedException { 077 inner.put(callRunner); 078 } 079 080 @Override 081 public boolean offer(CallRunner callRunner, long timeout, TimeUnit unit) 082 throws InterruptedException { 083 return inner.offer(callRunner, timeout, unit); 084 } 085 086 @Override 087 public CallRunner take() throws InterruptedException { 088 return inner.take(); 089 } 090 091 @Override 092 public CallRunner poll(long timeout, TimeUnit unit) throws InterruptedException { 093 return inner.poll(timeout, unit); 094 } 095 096 @Override 097 public int remainingCapacity() { 098 return inner.remainingCapacity(); 099 } 100 101 @Override 102 public boolean remove(Object o) { 103 return inner.remove(o); 104 } 105 106 @Override 107 public boolean containsAll(Collection<?> c) { 108 return inner.containsAll(c); 109 } 110 111 @Override 112 public boolean addAll(Collection<? extends CallRunner> c) { 113 return inner.addAll(c); 114 } 115 116 @Override 117 public boolean removeAll(Collection<?> c) { 118 return inner.removeAll(c); 119 } 120 121 @Override 122 public boolean retainAll(Collection<?> c) { 123 return inner.retainAll(c); 124 } 125 126 @Override 127 public void clear() { 128 inner.clear(); 129 } 130 131 @Override 132 public int size() { 133 return inner.size(); 134 } 135 136 @Override 137 public boolean isEmpty() { 138 return inner.isEmpty(); 139 } 140 141 @Override 142 public boolean contains(Object o) { 143 return inner.contains(o); 144 } 145 146 @Override 147 public Iterator<CallRunner> iterator() { 148 return inner.iterator(); 149 } 150 151 @Override 152 public Object[] toArray() { 153 return inner.toArray(); 154 } 155 156 @Override 157 public <T> T[] toArray(T[] a) { 158 return inner.toArray(a); 159 } 160 161 @Override 162 public int drainTo(Collection<? super CallRunner> c) { 163 return inner.drainTo(c); 164 } 165 166 @Override 167 public int drainTo(Collection<? super CallRunner> c, int maxElements) { 168 return inner.drainTo(c, maxElements); 169 } 170 171 public static boolean hasObservedARecentConfigurationChange() { 172 return configurationRecentlyChanged; 173 } 174 175 @Override 176 public void onConfigurationChange(Configuration conf) { 177 configurationRecentlyChanged = true; 178 } 179}