1 22 package org.jboss.tm.recovery; 23 24 import java.io.File ; 25 import java.io.FileInputStream ; 26 import java.io.IOException ; 27 import java.nio.ByteBuffer ; 28 import java.nio.channels.FileChannel ; 29 import java.util.Map ; 30 31 43 public class SimpleHeuristicStatusLogReader 44 implements HeuristicStatusLogReader 45 { 46 47 private File logFile; 48 49 54 public SimpleHeuristicStatusLogReader(File logFile) 55 { 56 this.logFile = logFile; 57 } 58 59 64 public String getLogFileName() 65 { 66 return logFile.toString(); 67 } 68 69 80 public void recover(Map heuristicallyCompletedTransactions) 81 { 82 FileInputStream fis; 83 84 try 85 { 86 fis = new FileInputStream (logFile); 87 88 } 89 catch (IOException e) 90 { 91 throw new RuntimeException (e); 92 } 93 94 try 95 { 96 if (fis.available() < LogRecord.FULL_HEADER_LEN) 97 return; 99 FileChannel channel = fis.getChannel(); 100 ByteBuffer buf = ByteBuffer.allocate(LogRecord.FULL_HEADER_LEN); 101 channel.read(buf); 102 103 int len = LogRecord.getNextRecordLength(buf, 0); 104 LogRecord.HeurData data = new LogRecord.HeurData(); 105 106 while (len > 0) 107 { 108 buf = ByteBuffer.allocate(len + LogRecord.FULL_HEADER_LEN); 109 if (channel.read(buf) < len) 110 break; buf.flip(); 112 LogRecord.getHeurData(buf, len, data); 113 switch (data.recordType) 114 { 115 case LogRecord.HEUR_STATUS: 116 heuristicallyCompletedTransactions.put( 117 new Long (data.localTransactionId), 118 data); 119 break; 120 121 case LogRecord.HEUR_FORGOTTEN: 122 heuristicallyCompletedTransactions.remove( 123 new Long (data.localTransactionId)); 124 break; 125 126 default: 127 break; 129 } 130 len = LogRecord.getNextRecordLength(buf, len); 131 } 132 } 133 catch (IOException ignore) 134 { 135 } 136 try 137 { 138 fis.close(); 139 } 140 catch (IOException e) 141 { 142 throw new RuntimeException (e); 143 } 144 145 } 146 147 150 public void finishRecovery() 151 { 152 logFile.delete(); 153 } 154 155 } 156 | Popular Tags |