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