~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to java/src/IceGridGUI/Application/ReplicaGroupEditor.java

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
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.
7
7
//
8
8
// **********************************************************************
 
9
 
9
10
package IceGridGUI.Application;
10
11
 
11
12
import java.awt.event.ActionEvent;
44
45
            {
45
46
                ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
46
47
                writeDescriptor();
47
 
                ReplicaGroupDescriptor descriptor = 
48
 
                    (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
 
48
                ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
49
49
                replicaGroup.destroy(); // just removes the child
50
 
                
 
50
 
51
51
                try
52
52
                {
53
53
                    replicaGroups.tryAdd(descriptor, true);
66
66
                        assert false;
67
67
                    }
68
68
                    root.setSelectedNode(replicaGroup);
69
 
                    
 
69
 
70
70
                    JOptionPane.showMessageDialog(
71
71
                        root.getCoordinator().getMainFrame(),
72
72
                        e.toString(),
95
95
                Object savedDescriptor = replicaGroup.saveDescriptor();
96
96
                ReplicaGroups replicaGroups = (ReplicaGroups)replicaGroup.getParent();
97
97
                writeDescriptor();
98
 
                ReplicaGroupDescriptor descriptor = 
99
 
                    (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
100
 
                
101
 
                replicaGroups.removeChild(replicaGroup);            
 
98
                ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
 
99
 
 
100
                replicaGroups.removeChild(replicaGroup);
102
101
                try
103
102
                {
104
103
                    replicaGroups.tryAdd(descriptor, false);
126
125
                        JOptionPane.ERROR_MESSAGE);
127
126
                    return false;
128
127
                }
129
 
                    
 
128
 
130
129
                //
131
130
                // Success
132
131
                //
133
132
 
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);
138
136
 
139
137
                _target = replicaGroups.findChildWithDescriptor(descriptor);
140
138
                root.updated();
144
142
                    root.setSelectedNode(_target);
145
143
                }
146
144
            }
147
 
            
 
145
 
148
146
            if(refresh)
149
147
            {
150
148
                root.getCoordinator().getCurrentTab().showNode(_target);
175
173
 
176
174
    ReplicaGroupEditor()
177
175
    {
178
 
        _objects = new MapField(this, "Identity", "Type", true);
179
 
        
 
176
        _objects = new SimpleMapField(this, true, "Identity", "Type");
 
177
 
180
178
        //
181
179
        // load balancing
182
180
        //
188
186
                    {
189
187
                        updated();
190
188
 
191
 
                        Object item = e.getItem();      
 
189
                        Object item = e.getItem();
192
190
                        _loadSampleLabel.setVisible(item == ADAPTIVE);
193
191
                        _loadSample.setVisible(item == ADAPTIVE);
194
192
                    }
205
203
        _id.setToolTipText("Must be unique within this IceGrid deployment");
206
204
 
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");
210
207
 
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>");
216
213
 
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?");
223
218
    }
224
 
    
 
219
 
225
220
    void writeDescriptor()
226
221
    {
227
 
        ReplicaGroupDescriptor descriptor = 
228
 
            (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
 
222
        ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
229
223
 
230
224
        descriptor.id = _id.getText().trim();
231
225
        descriptor.description = _description.getText();
232
226
        descriptor.objects = _objectList;
233
 
        
 
227
 
234
228
        Object loadBalancing = _loadBalancing.getSelectedItem();
235
229
        if(loadBalancing == ORDERED)
236
230
        {
237
 
            descriptor.loadBalancing =  new OrderedLoadBalancingPolicy(
238
 
                _nReplicas.getText().trim());
 
231
            descriptor.loadBalancing =  new OrderedLoadBalancingPolicy(_nReplicas.getText().trim());
239
232
        }
240
233
        else if(loadBalancing == RANDOM)
241
234
        {
242
 
            descriptor.loadBalancing = new RandomLoadBalancingPolicy(
243
 
                _nReplicas.getText().trim());
 
235
            descriptor.loadBalancing = new RandomLoadBalancingPolicy(_nReplicas.getText().trim());
244
236
        }
245
237
        else if(loadBalancing == ROUND_ROBIN)
246
238
        {
247
 
            descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(
248
 
                _nReplicas.getText().trim());
 
239
            descriptor.loadBalancing = new RoundRobinLoadBalancingPolicy(_nReplicas.getText().trim());
249
240
        }
250
241
        else if(loadBalancing == ADAPTIVE)
251
242
        {
252
243
            descriptor.loadBalancing = new AdaptiveLoadBalancingPolicy(
253
 
                _nReplicas.getText().trim(), 
254
 
                _loadSample.getSelectedItem().toString().trim());
 
244
                _nReplicas.getText().trim(), _loadSample.getSelectedItem().toString().trim());
255
245
        }
256
246
        else
257
247
        {
258
248
            assert false;
259
249
        }
260
 
    }       
261
 
    
 
250
    }
 
