-
Notifications
You must be signed in to change notification settings - Fork 33
/
PacketReference.java
2740 lines (2369 loc) · 91.4 KB
/
PacketReference.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, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 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.jmsserver.core;
import java.util.*;
import java.lang.ref.*;
import java.io.*;
import java.util.concurrent.ConcurrentHashMap;
import com.sun.messaging.jmq.io.*;
import com.sun.messaging.jmq.jmsserver.Globals;
import com.sun.messaging.jmq.jmsserver.DMQ;
import com.sun.messaging.jmq.jmsserver.resources.BrokerResources;
import com.sun.messaging.jmq.jmsserver.data.TransactionUID;
import com.sun.messaging.jmq.jmsserver.data.TransactionState;
import com.sun.messaging.jmq.jmsserver.data.TransactionList;
import com.sun.messaging.jmq.jmsserver.data.TransactionBroker;
import com.sun.messaging.jmq.jmsserver.service.ConnectionUID;
import com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection;
import com.sun.messaging.jmq.jmsserver.util.*;
import com.sun.messaging.jmq.jmsserver.persist.api.Store;
import com.sun.messaging.jmq.jmsserver.persist.api.PartitionedStore;
import com.sun.messaging.jmq.jmsserver.service.Connection;
import com.sun.messaging.jmq.util.DestType;
import com.sun.messaging.jmq.util.ServiceType;
import com.sun.messaging.jmq.util.lists.*;
import com.sun.messaging.jmq.util.UID;
import com.sun.messaging.jmq.util.log.Logger;
import com.sun.messaging.jmq.jmsserver.cluster.api.ClusterBroadcast;
import com.sun.messaging.jmq.jmsserver.memory.MemoryGlobals;
import com.sun.messaging.jmq.jmsserver.FaultInjection;
/**
* This class contains the references for a packet which is passed around the system.
*
* An optimization of this class would allow messages to be retrieved from the persistent store (if they are persistent)
*
*/
public class PacketReference implements Sized, Ordered {
private static FaultInjection FI = FaultInjection.getInjection();
private static ConsumerUID queueUID = null;
/**
* Controls if we should enable the fix for bug 6196233 and prepend the message ID with "ID:"
*/
private static boolean PREPEND_ID = Globals.getConfig().getBooleanProperty(Globals.IMQ + ".fix.JMSMessageID", false);
private boolean commit2pwait = Globals.getConfig().getBooleanProperty(Globals.IMQ + ".cluster.2pcommitAckWaitReply", false);
static {
queueUID = new ConsumerUID(true /* empty */);
queueUID.setShouldStore(true);
}
private static boolean DEBUG = false;
private static boolean DEBUG_CLUSTER_TXN = Globals.getConfig().getBooleanProperty(Globals.IMQ + ".cluster.debug.txn") || DEBUG;
/**
* set once store() is called
*/
private boolean isStored = false;
private boolean neverStore = false;
/**
* ets once store + interests are saved
*/
private boolean isStoredWithInterest = false;
/**
* has packet been destroyed
*/
private boolean destroyed = false;
/**
* message id for the packet
*/
private SysMessageID msgid;
ConnectionUID con_uid;
/**
* time the packet reference was created (entered the system)
*/
private long creationtime;
/**
* time the packet reference was last accessed
*/
private long lastaccesstime;
/**
* sequence # (used for sorting queue browsers)
*/
private int sequence;
/**
* if the message is persisted
*/
private boolean persist;
/**
* determines if the message should remain even if its expired (if the lbit count is > 0)
*/
private Set lbit_set = null;
/**
* size of the packet data
*/
private long size;
/**
* message properties (null if swapped)
*/
private Hashtable props;
private HashMap headers;
/**
* original packet or SoftReference (null if swapped)
*/
private Object pktPtr;
/**
* priority of the packet
*/
private int priority = 4;
/**
* isQueue setting
*/
boolean isQueue = false;
/**
* flag called when a packet "should" be removed but is is remaining in memory (because the lbit is set on the packet
*/
boolean invalid = false;
/**
* For remote message reference and its replacement ref only
*/
boolean overrided = false;
Object lockObject = new Object();
boolean canLock = false;
boolean locked = false;
boolean overriding = false;
Thread lockOwner = null;
private Object destroyRemoteLock = new Object();
private List<Thread> destroyRemoteReadLocks = new ArrayList<>();
private Thread destroyRemoteWriteLockThread = null;
/**
* destination uid
*/
DestinationUID destination = null;
private ExpirationInfo expireInfo = null;
private boolean expired = false;
MessageDeliveryTimeInfo deliveryTimeInfo = null;
/**
* timestamp on the packet (for sorting)
*/
long timestamp = 0;
/**
* transaction id
*/
TransactionUID transactionid;
/**
* override redeliver
*/
boolean overrideRedeliver = false;
BrokerAddress addr = null;
Destination d = null;
String clientID = null;
int interestCnt;
int deliveredCnt;
int ackCnt;
int deadCnt;
Map ackInfo = null;
private static final int INITIAL = 0;
private static final int ROUTED = 1;
private static final int DELIVERED = 2;
private static final int CONSUMED = 3;
private static final int ACKED = 4;
private static final int DEAD = 5;
/**
* Indicates if this message is in delivery or has been delivered to client
*/
Map inDelivery = new ConcurrentHashMap();
/**
* true if the message is to be removed and need to be prevented delivering to client
*/
boolean inRemoval = false;
boolean inReplacing = false;
ConsumerUID lastDead = null;
private PartitionedStore pstore = null;
static {
if (Globals.getLogger().getLevel() <= Logger.DEBUG) {
DEBUG = true;
}
}
public PartitionedStore getPartitionedStore() {
return pstore;
}
Object order = null;
@Override
public Object getOrder() {
return order;
}
@Override
public void setOrder(Object o) {
this.order = o;
}
static class ConsumerMessagePair {
private ConsumerUID uid;
private int state = INITIAL;
private int redeliverCnt = 0;
private boolean stored;
private String deadComment = null;
private Reason deadReason = null;
private Throwable deadException = null;
private long timestamp = 0;
private String deadBroker = null;
ConsumerMessagePair(ConsumerUID uid, boolean stored) {
this.uid = uid;
this.stored = stored;
}
public synchronized int setRedeliver(int n) {
redeliverCnt = n;
return redeliverCnt;
}
public synchronized int incrementRedeliver() {
redeliverCnt++;
return redeliverCnt;
}
public synchronized int incrementRedeliver(int n) {
redeliverCnt += n;
return redeliverCnt;
}
public synchronized int decrementRedeliver() {
redeliverCnt--;
return redeliverCnt;
}
public synchronized boolean setState(int state) {
if (this.state == state) {
return false;
}
this.state = state;
timestamp = System.currentTimeMillis();
return true;
}
public synchronized int getState() {
return state;
}
public synchronized boolean compareAndSetState(int state, int expected) {
if (this.state != expected) {
return false;
}
timestamp = System.currentTimeMillis();
this.state = state;
return true;
}
public synchronized boolean compareState(int expected) {
return this.state == expected;
}
public synchronized boolean compareStateGT(int expected) {
return this.state > expected;
}
public synchronized boolean compareStateLT(int expected) {
return this.state < expected;
}
public synchronized boolean setStateIfLess(int state, int max) {
if (compareStateLT(max)) {
return setState(state);
}
return false;
}
public boolean isStored() {
return stored;
}
public int getRedeliverCount() {
return redeliverCnt;
}
public void setRedeliverCount(int cnt) {
redeliverCnt = cnt;
}
public void setDeadComment(String str) {
deadComment = str;
}
public void setDeadReason(Reason r) {
deadReason = r;
}
public String getDeadComment() {
return deadComment;
}
public Reason getDeadReason() {
return deadReason;
}
public Throwable getDeadException() {
return deadException;
}
public void setDeadException(Throwable thr) {
deadException = thr;
}
public void setDeadBroker(String bkr) {
deadBroker = bkr;
}
public String getDeadBroker() {
return deadBroker;
}
@Override
public String toString() {
return ": CMPair[" + uid.longValue() + ":" + stateToString(state) + ":" + stored + "] - " + timestamp;
}
}
public static ConsumerUID getQueueUID() {
return queueUID;
}
public static PacketReference createReferenceWithDestination(PartitionedStore ps, Packet p, Destination dest, Connection con) throws BrokerException {
PacketReference ref = createReference(ps, p, dest.getDestinationUID(), con);
if (dest.isDMQ()) {
ref.clearDeliveryTimeInfo();
}
return ref;
}
public static PacketReference createReference(PartitionedStore ps, Packet p, DestinationUID duid, Connection con) throws BrokerException {
PacketReference pr = new PacketReference(ps, p, duid, con);
if (con != null && (pr.getExpireInfo() != null || pr.getDeliveryTimeInfo() != null)) {
con.checkClockSkew(pr.getTime(), pr.getTimestamp(), pr.getExpireTime(), pr.getDeliveryTime());
}
return pr;
}
public static PacketReference createReference(PartitionedStore ps, Packet p, Connection con) throws BrokerException {
return createReference(ps, p, (DestinationUID) null, con);
}
public static void moveMessage(PartitionedStore storep, PacketReference oldLoc, PacketReference newLoc, Set targets) throws BrokerException, IOException {
if (targets == null) {
// get from the original message
throw new RuntimeException("Internal error: moving message" + " to null targets not supported");
}
if (!oldLoc.isStored && oldLoc.persist) {
newLoc.store(targets);
return;
}
ReturnInfo info = calculateConsumerInfo(targets, oldLoc.persist);
newLoc.ackInfo = info.ackInfo;
newLoc.ackCnt = info.ackInfo.size();
if (info.uids == null || info.uids.length == 0) {
// nothing to store XXXremove old?
newLoc.neverStore = true;
newLoc.isStored = false;
newLoc.isStoredWithInterest = false;
return;
}
if (oldLoc.isStored && oldLoc.persist && !oldLoc.neverStore) {
storep.moveMessage(newLoc.getPacket(), oldLoc.getDestinationUID(), newLoc.getDestinationUID(), info.uids, info.states, Destination.PERSIST_SYNC);
newLoc.isStored = true;
newLoc.isStoredWithInterest = true;
oldLoc.isStored = false;
oldLoc.isStoredWithInterest = false;
} else if (oldLoc.persist) {
storep.storeMessage(newLoc.getDestinationUID(), newLoc.getPacket(), info.uids, info.states, Destination.PERSIST_SYNC);
newLoc.isStored = true;
newLoc.isStoredWithInterest = true;
newLoc.neverStore = false;
} else {
newLoc.isStored = false;
newLoc.isStoredWithInterest = false;
newLoc.neverStore = true;
}
return;
}
static class ReturnInfo {
ConsumerUID uids[];
int states[];
int interestCnt;
Map ackInfo;
}
// LKS- BUG SOMEWHERE BELOW
/*
* this method is called when a set of consumers are being routed
*/
private static ReturnInfo calculateConsumerInfo(Collection consumers, boolean checkStored) {
if (consumers.isEmpty()) {
return null;
}
ReturnInfo ri = new ReturnInfo();
ri.ackInfo = Collections.synchronizedMap(new HashMap());
ArrayList storedConsumers = (checkStored ? new ArrayList() : null);
Iterator itr = consumers.iterator();
while (itr.hasNext()) {
Object o = itr.next();
ConsumerUID cuid = null;
if (o instanceof Consumer) {
cuid = ((Consumer) o).getStoredConsumerUID();
} else {
cuid = (ConsumerUID) o;
}
ri.interestCnt++;
boolean store = false;
if (storedConsumers != null && cuid.shouldStore()) {
storedConsumers.add(cuid);
store = true;
}
ConsumerMessagePair cmp = new ConsumerMessagePair(cuid, store);
ri.ackInfo.put(cuid, cmp);
}
if (storedConsumers != null) {
ConsumerUID[] type = new ConsumerUID[0];
ri.uids = (ConsumerUID[]) storedConsumers.toArray(type);
ri.states = new int[ri.uids.length];
for (int i = 0; i < ri.states.length; i++) {
ri.states[i] = PartitionedStore.INTEREST_STATE_ROUTED;
}
}
return ri;
}
/**
* create a new PacketReference object
*/
private PacketReference(PartitionedStore ps, Packet pkt, DestinationUID duid, Connection con) throws BrokerException {
this.pstore = ps;
this.creationtime = System.currentTimeMillis();
this.lastaccesstime = creationtime;
this.msgid = (SysMessageID) pkt.getSysMessageID().clone();
this.isQueue = pkt.getIsQueue();
this.persist = pkt.getPersistent();
this.priority = pkt.getPriority();
this.sequence = pkt.getSequence();
this.timestamp = pkt.getTimestamp();
if (pkt.getRedelivered()) {
overrideRedeliver = true;
}
if (con != null) {
this.clientID = (String) con.getClientData(IMQConnection.CLIENT_ID);
}
setExpireTime(pkt.getExpiration());
this.size = pkt.getPacketSize();
String d = pkt.getDestination();
this.con_uid = (con == null ? null : con.getConnectionUID());
if (duid != null) {
destination = duid;
} else {
destination = DestinationUID.getUID(d, isQueue);
}
long tid = pkt.getTransactionID();
synchronized (this) {
setPacketObject(false, pkt);
}
if (tid != 0) {
transactionid = new TransactionUID(tid);
} else {
transactionid = null;
}
setDeliveryTime(pkt.getDeliveryTime());
}
public void setSequence(int seq) {
this.sequence = seq;
}
public String getClientID() {
return clientID;
}
private ConsumerMessagePair getAck(Object obj) {
ConsumerUID cuid = null;
if (obj instanceof ConsumerUID) {
cuid = (ConsumerUID) obj;
} else if (obj instanceof Consumer) {
cuid = ((Consumer) obj).getConsumerUID();
} else {
throw new RuntimeException("Bogus ID");
}
if (ackInfo == null) {
throw new RuntimeException("No AckInfo for message " + getSysMessageID());
}
return (ConsumerMessagePair) ackInfo.get(cuid);
}
/**
* If this method returns, caller is resposible to call postAcnkowledgedRemoval()
*/
protected boolean removeConsumerForDeliveryDelayed(Consumer c) {
if (ackInfo == null) {
return false;
}
// ConsumerUID cuid = c.getConsumerUID();
ConsumerUID suid = c.getStoredConsumerUID();
ConsumerMessagePair cmp = (ConsumerMessagePair) ackInfo.get(suid);
if (cmp == null) {
return false;
}
ackInfo.remove(suid);
boolean rm = false;
synchronized (this) {
interestCnt--;
rm = (interestCnt == 0);
}
if (!isLocal() && rm) {
acquireDestroyRemoteReadLock();
synchronized (this) {
rm = (interestCnt == 0);
}
if (!rm) {
clearDestroyRemoteReadLock();
}
}
return rm;
}
protected Collection getAllConsumerUIDForDeliveryDelayed() {
return ackInfo.keySet();
}
/*
* -------------------------------------------------------------------
*
* ACCESS METHODS
*
* --------------------------------------------------------------------
*/
public void setDestination(Destination d) {
this.d = d;
}
public Destination getDestination() {
if (d == null) {
Destination[] ds = Globals.getDestinationList().getDestination(pstore, destination);
d = ds[0];
if (d != null && d.isDMQ()) {
clearDeliveryTimeInfo();
}
}
return d;
}
public boolean isStored() {
return isStored;
}
public void setBrokerAddress(BrokerAddress a) {
addr = a;
if (!isLocal()) {
clearDeliveryTimeInfo();
}
}
public BrokerAddress getBrokerAddress() {
return addr;
}
public boolean isLocal() {
return addr == null || addr == Globals.getMyAddress();
}
@Override
public String toString() {
return "PacketReference[" + msgid + "]";
}
Set deliveredMsgAcks = new HashSet();
public synchronized boolean getMessageDeliveredAck(ConsumerUID uid) {
return !deliveredMsgAcks.isEmpty() && deliveredMsgAcks.contains(uid);
}
public synchronized ConsumerUID[] getConsumersForMsgDelivered() {
return (ConsumerUID[]) deliveredMsgAcks.toArray(new ConsumerUID[deliveredMsgAcks.size()]);
}
public synchronized void removeMessageDeliveredAck(ConsumerUID uid) {
deliveredMsgAcks.remove(uid);
}
public synchronized void addMessageDeliveredAck(ConsumerUID uid) {
deliveredMsgAcks.add(uid);
}
LinkedHashMap<ConsumerUID, LinkedHashMap<ConsumerUID, ConnectionUID>> remoteConsumerUIDs = new LinkedHashMap<>();
/**
* At least destroyRemoteLock reader lock is required to call this method
*/
private void addRemoteConsumerUID(ConsumerUID suid, ConsumerUID cuid, ConnectionUID connuid) {
synchronized (remoteConsumerUIDs) {
LinkedHashMap<ConsumerUID, ConnectionUID> m = remoteConsumerUIDs.get(suid);
if (m == null) {
m = new LinkedHashMap<>();
remoteConsumerUIDs.put(suid, m);
}
m.put(cuid, connuid);
}
}
public void removeRemoteConsumerUID(ConsumerUID suid, ConsumerUID cuid) {
acquireDestroyRemoteReadLock();
try {
synchronized (remoteConsumerUIDs) {
LinkedHashMap<ConsumerUID, ConnectionUID> m = remoteConsumerUIDs.get(suid);
if (m != null) {
m.remove(cuid);
if (m.isEmpty()) {
remoteConsumerUIDs.remove(suid);
}
}
}
} finally {
clearDestroyRemoteReadLock();
}
}
/**
* Caller must ensure isLocal false to call this method
*/
public boolean isNoAckRemoteConsumers() {
acquireDestroyRemoteReadLock();
try {
Iterator<Map.Entry<ConsumerUID, LinkedHashMap<ConsumerUID, ConnectionUID>>> itr = null;
Map.Entry<ConsumerUID, LinkedHashMap<ConsumerUID, ConnectionUID>> pair = null;
LinkedHashMap<ConsumerUID, ConnectionUID> m = null;
Iterator<ConsumerUID> itr1 = null;
ConsumerUID cuid = null, suid = null;
synchronized (remoteConsumerUIDs) {
itr = remoteConsumerUIDs.entrySet().iterator();
while (itr.hasNext()) {
pair = itr.next();
suid = pair.getKey();
m = pair.getValue();
if (m == null || m.isEmpty()) {
continue;
}
try {
if (isAcknowledged(suid)) {
continue;
}
} catch (Exception e) {
continue;
}
itr1 = m.keySet().iterator();
while (itr1.hasNext()) {
cuid = itr1.next();
if (!cuid.isNoAck()) {
return false;
}
}
}
}
return true;
} finally {
clearDestroyRemoteReadLock();
}
}
/**
* At least destroyRemoteLock reader lock is required to call this method
*/
public boolean isLastRemoteConsumerUID(ConsumerUID suid, ConsumerUID cuid) {
ConsumerUID lastuid = null;
synchronized (remoteConsumerUIDs) {
LinkedHashMap<ConsumerUID, ConnectionUID> m = remoteConsumerUIDs.get(suid);
if (DEBUG) {
Globals.getLogger().log(Logger.INFO,
"PacketReference.isLastRemoteConsumerUID(" + suid + ", " + cuid + "): " + m + ", ref@" + this.hashCode() + "=" + this);
}
if (m == null) {
return true;
}
Iterator<ConsumerUID> itr = m.keySet().iterator();
while (itr.hasNext()) {
lastuid = itr.next();
if (DEBUG) {
Globals.getLogger().log(Logger.INFO, "PacketReference.isLastRemoteConsumerUID(" + suid + ", " + cuid + "): lastuid=" + lastuid + ", ref@"
+ this.hashCode() + "=" + this);
}
}
return (lastuid == null || lastuid.equals(cuid));
}
}
public Map<ConsumerUID, ConnectionUID> getRemoteConsumerUIDs() {
LinkedHashMap<ConsumerUID, ConnectionUID> allm = new LinkedHashMap<>();
synchronized (remoteConsumerUIDs) {
Iterator<LinkedHashMap<ConsumerUID, ConnectionUID>> itr = remoteConsumerUIDs.values().iterator();
LinkedHashMap<ConsumerUID, ConnectionUID> m = null;
while (itr.hasNext()) {
m = itr.next();
if (m != null && !m.isEmpty()) {
allm.putAll(m);
}
}
}
return allm;
}
private void setExpireTime(long time) {
if (time == 0) {
expireInfo = null;
} else {
expireInfo = new ExpirationInfo(msgid, time);
}
}
public long getExpireTime() {
if (expireInfo == null) {
return 0L;
}
return expireInfo.getExpireTime();
}
public ExpirationInfo getExpireInfo() {
return expireInfo;
}
private void setDeliveryTime(long time) {
if (time == 0L) {
deliveryTimeInfo = null;
} else {
deliveryTimeInfo = new MessageDeliveryTimeInfo(msgid, time);
}
}
public long getDeliveryTime() {
if (deliveryTimeInfo == null) {
return 0L;
}
return deliveryTimeInfo.getDeliveryTime();
}
public boolean isDeliveryDue() {
if (deliveryTimeInfo == null) {
return true;
}
return deliveryTimeInfo.isDeliveryDue();
}
public MessageDeliveryTimeInfo getDeliveryTimeInfo() {
getDestination();
return deliveryTimeInfo;
}
public void overrided() {
overrided = true;
}
public boolean isOverrided() {
return overrided;
}
public void overriding() {
overriding = true;
}
public boolean isOverriding() {
return overriding;
}
/**
* only called by the ref creator before put into MT access
*/
public void lock() {
canLock = true;
locked = true;
lockOwner = Thread.currentThread();
}
public void unlock() {
synchronized (lockObject) {
locked = false;
lockOwner = null;
lockObject.notifyAll();
}
}
public PacketReference checkLock(boolean wait) {
if (!canLock) {
return this;
}
synchronized (lockObject) {
if (locked && (lockOwner != null && Thread.currentThread() == lockOwner)) {
return this;
}
while (wait && locked) {
Globals.getLogger().log(Logger.INFO, "Wait for reference : " + this);
try {
lockObject.wait(5000);
} catch (InterruptedException e) {
}
}
if (locked) {
return null;
}
}
return this;
}
public void setInvalid() {
invalid = true;
}
private Packet getPacketObject() {
assert (pktPtr == null || pktPtr instanceof SoftReference || pktPtr instanceof Packet) : pktPtr;
Object ptr = pktPtr;
if (ptr == null) {
return null;
}
if (ptr instanceof SoftReference) {
return (Packet) ((SoftReference) pktPtr).get();
}
return (Packet) pktPtr;
}
private void setPacketObject(boolean soft, Packet p) {
assert Thread.holdsLock(this);
if (soft) {
pktPtr = new SoftReference(p);
} else {
pktPtr = p;
}
}
private void makePacketSoftRef() {
assert Thread.holdsLock(this);
Object ptr = pktPtr;
if (ptr instanceof Packet) {
pktPtr = new SoftReference(ptr);
}
}
public void setNeverStore(boolean s) {
neverStore = s;
}
public boolean getNeverStore() {
return neverStore;
}
@Override
public long byteSize() {
return size;
}
public void setStoredWithInterest(boolean withInterest) {
isStoredWithInterest = withInterest;
}
public synchronized void setLoaded() {
isStored = true;
makePacketSoftRef();
}
public ConnectionUID getProducingConnectionUID() {
return con_uid;
}
public int getPriority() {
return priority;
}
public TransactionUID getTransactionID() {
return transactionid;
}
public boolean getIsQueue() {
return this.isQueue;
}
public long getTime() {
return creationtime;
}
public long getSequence() {
return sequence;
}
/** @throws IllegalStateException */
public synchronized void setLastBit(ConsumerUID id) {
if (isInvalid() && isDestroyed()) {
throw new IllegalStateException(Globals.getBrokerResources().getString(BrokerResources.X_INTERNAL_EXCEPTION, "reference has been destroyed"));
}
if (lbit_set == null) {
lbit_set = new HashSet();
}
lbit_set.add(id);
}
public Hashtable getDebugState() {
Hashtable ht = new Hashtable();
ht.put("AckCount", String.valueOf(ackCnt));
ht.put("DeadCount", String.valueOf(deadCnt));
ht.put("ackInfo[#]", String.valueOf(ackInfo.size()));
ht.put("interestCount", String.valueOf(interestCnt));
ht.put("inRemoval", Boolean.valueOf(inRemoval));
ht.put("inReplacing", Boolean.valueOf(inReplacing));
Vector vt = new Vector();
List l = null;
synchronized (this) {
ht.put("inDeliverySize", String.valueOf(inDelivery.size()));
l = new ArrayList(inDelivery.keySet());
}
Iterator itr = l.iterator();
while (itr.hasNext()) {
vt.add(itr.next());
}
ht.put("InDelivery", vt);
vt = new Vector();
ConsumerMessagePair cmp = null;
synchronized (ackInfo) {
itr = ackInfo.keySet().iterator();
while (itr.hasNext()) {
Object key = itr.next();
try {
cmp = getAck(key);
} catch (Exception e) {