-
Notifications
You must be signed in to change notification settings - Fork 33
/
BrokerDestPropsDialog.java
1090 lines (919 loc) · 36.3 KB
/
BrokerDestPropsDialog.java
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000, 2017 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.messaging.jmq.admin.apps.console;
import java.util.Enumeration;
import java.util.Vector;
import java.awt.Insets;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.table.AbstractTableModel;
import javax.swing.event.TableModelEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import com.sun.messaging.jmq.util.DestType;
import com.sun.messaging.jmq.util.admin.DestinationInfo;
import com.sun.messaging.jmq.util.admin.DurableInfo;
import com.sun.messaging.jmq.util.DestLimitBehavior;
import com.sun.messaging.jmq.admin.util.Globals;
import com.sun.messaging.jmq.admin.bkrutil.BrokerAdminUtil;
import com.sun.messaging.jmq.admin.bkrutil.BrokerConstants;
import com.sun.messaging.jmq.admin.event.BrokerAdminEvent;
import com.sun.messaging.jmq.admin.apps.console.util.LabelledComponent;
import com.sun.messaging.jmq.admin.apps.console.util.LabelValuePanel;
import com.sun.messaging.jmq.admin.apps.console.util.BytesField;
import com.sun.messaging.jmq.admin.apps.console.util.IntegerField;
import com.sun.messaging.jmq.admin.apps.console.util.SpecialValueField;
import com.sun.messaging.jmq.admin.resources.AdminResources;
import com.sun.messaging.jmq.admin.resources.AdminConsoleResources;
/**
* This dialog is used to display the properties of a physical destination on the broker.
*/
public class BrokerDestPropsDialog extends AdminDialog implements ListSelectionListener, BrokerConstants {
private static final long serialVersionUID = -5565520883883363004L;
private final static int UNLIMITED_VALUE_0 = 0;
private final static int UNLIMITED_VALUE_NEG1 = -1; // for active/failover consumers
private static AdminResources ar = Globals.getAdminResources();
private static AdminConsoleResources acr = Globals.getAdminConsoleResources();
private static String[] columnNames = { ar.getString(ar.I_JMQCMD_SUB_NAME), ar.getString(ar.I_JMQCMD_CLIENT_ID), ar.getString(ar.I_JMQCMD_DURABLE),
ar.getString(ar.I_JMQCMD_SUB_NUM_MSG), ar.getString(ar.I_JMQCMD_SUB_STATE) };
/*
* The tabbed pane and the individual tabs.
*/
private JTabbedPane tabbedPane;
/*
* Applicable to Queues and Topics. Basic destination info.
*/
private JLabel destNameValue;
private JLabel destTypeValue;
private JLabel destStateValue;
/*
* Applicable to Queues and Topics. Current destination info.
*/
private JLabel curNumProducers;
private LabelledComponent curNumProducersLabelC;
private JLabel curNumActive;
private LabelledComponent curNumActiveLabelC;
private JLabel curNumFailover;
private LabelledComponent curNumFailoverLabelC;
private JLabel curNumMesgsValue;
private JLabel curNumMesgBytesValue;
/*
* Applicable to Queues only. Active Consumer Count
*/
private IntegerField activeConsumerIF;
private LabelledComponent activeConsumerLabelC;
private SpecialValueField activeConsumerSF;
/*
* Applicable to Queues only. Failover Consumer Count
*/
private IntegerField failoverConsumerIF;
private LabelledComponent failoverConsumerLabelC;
private SpecialValueField failoverConsumerSF;
/*
* Applicable to Queues and Topics. Max Producer Count
*/
private IntegerField maxProducerIF;
private LabelledComponent maxProducerLabelC;
private SpecialValueField maxProducerSF;
/*
* Applicable to Queues and Topics. Components for supporting Queue Size Limit.
*/
private BytesField mesgSizeLimitBF;
private LabelledComponent mesgSizeLimitLabelC;
private SpecialValueField mesgSizeLimitSF;
/*
* Applicable to Queues and Topics. Components for supporting Queue Message Limit.
*/
IntegerField mesgLimitIF;
SpecialValueField mesgLimitSF;
private LabelledComponent mesgLimitLabelC;
/*
* Applicable to Queues and Topics. Components for supporting Destination Maximum Size per Message.
*/
BytesField maxSizePerMsgBF;
SpecialValueField maxSizePerMsgSF;
/*
* Applicable to Topics only. Durable Subscriptions related components.
*/
private PropsTableModel model;
private JTable table;
private JScrollPane scrollPane;
private JButton deleteButton, purgeButton;
/*
* Applicable to Queus and Topics. Limit behavior and use DMQ.
*/
private JComboBox limitBehaviorCb;
private JCheckBox useDMQCkb;
/*
* These should always contain the latest info sent from the broker before show().
*/
private DestinationInfo destInfo;
private Vector durables;
/*
* These are used to indicate which durable subscription is currently selected.
*/
private int selectedRow = -1;
private String selectedDurName = null;
private String selectedClientID = null;
private boolean resetScrollbarPolicy = true;
public BrokerDestPropsDialog(Frame parent) {
super(parent, acr.getString(acr.I_BROKER_DEST_PROPS), (OK | CANCEL | HELP));
setHelpId(ConsoleHelpID.BROKER_DEST_PROPS);
}
@Override
public void doClose() {
setVisible(false);
reset();
}
@Override
public void doReset() {
}
@Override
public void doClear() {
}
@Override
public void doCancel() {
setVisible(false);
}
@Override
public void doOK() {
BrokerAdminEvent bae = new BrokerAdminEvent(this, BrokerAdminEvent.UPDATE_DEST);
DestinationInfo destInfo = getUpdateDestinationInfo();
bae.setDestinationInfo(destInfo);
bae.setOKAction(true);
fireAdminEventDispatched(bae);
}
private DestinationInfo getUpdateDestinationInfo() {
int activeConsumers = -1;
int failoverConsumers = -1;
int maxProducers = -1;
long mesgSizeLimitValue = -1;
int mesgLimitValue = -1;
long maxSizePerMsgValue = -1;
boolean useDMQ;
int limitBehavior;
DestinationInfo updateDestInfo = new DestinationInfo();
/*
* We check if the value set in the GUI differs from the original value. It is set (and set to the broker) only if it is
* different. We do this to prevent sending across values for properties that did not change. In some cases, this is
* harmless. But for some (e.g. for the DMQ), updates to certain properties is not allowed and the old behavior will
* cause an error.
*/
if (DestType.isQueue(destInfo.type)) {
/*
* Max Active Consumers
*/
if (activeConsumerSF.isSpecialValueSet()) {
activeConsumers = UNLIMITED_VALUE_NEG1;
} else {
activeConsumers = Integer.parseInt(activeConsumerIF.getText());
}
if (activeConsumers != destInfo.maxActiveConsumers) {
updateDestInfo.setMaxActiveConsumers(activeConsumers);
}
/*
* Max Backup Consumers
*/
if (failoverConsumerSF.isSpecialValueSet()) {
failoverConsumers = UNLIMITED_VALUE_NEG1;
} else {
failoverConsumers = Integer.parseInt(failoverConsumerIF.getText());
}
if (failoverConsumers != destInfo.maxFailoverConsumers) {
updateDestInfo.setMaxFailoverConsumers(failoverConsumers);
}
}
/*
* Max Producers
*/
if (maxProducerSF.isSpecialValueSet()) {
maxProducers = UNLIMITED_VALUE_NEG1;
} else {
maxProducers = Integer.parseInt(maxProducerIF.getText());
}
if (maxProducers != destInfo.maxProducers) {
updateDestInfo.setMaxProducers(maxProducers);
}
/*
* Max Total Message Bytes
*/
if (mesgSizeLimitSF.isSpecialValueSet()) {
mesgSizeLimitValue = UNLIMITED_VALUE_NEG1;
} else {
mesgSizeLimitValue = mesgSizeLimitBF.getValue();
}
if (mesgSizeLimitValue != destInfo.maxMessageBytes) {
updateDestInfo.setMaxMessageBytes(mesgSizeLimitValue);
}
/*
* Max Number of Messages
*/
if (mesgLimitSF.isSpecialValueSet()) {
mesgLimitValue = UNLIMITED_VALUE_NEG1;
} else {
mesgLimitValue = Integer.parseInt(mesgLimitIF.getText());
}
if (mesgLimitValue != destInfo.maxMessages) {
updateDestInfo.setMaxMessages(mesgLimitValue);
}
/*
* Max Bytes per Messages
*/
if (maxSizePerMsgSF.isSpecialValueSet()) {
maxSizePerMsgValue = UNLIMITED_VALUE_NEG1;
} else {
maxSizePerMsgValue = maxSizePerMsgBF.getValue();
}
if (maxSizePerMsgValue != destInfo.maxMessageSize) {
updateDestInfo.setMaxMessageSize(maxSizePerMsgValue);
}
/*
* Limit behavior
*/
limitBehavior = getLimitBehavValue((String) limitBehaviorCb.getSelectedItem());
if (limitBehavior != destInfo.destLimitBehavior) {
updateDestInfo.setLimitBehavior(limitBehavior);
}
/*
* Use DMQ
*/
useDMQ = useDMQCkb.isSelected();
if (useDMQ != destInfo.useDMQ()) {
updateDestInfo.setUseDMQ(useDMQ);
}
return (updateDestInfo);
}
@Override
public JPanel createWorkPanel() {
JPanel workPanel;
workPanel = new JPanel();
tabbedPane = new JTabbedPane();
tabbedPane.addTab(acr.getString(acr.I_DEST_PROP_BASIC), makeBasicTab());
tabbedPane.addTab(acr.getString(acr.I_DEST_PROP_SUB), makeDurTab());
workPanel.add(tabbedPane);
return (workPanel);
}
private JPanel makeBasicTab() {
JPanel basicPanel;
GridBagLayout basicGridbag;
GridBagConstraints basicConstraints;
LabelledComponent tmpLabelC;
LabelledComponent lvpItems[];
LabelValuePanel lvp;
int i = 0;
basicPanel = new JPanel();
basicGridbag = new GridBagLayout();
basicConstraints = new GridBagConstraints();
basicPanel.setLayout(basicGridbag);
basicConstraints.gridx = 0;
basicConstraints.anchor = GridBagConstraints.WEST;
basicConstraints.fill = GridBagConstraints.NONE;
basicConstraints.insets = new Insets(10, 0, 10, 0);
basicConstraints.ipadx = 0;
basicConstraints.ipady = 0;
basicConstraints.weightx = 1.0;
/*
* Basic destination info: name, type, state
*/
lvpItems = new LabelledComponent[3];
destNameValue = new JLabel();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_NAME), destNameValue);
lvpItems[0] = tmpLabelC;
destTypeValue = new JLabel();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_TYPE), destTypeValue);
lvpItems[1] = tmpLabelC;
destStateValue = new JLabel();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_STATE) + ":", destStateValue);
lvpItems[2] = tmpLabelC;
basicConstraints.gridx = 0;
basicConstraints.gridy = 0;
lvp = new LabelValuePanel(lvpItems, 4, 3);
basicGridbag.setConstraints(lvp, basicConstraints);
basicPanel.add(lvp);
basicConstraints.gridx = 0;
basicConstraints.gridy = 1;
basicConstraints.insets = new Insets(0, 0, 0, 0);
basicConstraints.fill = GridBagConstraints.HORIZONTAL;
JSeparator separator = new JSeparator();
basicGridbag.setConstraints(separator, basicConstraints);
basicPanel.add(separator);
/*
* Reset
*/
basicConstraints.gridwidth = 1;
basicConstraints.fill = GridBagConstraints.NONE;
/*
* Current number or message size / bytes info
*/
lvpItems = new LabelledComponent[5];
curNumMesgsValue = new JLabel();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_NUM_MSGS), curNumMesgsValue);
lvpItems[i++] = tmpLabelC;
curNumMesgBytesValue = new JLabel();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_TTL_SIZE_MSGS), curNumMesgBytesValue, acr.getString(acr.I_BYTES));
lvpItems[i++] = tmpLabelC;
curNumProducers = new JLabel();
curNumProducersLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_DEST_NUM_PRODUCERS), curNumProducers);
lvpItems[i++] = curNumProducersLabelC;
curNumActive = new JLabel();
curNumActiveLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_CUR_NUM_ACTIVE), curNumActive);
lvpItems[i++] = curNumActiveLabelC;
curNumFailover = new JLabel();
curNumFailoverLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_CUR_NUM_FAILOVER), curNumFailover);
lvpItems[i++] = curNumFailoverLabelC;
basicConstraints.gridx = 0;
basicConstraints.gridy = 2;
basicConstraints.insets = new Insets(10, 0, 10, 0);
lvp = new LabelValuePanel(lvpItems, 4, 5);
basicGridbag.setConstraints(lvp, basicConstraints);
basicPanel.add(lvp);
basicConstraints.gridx = 0;
basicConstraints.gridy = 3;
basicConstraints.insets = new Insets(0, 0, 0, 0);
basicConstraints.fill = GridBagConstraints.HORIZONTAL;
separator = new JSeparator();
basicGridbag.setConstraints(separator, basicConstraints);
basicPanel.add(separator);
/*
* Reset
*/
basicConstraints.gridwidth = 1;
basicConstraints.fill = GridBagConstraints.NONE;
i = 0;
lvpItems = new LabelledComponent[6];
/*
* Queue message limit
*/
mesgLimitIF = new IntegerField(0, Integer.MAX_VALUE, 11);
mesgLimitSF = new SpecialValueField(mesgLimitIF, acr.getString(acr.I_BROKER_UNLIMITED));
mesgLimitLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_MAX_NUM_MSGS), mesgLimitSF, LabelledComponent.NORTH);
lvpItems[i++] = mesgLimitLabelC;
/*
* Queue size limit
*/
mesgSizeLimitBF = new BytesField(0, Long.MAX_VALUE, 11);
mesgSizeLimitSF = new SpecialValueField(mesgSizeLimitBF, acr.getString(acr.I_BROKER_UNLIMITED));
mesgSizeLimitLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_MAX_TTL_SIZE_MSGS), mesgSizeLimitSF, LabelledComponent.NORTH);
lvpItems[i++] = mesgSizeLimitLabelC;
/*
* Destination Maximum Size per Message
*/
maxSizePerMsgBF = new BytesField(0, Long.MAX_VALUE, 11);
maxSizePerMsgSF = new SpecialValueField(maxSizePerMsgBF, acr.getString(acr.I_BROKER_UNLIMITED));
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_MAX_SIZE_PER_MSG), maxSizePerMsgSF, LabelledComponent.NORTH);
lvpItems[i++] = tmpLabelC;
/*
* Max Producers
*/
maxProducerIF = new IntegerField(0, Integer.MAX_VALUE, 11);
maxProducerSF = new SpecialValueField(maxProducerIF, acr.getString(acr.I_BROKER_UNLIMITED));
maxProducerLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_MAX_PRODUCERS), maxProducerSF, LabelledComponent.NORTH);
lvpItems[i++] = maxProducerLabelC;
/*
* Active Consumers
*/
activeConsumerIF = new IntegerField(0, Integer.MAX_VALUE, 11);
activeConsumerSF = new SpecialValueField(activeConsumerIF, acr.getString(acr.I_BROKER_UNLIMITED));
activeConsumerLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_ACTIVE_CONSUMER), activeConsumerSF, LabelledComponent.NORTH);
lvpItems[i++] = activeConsumerLabelC;
/*
* Failover Consumers
*/
failoverConsumerIF = new IntegerField(0, Integer.MAX_VALUE, 11);
failoverConsumerSF = new SpecialValueField(failoverConsumerIF, acr.getString(acr.I_BROKER_UNLIMITED));
failoverConsumerLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_FAILOVER_CONSUMER), failoverConsumerSF, LabelledComponent.NORTH);
lvpItems[i++] = failoverConsumerLabelC;
lvp = new LabelValuePanel(lvpItems, 4, 5);
basicConstraints.gridx = 0;
basicConstraints.gridy = 4;
basicConstraints.insets = new Insets(10, 0, 10, 0);
basicGridbag.setConstraints(lvp, basicConstraints);
basicPanel.add(lvp);
basicConstraints.gridx = 0;
basicConstraints.gridy = 5;
basicConstraints.insets = new Insets(0, 0, 0, 0);
basicConstraints.fill = GridBagConstraints.HORIZONTAL;
separator = new JSeparator();
basicGridbag.setConstraints(separator, basicConstraints);
basicPanel.add(separator);
/*
* Reset
*/
basicConstraints.gridwidth = 1;
basicConstraints.fill = GridBagConstraints.NONE;
i = 0;
/*
* Limit Behavior, Use Dead Message Queue
*/
lvpItems = new LabelledComponent[2];
limitBehaviorCb = new JComboBox(BKR_LIMIT_BEHAV_VALID_VALUES.toArray(new String[BKR_LIMIT_BEHAV_VALID_VALUES.size()]));
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_LIMIT_BEHAVIOR), limitBehaviorCb);
lvpItems[i++] = tmpLabelC;
useDMQCkb = new JCheckBox();
tmpLabelC = new LabelledComponent(acr.getString(acr.I_BROKER_USE_DMQ), useDMQCkb);
lvpItems[i++] = tmpLabelC;
basicConstraints.gridx = 0;
basicConstraints.gridy = 6;
basicConstraints.insets = new Insets(10, 0, 10, 0);
lvp = new LabelValuePanel(lvpItems, 4, 2);
basicGridbag.setConstraints(lvp, basicConstraints);
basicPanel.add(lvp);
return (basicPanel);
}
private JPanel makeDurTab() {
JPanel durPanel;
JLabel tmpLabel;
GridBagLayout durGridbag;
GridBagConstraints durConstraints;
durPanel = new JPanel();
durGridbag = new GridBagLayout();
durConstraints = new GridBagConstraints();
durPanel.setLayout(durGridbag);
/*
* Calculations to determine the preferred width for the table.
*
* We use the length of the longest column header (as displayed in a JLabel) multiplied by the number of columns.
*/
int tmpWidth = 0, maxWidth = 0;
for (int i = 0; i < columnNames.length; ++i) {
tmpLabel = new JLabel(columnNames[i]);
tmpWidth = tmpLabel.getPreferredSize().width;
if (tmpWidth > maxWidth) {
maxWidth = tmpWidth;
}
}
int colWidth = maxWidth * columnNames.length;
model = new PropsTableModel();
table = new JTable(model);
// int w2 = table.getColumnModel().getTotalColumnWidth();
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel lsm = table.getSelectionModel();
lsm.addListSelectionListener(this);
/*
* Set vertical scrollbar policy to VERTICAL_SCROLLBAR_ALWAYS initially to workaround a layout problem which occurs when
* a scrollbar is actually needed.
*
* The policy is reset back to VERTICAL_SCROLLBAR_AS_NEEDED in show().
*/
scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
table.setPreferredScrollableViewportSize(new Dimension(colWidth, 21 * table.getRowHeight()));
durConstraints.gridx = 0;
durConstraints.gridy = 0;
durGridbag.setConstraints(scrollPane, durConstraints);
durPanel.add(scrollPane);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
deleteButton = new JButton(acr.getString(acr.I_DELETE));
deleteButton.setEnabled(false);
deleteButton.addActionListener(this);
buttonPanel.add(deleteButton);
purgeButton = new JButton(acr.getString(acr.I_PURGE));
purgeButton.setEnabled(false);
purgeButton.addActionListener(this);
buttonPanel.add(purgeButton);
durConstraints.gridx = 0;
durConstraints.gridy = 1;
durConstraints.anchor = GridBagConstraints.EAST;
durConstraints.insets = new Insets(0, 5, 0, 0);
durGridbag.setConstraints(buttonPanel, durConstraints);
durPanel.add(buttonPanel);
return (durPanel);
}
public void show(DestinationInfo destInfo, Vector durables) {
int value;
long lvalue;
String svalue;
Dimension d;
int prefWidth, totalWidth;
this.destInfo = destInfo;
this.durables = durables;
reset();
/*
* Enable/disable appropriate components.
*/
if (DestType.isQueue(destInfo.type)) {
/*
* Durable tab
*/
tabbedPane.setEnabledAt(1, false);
/*
* Enable Active/Failover Consumers for Queue
*/
setActiveConsumersEnabled(true);
setFailoverConsumersEnabled(true);
/*
* Enable Cur Number of Actve/Failover Consumers.
*/
curNumFailoverLabelC.setEnabled(true);
curNumFailover.setEnabled(true);
/*
* Populate the data into the Active/Failover fields.
*/
value = destInfo.maxActiveConsumers;
if (value != UNLIMITED_VALUE_NEG1) {
activeConsumerIF.setText(String.valueOf(value));
}
checkUnlimitedNeg1(activeConsumerSF, value);
value = destInfo.maxFailoverConsumers;
if (value != UNLIMITED_VALUE_NEG1) {
failoverConsumerIF.setText(String.valueOf(value));
}
checkUnlimitedNeg1(failoverConsumerSF, value);
curNumActiveLabelC.setLabelText(acr.getString(acr.I_BROKER_CUR_NUM_ACTIVE));
curNumActive.setText(String.valueOf(destInfo.naConsumers));
} else if (DestType.isTopic(destInfo.type)) {
/*
* Durable tab
*/
tabbedPane.setEnabledAt(1, true);
/*
* Disable Active/Failover Consumers for Topic
*/
setActiveConsumersEnabled(false);
setFailoverConsumersEnabled(false);
/*
* Disable Cur Number of Active/Failover Consumers.
*/
curNumFailoverLabelC.setEnabled(false);
curNumFailover.setEnabled(false);
curNumActiveLabelC.setLabelText(acr.getString(acr.I_BROKER_CUR_NUM_CONSUMERS));
curNumActive.setText(String.valueOf(destInfo.nConsumers));
}
/*
* Populate fields with more information
*/
/*
* Basic destination info (dest name, dest type, dest state)
*/
destNameValue.setText(destInfo.name);
destTypeValue.setText(BrokerAdminUtil.getDestinationType(destInfo.type));
// destStateValue.setText(DestState.toString(destInfo.destState));
destStateValue.setText(BrokerAdminUtil.getDestinationState(destInfo.destState));
/*
* Current destination info.
*/
curNumProducers.setText(String.valueOf(destInfo.nProducers));
curNumFailover.setText(String.valueOf(destInfo.nfConsumers));
curNumMesgsValue.setText(String.valueOf(destInfo.nMessages));
curNumMesgBytesValue.setText(String.valueOf(destInfo.nMessageBytes));
/*
* Max info.
*/
value = destInfo.maxProducers;
if (value != UNLIMITED_VALUE_NEG1) {
maxProducerIF.setText(String.valueOf(value));
}
checkUnlimitedNeg1(maxProducerSF, value);
lvalue = destInfo.maxMessageBytes;
if (lvalue != UNLIMITED_VALUE_NEG1) {
mesgSizeLimitBF.setText(String.valueOf(lvalue));
}
checkBothUnlimited(mesgSizeLimitSF, lvalue);
value = destInfo.maxMessages;
if (value != UNLIMITED_VALUE_NEG1) {
mesgLimitIF.setText(String.valueOf(value));
}
checkBothUnlimited(mesgLimitSF, value);
/*
* Max size per msg - applicable to both queues and topics.
*/
lvalue = destInfo.maxMessageSize;
if (lvalue != UNLIMITED_VALUE_NEG1) {
maxSizePerMsgBF.setText(String.valueOf(lvalue));
}
checkBothUnlimited(maxSizePerMsgSF, lvalue);
/*
* Limit behavior
*/
svalue = DestLimitBehavior.getString(destInfo.destLimitBehavior);
limitBehaviorCb.setSelectedItem(svalue);
/*
* Use DMQ
*/
if (destInfo.useDMQ()) {
useDMQCkb.setSelected(true);
} else {
useDMQCkb.setSelected(false);
}
/*
* Durable subscriptions info.
*/
if (DestType.isTopic(destInfo.type)) {
// Columns of the table are intact
model.fireTableDataChanged();
clearSelection();
}
/*
* Reset the vertical scrollbar policy back to VERTICAL_SCROLLBAR_AS_NEEDED. This is to workaround the bug where if it
* was initially VERTICAL_SCROLLBAR_AS_NEEDED and later a scrollbar was* needed. The extra width needed would cause some
* layout problems.
*
* By forcing the scrollbar to be on always initially, we 'claim' the space needed later for when a scrollbar is needed.
* At least it appears to work that way.
*/
if (resetScrollbarPolicy) {
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
resetScrollbarPolicy = false;
}
/*
* Resize the viewable area of table in the scrollpane. This is to workaround the case where the collumn headers are
* really narrow e.g. one letter names.
*
* If such names are used, the calculations done in makeDurTab() produce widths that don't appear to be wide enough.
* Also, table.getColumnModel().getTotalColumnWidth() will return a 'satisfactory' width only after the table/scrollpane
* has been fully inserted into the instance hierarchy - not the case in makeDurTab().
*/
d = table.getPreferredScrollableViewportSize();
prefWidth = d.width;
totalWidth = table.getColumnModel().getTotalColumnWidth();
if (prefWidth < totalWidth) {
d.width = totalWidth;
table.setPreferredScrollableViewportSize(d);
}
setVisible(true);
}
public void refresh(Vector durables) {
this.durables = durables;
model.fireTableChanged(new TableModelEvent(model));
clearSelection();
}
private void setActiveConsumersEnabled(boolean enable) {
activeConsumerLabelC.setEnabled(enable);
activeConsumerSF.setSpecialValueSet(enable);
activeConsumerIF.setEnabled(enable);
}
private void setFailoverConsumersEnabled(boolean enable) {
failoverConsumerLabelC.setEnabled(enable);
failoverConsumerSF.setSpecialValueSet(enable);
failoverConsumerIF.setEnabled(enable);
}
private void reset() {
destNameValue.setText("");
destTypeValue.setText("");
destStateValue.setText("");
curNumActive.setText("");
curNumFailover.setText("");
curNumMesgsValue.setText("");
curNumMesgBytesValue.setText("");
activeConsumerSF.setEnabled(true);
activeConsumerSF.setSpecialValueSet(true);
activeConsumerIF.setText("0");
failoverConsumerSF.setEnabled(true);
failoverConsumerSF.setSpecialValueSet(true);
failoverConsumerIF.setText("0");
mesgSizeLimitSF.setEnabled(true);
mesgSizeLimitSF.setSpecialValueSet(true);
mesgSizeLimitBF.setText("0");
mesgSizeLimitBF.setUnit(BytesField.BYTES);
mesgLimitSF.setEnabled(true);
mesgLimitSF.setSpecialValueSet(true);
mesgLimitIF.setText("0");
maxSizePerMsgSF.setEnabled(true);
maxSizePerMsgSF.setSpecialValueSet(true);
maxSizePerMsgBF.setText("0");
maxSizePerMsgBF.setUnit(BytesField.BYTES);
limitBehaviorCb.setSelectedItem(BKR_LIMIT_BEHAV_VALID_VALUES.get(0));
useDMQCkb.setSelected(true);
clearSelection();
deleteButton.setEnabled(false);
purgeButton.setEnabled(false);
tabbedPane.setSelectedIndex(0);
}
private void clearSelection() {
if (table != null) {
table.clearSelection();
}
/*
* Disable delete, purge button.
*/
deleteButton.setEnabled(false);
purgeButton.setEnabled(false);
/*
* Reset selected row.
*/
selectedRow = -1;
selectedDurName = null;
selectedClientID = null;
}
private void doDelete() {
if ((selectedRow > -1) && (selectedDurName != null) && (selectedClientID != null)) {
/*
* Dispatch the admin event.
*/
BrokerAdminEvent bae = new BrokerAdminEvent(this, BrokerAdminEvent.DELETE_DUR);
bae.setDurableName(selectedDurName);
bae.setClientID(selectedClientID);
bae.setOKAction(false);
fireAdminEventDispatched(bae);
}
}
private void doPurge() {
if ((selectedRow > -1) && (selectedDurName != null) && (selectedClientID != null)) {
/*
* Dispatch the admin event.
*/
BrokerAdminEvent bae = new BrokerAdminEvent(this, BrokerAdminEvent.PURGE_DUR);
bae.setDurableName(selectedDurName);
bae.setClientID(selectedClientID);
bae.setOKAction(false);
fireAdminEventDispatched(bae);
}
}
/*
* BEGIN INTERFACE ActionListener
*/
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == deleteButton) {
doDelete();
} else if (source == purgeButton) {
doPurge();
} else {
super.actionPerformed(e);
}
}
/*
* END INTERFACE ActionListener
*/
/*
* private void checkUnlimited0(SpecialValueField sf, long val) { if (valueIsUnlimited0(val)) {
* sf.setSpecialValueSet(true); } else { sf.setSpecialValueSet(false); } }
*/
private void checkUnlimitedNeg1(SpecialValueField sf, long val) {
if (valueIsUnlimitedNeg1(val)) {
sf.setSpecialValueSet(true);
} else {
sf.setSpecialValueSet(false);
}
}
/*
* Checks for both 0 and -1 values if unlimited.
*/
private void checkBothUnlimited(SpecialValueField sf, long val) {
if (valueIsUnlimited0(val) || valueIsUnlimitedNeg1(val)) {
sf.setSpecialValueSet(true);
} else {
sf.setSpecialValueSet(false);
}
}
private boolean valueIsUnlimited0(long val) {
if (val == UNLIMITED_VALUE_0) {
return (true);
}
return (false);
}
private boolean valueIsUnlimitedNeg1(long val) {
if (val == UNLIMITED_VALUE_NEG1) {
return (true);
}
return (false);
}
/*
* BEGIN INTERFACE ListSelectionListener
*/
@Override
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
boolean isAdjusting = e.getValueIsAdjusting();
if (isAdjusting) {
if (lsm.isSelectionEmpty()) {
deleteButton.setEnabled(false);
purgeButton.setEnabled(false);
} else {
selectedRow = lsm.getMinSelectionIndex();
selectedDurName = (String) model.getValueAt(selectedRow, 0);
selectedClientID = (String) model.getValueAt(selectedRow, 1);
}
}
String durable = (String) model.getValueAt(selectedRow, 2);
if (durable != null && durable.trim().toLowerCase().equals("true")) {
deleteButton.setEnabled(true);
purgeButton.setEnabled(true);
} else {
deleteButton.setEnabled(false);
purgeButton.setEnabled(false);
}
}
/*
* END INTERFACE ListSelectionListener
*/
class PropsTableModel extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 900570854004520103L;
/**
* Returns the number of collumns in table.
*
* @return The number of collumns in table.
*/
@Override
public int getColumnCount() {