251
 
262
252
    boolean isSimpleUpdate()
263
253
    {
264
 
        ReplicaGroupDescriptor descriptor = 
265
 
            (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
 
254
        ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)getReplicaGroup().getDescriptor();
266
255
        return descriptor.id.equals(_id.getText().trim());
267
256
    }
268
257
 
271
260
        builder.append("Replica Group ID");
272
261
        builder.append(_id, 3);
273
262
        builder.nextLine();
274
 
        
 
263
 
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();
285
273
 
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();
299
286
 
320
307
        // First validate stringified identities
321
308
        //
322
309
        _objectList = mapToObjectDescriptorSeq(_objects.get());
323
 
        
 
310
 
324
311
        if(_objectList == null)
325
312
        {
326
313
            return false;
329
316
        return check(new String[]{"Replica Group ID", _id.getText().trim()});
330
317
    }
331
318
 
332
 
 
333
319
    void show(ReplicaGroup replicaGroup)
334
320
    {
335
321
        //
342
328
 
343
329
        Utils.Resolver resolver = getDetailResolver();
344
330
        boolean isEditable = (resolver == null);
345
 
        
346
 
        ReplicaGroupDescriptor descriptor = 
347
 
            (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
348
 
        
 
331
 
 
332
        ReplicaGroupDescriptor descriptor = (ReplicaGroupDescriptor)replicaGroup.getDescriptor();
 
333
 
349
334
        _id.setText(descriptor.id);
350
335
        _id.setEditable(isEditable);
351
 
        
352
 
        _description.setText(
353
 
            Utils.substitute(descriptor.description, resolver));
 
336
 
 
337
        _description.setText(Utils.substitute(descriptor.description, resolver));
354
338
        _description.setEditable(isEditable);
355
339
        _description.setOpaque(isEditable);
356
340
 
367
351
        else if(descriptor.loadBalancing instanceof RandomLoadBalancingPolicy)
368
352
        {
369
353
            _loadBalancing.setSelectedItem(RANDOM);
370
 
            _nReplicas.setText(
371
 
                Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
 
354
            _nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
372
355
            _loadSample.setSelectedItem("1");
373
356
        }
374
357
        else if(descriptor.loadBalancing instanceof OrderedLoadBalancingPolicy)
375
358
        {
376
359
            _loadBalancing.setSelectedItem(ORDERED);
377
 
            _nReplicas.setText(
378
 
                Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
 
360
            _nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
379
361
            _loadSample.setSelectedItem("1");
380
362
        }
381
363
        else if(descriptor.loadBalancing instanceof RoundRobinLoadBalancingPolicy)
382
364
        {
383
365
            _loadBalancing.setSelectedItem(ROUND_ROBIN);
384
 
            _nReplicas.setText(
385
 
                Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
 
366
            _nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
386
367
            _loadSample.setSelectedItem("1");
387
368
        }
388
369
        else if(descriptor.loadBalancing instanceof AdaptiveLoadBalancingPolicy)
389
370
        {
390
371
            _loadBalancing.setSelectedItem(ADAPTIVE);
391
 
            _nReplicas.setText(
392
 
                Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
 
372
            _nReplicas.setText(Utils.substitute(descriptor.loadBalancing.nReplicas, resolver));
393
373
 
394
374
            _loadSample.setSelectedItem(
395
 
                Utils.substitute(
396
 
                    ((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample,
397
 
                    resolver));
 
375
                Utils.substitute(((AdaptiveLoadBalancingPolicy)descriptor.loadBalancing).loadSample, resolver));
398
376
        }
399
377
        else
400
378
        {
405
383
        _loadBalancing.setEnabled(isEditable);
406
384
 
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())
411
389
        {
418
396
        return (ReplicaGroup)_target;
419
397
    }
420
398
 
421
 
    private java.util.Map objectDescriptorSeqToMap(java.util.List objects)
 
399
    private java.util.Map<String, String> objectDescriptorSeqToMap(java.util.List<ObjectDescriptor> objects)
422
400
    {
423
 
        java.util.Map result = new java.util.TreeMap();
424
 
        java.util.Iterator p = objects.iterator();
425
 
        while(p.hasNext())
 
401
        java.util.Map<String, String> result = new java.util.TreeMap<String, String>();
 
402
        for(ObjectDescriptor p : objects)
426
403
        {
427
 
            ObjectDescriptor od = (ObjectDescriptor)p.next();
428
 
            result.put(Ice.Util.identityToString(od.id), 
429
 
                       od.type);
 
404
            result.put(Ice.Util.identityToString(p.id), p.type);
430
405
        }
431
406
        return result;
432
407
    }
433
 
    
434
 
    private java.util.LinkedList mapToObjectDescriptorSeq(java.util.Map map)
 
408
 
 
409
    private java.util.LinkedList<ObjectDescriptor> mapToObjectDescriptorSeq(java.util.Map<String, String> map)
435
410
    {
436
411
        String badIdentities = "";
437
 
        java.util.LinkedList result = new java.util.LinkedList();
438
 
        java.util.Iterator p = map.entrySet().iterator();
439
 
        
440
 
        while(p.hasNext())
 
412
        java.util.LinkedList<ObjectDescriptor> result = new java.util.LinkedList<ObjectDescriptor>();
 
413
 
 
414
        for(java.util.Map.Entry<String, String> p : map.entrySet())
441
415
        {
442
 
            java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
443
416
            try
444
417
            {
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));
448
421
            }
449
422
            catch(Ice.IdentityParseException ex)
450
423
            {
451
 
                badIdentities += "- " + (String)entry.getKey() + "\n";
 
424
                badIdentities += "- " + p.getKey() + "\n";
452
425
            }
453
426
        }
454
427
        if(!badIdentities.equals(""))
475
448
    private JTextField _id = new JTextField(20);
476
449
    private JTextArea _description = new JTextArea(3, 20);
477
450
 
478
 
    private JComboBox _loadBalancing = new JComboBox(new Object[]
479
 
        {ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN}); 
480
 
    
 
451
    private JComboBox _loadBalancing = new JComboBox(new Object[] {ADAPTIVE, ORDERED, RANDOM, ROUND_ROBIN});
 
452
 
481
453
    private JTextField _nReplicas = new JTextField(20);
482
454
 
483
455
    private JLabel _loadSampleLabel;
484
 
    private JComboBox _loadSample = new JComboBox(new Object[]
485
 
        {"1", "5", "15"});
486
 
    
487
 
    private MapField _objects;
488
 
    private java.util.LinkedList _objectList;
 
456
    private JComboBox _loadSample = new JComboBox(new Object[] {"1", "5", "15"});
 
457
 
 
458
    private SimpleMapField _objects;
 
459
    private java.util.LinkedList<ObjectDescriptor> _objectList;
489
460
}