1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.sun.jini.mahalo;
21
22 import java.io.Serializable;
23 import java.rmi.RemoteException;
24 import java.util.Date;
25 import java.util.Enumeration;
26 import java.util.List;
27 import java.util.Vector;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
30
31 import net.jini.core.transaction.CannotAbortException;
32 import net.jini.core.transaction.CannotCommitException;
33 import net.jini.core.transaction.CannotJoinException;
34 import net.jini.core.transaction.TimeoutExpiredException;
35 import net.jini.core.transaction.Transaction;
36 import net.jini.core.transaction.TransactionException;
37 import net.jini.core.transaction.server.CrashCountException;
38 import net.jini.core.transaction.server.ServerTransaction;
39 import net.jini.core.transaction.server.TransactionConstants;
40 import net.jini.core.transaction.server.TransactionManager;
41 import net.jini.core.transaction.server.TransactionParticipant;
42 import net.jini.id.Uuid;
43 import net.jini.security.ProxyPreparer;
44
45 import com.sun.jini.constants.TimeConstants;
46 import com.sun.jini.constants.TxnConstants;
47 import com.sun.jini.landlord.LeasedResource;
48 import com.sun.jini.logging.Levels;
49 import com.sun.jini.mahalo.log.ClientLog;
50 import com.sun.jini.mahalo.log.LogException;
51 import com.sun.jini.mahalo.log.LogManager;
52 import com.sun.jini.thread.TaskManager;
53 import com.sun.jini.thread.WakeupManager;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 class TxnManagerTransaction
73 implements TransactionConstants, TimeConstants, LeasedResource, Serializable
74 {
75 static final long serialVersionUID = -2088463193687796098L;
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 private static final boolean states[][] = {
118
119
120
121
122
123
124
125
126
127
128
129 private List parts = new Vector();
130
131
132
133
134 private final ServerTransaction str;
135
136
137
138
139 private int trstate;
140
141
142
143
144 private long expires;
145
146
147
148
149 private transient LogManager logmgr;
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 private transient TaskManager threadpool;
185
186
187
188
189 private transient WakeupManager wm;
190
191
192
193
194 private transient TxnSettler settler;
195
196
197
198
199 private transient Job job;
200
201
202
203
204 private Uuid uuid;
205
206
207
208
209
210
211
212
213 private transient Object leaseLock = new Object();
214
215
216
217
218
219
220
221
222
223
224
225
226 private transient Object jobLock = new Object();
227
228
229
230
231
232
233
234
235
236
237
238
239 private transient Object stateLock = new Object();
240
241
242
243 private static final Logger operationsLogger =
244 TxnManagerImpl.operationsLogger;
245
246
247 private static final Logger transactionsLogger =
248 TxnManagerImpl.transactionsLogger;
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268 TxnManagerTransaction(TransactionManager mgr, LogManager logmgr, long id,
269 TaskManager threadpool, WakeupManager wm, TxnSettler settler,
270 Uuid uuid)
271 {
272 if (logmgr == null)
273 throw new IllegalArgumentException("TxnManagerTransaction: " +
274 "log manager must be non-null");
275 if (mgr == null)
276 throw new IllegalArgumentException("TxnManagerTransaction: " +
277 "transaction manager must be non-null");
278
279 if (threadpool == null)
280 throw new IllegalArgumentException("TxnManagerTransaction: " +
281 "threadpool must be non-null");
282
283 if (wm == null)
284 throw new IllegalArgumentException("TxnManagerTransaction: " +
285 "wakeup manager must be non-null");
286
287 if (settler == null)
288 throw new IllegalArgumentException("TxnManagerTransaction: " +
289 "settler must be non-null");
290
291 if (uuid == null)
292 throw new IllegalArgumentException("TxnManagerTransaction: " +
293 "uuid must be non-null");
294
295 this.threadpool = threadpool;
296 this.wm = wm;
297 this.logmgr = logmgr ;
298 str = new ServerTransaction(mgr, id);
299 this.settler = settler;
300 this.uuid = uuid;
301
302 trstate = ACTIVE;
303
304
305 }
306
307
308
309
310
311
312
313
314
315 void add(ParticipantHandle handle)
316 throws InternalManagerException
317 {
318 if (operationsLogger.isLoggable(Level.FINER)) {
319 operationsLogger.entering(TxnManagerTransaction.class.getName(),
320 "add", handle);
321 }
322
323 if (handle == null)
324 throw new NullPointerException("ParticipantHolder: add: " +
325 "cannot add null handle");
326
327
328
329
330 try {
331 if (transactionsLogger.isLoggable(Level.FINEST)) {
332 transactionsLogger.log(Level.FINEST,
333 "Adding ParticipantHandle: {0}", handle);
334 }
335 parts.add(handle);
336 } catch (Exception e) {
337 if (transactionsLogger.isLoggable(Level.SEVERE)) {
338 transactionsLogger.log(Level.SEVERE,
339 "Unable to add ParticipantHandle", e);
340 }
341 throw new InternalManagerException("TxnManagerTransaction: " +
342 "add: " + e.getMessage());
343 }
344 if (operationsLogger.isLoggable(Level.FINER)) {
345 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
346 "add");
347 }
348 }
349
350
351
352
353
354
355
356
357
358 void modifyParticipant(ParticipantHandle handle, int state) {
359 if (operationsLogger.isLoggable(Level.FINER)) {
360 operationsLogger.entering(TxnManagerTransaction.class.getName(),
361 "modifyParticipant", new Object[] {handle, new Integer(state)});
362 }
363 ParticipantHandle ph = null;
364
365 if (handle == null)
366 throw new NullPointerException("ParticipantHolder: " +
367 "modifyParticipant: cannot modify null handle");
368
369 if (parts.contains(ph))
370 ph = (ParticipantHandle) parts.get(parts.indexOf(handle));
371
372 if (ph == null) {
373 if (operationsLogger.isLoggable(Level.FINER)) {
374 operationsLogger.exiting(
375 TxnManagerTransaction.class.getName(),
376 "modifyParticipant");
377 }
378
379 return;
380 }
381
382 ph.setPrepState(state);
383 if (operationsLogger.isLoggable(Level.FINER)) {
384 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
385 "modifyParticipant");
386 }
387 }
388
389
390
391
392
393
394
395
396
397
398 boolean modifyTxnState(int state) {
399 if (operationsLogger.isLoggable(Level.FINER)) {
400 operationsLogger.entering(TxnManagerTransaction.class.getName(),
401 "modifyTxnState", new Integer(state));
402 }
403 boolean result = false;
404 synchronized (stateLock) {
405 switch (state) {
406 case ACTIVE:
407 case VOTING:
408 case COMMITTED:
409 case ABORTED:
410 result = states[trstate][state];
411 break;
412
413 default:
414 throw new IllegalArgumentException("TxnManagerTransaction: " +
415 "modifyTxnState: invalid state");
416 }
417
418 if (result)
419 trstate = state;
420 }
421 if (operationsLogger.isLoggable(Level.FINER)) {
422 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
423 "modifyTxnState", Boolean.valueOf(result));
424 }
425 return result;
426 }
427
428
429
430
431
432
433
434
435
436
437
438
439 public void
440 join(TransactionParticipant preparedPart, long crashCount)
441 throws CannotJoinException, CrashCountException, RemoteException
442 {
443 if (operationsLogger.isLoggable(Level.FINER)) {
444 operationsLogger.entering(TxnManagerTransaction.class.getName(),
445 "join", new Object[] {preparedPart, new Long(crashCount)});
446 }
447
448
449
450 if (getState() != ACTIVE)
451 throw new CannotJoinException("not active");
452
453 if ((getState() == ACTIVE) && (ensureCurrent() == false)) {
454 doAbort(0);
455 throw new CannotJoinException("Lease expired");
456 }
457
458
459
460 try {
461 ParticipantHandle ph =
462 new ParticipantHandle(preparedPart, crashCount);
463 ParticipantHandle phtmp = (ParticipantHandle)
464 ((parts.contains(ph))?
465 parts.get(parts.indexOf(ph)):
466 null);
467
468 if (transactionsLogger.isLoggable(Level.FINEST)) {
469 transactionsLogger.log(Level.FINEST,
470 "Retrieved ParticipantHandle: {0}", phtmp);
471 }
472 if (phtmp != null) {
473 long oldcount = phtmp.getCrashCount();
474 if (oldcount == crashCount) {
475 return;
476 } else {
477 throw new CrashCountException("TxnManagerTransaction: " +
478 "join: old = " + oldcount +
479 " new = " + crashCount);
480 }
481 }
482
483 add(ph);
484
485 } catch (InternalManagerException ime) {
486 if (transactionsLogger.isLoggable(Level.SEVERE)) {
487 transactionsLogger.log(Level.SEVERE,
488 "TransactionParticipant unable to join", ime);
489 }
490 throw ime;
491 } catch (RemoteException re) {
492 if (transactionsLogger.isLoggable(Level.FINEST)) {
493 transactionsLogger.log(Level.FINEST,
494 "TransactionParticipant unable to be stored", re);
495 }
496 throw re;
497 }
498 if (operationsLogger.isLoggable(Level.FINER)) {
499 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
500 "join");
501 }
502 }
503
504
505
506
507
508
509
510
511
512
513
514 public int getState() {
515 if (operationsLogger.isLoggable(Level.FINER)) {
516 operationsLogger.entering(TxnManagerTransaction.class.getName(),
517 "getState");
518 }
519 synchronized (stateLock) {
520 if (operationsLogger.isLoggable(Level.FINER)) {
521 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
522 "getState", new Integer(trstate));
523 }
524 return trstate;
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 void commit(long waitFor)
552 throws CannotCommitException, TimeoutExpiredException, RemoteException
553 {
554 if (operationsLogger.isLoggable(Level.FINER)) {
555 operationsLogger.entering(TxnManagerTransaction.class.getName(),
556 "commit", new Long(waitFor));
557 }
558 long starttime = System.currentTimeMillis();
559
560
561
562
563 if ((getState() == ACTIVE) && (ensureCurrent() == false)) {
564 doAbort(0);
565 throw new CannotCommitException("Lease expired");
566 }
567
568 if (getState() == ABORTED)
569 throw new CannotCommitException("attempt to commit " +
570 "ABORTED transaction");
571
572
573
574
575
576
577 Vector joinvec = parthandles();
578
579 if (joinvec == null) {
580 if (!modifyTxnState(VOTING))
581 throw new CannotCommitException("attempt to commit " +
582 "ABORTED transaction");
583
584 if (modifyTxnState(COMMITTED))
585 return;
586 else
587 throw new CannotCommitException("attempt to commit " +
588 "ABORTED transaction");
589 }
590
591 try {
592 Enumeration joined = joinvec.elements();
593 int numparts = joinvec.size();
594 ParticipantHandle[] phs = new ParticipantHandle[numparts];
595 joinvec.copyInto(phs);
596
597 long now = starttime;
598 long transpired = 0;
599 long remainder = 0;
600
601 ClientLog log = logmgr.logFor(str.id);
602
603 if (transactionsLogger.isLoggable(Level.FINEST)) {
604 transactionsLogger.log(Level.FINEST,
605 "{0} TransactionParticipants have joined",
606 new Integer(numparts));
607 }
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628 int oldstate = getState();
629 Integer result = new Integer(ABORTED);
630 Exception alternateException = null;
631
632
633
634
635
636
637
638
639
640
641
642
643 if (modifyTxnState(VOTING)) {
644
645 if (oldstate == ACTIVE)
646 log.write(new CommitRecord(phs));
647
648
649
650
651
652
653 synchronized (jobLock) {
654 if (job == null) {
655 if (phs.length == 1)
656 job = new
657 PrepareAndCommitJob(
658 str, threadpool, wm, log, phs[0]);
659 else
660 job = new PrepareJob(str, threadpool, wm, log, phs);
661
662 job.scheduleTasks();
663 }
664 }
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684 synchronized (jobLock) {
685 if ((job instanceof PrepareJob) ||
686 (job instanceof PrepareAndCommitJob)) {
687 try {
688 if (job.isCompleted(Long.MAX_VALUE)) {
689 result = (Integer) job.computeResult();
690 if (result.intValue() == ABORTED &&
691 job instanceof PrepareAndCommitJob) {
692 PrepareAndCommitJob pj =
693 (PrepareAndCommitJob)job;
694 alternateException =
695 pj.getAlternateException();
696 }
697 }
698 } catch (JobNotStartedException jnse) {
699
700 result = new Integer(NOTCHANGED);
701 } catch (ResultNotReadyException rnre) {
702
703 } catch (JobException je) {
704
705 }
706 }
707 }
708 } else {
709
710
711
712 if (getState() == ABORTED)
713 throw new CannotCommitException("transaction ABORTED");
714
715
716
717
718
719
720
721 if (getState() == COMMITTED)
722 result = new Integer(COMMITTED);
723 }
724
725 if (transactionsLogger.isLoggable(Level.FINEST)) {
726 transactionsLogger.log(Level.FINEST,
727 "Voting result: {0}",
728 TxnConstants.getName(result.intValue()));
729 }
730
731 switch (result.intValue()) {
732 case NOTCHANGED:
733 break;
734
735 case ABORTED:
736 now = System.currentTimeMillis();
737 transpired = now - starttime;
738 remainder = waitFor - transpired;
739
740 if (remainder >=0)
741 doAbort(remainder);
742 else
743 doAbort(0);
744
745 if (alternateException == null) {
746 throw new CannotCommitException(
747 "Unable to commit transaction: "
748 + getParticipantInfo());
749 } else {
750 throw new RemoteException(
751 "Problem communicating with participant",
752 alternateException);
753 }
754
755 case PREPARED:
756
757
758
759
760
761 if(modifyTxnState(COMMITTED)) {
762
763 synchronized (jobLock) {
764 job = new CommitJob(str, threadpool, wm, log, phs);
765 job.scheduleTasks();
766 }
767 } else {
768 throw new CannotCommitException("attempt to commit " +
769 "ABORTED transaction");
770 }
771
772
773
774
775
776 case COMMITTED:
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 synchronized (jobLock) {
809
810
811
812
813
814 if (job instanceof PrepareAndCommitJob) {
815 if(!modifyTxnState(COMMITTED))
816 throw new CannotCommitException("transaction " +
817 "ABORTED");
818 break;
819 }
820
821
822
823
824 if (job instanceof AbortJob)
825 throw new CannotCommitException("transaction " +
826 "ABORTED");
827 }
828
829 if (getState() != COMMITTED)
830 throw new
831 InternalManagerException("TxnManagerTransaction: " +
832 "commit: " + job + " got bad state: " +
833 TxnConstants.getName(result.intValue()));
834
835
836 now = System.currentTimeMillis();
837 transpired = now - starttime;
838
839 boolean committed = false;
840
841
842
843
844
845
846
847 try {
848 remainder = waitFor - transpired;
849 synchronized (jobLock) {
850 if (remainder <= 0 || !job.isCompleted(remainder)) {
851
852
853
854
855
856 settler.noteUnsettledTxn(str.id);
857 throw new TimeoutExpiredException(
858 "timeout expired", true);
859 } else {
860 result = (Integer) job.computeResult();
861 committed = true;
862 }
863 }
864 } catch (ResultNotReadyException rnre) {
865
866
867 } catch (JobNotStartedException jnse) {
868
869 } catch (JobException je) {
870
871 }
872
873 if (committed)
874 break;
875
876 default:
877 throw new InternalManagerException("TxnManagerTransaction: " +
878 "commit: " + job + " got bad state: " +
879 TxnConstants.getName(result.intValue()));
880 }
881
882
883
884 log.invalidate();
885 } catch (RuntimeException rte) {
886 if (transactionsLogger.isLoggable(Level.FINEST)) {
887 transactionsLogger.log(Level.FINEST,
888 "Problem committing transaction",
889 rte);
890 }
891 throw rte;
892 } catch (LogException le) {
893 if (transactionsLogger.isLoggable(Level.FINEST)) {
894 transactionsLogger.log(Level.FINEST,
895 "Problem persisting transaction",
896 le);
897 }
898 throw new CannotCommitException("Unable to log");
899 }
900 if (operationsLogger.isLoggable(Level.FINER)) {
901 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
902 "commit");
903 }
904 }
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925 void abort(long waitFor)
926 throws CannotAbortException, TimeoutExpiredException
927 {
928 if (operationsLogger.isLoggable(Level.FINER)) {
929 operationsLogger.entering(TxnManagerTransaction.class.getName(),
930 "abort", new Long(waitFor));
931 }
932 long starttime = System.currentTimeMillis();
933
934
935
936
937
938
939
940
941 try {
942 Vector joinvec = parthandles();
943
944 if (joinvec == null) {
945 if (modifyTxnState(ABORTED))
946 return;
947 else
948 throw new
949 CannotAbortException("Transaction already COMMITTED");
950 }
951
952 Enumeration joined = joinvec.elements();
953 int numparts = joinvec.size();
954 ParticipantHandle[] phs = new ParticipantHandle[numparts];
955 joinvec.copyInto(phs);
956
957 ClientLog log = logmgr.logFor(str.id);
958
959
960
961
962
963
964
965
966
967
968
969
970
971 if (modifyTxnState(ABORTED)) {
972 log.write(new AbortRecord(phs));
973
974 synchronized (jobLock) {
975 if (!(job instanceof AbortJob)) {
976 if (job != null)
977 job.stop();
978 job = new AbortJob(str, threadpool, wm, log, phs);
979 job.scheduleTasks();
980 }
981 }
982 } else {
983 throw new CannotAbortException("Transaction already COMMITTED");
984 }
985
986
987
988
989
990
991
992
993
994
995
996 long now = System.currentTimeMillis();
997 long transpired = now - starttime;
998
999 Integer result = new Integer(ACTIVE);
1000 boolean aborted = false;
1001
1002 long remainder = waitFor - transpired;
1003
1004 try {
1005 synchronized (jobLock) {
1006 if (remainder<= 0 || !job.isCompleted(remainder)) {
1007 settler.noteUnsettledTxn(str.id);
1008 throw new TimeoutExpiredException(
1009 "timeout expired",false);
1010 } else {
1011 result = (Integer) job.computeResult();
1012 aborted = true;
1013 }
1014 }
1015 } catch (ResultNotReadyException rnre) {
1016
1017 } catch (JobNotStartedException jnse) {
1018
1019 } catch (JobException je) {
1020 settler.noteUnsettledTxn(str.id);
1021 throw new TimeoutExpiredException("timeout expired", false);
1022 }
1023
1024
1025 if (!aborted)
1026 throw new InternalManagerException("TxnManagerTransaction: " +
1027 "abort: AbortJob got bad state: " +
1028 TxnConstants.getName(result.intValue()));
1029
1030 log.invalidate();
1031 } catch (RuntimeException rte) {
1032 if (transactionsLogger.isLoggable(Level.SEVERE)) {
1033 transactionsLogger.log(Level.SEVERE,
1034 "Problem aborting transaction",
1035 rte);
1036 }
1037 throw new InternalManagerException("TxnManagerTransaction: " +
1038 "abort: fatal error");
1039 } catch (LogException le) {
1040 if (transactionsLogger.isLoggable(Level.FINEST)) {
1041 transactionsLogger.log(Level.FINEST,
1042 "Problem persisting transaction",
1043 le);
1044 }
1045 throw new CannotAbortException("Unable to log");
1046 }
1047 if (operationsLogger.isLoggable(Level.FINER)) {
1048 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1049 "abort");
1050 }
1051 }
1052
1053 public Transaction getTransaction() {
1054 if (operationsLogger.isLoggable(Level.FINER)) {
1055 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1056 "getTransaction");
1057 }
1058 if (operationsLogger.isLoggable(Level.FINER)) {
1059 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1060 "getTransaction", str);
1061 }
1062 return str;
1063 }
1064
1065 public long getExpiration() {
1066 if (operationsLogger.isLoggable(Level.FINER)) {
1067 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1068 "getExpiration");
1069 }
1070 synchronized (leaseLock) {
1071 if (operationsLogger.isLoggable(Level.FINER)) {
1072 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1073 "getExpiration", new Date(expires));
1074 }
1075 return expires;
1076 }
1077 }
1078
1079 public void setExpiration(long newExpiration) {
1080 if (operationsLogger.isLoggable(Level.FINER)) {
1081 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1082 "setExpiration", new Date(newExpiration));
1083 }
1084 synchronized (leaseLock) {
1085 expires = newExpiration;
1086 }
1087 if (operationsLogger.isLoggable(Level.FINER)) {
1088 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1089 "setExpiration");
1090 }
1091 }
1092
1093 public Uuid getCookie() {
1094 if (operationsLogger.isLoggable(Level.FINER)) {
1095 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1096 "getCookie");
1097 }
1098 if (operationsLogger.isLoggable(Level.FINER)) {
1099 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1100 "getCookie", uuid);
1101 }
1102 return uuid;
1103 }
1104
1105 private void doAbort(long timeout) {
1106 if (operationsLogger.isLoggable(Level.FINER)) {
1107 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1108 "doAbort", new Long(timeout));
1109 }
1110 try {
1111 str.abort(timeout);
1112 } catch (RemoteException re) {
1113
1114 if (transactionsLogger.isLoggable(Levels.HANDLED)) {
1115 transactionsLogger.log(Levels.HANDLED,
1116 "Trouble aborting transaction", re);
1117 }
1118 } catch (TimeoutExpiredException te) {
1119
1120
1121 if (transactionsLogger.isLoggable(Levels.HANDLED)) {
1122 transactionsLogger.log(Levels.HANDLED,
1123 "Trouble aborting transaction", te);
1124 }
1125 } catch (TransactionException bte) {
1126
1127
1128
1129 if (transactionsLogger.isLoggable(Levels.HANDLED)) {
1130 transactionsLogger.log(Levels.HANDLED,
1131 "Trouble aborting transaction", bte);
1132 }
1133 }
1134 if (operationsLogger.isLoggable(Level.FINER)) {
1135 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1136 "doAbort");
1137 }
1138
1139 }
1140
1141 synchronized boolean ensureCurrent() {
1142 if (operationsLogger.isLoggable(Level.FINER)) {
1143 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1144 "ensureCurrent");
1145 }
1146 long cur = System.currentTimeMillis();
1147 boolean result = false;
1148 long useby = getExpiration();
1149
1150 if (useby > cur)
1151 result = true;
1152 if (operationsLogger.isLoggable(Level.FINER)) {
1153 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1154 "ensureCurrent", Boolean.valueOf(result));
1155 }
1156 return result;
1157 }
1158
1159
1160 private Vector parthandles() {
1161 if (operationsLogger.isLoggable(Level.FINER)) {
1162 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1163 "parthandles");
1164 }
1165 if ( (parts == null ) || ( parts.size() == 0 ) )
1166 return null;
1167
1168 Vector vect = new Vector(parts);
1169
1170 if (transactionsLogger.isLoggable(Level.FINEST)) {
1171 transactionsLogger.log(Level.FINEST,
1172 "Retrieved {0} participants",
1173 new Integer(vect.size()));
1174 }
1175
1176 if (operationsLogger.isLoggable(Level.FINER)) {
1177 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1178 "parthandles");
1179 }
1180
1181 return vect;
1182 }
1183
1184 private String getParticipantInfo() {
1185 if (operationsLogger.isLoggable(Level.FINER)) {
1186 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1187 "getParticipantInfo");
1188 }
1189 if ( (parts == null ) || ( parts.size() == 0 ) )
1190 return "No participants";
1191
1192 if (transactionsLogger.isLoggable(Level.FINEST)) {
1193 transactionsLogger.log(Level.FINEST,
1194 "{0} participants joined", new Integer(parts.size()));
1195 }
1196 StringBuffer sb = new StringBuffer(parts.size() + " Participants: ");
1197 ParticipantHandle ph;
1198 for (int i=0; i < parts.size(); i++) {
1199 ph = (ParticipantHandle)parts.get(i);
1200 sb.append(
1201 "{" + i + ", "
1202 + ph.getPreParedParticipant().toString() + ", "
1203 + TxnConstants.getName(ph.getPrepState())
1204 + "} ");
1205 }
1206 if (operationsLogger.isLoggable(Level.FINER)) {
1207 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1208 "getParticipantInfo", sb.toString());
1209 }
1210
1211 return sb.toString();
1212 }
1213
1214 void restoreTransientState(ProxyPreparer preparer)
1215 throws RemoteException
1216 {
1217 if (operationsLogger.isLoggable(Level.FINER)) {
1218 operationsLogger.entering(TxnManagerTransaction.class.getName(),
1219 "restoreTransientState");
1220 }
1221 if ( (parts == null ) || ( parts.size() == 0 ) )
1222 return;
1223
1224 ParticipantHandle[] handles = (ParticipantHandle[])
1225 parts.toArray(new ParticipantHandle[parts.size()]);
1226 for (int i=0; i < handles.length; i++) {
1227 handles[i].restoreTransientState(preparer);
1228 if (transactionsLogger.isLoggable(Level.FINEST)) {
1229 transactionsLogger.log(Level.FINEST,
1230 "Restored transient state for {0}",
1231 handles[i]);
1232 }
1233 }
1234
1235 if (operationsLogger.isLoggable(Level.FINER)) {
1236 operationsLogger.exiting(TxnManagerTransaction.class.getName(),
1237 "restoreTransientState");
1238 }
1239 }
1240 }