comparison src/org/dancres/blitz/tools/DumpEntries.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.tools;
2
3 import java.io.IOException;
4
5 import java.rmi.RMISecurityManager;
6
7 import org.dancres.blitz.disk.Disk;
8 import org.dancres.blitz.disk.DiskTxn;
9
10 import org.dancres.blitz.config.ConfigurationFactory;
11
12 import org.dancres.blitz.entry.EntryRepositoryFactory;
13 import org.dancres.blitz.entry.EntryRepository;
14 import org.dancres.blitz.entry.SearchVisitor;
15 import org.dancres.blitz.entry.SearchOffer;
16
17 import org.dancres.blitz.mangler.MangledEntry;
18 import org.dancres.blitz.mangler.EntryMangler;
19
20 /**
21 <p>DumpEntries performs an off-line dump of the contents of a Blitz
22 instance.</p>
23
24 <p><b>WARNING:</b> <em>DO NOT</em> run this tool against an active space
25 instance's databases. Shut it down first using
26 <code>SyncAndShutdown</code>.</p>
27
28 <p>Single required argument is the configuration file for the space instance
29 whose contents you wish to dump. By default, the tool will print both
30 internal Entry information associated with storage functions <em>and</em>
31 attempt to unpack the Entry instance and display it on
32 <code>System.out</code>. The displaying of unpacked Entry instances may
33 be problematic in cases such as when a codebase is not available thus
34 this step can be disabled by passing in <code>-Dnounpack=true</code>.</p>
35
36 <p>Typical usages:
37
38 <pre>
39 java -Xmx256m -Djava.security.policy=config/policy.all
40 -classpath /home/dan/lib/db.jar:/home/dan/jini/jini2_0/lib/jsk-platform.jar:/home/dan/src/jini/space/build:/home/dan/jini/jini2_0/lib/jini-ext.jar:/home/dan/jini/jini2_0/lib/sun-util.jar
41 org.dancres.blitz.tools.DumpEntries config/blitz.config
42
43 java -Dnounpack=true -Xmx256m -Djava.security.policy=config/policy.all
44 -classpath /home/dan/lib/db.jar:/home/dan/jini/jini2_0/lib/jsk-platform.jar:/home/dan/src/jini/space/build:/home/dan/jini/jini2_0/lib/jini-ext.jar:/home/dan/jini/jini2_0/lib/sun-util.jar
45 org.dancres.blitz.tools.DumpEntries config/blitz.config
46 </pre>
47 </p>
48
49 <p>This tool is non-destructive so it's perfectly possible to shut a
50 Blitz instance down using <code>SyncAndShutdown</code>,
51 run this tool and then restart the space.</p>
52
53 <p>It's also worth mentioning that, because Blitz's transient mode is
54 still disk backed to allow for swapping, this tool can be used to examine
55 the contents of a transient Blitz instance shutdown with <code>
56 SyncAndShutdown</code>.</p>
57
58 @see org.dancres.blitz.tools.SyncAndShutdown
59 */
60 public class DumpEntries {
61 public static void main(String args[]) {
62 if (args.length != 1) {
63 System.err.println("Usage: DumpEntries <config_file>");
64 System.exit(-1);
65 }
66
67 /**
68 We need this to access codebases for objects
69 */
70 System.setSecurityManager(new RMISecurityManager());
71
72 try {
73 ConfigurationFactory.setup(args);
74
75 Disk.init();
76
77 String[] myKnownTypes =
78 EntryRepositoryFactory.get().get(EntryRepository.ROOT_TYPE).getSubtypes();
79
80 for (int i = 0; i < myKnownTypes.length; i++) {
81 EntryRepository myRepos =
82 EntryRepositoryFactory.get().get(myKnownTypes[i]);
83
84 System.out.println("Repository: " + myKnownTypes[i]);
85 dumpRepos(myRepos);
86
87 System.out.println("");
88 }
89
90 } catch (IOException anIOE) {
91 System.err.println("Yikes, got I/O problems");
92 anIOE.printStackTrace(System.err);
93 } finally {
94 try {
95 Disk.stop();
96 } catch (Exception anE) {
97 System.err.println("Warning failed to close Disk properly");
98 anE.printStackTrace(System.err);
99 }
100 }
101 }
102
103 private static void dumpRepos(EntryRepository aRepos) throws IOException {
104 if (aRepos == null) {
105 System.out.println("Empty");
106 return;
107 }
108
109 DiskTxn myTxn = DiskTxn.newTxn();
110
111 try {
112 if (aRepos.noSchemaDefined()) {
113 System.out.println("Has No Schema");
114 return;
115 }
116
117 if (aRepos.getTotalStoredEntries() == 0) {
118 System.out.println("No entries");
119 return;
120 } else {
121 System.out.println("Total entries: " +
122 aRepos.getTotalStoredEntries());
123 }
124
125 System.out.println("");
126 DumpVisitor myVisitor = new DumpVisitor();
127
128 aRepos.find(MangledEntry.NULL_TEMPLATE, myVisitor);
129
130 System.out.println("Lease expired entries (ignored): " +
131 (aRepos.getTotalStoredEntries() - myVisitor.getTotalEntries()));
132 } finally {
133 myTxn.commit();
134 }
135 }
136
137 private static final class DumpVisitor implements SearchVisitor {
138 private EntryMangler theMangler = new EntryMangler();
139 private int theTotalEntries;
140
141 public int offer(SearchOffer anOffer) {
142
143 ++theTotalEntries;
144
145 MangledEntry myEntry = anOffer.getEntry();
146 myEntry.dump(System.out);
147
148 System.out.println();
149
150 if (!Boolean.getBoolean("nounpack")) {
151 try {
152 System.out.println("Unpacked Entry.toString(): " + theMangler.unMangle(myEntry));
153 } catch (Exception anE) {
154 System.err.println("Couldn't unpack entry");
155 anE.printStackTrace(System.err);
156 }
157 } else {
158 System.out.println("Unpack disabled");
159 }
160
161 System.out.println("");
162 System.out.println("--------------------------------------------");
163 System.out.println("");
164
165 return SearchVisitor.TRY_AGAIN;
166 }
167
168 int getTotalEntries() {
169 return theTotalEntries;
170 }
171
172 public boolean isDeleter() {
173 return false;
174 }
175 }
176 }