01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: DumpFileReader.java,v 1.43.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.util.HashSet;
13: import java.util.Set;
14: import java.util.StringTokenizer;
15:
16: import com.sleepycat.je.DatabaseException;
17: import com.sleepycat.je.dbi.EnvironmentImpl;
18: import com.sleepycat.je.utilint.DbLsn;
19:
20: /**
21: * The DumpFileReader prints every log entry to stdout.
22: */
23: public abstract class DumpFileReader extends FileReader {
24:
25: /* A set of the entry type numbers that this DumpFileReader should dump. */
26: private Set targetEntryTypes;
27:
28: /* A set of the txn ids that this DumpFileReader should dump. */
29: protected Set targetTxnIds;
30:
31: /* If true, dump the long version of the entry. */
32: protected boolean verbose;
33:
34: /**
35: * Create this reader to start at a given LSN.
36: */
37: public DumpFileReader(EnvironmentImpl env, int readBufferSize,
38: long startLsn, long finishLsn, String entryTypes,
39: String txnIds, boolean verbose) throws IOException,
40: DatabaseException {
41:
42: super (env, readBufferSize, true, // read forward
43: startLsn, null, // single file number
44: DbLsn.NULL_LSN, // end of file lsn
45: finishLsn); // finish lsn
46:
47: /* If entry types is not null, record the set of target entry types. */
48: targetEntryTypes = new HashSet();
49: if (entryTypes != null) {
50: StringTokenizer tokenizer = new StringTokenizer(entryTypes,
51: ",");
52: while (tokenizer.hasMoreTokens()) {
53: String typeString = (String) tokenizer.nextToken();
54: targetEntryTypes.add(new Byte(typeString.trim()));
55: }
56: }
57: /* If txn ids is not null, record the set of target txn ids. */
58: targetTxnIds = new HashSet();
59: if (txnIds != null) {
60: StringTokenizer tokenizer = new StringTokenizer(txnIds, ",");
61: while (tokenizer.hasMoreTokens()) {
62: String txnIdString = (String) tokenizer.nextToken();
63: targetTxnIds.add(new Long(txnIdString.trim()));
64: }
65: }
66: this .verbose = verbose;
67: }
68:
69: /**
70: * @return true if this reader should process this entry, or just
71: * skip over it.
72: */
73: protected boolean isTargetEntry(byte logEntryTypeNumber,
74: byte logEntryTypeVersion) {
75: if (targetEntryTypes.size() == 0) {
76: /* We want to dump all entry types. */
77: return true;
78: } else {
79: return targetEntryTypes.contains(new Byte(
80: logEntryTypeNumber));
81: }
82: }
83:
84: public void summarize() {
85: }
86: }
|