KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > log > FileHandle


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: FileHandle.java,v 1.19 2006/10/30 21:14:20 bostic Exp $
7  */

8
9 package com.sleepycat.je.log;
10
11 import java.io.IOException JavaDoc;
12 import java.io.RandomAccessFile JavaDoc;
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 JavaDoc file;
24     private Latch fileLatch;
25     private boolean oldHeaderVersion;
26
27     FileHandle(RandomAccessFile JavaDoc file,
28                String JavaDoc fileName,
29                EnvironmentImpl env,
30                boolean oldHeaderVersion) {
31         this.file = file;
32         this.oldHeaderVersion = oldHeaderVersion;
33         fileLatch = LatchSupport.makeLatch(fileName + "_fileHandle", env);
34     }
35
36     RandomAccessFile JavaDoc getFile() {
37         return file;
38     }
39
40     boolean isOldHeaderVersion() {
41         return oldHeaderVersion;
42     }
43
44     void latch()
45         throws DatabaseException {
46
47         fileLatch.acquire();
48     }
49
50     boolean latchNoWait()
51         throws DatabaseException {
52
53         return fileLatch.acquireNoWait();
54     }
55
56     void release()
57         throws DatabaseException {
58
59         fileLatch.release();
60     }
61
62     void close()
63     throws IOException JavaDoc {
64
65     if (file != null) {
66         file.close();
67         file = null;
68     }
69     }
70 }
71
Popular Tags