1 22 package org.jboss.tm.recovery; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.io.RandomAccessFile ; 27 import java.nio.ByteBuffer ; 28 import java.nio.channels.FileChannel ; 29 30 import org.jboss.logging.Logger; 31 32 47 public class HeuristicStatusLog 48 { 49 52 private static Logger errorLog = 53 Logger.getLogger(HeuristicStatusLog.class); 54 55 58 private static boolean traceEnabled = errorLog.isTraceEnabled(); 59 60 63 private File logFile; 64 65 68 RandomAccessFile os; 69 70 73 private FileChannel channel; 74 75 81 HeuristicStatusLog(File dir) 82 throws IOException 83 { 84 logFile = File.createTempFile("HEURISTIC_STATUS_LOG", ".log", dir); 85 os = new RandomAccessFile (logFile, "rw"); 86 channel = os.getChannel(); 87 channel.force(true); 88 } 89 90 96 void write(ByteBuffer record) 97 { 98 if (traceEnabled) 99 { 100 errorLog.trace("Heuristic status log record:" + 101 HexDump.fromBuffer(record.array())); 102 errorLog.trace(LogRecord.toString(record)); 103 } 104 105 try 106 { 107 channel.write(record); 108 channel.force(true); 109 } 110 catch (IOException e) 111 { 112 errorLog.error("Error writing heuristic status log " + 113 logFile.getName(), e); 114 } 115 } 116 117 120 void close() 121 { 122 try 123 { 124 os.close(); 125 } 126 catch (IOException e) 127 { 128 errorLog.error("Error closing heuristic status log " + 129 logFile.getName(), e); 130 } 131 } 132 133 } 134 | Popular Tags |