01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: FileHandle.java,v 1.19.2.2 2008/01/07 15:14:13 cwl Exp $
07: */
08:
09: package com.sleepycat.je.log;
10:
11: import java.io.IOException;
12: import java.io.RandomAccessFile;
13:
14: import com.sleepycat.je.DatabaseException;
15: import com.sleepycat.je.dbi.EnvironmentImpl;
16: import com.sleepycat.je.latch.Latch;
17: import com.sleepycat.je.latch.LatchSupport;
18:
19: /**
20: * A FileHandle embodies a File and its accompanying latch.
21: */
22: class FileHandle {
23: private RandomAccessFile file;
24: private Latch fileLatch;
25: private boolean oldHeaderVersion;
26:
27: FileHandle(RandomAccessFile file, String fileName,
28: EnvironmentImpl env, boolean oldHeaderVersion) {
29: this .file = file;
30: this .oldHeaderVersion = oldHeaderVersion;
31: fileLatch = LatchSupport.makeLatch(fileName + "_fileHandle",
32: env);
33: }
34:
35: RandomAccessFile getFile() {
36: return file;
37: }
38:
39: boolean isOldHeaderVersion() {
40: return oldHeaderVersion;
41: }
42:
43: void latch() throws DatabaseException {
44:
45: fileLatch.acquire();
46: }
47:
48: boolean latchNoWait() throws DatabaseException {
49:
50: return fileLatch.acquireNoWait();
51: }
52:
53: void release() throws DatabaseException {
54:
55: fileLatch.release();
56: }
57:
58: void close() throws IOException {
59:
60: if (file != null) {
61: file.close();
62: file = null;
63: }
64: }
65: }
|