KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jotm > TransactionRecoveryImpl


1 /*
2  * @(#) TransactionRecoveryImpl.java
3  *
4  * JOTM: Java Open Transaction Manager
5  *
6  *
7  * This module was originally developed by
8  *
9  * - Bull S.A. as part of the JOnAS application server code released in
10  * July 1999 (www.bull.com)
11  *
12  * --------------------------------------------------------------------------
13  * The original code and portions created by Bull SA are
14  * Copyright (c) 1999 BULL SA
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are met:
19  *
20  * -Redistributions of source code must retain the above copyright notice, this
21  * list of conditions and the following disclaimer.
22  *
23  * -Redistributions in binary form must reproduce the above copyright notice,
24  * this list of conditions and the following disclaimer in the documentation
25  * and/or other materials provided with the distribution.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  *
39  * --------------------------------------------------------------------------
40  * $Id: TransactionRecoveryImpl.java,v 1.6 2005/04/21 22:51:49 tonyortiz Exp $
41  * --------------------------------------------------------------------------
42  */

43
44 package org.objectweb.jotm;
45
46 import java.io.IOException JavaDoc;
47 import java.io.FileInputStream JavaDoc;
48 import java.nio.ByteBuffer JavaDoc;
49 import java.util.Collections JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Map JavaDoc;
52 import java.util.Properties JavaDoc;
53 import java.util.Vector JavaDoc;
54
55 import javax.transaction.SystemException JavaDoc;
56 import javax.transaction.xa.XAResource JavaDoc;
57
58 import org.objectweb.howl.log.Configuration;
59 import org.objectweb.howl.log.LogConfigurationException;
60 import org.objectweb.howl.log.LogException;
61 import org.objectweb.howl.log.LogRecord;
62 import org.objectweb.howl.log.LogRecordType;
63 import org.objectweb.howl.log.ReplayListener;
64 import org.objectweb.howl.log.xa.XACommittingTx;
65 import org.objectweb.howl.log.xa.XALogRecord;
66 import org.objectweb.howl.log.xa.XALogger;
67
68 import javax.transaction.xa.XAException JavaDoc;
69
70 /**
71  *
72  * @author Tony Ortiz
73  */

