summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/PropertiesAdminI.java
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2012-08-30 14:43:15 +0200
committerBenoit Foucher <benoit@zeroc.com>2012-08-30 14:43:15 +0200
commitaab12cf1719b425b5a2c571b8938d47cdd71d151 (patch)
tree876561b05764721306eb8629883e7b0b9cbbc99a /java/src/IceInternal/PropertiesAdminI.java
parentminor g++ warning (diff)
downloadice-aab12cf1719b425b5a2c571b8938d47cdd71d151.tar.bz2
ice-aab12cf1719b425b5a2c571b8938d47cdd71d151.tar.xz
ice-aab12cf1719b425b5a2c571b8938d47cdd71d151.zip
ICE-4774: Merged skype_props enhancement
Diffstat (limited to 'java/src/IceInternal/PropertiesAdminI.java')
-rw-r--r--java/src/IceInternal/PropertiesAdminI.java182
1 files changed, 175 insertions, 7 deletions
diff --git a/java/src/IceInternal/PropertiesAdminI.java b/java/src/IceInternal/PropertiesAdminI.java
index 48e7db5c1d9..bb698bcf8ac 100644
--- a/java/src/IceInternal/PropertiesAdminI.java
+++ b/java/src/IceInternal/PropertiesAdminI.java
@@ -9,24 +9,192 @@
package IceInternal;
-class PropertiesAdminI extends Ice._PropertiesAdminDisp
+public class PropertiesAdminI extends Ice._PropertiesAdminDisp implements Ice.NativePropertiesAdmin
{
- PropertiesAdminI(Ice.Properties properties)
+ public PropertiesAdminI(String name, Ice.Properties properties, Ice.Logger logger)
{
+ _name = name;
_properties = properties;
+ _logger = logger;
}
-
- public String
+
+ public synchronized String
getProperty(String name, Ice.Current current)
{
return _properties.getProperty(name);
}
-
- public java.util.TreeMap<String, String>
+
+ public synchronized java.util.TreeMap<String, String>
getPropertiesForPrefix(String name, Ice.Current current)
{
return new java.util.TreeMap<String, String>(_properties.getPropertiesForPrefix(name));
}
-
+
+ public void
+ setProperties_async(Ice.AMD_PropertiesAdmin_setProperties cb, java.util.Map<String, String> props,
+ Ice.Current current)
+ {
+ java.util.Map<String, String> added = new java.util.HashMap<String, String>();
+ java.util.Map<String, String> changed = new java.util.HashMap<String, String>();
+ java.util.Map<String, String> removed = new java.util.HashMap<String, String>();
+ Ice.PropertiesAdminUpdateCallback callback;
+
+ synchronized(this)
+ {
+ java.util.Map<String, String> old = _properties.getPropertiesForPrefix("");
+ final int traceLevel = _properties.getPropertyAsInt("Ice.Trace.Admin.Properties");
+
+ //
+ // Compute the difference between the new property set and the existing property set:
+ //
+ // 1) Any properties in the new set that were not defined in the existing set.
+ //
+ // 2) Any properties that appear in both sets but with different values.
+ //
+ // 3) Any properties not present in the new set but present in the existing set.
+ // In other words, the property has been removed.
+ //
+ for(java.util.Map.Entry<String, String> e : props.entrySet())
+ {
+ final String key = e.getKey();
+ final String value = e.getValue();
+ if(!old.containsKey(key))
+ {
+ if(value.length() > 0)
+ {
+ //
+ // This property is new.
+ //
+ added.put(key, value);
+ }
+ }
+ else
+ {
+ if(!value.equals(old.get(key)))
+ {
+ if(value.length() == 0)
+ {
+ //
+ // This property was removed.
+ //
+ removed.put(key, value);
+ }
+ else
+ {
+ //
+ // This property has changed.
+ //
+ changed.put(key, value);
+ }
+ }
+
+ old.remove(key);
+ }
+ }
+
+ if(traceLevel > 0 && (!added.isEmpty() || !changed.isEmpty() || !removed.isEmpty()))
+ {
+ StringBuilder out = new StringBuilder(128);
+ out.append("Summary of property changes");
+
+ if(!added.isEmpty())
+ {
+ out.append("\nNew properties:");
+ for(java.util.Map.Entry<String, String> e : added.entrySet())
+ {
+ out.append("\n ");
+ out.append(e.getKey());
+ if(traceLevel > 1)
+ {
+ out.append(" = ");
+ out.append(e.getValue());
+ }
+ }
+ }
+
+ if(!changed.isEmpty())
+ {
+ out.append("\nChanged properties:");
+ for(java.util.Map.Entry<String, String> e : changed.entrySet())
+ {
+ out.append("\n ");
+ out.append(e.getKey());
+ if(traceLevel > 1)
+ {
+ out.append(" = ");
+ out.append(e.getValue());
+ out.append(" (old value = ");
+ out.append(_properties.getProperty(e.getKey()));
+ out.append(")");
+ }
+ }
+ }
+
+ if(!removed.isEmpty())
+ {
+ out.append("\nRemoved properties:");
+ for(java.util.Map.Entry<String, String> e : removed.entrySet())
+ {
+ out.append("\n ");
+ out.append(e.getKey());
+ }
+ }
+
+ _logger.trace(_name, out.toString());
+ }
+
+ //
+ // Update the property set.
+ //
+
+ for(java.util.Map.Entry<String, String> e : added.entrySet())
+ {
+ _properties.setProperty(e.getKey(), e.getValue());
+ }
+
+ for(java.util.Map.Entry<String, String> e : changed.entrySet())
+ {
+ _properties.setProperty(e.getKey(), e.getValue());
+ }
+
+ for(java.util.Map.Entry<String, String> e : removed.entrySet())
+ {
+ _properties.setProperty(e.getKey(), "");
+ }
+
+ callback = _updateCallback;
+ }
+
+ //
+ // Send the response now so that we do not block the client during the call to the update callback.
+ //
+ cb.ice_response();
+
+ if(callback != null)
+ {
+ java.util.Map<String, String> changes = new java.util.HashMap<String, String>(added);
+ changes.putAll(changed);
+ changes.putAll(removed);
+
+ try
+ {
+ callback.updated(changes);
+ }
+ catch(RuntimeException ex)
+ {
+ // Ignore.
+ }
+ }
+ }
+
+ public synchronized void
+ setUpdateCallback(Ice.PropertiesAdminUpdateCallback cb)
+ {
+ _updateCallback = cb;
+ }
+
+ private final String _name;
private final Ice.Properties _properties;
+ private final Ice.Logger _logger;
+ private Ice.PropertiesAdminUpdateCallback _updateCallback;
}