1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package IceInternal;
public class PropertiesAdminI extends Ice._PropertiesAdminDisp implements Ice.NativePropertiesAdmin
{
public PropertiesAdminI(String name, Ice.Properties properties, Ice.Logger logger)
{
_name = name;
_properties = properties;
_logger = logger;
}
public synchronized String
getProperty(String name, Ice.Current current)
{
return _properties.getProperty(name);
}
public synchronized java.util.TreeMap<String, String>
getPropertiesForPrefix(String name, Ice.Current current)
{
return new java.util.TreeMap<String, String>(_properties.getPropertiesForPrefix(name));
}
synchronized public void
setProperties_async(Ice.AMD_PropertiesAdmin_setProperties cb, java.util.Map<String, String> props,
Ice.Current current)
{
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.
//
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>();
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(), "");
}
//
// Send the response now so that we do not block the client during the call to the update callback.
//
cb.ice_response();
if(!_updateCallbacks.isEmpty())
{
//
// Copy the callbacks to allow callbacks to update the callbacks.
//
java.util.List<Ice.PropertiesAdminUpdateCallback> callbacks =
new java.util.ArrayList<Ice.PropertiesAdminUpdateCallback>(_updateCallbacks);
java.util.Map<String, String> changes = new java.util.HashMap<String, String>(added);
changes.putAll(changed);
changes.putAll(removed);
for(Ice.PropertiesAdminUpdateCallback callback : callbacks)
{
try
{
callback.updated(changes);
}
catch(RuntimeException ex)
{
// Ignore.
}
}
}
}
public synchronized void
addUpdateCallback (Ice.PropertiesAdminUpdateCallback cb)
{
_updateCallbacks.add(cb);
}
public synchronized void
removeUpdateCallback(Ice.PropertiesAdminUpdateCallback cb)
{
_updateCallbacks.remove(cb);
}
private final String _name;
private final Ice.Properties _properties;
private final Ice.Logger _logger;
private java.util.List<Ice.PropertiesAdminUpdateCallback> _updateCallbacks =
new java.util.ArrayList<Ice.PropertiesAdminUpdateCallback>();
}
|