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.coprocessor; 019 020import java.io.DataInput; 021import java.io.DataOutput; 022import java.io.File; 023import java.io.IOException; 024import java.io.InputStream; 025import java.io.OutputStream; 026import java.io.Reader; 027import java.io.Writer; 028import java.net.InetSocketAddress; 029import java.net.URL; 030import java.util.Collection; 031import java.util.Iterator; 032import java.util.List; 033import java.util.Map; 034import java.util.Set; 035import java.util.concurrent.TimeUnit; 036import java.util.regex.Pattern; 037 038import org.apache.hadoop.conf.Configuration; 039import org.apache.hadoop.fs.Path; 040import org.apache.yetus.audience.InterfaceAudience; 041 042 043/** 044 * Wraps a Configuration to make it read-only. 045 */ 046@InterfaceAudience.Private 047class ReadOnlyConfiguration extends Configuration { 048 private final Configuration conf; 049 050 ReadOnlyConfiguration(final Configuration conf) { 051 this.conf = conf; 052 } 053 054 @Override 055 public void setDeprecatedProperties() { 056 throw new UnsupportedOperationException("Read-only Configuration"); 057 } 058 059 @Override 060 public void addResource(String name) { 061 throw new UnsupportedOperationException("Read-only Configuration"); 062 } 063 064 @Override 065 public void addResource(URL url) { 066 throw new UnsupportedOperationException("Read-only Configuration"); 067 } 068 069 @Override 070 public void addResource(Path file) { 071 throw new UnsupportedOperationException("Read-only Configuration"); 072 } 073 074 @Override 075 public void addResource(InputStream in) { 076 throw new UnsupportedOperationException("Read-only Configuration"); 077 } 078 079 @Override 080 public void addResource(InputStream in, String name) { 081 throw new UnsupportedOperationException("Read-only Configuration"); 082 } 083 084 @Override 085 public void addResource(Configuration conf) { 086 throw new UnsupportedOperationException("Read-only Configuration"); 087 } 088 089 @Override 090 public synchronized void reloadConfiguration() { 091 // This is a write operation. We need to allow it though because if any Configuration in 092 // current JVM context calls addDefaultResource, this forces a reload of all Configurations 093 // (all Configurations are 'registered' by the default constructor. Rather than turn 094 // somersaults, let this 'write' operation through. 095 this.conf.reloadConfiguration(); 096 } 097 098 @Override 099 public String get(String name) { 100 return conf.get(name); 101 } 102 103 // Do not add @Override because it is not in Hadoop 2.6.5 104 public void setAllowNullValueProperties(boolean val) { 105 throw new UnsupportedOperationException("Read-only Configuration"); 106 } 107 108 @Override 109 public String getTrimmed(String name) { 110 return conf.getTrimmed(name); 111 } 112 113 @Override 114 public String getTrimmed(String name, String defaultValue) { 115 return conf.getTrimmed(name, defaultValue); 116 } 117 118 @Override 119 public String getRaw(String name) { 120 return conf.getRaw(name); 121 } 122 123 @Override 124 public void set(String name, String value) { 125 throw new UnsupportedOperationException("Read-only Configuration"); 126 } 127 128 @Override 129 public void set(String name, String value, String source) { 130 throw new UnsupportedOperationException("Read-only Configuration"); 131 } 132 133 @Override 134 public synchronized void unset(String name) { 135 throw new UnsupportedOperationException("Read-only Configuration"); 136 } 137 138 @Override 139 public synchronized void setIfUnset(String name, String value) { 140 throw new UnsupportedOperationException("Read-only Configuration"); 141 } 142 143 @Override 144 public String get(String name, String defaultValue) { 145 return conf.get(name, defaultValue); 146 } 147 148 @Override 149 public int getInt(String name, int defaultValue) { 150 return conf.getInt(name, defaultValue); 151 } 152 153 @Override 154 public int[] getInts(String name) { 155 return conf.getInts(name); 156 } 157 158 @Override 159 public void setInt(String name, int value) { 160 throw new UnsupportedOperationException("Read-only Configuration"); 161 } 162 163 @Override 164 public long getLong(String name, long defaultValue) { 165 return conf.getLong(name, defaultValue); 166 } 167 168 @Override 169 public long getLongBytes(String name, long defaultValue) { 170 return conf.getLongBytes(name, defaultValue); 171 } 172 173 @Override 174 public void setLong(String name, long value) { 175 throw new UnsupportedOperationException("Read-only Configuration"); 176 } 177 178 @Override 179 public float getFloat(String name, float defaultValue) { 180 return conf.getFloat(name, defaultValue); 181 } 182 183 @Override 184 public void setFloat(String name, float value) { 185 throw new UnsupportedOperationException("Read-only Configuration"); 186 } 187 188 @Override 189 public double getDouble(String name, double defaultValue) { 190 return conf.getDouble(name, defaultValue); 191 } 192 193 @Override 194 public void setDouble(String name, double value) { 195 throw new UnsupportedOperationException("Read-only Configuration"); 196 } 197 198 @Override 199 public boolean getBoolean(String name, boolean defaultValue) { 200 return conf.getBoolean(name, defaultValue); 201 } 202 203 @Override 204 public void setBoolean(String name, boolean value) { 205 throw new UnsupportedOperationException("Read-only Configuration"); 206 } 207 208 @Override 209 public void setBooleanIfUnset(String name, boolean value) { 210 throw new UnsupportedOperationException("Read-only Configuration"); 211 } 212 213 @Override 214 public <T extends Enum<T>> void setEnum(String name, T value) { 215 throw new UnsupportedOperationException("Read-only Configuration"); 216 } 217 218 @Override 219 public <T extends Enum<T>> T getEnum(String name, T defaultValue) { 220 return conf.getEnum(name, defaultValue); 221 } 222 223 @Override 224 public void setTimeDuration(String name, long value, TimeUnit unit) { 225 throw new UnsupportedOperationException("Read-only Configuration"); 226 } 227 228 @Override 229 public long getTimeDuration(String name, long defaultValue, TimeUnit unit) { 230 return conf.getTimeDuration(name, defaultValue, unit); 231 } 232 233 @Override 234 public Pattern getPattern(String name, Pattern defaultValue) { 235 return conf.getPattern(name, defaultValue); 236 } 237 238 @Override 239 public void setPattern(String name, Pattern pattern) { 240 throw new UnsupportedOperationException("Read-only Configuration"); 241 } 242 243 @Override 244 public synchronized String[] getPropertySources(String name) { 245 return conf.getPropertySources(name); 246 } 247 248 @Override 249 public Configuration.IntegerRanges getRange(String name, String defaultValue) { 250 return conf.getRange(name, defaultValue); 251 } 252 253 @Override 254 public Collection<String> getStringCollection(String name) { 255 return conf.getStringCollection(name); 256 } 257 258 @Override 259 public String[] getStrings(String name) { 260 return conf.getStrings(name); 261 } 262 263 @Override 264 public String[] getStrings(String name, String... defaultValue) { 265 return conf.getStrings(name, defaultValue); 266 } 267 268 @Override 269 public Collection<String> getTrimmedStringCollection(String name) { 270 return conf.getTrimmedStringCollection(name); 271 } 272 273 @Override 274 public String[] getTrimmedStrings(String name) { 275 return conf.getTrimmedStrings(name); 276 } 277 278 @Override 279 public String[] getTrimmedStrings(String name, String... defaultValue) { 280 return conf.getTrimmedStrings(name, defaultValue); 281 } 282 283 @Override 284 public void setStrings(String name, String... values) { 285 throw new UnsupportedOperationException("Read-only Configuration"); 286 } 287 288 @Override 289 public char[] getPassword(String name) throws IOException { 290 return conf.getPassword(name); 291 } 292 293 @Override 294 public InetSocketAddress getSocketAddr(String hostProperty, String addressProperty, 295 String defaultAddressValue, int defaultPort) { 296 return conf.getSocketAddr(hostProperty, addressProperty, defaultAddressValue, defaultPort); 297 } 298 299 @Override 300 public InetSocketAddress getSocketAddr(String name, String defaultAddress, int defaultPort) { 301 return conf.getSocketAddr(name, defaultAddress, defaultPort); 302 } 303 304 @Override 305 public void setSocketAddr(String name, InetSocketAddress addr) { 306 throw new UnsupportedOperationException("Read-only Configuration"); 307 } 308 309 @Override 310 public InetSocketAddress updateConnectAddr(String hostProperty, String addressProperty, 311 String defaultAddressValue, InetSocketAddress addr) { 312 throw new UnsupportedOperationException("Read-only Configuration"); 313 } 314 315 @Override 316 public InetSocketAddress updateConnectAddr(String name, InetSocketAddress addr) { 317 throw new UnsupportedOperationException("Read-only Configuration"); 318 } 319 320 @Override 321 public Class<?> getClassByName(String name) throws ClassNotFoundException { 322 return conf.getClassByName(name); 323 } 324 325 @Override 326 public Class<?> getClassByNameOrNull(String name) { 327 return conf.getClassByNameOrNull(name); 328 } 329 330 @Override 331 public Class<?>[] getClasses(String name, Class<?>... defaultValue) { 332 return conf.getClasses(name, defaultValue); 333 } 334 335 @Override 336 public Class<?> getClass(String name, Class<?> defaultValue) { 337 return conf.getClass(name, defaultValue); 338 } 339 340 @Override 341 public <U> Class<? extends U> getClass(String name, Class<? extends U> defaultValue, 342 Class<U> xface) { 343 return conf.getClass(name, defaultValue, xface); 344 } 345 346 @Override 347 public <U> List<U> getInstances(String name, Class<U> xface) { 348 return conf.getInstances(name, xface); 349 } 350 351 @Override 352 public void setClass(String name, Class<?> theClass, Class<?> xface) { 353 throw new UnsupportedOperationException("Read-only Configuration"); 354 } 355 356 @Override 357 public Path getLocalPath(String dirsProp, String path) throws IOException { 358 return conf.getLocalPath(dirsProp, path); 359 } 360 361 @Override 362 public File getFile(String dirsProp, String path) throws IOException { 363 return conf.getFile(dirsProp, path); 364 } 365 366 @Override 367 public URL getResource(String name) { 368 return conf.getResource(name); 369 } 370 371 @Override 372 public InputStream getConfResourceAsInputStream(String name) { 373 return conf.getConfResourceAsInputStream(name); 374 } 375 376 @Override 377 public Reader getConfResourceAsReader(String name) { 378 return conf.getConfResourceAsReader(name); 379 } 380 381 @Override 382 public Set<String> getFinalParameters() { 383 return conf.getFinalParameters(); 384 } 385 386 @Override 387 public int size() { 388 return conf.size(); 389 } 390 391 @Override 392 public void clear() { 393 throw new UnsupportedOperationException("Read-only Configuration"); 394 } 395 396 @Override 397 public Iterator<Map.Entry<String, String>> iterator() { 398 return conf.iterator(); 399 } 400 401 @Override 402 public void writeXml(OutputStream out) throws IOException { 403 conf.writeXml(out); 404 } 405 406 @Override 407 public void writeXml(Writer out) throws IOException { 408 conf.writeXml(out); 409 } 410 411 @Override 412 public ClassLoader getClassLoader() { 413 return conf.getClassLoader(); 414 } 415 416 @Override 417 public void setClassLoader(ClassLoader classLoader) { 418 throw new UnsupportedOperationException("Read-only Configuration"); 419 } 420 421 @Override 422 public String toString() { 423 return conf.toString(); 424 } 425 426 @Override 427 public synchronized void setQuietMode(boolean quietmode) { 428 throw new UnsupportedOperationException("Read-only Configuration"); 429 } 430 431 @Override 432 public void readFields(DataInput in) throws IOException { 433 throw new UnsupportedOperationException("Read-only Configuration"); 434 } 435 436 @Override 437 public void write(DataOutput out) throws IOException { 438 conf.write(out); 439 } 440 441 @Override 442 public Map<String, String> getValByRegex(String regex) { 443 return conf.getValByRegex(regex); 444 } 445}