comparison src/org/dancres/blitz/tools/SyncAndShutdown.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.RemoteException;
6 import java.rmi.RMISecurityManager;
7
8 import net.jini.discovery.*;
9
10 import net.jini.lookup.*;
11 import net.jini.lookup.entry.Name;
12
13 import net.jini.core.lookup.ServiceItem;
14 import net.jini.core.lookup.ServiceTemplate;
15
16 import net.jini.core.entry.Entry;
17
18 import net.jini.admin.Administrable;
19
20 import net.jini.space.JavaSpace;
21
22 import net.jini.core.transaction.TransactionException;
23
24 import org.dancres.blitz.remote.BlitzAdmin;
25
26 import org.dancres.jini.util.DiscoveryUtil;
27 import org.dancres.jini.util.ServiceLocator;
28
29 /**
30 <p>SyncAndShutdown accepts a spacename as an argument and attempts to
31 shut it down cleanly having sync'd it's contents to disk (this second
32 step isn't strictly necessary but does ensure that all state is available
33 from the underlying databases without any dependency on the log files).
34 This tool will only work with a Blitz JavaSpace owing to it's dependence
35 upon the <code>BlitzAdmin</code> interface.</p>
36
37 <p>Once a Blitz instance has been shutdown in this manner, one may, for
38 example, use <code>DumpEntries</code> to examine it's Entry content.</p>
39
40 <p>Typical usage:
41
42 <pre>
43 java -Xmx256m -Djava.security.policy=config/policy.all
44 -classpath /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.SyncAndShutdown dancres
46 </pre>
47
48 <p>This tool is non-destructive so it's perfectly possible to shut a
49 Blitz instance down, run <code>DumpEntries</code> and then restart the
50 space.</p>
51
52 <p>Note if there are active transactions, Blitz will by default refuse
53 to honour the request. You can force Blitz to shutdown by adding
54 <code>-Dforce=true</code> to the command-line(s) above.</p>
55
56 @see org.dancres.blitz.remote.BlitzAdmin
57 @see org.dancres.blitz.tools.DumpEntries
58 */
59 public class SyncAndShutdown {
60 private static final long MAX_DISCOVER_TIME = 15 * 1000;
61
62 public static void main(String args[]) {
63 if (System.getSecurityManager() == null)
64 System.setSecurityManager(new RMISecurityManager());
65
66 boolean amForced = Boolean.getBoolean("force");
67
68 try {
69 try {
70 Object myProxy = null;
71
72 if (args.length == 1)
73 myProxy = ServiceLocator.getService(JavaSpace.class,
74 args[0],
75 MAX_DISCOVER_TIME);
76 else if (args.length == 2) {
77 myProxy = ServiceLocator.getService(args[0],
78 JavaSpace.class,
79 args[1]);
80 } else {
81 System.err.println("Wrong number of arguments - should be <spacename> or <LUS host> <spacename>");
82 System.exit(-1);
83 }
84
85 if (myProxy != null) {
86 System.err.println("Found space: " + myProxy);
87
88 DiscoveryUtil.dumpInterfaces(myProxy.getClass());
89
90 if (DiscoveryUtil.hasInterface(myProxy,
91 Administrable.class)) {
92 Administrable myAdmin = (Administrable) myProxy;
93
94 Object myAdminProxy = myAdmin.getAdmin();
95
96 DiscoveryUtil.dumpInterfaces(myAdminProxy.getClass());
97
98 if (DiscoveryUtil.hasInterface(myAdminProxy,
99 BlitzAdmin.class)) {
100 BlitzAdmin myBlitzAdmin =
101 (BlitzAdmin) myAdminProxy;
102
103 try {
104 System.err.println("Invoking checkpoint");
105 myBlitzAdmin.requestSnapshot();
106 } catch (TransactionException aTE) {
107 System.err.println("Failed to checkpoint");
108 aTE.printStackTrace(System.err);
109
110 if (amForced) {
111 System.err.println("Ignoring checkpoint " +
112 "failure and forcing shutdown");
113 } else {
114 System.exit(-1);
115 }
116 }
117
118 System.err.println("Invoking shutdown");
119 myBlitzAdmin.shutdown();
120 } else {
121 System.err.println("No BlitzAdmin interface found - can't be Blitz");
122 }
123 } else {
124 System.err.println("No admin interface present - can't be Blitz");
125 }
126 }
127 } catch (InterruptedException anIE) {
128 System.err.println("!!! Whoops service not found :( !!!");
129 }
130 } catch (ClassNotFoundException aCNFE) {
131 System.err.println("ClassNotFound exception");
132 aCNFE.printStackTrace(System.err);
133 } catch (RemoteException anRE) {
134 System.err.println("Remote exception");
135 anRE.printStackTrace(System.err);
136 } catch (IOException anIOE) {
137 System.err.println("Failed to configure discovery");
138 anIOE.printStackTrace(System.err);
139 }
140 }
141 }