1 23 24 28 50 package com.sun.jts.CosTransactions; 51 52 54 import java.util.*; 55 import java.util.logging.Logger ; 56 import java.util.logging.Level ; 57 import com.sun.logging.LogDomains; 58 import com.sun.jts.utils.LogFormatter; 59 60 72 79 class LogFile { 80 81 83 final static int UNFORCED = 0; 84 final static int FORCED = 1; 85 86 88 final static int NORMAL = 0; 89 final static int KEYPOINT_START = 1; 90 final static int KEYPOINT_END = 2; 91 final static int REWRITE = 3; 92 93 96 97 static Logger _logger = LogDomains.getLogger(LogDomains.TRANSACTION_LOGGER); 98 99 101 LogHandle handle = null; 102 103 111 LogFile( LogHandle handle ) { 112 113 115 this.handle = handle; 116 117 } 118 119 139 synchronized boolean write( int writeType, 140 byte[] record, 141 int recordType, 142 LogLSN recordLSN ) { 143 144 boolean result = true; 145 146 149 try { 150 LogLSN resultLSN = handle.writeRecord(record,recordType, 151 (writeType==LogFile.FORCED ? LogHandle.FORCE : LogHandle.BUFFER)); 152 if( recordLSN != null ) 153 recordLSN.copy(resultLSN); 154 } catch( LogException le ) { 155 _logger.log(Level.SEVERE,"jts.log_error",le.toString()); 156 String msg = LogFormatter.getLocalizedMessage(_logger,"jts.log_error", 157 new java.lang.Object [] {le.toString()}); 158 throw new org.omg.CORBA.INTERNAL (msg); 159 } 163 164 return result; 165 } 166 167 180 synchronized boolean checkpoint( LogLSN firstLSN ) { 181 182 boolean result = true; 183 LogLSN checkLSN; 184 185 187 if( firstLSN.isNULL() ) 188 checkLSN = new LogLSN(LogLSN.HEAD_LSN); 189 else 190 checkLSN = new LogLSN(firstLSN); 191 192 194 try { 195 handle.checkLSN(checkLSN); 196 handle.truncate(checkLSN,LogHandle.TAIL_NOT_INCLUSIVE); 197 } catch( LogException le ) { 198 result = false; 199 } 200 201 return result; 202 } 203 204 213 synchronized boolean writeRestart( byte[] record ) { 214 215 boolean result = false; 216 217 219 try { 220 handle.writeRestart(record); 221 result = true; 222 } catch( LogException le ) { 223 result = false; 224 } 225 226 return result; 227 } 228 229 238 synchronized byte[] readRestart() { 239 byte[] result = null; 240 241 243 try { 244 result = handle.readRestart(); 245 } catch( LogException le ) { 246 } 247 248 return result; 249 } 250 251 261 synchronized boolean close( boolean deleteFile ) { 262 263 boolean result = true; 264 265 267 try { 268 handle.closeFile(deleteFile); 269 } catch( LogException le ) { 270 result = false; 271 } 272 273 return result; 274 } 275 276 291 synchronized Vector getLogRecords() { 292 Vector logRecords = new Vector(); 293 boolean keypointEndFound = false; 294 LogCursor logCursor; 295 296 298 try { 299 logCursor = handle.openCursor(LogLSN.HEAD_LSN,LogLSN.TAIL_LSN); 300 } catch( LogException le ) { 301 302 return new Vector(); 303 } 304 305 307 try { 308 LogLSN lsn = new LogLSN(); 309 int[] recordType = new int[1]; 310 311 for(;;) { 312 byte[] logRecord = logCursor.readCursor(recordType,lsn); 313 314 316 switch( recordType[0] ) { 317 318 324 case LogFile.KEYPOINT_START : 325 if( keypointEndFound ) 326 throw new LogException(null,LogException.LOG_END_OF_CURSOR,2); 327 break; 328 329 333 case LogFile.KEYPOINT_END : 334 keypointEndFound = true; 335 break; 336 337 341 case LogFile.NORMAL : 342 case LogFile.REWRITE : 343 if( (recordType[0] == LogFile.NORMAL) || keypointEndFound ) 344 logRecords.addElement(logRecord); 345 break; 346 347 349 default : 350 break; 351 } 352 } 353 } catch( LogException le ) { 354 355 358 if( le.errorCode != LogException.LOG_END_OF_CURSOR ) { 359 return new Vector(); 360 } 361 } 362 363 365 try { 366 handle.closeCursor(logCursor); 367 } catch( LogException le ) { 368 } 369 370 return logRecords; 371 } 372 373 381 void dump() { 382 384 387 } 388 } 389 | Popular Tags |