74
75 public class TransactionRecoveryImpl implements TransactionRecovery {
76
77     private transient static TransactionRecoveryImpl unique = null;
78
79     // Static hashtable: Resource Manager Name ---> Connection
80
private transient static Map JavaDoc nameResourceManager = Collections.synchronizedMap(new HashMap JavaDoc());
81
82     // Static hashtable: XA Resource Name ---> XAResource
83
private transient static Map JavaDoc nameXAResource = Collections.synchronizedMap(new HashMap JavaDoc());
84
85     // Jotm Recovery
86
private transient static JotmRecovery tmrecovery = null;
87     //private transient static boolean dorecovery = false;
88
private transient static boolean startrecoverycalled = false;
89
90     // XALogger info
91
private transient static XALogger xaLog = null;
92     private transient static XACommittingTx rmCommitTx = null;
93
94     // Vector used to hold all registered Resource Managers
95
// until they can be written to the Howl Logger.
96
private transient static Vector JavaDoc vRmRegistration = new Vector JavaDoc();
97     private RmRegistration myrmRegistration = null;
98     
99     /**
100      * -Djotm.base property
101      */

102     private static final String JavaDoc JOTM_BASE = "jotm.base";
103
104     /**
105      * jonas.base property
106      */

107     private static final String JavaDoc JONAS_BASE = "jonas.base";
108     
109     /**
110      * configuration directory name
111      */

112     private static final String JavaDoc CONFIG_DIR = "conf";
113
114     /**
115      * System properties
116      */

117     private static Properties JavaDoc systEnv = System.getProperties();
118
119     /**
120      * JONAS_BASE
121      */

122     private static String JavaDoc jonasBase = systEnv.getProperty(JONAS_BASE);
123     
124     /**
125      * JOTM_BASE
126      */

127     private static String JavaDoc jotmBase = systEnv.getProperty(JOTM_BASE);
128
129     /**
130      * Separator of file
131      */

132     private static String JavaDoc fileSeparator = systEnv.getProperty("file.separator");
133
134     /**
135      * Default constructor.
136      */

137
138     public TransactionRecoveryImpl() throws LogException, IOException JavaDoc, Exception JavaDoc {
139             
140         if (TraceTm.recovery.isDebugEnabled()) {
141             TraceTm.recovery.debug("TransactionRecoveryImpl constructor");
142         }
143
144         unique = this;
145         
146         // Check the JONAS_BASE and JOTM_BASE environment properties
147
// If on of them is not found, check the transactionRecovery value
148
// from Current to see if recovery is enabled(true)/disabled(false).
149

150         String JavaDoc myBase=null;
151         
152         if (jonasBase == null) {
153             if (jotmBase == null) {
154                 if (!Current.getDefaultRecovery()) {
155                     if (TraceTm.recovery.isDebugEnabled()) {
156                         TraceTm.recovery.debug("JOTM Recovery is disabled");
157                     }
158                     return; // transaction recovery is disabled
159
}
160             } else {
161                myBase = jotmBase;
162             }
163         } else {
164            myBase = jonasBase;
165         }
166         
167         myBase = myBase.trim();
168
169         // JOTM_BASE/conf/fileName
170
String JavaDoc fileFullPathname = myBase + fileSeparator + CONFIG_DIR + fileSeparator + "jotm.properties";
171         
172         if (TraceTm.recovery.isDebugEnabled()) {
173             TraceTm.recovery.debug("JOTM properties file= " + fileFullPathname);
174         }
175
176         Properties JavaDoc howlprop = new Properties JavaDoc();
177         try {
178             FileInputStream JavaDoc inStr = new FileInputStream JavaDoc(fileFullPathname);
179             systEnv.load(inStr);
180         } catch (Exception JavaDoc e){
181             Current.setDefaultRecovery(false);
182             return;
183         }
184         
185         if (systEnv.getProperty("jotm.recovery.Enabled").trim().equalsIgnoreCase("true")) { // recovery is enabled
186
Current.setDefaultRecovery(true);
187             if (TraceTm.recovery.isDebugEnabled()) {
188                 TraceTm.recovery.debug("JOTM Recovery is enabled");
189             }
190         } else { // recovery disabled
191
Current.setDefaultRecovery(false);
192             if (TraceTm.recovery.isDebugEnabled()) {
193                 TraceTm.recovery.debug("JOTM Recovery is disabled");
194             }
195             return;
196         }
197         
198         String JavaDoc myhowlprop = null;
199         myhowlprop = systEnv.getProperty ("howl.log.ListConfiguration", "false");
200         howlprop.put("listConfig", myhowlprop);
201         myhowlprop = systEnv.getProperty ("howl.log.BufferSize", "4");
202         howlprop.put("bufferSize", myhowlprop);
203         myhowlprop = systEnv.getProperty ("howl.log.MinimumBuffers", "16");
204         howlprop.put("minBuffers", myhowlprop);
205         myhowlprop = systEnv.getProperty ("howl.log.MaximumBuffers", "16");
206         howlprop.put("maxBuffers", myhowlprop);
207         myhowlprop = systEnv.getProperty ("howl.log.MaximumBlocksPerFile", "200");
208         howlprop.put("maxBlocksPerFile", myhowlprop);
209         myhowlprop = systEnv.getProperty ("howl.log.FileDirectory", systEnv.getProperty ("basedir", "."));
210         howlprop.put("logFileDir", myhowlprop);
211         myhowlprop = systEnv.getProperty ("howl.log.FileName", "howl");
212         howlprop.put("logFileName", myhowlprop);
213         myhowlprop = systEnv.getProperty ("howl.log.MaximumFiles", "2");
214         howlprop.put("maxLogFiles", myhowlprop);
215         
216         try {
217             howlOpenLog (howlprop);
218         } catch (Exception JavaDoc e) {
219             TraceTm.jotm.warn("howlOpenLog: LogException occured in howlOpenLog() " + e.getMessage());
220             Current.setDefaultRecovery(false);
221             TraceTm.recovery.warn("JOTM Recovery is disabled");
222             return;
223         }
224     }
225
226     /**
227      * Returns the unique instance of the class or <code>null</code> if not
228      * initialized in case of plain client.
229      *
230      * @return The <code>TransactionRecovery</code> object created
231      */

232
233     public static TransactionRecoveryImpl getTransactionRecovery() {
234
235         return unique;
236     }
237
238     public JotmRecovery getJotmRecovery() {
239
240         return tmrecovery;
241     }
242     
243     public Vector JavaDoc getRmRegistration() {
244
245         return vRmRegistration;
246     }
247     // ------------------------------------------------------------------
248
// JOTM Recovery Support Methods
249
// ------------------------------------------------------------------
250

251     /**
252      * Register a Resource Manager with the JOTM Transaction Manager.
253      *
254      * @param rmName The Resource Manager to be registered.
255      */

256
257      /* added 04/13/05 */
258     public void registerResourceManager (String JavaDoc rmName, XAResource JavaDoc rmXares, String JavaDoc info,
259                                          Properties JavaDoc rmProperties,
260                                          TransactionResourceManager trm) throws XAException JavaDoc {
261             if ( TraceTm.recovery.isDebugEnabled() ) {
262                 TraceTm.recovery.debug("Register Resource Manager Properties " + rmName + rmProperties + " to Connection " + rmXares);
263             }
264             
265             this.registerResourceManager (rmName, rmXares, info, trm);
266     }
267
268     public void registerResourceManager (String JavaDoc rmName, XAResource JavaDoc rmXares, String JavaDoc info,
269                                          TransactionResourceManager tranrm) throws XAException JavaDoc {
270
271         if (!(tranrm==null)) { // initial implementation, call back immediately
272
tranrm.returnXAResource(rmName, rmXares);
273         }
274         
275         if (!Current.getDefaultRecovery()) {
276             if (TraceTm.recovery.isDebugEnabled()) {
277                 TraceTm.recovery.debug("JOTM Recovery is disabled");
278             }
279             return; // transaction recovery is disabled
280
}
281         
282         // put the Resource Manager/XAResource mapping into the hashtable
283

284         if ( TraceTm.recovery.isDebugEnabled() ) {
285             TraceTm.recovery.debug("Register Resource Manager " + rmName + " to Connection " + rmXares);
286         }
287
288         XAResource JavaDoc xares = null;
289         Object JavaDoc hash_key = new String JavaDoc(rmName);
290
291         Object JavaDoc myrmXares = (Object JavaDoc) nameResourceManager.get(hash_key);
292
293         if (myrmXares == null) {
294             nameResourceManager.put(hash_key, rmXares);
295         }
296         else {
297             xares = (XAResource JavaDoc) myrmXares;
298             
299             if (xares.equals(rmXares)) {
300                 if( TraceTm.recovery.isDebugEnabled() ) {
301                     TraceTm.recovery.debug(rmName + " already registered");
302                     return;
303                 }
304             }
305             else {
306                 nameResourceManager.put(hash_key, rmXares);
307             }
308         }
309
310         myrmRegistration = new RmRegistration();
311         myrmRegistration.rmAddRegistration (rmName, rmXares, rmXares.getClass().getName());
312         vRmRegistration.addElement(myrmRegistration);
313
314         // if startResourceManagerRecovery has been called before
315
// (e.g. during Jonas startup)it must be called when a
316
// Resource Manager registered
317

318         if (startrecoverycalled) {
319             try {
320                 startResourceManagerRecovery ();
321             } catch (XAException JavaDoc e) {
322                 throw new XAException JavaDoc ("startResourceManagerRecovery failed" + e.getMessage());
323             }
324         }
325         
326     }
327
328     /**
329      * Provide information regarding the status and state of the XAResource.
330      *
331      * @param rmName The Resource Manager to be reported upon.
332      *
333      * @return XAResource The XAResource assigned to the Resource Managere.
334      */

335
336     public XAResource JavaDoc reportResourceManager (String JavaDoc rmName) throws XAException JavaDoc {
337         
338         if (!Current.getDefaultRecovery()) {
339             if (TraceTm.recovery.isDebugEnabled()) {
340                 TraceTm.recovery.debug("JOTM Recovery is disabled");
341             }
342             return null; // transaction recovery is disabled
343
}
344         
345         // given the name, get the corresponding Connection from the hashtable.
346

347         if( TraceTm.recovery.isDebugEnabled() ) {
348             TraceTm.recovery.debug("get Connection from Resource Manager " + rmName);
349         }
350
351         Object JavaDoc hash_key = new String JavaDoc(rmName);
352         XAResource JavaDoc myXares = (XAResource JavaDoc) nameResourceManager.get(hash_key);
353
354         if (myXares == null) {
355             throw new XAException JavaDoc ("Named Resource Manager " + rmName + " does not exist");
356         }
357
358         return myXares;
359     }
360
361     /**
362      * Unregister a Resource Manager from the JOTM Transaction Manager.
363      *
364      * @param rmName The Resource Manager to be unregistered.
365      */

366
367     public void unregisterResourceManager(String JavaDoc rmName, XAResource JavaDoc rmXares) throws XAException JavaDoc {
368         
369         if (!Current.getDefaultRecovery()) {
370             if (TraceTm.recovery.isDebugEnabled()) {
371                 TraceTm.recovery.debug("JOTM Recovery is disabled");
372             }
373             return; // transaction recovery is disabled
374
}
375         
376         // Unregister the Resource Manager from the name (hash table).
377

378         if ( TraceTm.recovery.isDebugEnabled() ) {
379             TraceTm.recovery.debug("Remove Resource Manager " + rmName + " from Connection " + rmXares);
380         }
381
382         Object JavaDoc hash_key = new String JavaDoc(rmName);
383         XAResource JavaDoc myrmXares = (XAResource JavaDoc) nameResourceManager.get(hash_key);
384
385         if (myrmXares.equals(rmXares)) {
386             nameResourceManager.remove(hash_key);
387         }
388         else {
389             throw new XAException JavaDoc ("Resource Manager " + rmName + " not associated to " + rmXares);
390         }
391     }
392     
393     /**
394      * Log (in Howl) every Resource Manager (XAResource) that has been
395      * registered.
396      *
397      * @exception XAException Thrown if the transaction manager
398      * encounters an unexpected error condition
399      */

400
401     public void startResourceManagerRecovery () throws XAException JavaDoc {
402         
403         if (!Current.getDefaultRecovery()) {
404             if (TraceTm.recovery.isDebugEnabled()) {
405                 TraceTm.recovery.debug("JOTM Recovery is disabled");
406             }
407             return; // transaction recovery is disabled
408
}
409
410         int rmcount = vRmRegistration.size();
411         if (TraceTm.recovery.isDebugEnabled()) {
412             TraceTm.recovery.debug("LogResourceManager count= " +rmcount);
413         }
414
415         if (rmcount == 0) return;
416
417         XACommittingTx myrmCommitTx = null;
418
419         byte [] [] rmBuffer = new byte [rmcount + 1] [];
420
421         byte [] rmRecord1 = null;
422         byte [] rmRecord2 = null;
423
424         String JavaDoc resm1 = "RM1";
425         String JavaDoc resm2 = "RM2";
426
427         long rmdate = System.currentTimeMillis();
428
429         rmRecord1 = new byte[3+8+4];
430
431         ByteBuffer JavaDoc rm1 = ByteBuffer.wrap(rmRecord1);
432         rm1.put(resm1.getBytes());
433         rm1.putLong(rmdate);
434         rm1.putInt(rmcount);
435
436         rmBuffer [0] = rm1.array();
437
438         for (int i = 0; i < rmcount; i++) {
439             myrmRegistration = (RmRegistration)vRmRegistration.elementAt(i);
440             String JavaDoc rmName = myrmRegistration.rmGetName();
441             XAResource JavaDoc xaRes = myrmRegistration.rmGetXaRes();
442             String JavaDoc xaresName = myrmRegistration.rmGetXaResName();
443
444             if (TraceTm.recovery.isDebugEnabled()) {
445                 TraceTm.recovery.debug("LogResourceManager rmName= " + rmName);
446                 TraceTm.recovery.debug(" xaRes= " + xaresName);
447                 TraceTm.recovery.debug(" rmIndex= " + i);
448             }
449
450             int rmlength = rmName.length();
451             int xaReslength= xaRes.toString().length();
452             int xaResNamelength = xaresName.length();
453
454             if (TraceTm.recovery.isDebugEnabled()) {
455                 TraceTm.recovery.debug("rm length=" + rmlength);
456                 TraceTm.recovery.debug("xaRes length= " + xaReslength);
457             }
458
459             rmRecord2 = new byte[3+4+rmlength+4+xaReslength+4+xaResNamelength+4];
460             ByteBuffer JavaDoc rm2 = ByteBuffer.wrap(rmRecord2);
461
462             rm2.put(resm2.getBytes());
463             rm2.putInt(rmlength);
464             rm2.put(rmName.getBytes());
465             rm2.putInt(xaReslength);
466             rm2.put(xaRes.toString().getBytes());
467             rm2.putInt(xaResNamelength);
468             rm2.put(xaresName.getBytes());
469             rm2.putInt(i);
470
471             rmBuffer [i+1] = rm2.array(); // First record (0) is always rm1
472
}
473
474         try {
475             myrmCommitTx = howlCommitLog(rmBuffer);
476         } catch (Exception JavaDoc e) {
477             // If we cannot write the Log, we cannot perform recovery
478

479             String JavaDoc howlerror =
480                 "Cannot howlCommitLog:"
481                 + e
482                 + " --"
483                 + e.getMessage();
484             TraceTm.jotm.error("Got LogException from howlCommitLog: "+ howlerror);
485             rmCommitTx = null;
486
487             throw new XAException JavaDoc(howlerror);
488         }
489
490         if (!(rmCommitTx == null)) {
491             byte [] rmDone = new byte [11];
492             byte [] [] rmDoneRecord = new byte [1] [11];
493
494             rmDone = "RM3JOTMDONE".getBytes();
495
496             try {
497                 rmDoneRecord [0] = rmDone;
498                 howlDoneLog (rmDoneRecord, rmCommitTx);
499             } catch (Exception JavaDoc f) {
500                 String JavaDoc howlerror =
501                     "Cannot howlDoneLog:"
502                     + f
503                     + "--"
504                     + f.getMessage();
505                 TraceTm.jotm.error("Got LogException from howlDoneLog: "+ howlerror);
506             }
507         }
508
509         rmCommitTx = myrmCommitTx;
510         
511         try {
512             recoverResourceManager();
513         } catch (XAException JavaDoc e) {
514             throw new XAException JavaDoc("Cannot perform recovery " + e.getMessage());
515         }
516         
517         startrecoverycalled = true;
518     }
519     
520     /**
521      * Recover a Resource Manager with the JOTM Transaction Manager.
522      *
523      * @exception XAException Thrown if the transaction manager
524      * encounters an unexpected error condition
525      */

526
527     public void recoverResourceManager () throws XAException JavaDoc {
528         
529         if (!Current.getDefaultRecovery()) {
530             if (TraceTm.recovery.isDebugEnabled()) {
531                 TraceTm.recovery.debug("JOTM Recovery is disabled");
532             }
533             return; // transaction recovery is disabled
534
}
535         
536         if ( TraceTm.recovery.isDebugEnabled() ) {
537             TraceTm.recovery.debug("recoverResourceManager");
538         }
539
540         if (vRmRegistration.size()== 0){
541             if ( TraceTm.recovery.isDebugEnabled() ) {
542                 TraceTm.recovery.debug("Nothing to recover");
543             }
544             return;
545         }
546         
547         // If incomplete commit records were found in Howl, we may need to
548
// recover transactions (xids).
549

550         try {
551             tmrecovery.recoverTransactions(vRmRegistration);
552         } catch (XAException JavaDoc e) {
553             throw new XAException JavaDoc("Unable to recover transactions" + e.getMessage());
554         }
555     }
556
557     /* HOWL Support Methods */
558     
559     private class xaReplayListener implements ReplayListener {
560
561         public void onRecord (LogRecord lr) {
562
563             if (TraceTm.recovery.isDebugEnabled()) {
564                 TraceTm.recovery.debug("LogRecord type= " + lr.type);
565             }
566
567             switch(lr.type) {
568                 case LogRecordType.EOB:
569                     if (TraceTm.recovery.isDebugEnabled()) {
570                         TraceTm.recovery.debug("Howl End of Buffer Record");
571                     }
572                     break;
573                 case LogRecordType.END_OF_LOG:
574                     if (TraceTm.recovery.isDebugEnabled()) {
575                         TraceTm.recovery.debug("Howl End of Log Record");
576                     }
577                     break;
578                 case LogRecordType.XACOMMIT:
579                     if (TraceTm.recovery.isDebugEnabled()) {
580                         TraceTm.recovery.debug("Howl XA Commit Record");
581                     }
582                     tmrecovery.rebuildTransaction ((XALogRecord) lr);
583                     break;
584                 case LogRecordType.XADONE:
585                     if (TraceTm.recovery.isDebugEnabled()) {
586                         TraceTm.recovery.debug("Howl XA Done Record");
587                     }
588                     break;
589                 case LogRecordType.USER:
590                     if (TraceTm.recovery.isDebugEnabled()) {
591                         TraceTm.recovery.debug("Howl User Record");
592                     }
593                     break;
594                 default:
595                     if (TraceTm.recovery.isDebugEnabled()) {
596                         TraceTm.recovery.debug("Unknown Howl LogRecord");
597                     }
598                     break;
599             }
600         }
601
602         public void onError(LogException exception) {
603           // TODO Auto-generated method stub
604
if (TraceTm.recovery.isDebugEnabled()) {
605                 TraceTm.recovery.debug("onError");
606             }
607         }
608
609         public LogRecord getLogRecord() {
610             if (TraceTm.recovery.isDebugEnabled()) {
611                 TraceTm.recovery.debug("getLogRecord");
612             }
613             return new XALogRecord(120);
614         }
615     }
616    
617     /**
618      * open the Howl Log
619      */

620
621     synchronized void howlOpenLog (Properties JavaDoc phowlprop) throws SystemException JavaDoc {
622
623         if (!(xaLog == null)) {
624             if (TraceTm.recovery.isDebugEnabled()) {
625                 TraceTm.recovery.debug("Howl Log already opened");
626             }
627             return;
628         }
629
630         if (TraceTm.recovery.isDebugEnabled()) {
631             TraceTm.recovery.debug("Open howl log");
632         }
633
634         try {
635             Configuration cfg = new Configuration (phowlprop);
636             xaLog = new XALogger(cfg);
637         } catch (LogConfigurationException e) {
638             TraceTm.jotm.error("XALogger: LogConfigurationException");
639             throw new SystemException JavaDoc("LogConfigurationException occured in XALogger() " + e.getMessage());
640         } catch (IOException JavaDoc e) {
641             TraceTm.jotm.error("XALogger: IOException");
642             throw new SystemException JavaDoc("IOException occured in XALogger() " + e.getMessage());
643         } catch (Exception JavaDoc e) {
644             TraceTm.jotm.error("XALogger: Exception");
645             throw new SystemException JavaDoc("Exeception occurred in XALogger() " + e.getMessage());
646         }
647
648         tmrecovery = new JotmRecovery ();
649
650         xaReplayListener myxarl = new xaReplayListener();
651
652         if (TraceTm.recovery.isDebugEnabled()) {
653             TraceTm.recovery.debug("xaLog.open");
654         }
655
656         try {
657             xaLog.open (null);
658         } catch (LogException e) {
659             TraceTm.jotm.error("xaLog.open: LogException");
660             throw new SystemException JavaDoc("LogException occured in xaLog.open() " + e.getMessage());
661         } catch (IOException JavaDoc e) {
662             TraceTm.jotm.error("xaLog.open: IOException");
663             throw new SystemException JavaDoc("IOException occured in xaLog.open() " + e.getMessage());
664         } catch (InterruptedException JavaDoc e) {
665             TraceTm.jotm.error("xaLog.open: InterruptedException");
666             throw new SystemException JavaDoc("InterruptedException occured in xaLog.open() " + e.getMessage());
667         } catch (ClassNotFoundException JavaDoc e) {
668             TraceTm.jotm.error("xaLog.open: ClassNotFoundException");
669             throw new SystemException JavaDoc("ClassNotFoundException occured in xaLog.open() " + e.getMessage());
670         } catch (Exception JavaDoc e) {
671             TraceTm.jotm.error("xaLog.open: Exception " + e.getMessage());
672             throw new SystemException JavaDoc("Exception occurred in xaLog.open() " + e.getMessage());
673         }
674
675         xaLog.replayActiveTx (myxarl);
676     }
677
678     /**
679      * write the Done record to the Howl Log
680      */

681
682     void howlCloseLog () throws SystemException JavaDoc {
683
684         if (TraceTm.recovery.isDebugEnabled()) {
685             TraceTm.recovery.debug("Close howl log");
686         }
687
688         if (xaLog == null) return;
689
690         try {
691             xaLog.close();
692         } catch (IOException JavaDoc e) {
693             TraceTm.jotm.error("xaLog.close: IOException");
694             throw new SystemException JavaDoc("IOException occured in xaLog.close() " + e.getMessage());
695         } catch (InterruptedException JavaDoc e) {
696             TraceTm.jotm.error("xaLog.close: InterruptedException");
697             throw new SystemException JavaDoc("InterruptedException occured in xaLog.close() " + e.getMessage());
698         }
699
700         xaLog = null;
701
702         if (TraceTm.recovery.isDebugEnabled()) {
703             TraceTm.recovery.debug("Howl log closed");
704         }
705     }
706
707     /**
708      * write the Commit record to the Howl Log
709      */

710
711     public XACommittingTx howlCommitLog (byte [] [] xaCmRec) throws LogException, Exception JavaDoc {
712         if (TraceTm.recovery.isDebugEnabled()) {
713             TraceTm.recovery.debug("Commit howl log");
714         }
715         return xaLog.putCommit (xaCmRec);
716     }
717
718     /**
719      * write the Done record to the Howl Log
720      */

721
722     public void howlDoneLog (byte [] [] xaDnRec, XACommittingTx xaCmTx) throws LogException, Exception JavaDoc {
723         if (TraceTm.recovery.isDebugEnabled()) {
724             TraceTm.recovery.debug("Done howl log");
725         }
726         xaLog.putDone (xaDnRec, xaCmTx);
727     }
728     
729     /**
730      * close Transaction Recovery Log
731      */

732
733     public void forget () throws LogException, Exception JavaDoc {
734         
735         if (!Current.getDefaultRecovery()) {
736             if (TraceTm.recovery.isDebugEnabled()) {
737                 TraceTm.recovery.debug("JOTM Recovery is disabled");
738             }
739         } else {
740             howlCloseLog();
741         }
742
743    }
744
745 }
746
Popular Tags