KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: DumpFileReader.java,v 1.43 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.util.HashSet JavaDoc;
13 import java.util.Set JavaDoc;
14 import java.util.StringTokenizer JavaDoc;
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 JavaDoc targetEntryTypes;
27
28     /* A set of the txn ids that this DumpFileReader should dump. */
29     protected Set JavaDoc 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,
38               int readBufferSize,
39               long startLsn,
40               long finishLsn,
41               String JavaDoc entryTypes,
42               String JavaDoc txnIds,
43               boolean verbose)
44     throws IOException JavaDoc, DatabaseException {
45
46         super(env,
47               readBufferSize,
48               true, // read forward
49
startLsn,
50               null, // single file number
51
DbLsn.NULL_LSN, // end of file lsn
52
finishLsn); // finish lsn
53

54         /* If entry types is not null, record the set of target entry types. */
55         targetEntryTypes = new HashSet JavaDoc();
56         if (entryTypes != null) {
57             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(entryTypes, ",");
58             while (tokenizer.hasMoreTokens()) {
59                 String JavaDoc typeString = (String JavaDoc) tokenizer.nextToken();
60                 targetEntryTypes.add(new Byte JavaDoc(typeString.trim()));
61             }
62         }
63         /* If txn ids is not null, record the set of target txn ids. */
64         targetTxnIds = new HashSet JavaDoc();
65         if (txnIds != null) {
66             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(txnIds, ",");
67             while (tokenizer.hasMoreTokens()) {
68                 String JavaDoc txnIdString = (String JavaDoc) tokenizer.nextToken();
69                 targetTxnIds.add(new Long JavaDoc(txnIdString.trim()));
70             }
71         }
72         this.verbose = verbose;
73     }
74
75     /**
76      * @return true if this reader should process this entry, or just
77      * skip over it.
78      */

79     protected boolean isTargetEntry(byte logEntryTypeNumber,
80                                     byte logEntryTypeVersion) {
81     if (targetEntryTypes.size() == 0) {
82         /* We want to dump all entry types. */
83         return true;
84     } else {
85         return targetEntryTypes.contains(new Byte JavaDoc(logEntryTypeNumber));
86     }
87     }
88
89     public void summarize() {
90     }
91 }
92
Popular Tags