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 */ 018 019package org.apache.hadoop.conf; 020 021 022/** 023 * Exception indicating that configuration property cannot be changed 024 * at run time. 025 */ 026public class ReconfigurationException extends Exception { 027 028 private static final long serialVersionUID = 1L; 029 030 private String property; 031 private String newVal; 032 private String oldVal; 033 034 /** 035 * Construct the exception message. 036 */ 037 private static String constructMessage(String property, 038 String newVal, String oldVal) { 039 String message = "Could not change property " + property; 040 if (oldVal != null) { 041 message += " from \'" + oldVal; 042 } 043 if (newVal != null) { 044 message += "\' to \'" + newVal + "\'"; 045 } 046 return message; 047 } 048 049 050 /** 051 * Create a new instance of {@link ReconfigurationException}. 052 */ 053 public ReconfigurationException() { 054 super("Could not change configuration."); 055 this.property = null; 056 this.newVal = null; 057 this.oldVal = null; 058 } 059 060 /** 061 * Create a new instance of {@link ReconfigurationException}. 062 */ 063 public ReconfigurationException(String property, 064 String newVal, String oldVal, 065 Throwable cause) { 066 super(constructMessage(property, newVal, oldVal), cause); 067 this.property = property; 068 this.newVal = newVal; 069 this.oldVal = oldVal; 070 } 071 072 /** 073 * Create a new instance of {@link ReconfigurationException}. 074 */ 075 public ReconfigurationException(String property, 076 String newVal, String oldVal) { 077 super(constructMessage(property, newVal, oldVal)); 078 this.property = property; 079 this.newVal = newVal; 080 this.oldVal = oldVal; 081 } 082 083 /** 084 * Get property that cannot be changed. 085 */ 086 public String getProperty() { 087 return property; 088 } 089 090 /** 091 * Get value to which property was supposed to be changed. 092 */ 093 public String getNewValue() { 094 return newVal; 095 } 096 097 /** 098 * Get old value of property that cannot be changed. 099 */ 100 public String getOldValue() { 101 return oldVal; 102 } 103 104}