1
1
// **********************************************************************
3
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
8
8
// **********************************************************************
9
10
package IceGridGUI.Application;
11
12
import java.awt.event.ActionEvent;
45
46
ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
47
ReplicaGroupDescriptor descriptor =
48
(ReplicaGroupDescriptor)replicaGroup.getDescriptor();
48
ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
49
49
replicaGroup.destroy(); // just removes the child
53
53
replicaGroups.tryAdd(descriptor, true);
95
95
Object savedDescriptor = replicaGroup.saveDescriptor();
96
96
ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
98
ReplicaGroupDescriptor descriptor =
99
(ReplicaGroupDescriptor)replicaGroup.getDescriptor();
101
replicaGroups.removeChild(replicaGroup);
98
ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
100
replicaGroups.removeChild(replicaGroup);
104
103
replicaGroups.tryAdd(descriptor, false);
126
125
JOptionPane.ERROR_MESSAGE);
134
133
// replaced by brand new ReplicaGroup
135
134
replicaGroups.getEditable().
136
removeElement(replicaGroup.getId(),
137
replicaGroup.getEditable(), ReplicaGroup.class);
135
removeElement(replicaGroup.getId(), replicaGroup.getEditable(), ReplicaGroup.class);
139
137
_target = replicaGroups.findChildWithDescriptor(descriptor);
205
203
_id.setToolTipText("Must be unique within this IceGrid deployment");
207
205
_description.getDocument().addDocumentListener(_updateListener);
208
_description.setToolTipText(
209
"An optional description for this replica group");
206
_description.setToolTipText("An optional description for this replica group");
211
208
_nReplicas.getDocument().addDocumentListener(_updateListener);
212
209
_nReplicas.setToolTipText("<html>IceGrid returns the endpoints of "
215
212
+ "Enter 0 to returns the endpoints of all adapters.</html>");
217
214
_loadSample.setEditable(true);
218
JTextField loadSampleTextField = (JTextField)
219
_loadSample.getEditor().getEditorComponent();
215
JTextField loadSampleTextField = (JTextField)_loadSample.getEditor().getEditorComponent();
220
216
loadSampleTextField.getDocument().addDocumentListener(_updateListener);
221
_loadSample.setToolTipText(
222
"Use the load average or CPU usage over the last 1, 5 or 15 minutes?");
217
_loadSample.setToolTipText("Use the load average or CPU usage over the last 1, 5 or 15 minutes?");
225
220
void writeDescriptor()
227
ReplicaGroupDescriptor descriptor =
228
(ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
222
ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
230
224
descriptor.id = _id.getText().trim();
231
225
descriptor.description = _description.getText();
232
226
descriptor.objects = _objectList;
234
228
Object loadBalancing = _loadBalancing.getSelectedItem();
235
229
if(loadBalancing == ORDERED)
237
descriptor.loadBalancing = new OrderedLoadBalancingPolicy(
238
_nReplicas.getText().trim());
231
descriptor.loadBalancing = new OrderedLoadBalancingPolicy(_nReplicas.getText().trim());
240
233
else if(loadBalancing == RANDOM)
242
descriptor.loadBalancing = new RandomLoadBalancingPolicy(
243
_nReplicas.getText().trim());
235
descriptor.loadBalancing = new RandomLoadBalancingPolicy(_nReplicas.getText().trim());
245
237
else if(loadBalancing == ROUND_ROBIN)
247
descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(
248
_nReplicas.getText().trim());
239
descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(_nReplicas.getText().trim());
250
241
else if(loadBalancing == ADAPTIVE)
252
243
descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy(
253
_nReplicas.getText().trim(),
254
_loadSample.getSelectedItem().toString().trim());
244
_nReplicas.getText().trim(), _loadSample.getSelectedItem().toString().trim());
262
252
boolean isSimpleUpdate()
264
ReplicaGroupDescriptor descriptor =
265
(ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
254
ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
266
255
return descriptor.id.equals(_id.getText().trim());
271
260
builder.append("Replica Group ID");
272
261
builder.append(_id, 3);
273
262
builder.nextLine();
275
264
builder.append("Description");
276
265
builder.nextLine();
277
266
builder.append("");
278
267
builder.nextRow(-2);
279
268
CellConstraints cc = new CellConstraints();
280
269
JScrollPane scrollPane = new JScrollPane(_description);
281
builder.add(scrollPane,
282
cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
270
builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
283
271
builder.nextRow(2);
284
272
builder.nextLine();
292
280
builder.append("");
293
281
builder.nextRow(-6);
294
282
scrollPane = new JScrollPane(_objects);
295
builder.add(scrollPane,
296
cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
283
builder.add(scrollPane, cc.xywh(builder.getColumn(), builder.getRow(), 3, 7));
297
284
builder.nextRow(6);
298
285
builder.nextLine();
343
329
Utils.Resolver resolver = getDetailResolver();
344
330
boolean isEditable = (resolver == null);
346
ReplicaGroupDescriptor descriptor =
347
(ReplicaGroupDescriptor)replicaGroup.getDescriptor();
332
ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
349
334
_id.setText(descriptor.id);
350
335
_id.setEditable(isEditable);
352
_description.setText(
353
Utils.substitute(descriptor.description, resolver));
337
_description.setText(Utils.substitute(descriptor.description, resolver));
354
338
_description.setEditable(isEditable);
355
339
_description.setOpaque(isEditable);
367
351
else if(descriptor.loadBalancing instanceof RandomLoadBalancingPolicy)
369
353
_loadBalancing.setSelectedItem(RANDOM);
371
Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
354
_nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
372
355
_loadSample.setSelectedItem("1");
374
357
else if(descriptor.loadBalancing instanceof OrderedLoadBalancingPolicy)
376
359
_loadBalancing.setSelectedItem(ORDERED);
378
Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
360
_nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
379
361
_loadSample.setSelectedItem("1");
381
363
else if(descriptor.loadBalancing instanceof RoundRobinLoadBalancingPolicy)
383
365
_loadBalancing.setSelectedItem(ROUND_ROBIN);
385
Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
366
_nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
386
367
_loadSample.setSelectedItem("1");
388
369
else if(descriptor.loadBalancing instanceof AdaptiveLoadBalancingPolicy)
390
371
_loadBalancing.setSelectedItem(ADAPTIVE);
392
Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
372
_nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
394
374
_loadSample.setSelectedItem(
396
((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample,
375
Utils.substitute(((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample, resolver));
405
383
_loadBalancing.setEnabled(isEditable);
407
385
_applyButton.setEnabled(replicaGroup.isEphemeral());
408
_discardButton.setEnabled(replicaGroup.isEphemeral());
386
_discardButton.setEnabled(replicaGroup.isEphemeral());
409
387
detectUpdates(true);
410
388
if(replicaGroup.isEphemeral())
418
396
return (ReplicaGroup)_target;
421
private java.util.Map objectDescriptorSeqToMap(java.util.List objects)
399
private java.util.Map<String, String> objectDescriptorSeqToMap(java.util.List<ObjectDescriptor> objects)
423
java.util.Map result = new java.util.TreeMap();
424
java.util.Iterator p = objects.iterator();
401
java.util.Map<String, String> result = new java.util.TreeMap<String, String>();
402
for(ObjectDescriptor p : objects)
427
ObjectDescriptor od = (ObjectDescriptor)p.next();
428
result.put(Ice.Util.identityToString(od.id),
404
result.put(Ice.Util.identityToString(p.id), p.type);
434
private java.util.LinkedList mapToObjectDescriptorSeq(java.util.Map map)
409
private java.util.LinkedList<ObjectDescriptor> mapToObjectDescriptorSeq(java.util.Map<String, String> map)
436
411
String badIdentities = "";
437
java.util.LinkedList result = new java.util.LinkedList();
438
java.util.Iterator p = map.entrySet().iterator();
412
java.util.LinkedList<ObjectDescriptor> result = new java.util.LinkedList<ObjectDescriptor>();
414
for(java.util.Map.Entry<String, String> p : map.entrySet())
442
java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
445
Ice.Identity id = Ice.Util.stringToIdentity((String)entry.getKey());
446
String type = (String)entry.getValue();
418
Ice.Identity id = Ice.Util.stringToIdentity(p.getKey());
419
String type = p.getValue();
447
420
result.add(new ObjectDescriptor(id, type));
449
422
catch(Ice.IdentityParseException ex)
451
badIdentities += "- " + (String)entry.getKey() + "\n";
424
badIdentities += "- " + p.getKey() + "\n";
454
427
if(!badIdentities.equals(""))
475
448
private JTextField _id = new JTextField(20);
476
449
private JTextArea _description = new JTextArea(3, 20);
478
private JComboBox _loadBalancing = new JComboBox(new Object[]
479
{ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN});
451
private JComboBox _loadBalancing = new JComboBox(new Object[] {ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN});
481
453
private JTextField _nReplicas = new JTextField(20);
483
455
private JLabel _loadSampleLabel;
484
private JComboBox _loadSample = new JComboBox(new Object[]
487
private MapField _objects;
488
private java.util.LinkedList _objectList;
456
private JComboBox _loadSample = new JComboBox(new Object[] {"1", "5", "15"});
458
private SimpleMapField _objects;
459
private java.util.LinkedList<ObjectDescriptor> _objectList;