diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/CHANGES | 4 | ||||
-rw-r--r-- | java/src/Ice/PropertiesI.java | 83 | ||||
-rw-r--r-- | java/src/IceInternal/Instance.java | 15 | ||||
-rw-r--r-- | java/src/IceInternal/PropertyNames.java | 3 |
4 files changed, 91 insertions, 14 deletions
diff --git a/java/CHANGES b/java/CHANGES index f7b2183cdac..4f51fadb3ff 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompabible) ------------------------------------------------- +- Added a new property, Ice.Warn.UnusedProperties. If set to 1, when + the communicator is destroyed a warning will be printed listing all + properties that were set, but never read. Default is 0. + - Ice.LocalException and Ice.UserException now implement java.lang.Cloneable. diff --git a/java/src/Ice/PropertiesI.java b/java/src/Ice/PropertiesI.java index c87df8295c2..fb189b04610 100644 --- a/java/src/Ice/PropertiesI.java +++ b/java/src/Ice/PropertiesI.java @@ -11,14 +11,32 @@ package Ice; public final class PropertiesI extends LocalObjectImpl implements Properties { + class PropertyValue + { + public PropertyValue(String v, boolean u) + { + value = v; + used = u; + } + + public String value; + public boolean used; + } + public synchronized String getProperty(String key) { - String result = (String)_properties.get(key); - if(result == null) + String result = null; + PropertyValue pv = (PropertyValue)_properties.get(key); + if(pv == null) { result = System.getProperty(key); } + else + { + pv.used = true; + result = pv.value; + } if(result == null) { result = ""; @@ -29,11 +47,17 @@ public final class PropertiesI extends LocalObjectImpl implements Properties public synchronized String getPropertyWithDefault(String key, String value) { - String result = (String)_properties.get(key); - if(result == null) + String result = null; + PropertyValue pv = (PropertyValue)_properties.get(key); + if(pv == null) { result = System.getProperty(key); } + else + { + pv.used = true; + result = pv.value; + } if(result == null) { result = value; @@ -50,11 +74,17 @@ public final class PropertiesI extends LocalObjectImpl implements Properties public synchronized int getPropertyAsIntWithDefault(String key, int value) { - String result = (String)_properties.get(key); - if(result == null) + String result = null; + PropertyValue pv = (PropertyValue)_properties.get(key); + if(pv == null) { result = System.getProperty(key); } + else + { + pv.used = true; + result = pv.value; + } if(result == null) { return value; @@ -79,10 +109,11 @@ public final class PropertiesI extends LocalObjectImpl implements Properties { java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); String key = (String)entry.getKey(); - String value = (String)entry.getValue(); if(prefix.length() == 0 || key.startsWith(prefix)) { - result.put(key, value); + PropertyValue pv = (PropertyValue)entry.getValue(); + pv.used = true; + result.put(key, pv.value); } } return result; @@ -137,7 +168,16 @@ public final class PropertiesI extends LocalObjectImpl implements Properties // if(value != null && value.length() > 0) { - _properties.put(key, value); + PropertyValue pv = (PropertyValue)_properties.get(key); + if(pv != null) + { + pv.value = value; + } + else + { + pv = new PropertyValue(value, false); + } + _properties.put(key, pv); } else { @@ -155,7 +195,7 @@ public final class PropertiesI extends LocalObjectImpl implements Properties while(p.hasNext()) { java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); - result[i++] = "--" + entry.getKey() + "=" + entry.getValue(); + result[i++] = "--" + entry.getKey() + "=" + ((PropertyValue)entry.getValue()).value; } assert(i == result.length); return result; @@ -229,9 +269,26 @@ public final class PropertiesI extends LocalObjectImpl implements Properties return new PropertiesI(this); } + public synchronized java.util.List + getUnusedProperties() + { + java.util.List unused = new java.util.ArrayList(); + java.util.Iterator p = _properties.entrySet().iterator(); + while(p.hasNext()) + { + java.util.Map.Entry entry = (java.util.Map.Entry)p.next(); + PropertyValue pv = (PropertyValue)entry.getValue(); + if(!pv.used) + { + unused.add((String)entry.getKey()); + } + } + return unused; + } + PropertiesI(PropertiesI p) { - _properties.putAll(p._properties); + _properties = new java.util.HashMap(p._properties); } PropertiesI() @@ -242,7 +299,7 @@ public final class PropertiesI extends LocalObjectImpl implements Properties { if(defaults != null) { - _properties.putAll(defaults.getPropertiesForPrefix("")); + _properties = new java.util.HashMap(((PropertiesI)defaults)._properties); } boolean loadConfigFiles = false; @@ -365,7 +422,7 @@ public final class PropertiesI extends LocalObjectImpl implements Properties } } - setProperty("Ice.Config", value); + _properties.put("Ice.Config", new PropertyValue(value, true)); } private java.util.HashMap _properties = new java.util.HashMap(); diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index da3c96dfc0f..ebf3438ba64 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -658,6 +658,21 @@ public final class Instance { serverThreadPool.joinWithAllThreads(); } + + if(_initData.properties.getPropertyAsInt("Ice.Warn.UnusedProperties") > 0) + { + java.util.List unusedProperties = ((Ice.PropertiesI)_initData.properties).getUnusedProperties(); + if(unusedProperties.size() != 0) + { + String message = "The following properties were set but never read:"; + java.util.Iterator p = unusedProperties.iterator(); + while(p.hasNext()) + { + message += "\n " + (String)p.next(); + } + _initData.logger.warning(message); + } + } } private void diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java index 571ab12303e..85ea56e73b7 100644 --- a/java/src/IceInternal/PropertyNames.java +++ b/java/src/IceInternal/PropertyNames.java @@ -7,7 +7,7 @@ // // ********************************************************************** -// Generated by makeprops.py from file `../config/PropertyNames.def', Tue Feb 20 11:10:03 2007 +// Generated by makeprops.py from file `../config/PropertyNames.def', Tue May 15 12:31:29 2007 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -97,6 +97,7 @@ public final class PropertyNames "^Ice\\.Warn\\.Dispatch$", "^Ice\\.Warn\\.Endpoints$", "^Ice\\.Warn\\.UnknownProperties$", + "^Ice\\.Warn\\.UnusedProperties$", "^Ice\\.CacheMessageBuffers$", null }; |