KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: CheckpointFileReader.java,v 1.26 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.nio.ByteBuffer JavaDoc;
13
14 import com.sleepycat.je.DatabaseException;
15 import com.sleepycat.je.dbi.EnvironmentImpl;
16
17 /**
18  * CheckpointFileReader searches for root and checkpoint entries.
19  */

20 public class CheckpointFileReader extends FileReader {
21     /* Status about the last entry. */
22     private boolean isRoot;
23     private boolean isCheckpointEnd;
24     private boolean isCheckpointStart;
25
26     /**
27      * Create this reader to start at a given LSN.
28      */

29     public CheckpointFileReader(EnvironmentImpl env,
30                                 int readBufferSize,
31                                 boolean forward,
32                                 long startLsn,
33                                 long finishLsn,
34                                 long endOfFileLsn)
35         throws IOException JavaDoc, DatabaseException {
36
37         super(env, readBufferSize, forward, startLsn,
38           null, endOfFileLsn, finishLsn);
39     }
40
41     /**
42      * @return true if this is a targetted entry.
43      */

44     protected boolean isTargetEntry(byte logEntryTypeNumber,
45                                     byte logEntryTypeVersion) {
46         boolean isTarget = false;
47         isRoot = false;
48         isCheckpointEnd = false;
49         isCheckpointStart = false;
50         if (LogEntryType.LOG_CKPT_END.equalsType(logEntryTypeNumber,
51                          logEntryTypeVersion)) {
52             isTarget = true;
53             isCheckpointEnd = true;
54         } else if (LogEntryType.LOG_CKPT_START.equalsType(logEntryTypeNumber,
55                                                         logEntryTypeVersion)) {
56             isTarget = true;
57             isCheckpointStart = true;
58         } else if (LogEntryType.LOG_ROOT.equalsType(logEntryTypeNumber,
59                             logEntryTypeVersion)) {
60             isTarget = true;
61             isRoot = true;
62         }
63         return isTarget;
64     }
65     
66     /**
67      * This reader instantiate the first object of a given log entry
68      */

69     protected boolean processEntry(ByteBuffer JavaDoc entryBuffer)
70         throws DatabaseException {
71
72         /* Don't need to read the entry, since we just use the LSN. */
73         return true;
74     }
75
76     /**
77      * @return true if last entry was a root entry.
78      */

79     public boolean isRoot() {
80         return isRoot;
81     }
82
83     /**
84      * @return true if last entry was a checkpoint end entry.
85      */

86     public boolean isCheckpointEnd() {
87         return isCheckpointEnd;
88     }
89
90     /**
91      * @return true if last entry was a checkpoint start entry.
92      */

93     public boolean isCheckpointStart() {
94         return isCheckpointStart;
95     }
96 }
97
Popular Tags