01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: CheckpointFileReader.java,v 1.26.2.3 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.nio.ByteBuffer;
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, boolean forward, long startLsn,
31: long finishLsn, long endOfFileLsn) throws IOException,
32: DatabaseException {
33:
34: super (env, readBufferSize, forward, startLsn, null,
35: endOfFileLsn, finishLsn);
36: }
37:
38: /**
39: * @return true if this is a targetted entry.
40: */
41: protected boolean isTargetEntry(byte logEntryTypeNumber,
42: byte logEntryTypeVersion) {
43: boolean isTarget = false;
44: isRoot = false;
45: isCheckpointEnd = false;
46: isCheckpointStart = false;
47: if (LogEntryType.LOG_CKPT_END.equalsType(logEntryTypeNumber,
48: logEntryTypeVersion)) {
49: isTarget = true;
50: isCheckpointEnd = true;
51: } else if (LogEntryType.LOG_CKPT_START.equalsType(
52: logEntryTypeNumber, logEntryTypeVersion)) {
53: isTarget = true;
54: isCheckpointStart = true;
55: } else if (LogEntryType.LOG_ROOT.equalsType(logEntryTypeNumber,
56: logEntryTypeVersion)) {
57: isTarget = true;
58: isRoot = true;
59: }
60: return isTarget;
61: }
62:
63: /**
64: * This reader instantiate the first object of a given log entry
65: */
66: protected boolean processEntry(ByteBuffer entryBuffer)
67: throws DatabaseException {
68:
69: /* Don't need to read the entry, since we just use the LSN. */
70: return true;
71: }
72:
73: /**
74: * @return true if last entry was a root entry.
75: */
76: public boolean isRoot() {
77: return isRoot;
78: }
79:
80: /**
81: * @return true if last entry was a checkpoint end entry.
82: */
83: public boolean isCheckpointEnd() {
84: return isCheckpointEnd;
85: }
86:
87: /**
88: * @return true if last entry was a checkpoint start entry.
89: */
90: public boolean isCheckpointStart() {
91: return isCheckpointStart;
92: }
93: }
|