Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/tools/Cleanup.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 | fa7203ea1622 |
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>Triggers a cleanup of all Entry's in the specified Blitz instance.</p> | |
31 | |
32 @see org.dancres.blitz.remote.BlitzAdmin | |
33 */ | |
34 public class Cleanup { | |
35 private static final long MAX_DISCOVER_TIME = 15 * 1000; | |
36 | |
37 public static void main(String args[]) { | |
38 if (System.getSecurityManager() == null) | |
39 System.setSecurityManager(new RMISecurityManager()); | |
40 | |
41 try { | |
42 try { | |
43 Object myProxy = null; | |
44 | |
45 if (args.length == 1) | |
46 myProxy = ServiceLocator.getService(JavaSpace.class, | |
47 args[0], | |
48 MAX_DISCOVER_TIME); | |
49 else if (args.length == 2) { | |
50 myProxy = ServiceLocator.getService(args[0], | |
51 JavaSpace.class, | |
52 args[1]); | |
53 } else { | |
54 System.err.println("Wrong number of arguments - should be <spacename> or <LUS host> <spacename>"); | |
55 System.exit(-1); | |
56 } | |
57 | |
58 String myDir = args[0]; | |
59 | |
60 if (myProxy != null) { | |
61 System.err.println("Found space: " + myProxy); | |
62 | |
63 DiscoveryUtil.dumpInterfaces(myProxy.getClass()); | |
64 | |
65 if (DiscoveryUtil.hasInterface(myProxy, | |
66 Administrable.class)) { | |
67 Administrable myAdmin = (Administrable) myProxy; | |
68 | |
69 Object myAdminProxy = myAdmin.getAdmin(); | |
70 | |
71 DiscoveryUtil.dumpInterfaces(myAdminProxy.getClass()); | |
72 | |
73 if (DiscoveryUtil.hasInterface(myAdminProxy, | |
74 BlitzAdmin.class)) { | |
75 BlitzAdmin myBlitzAdmin = | |
76 (BlitzAdmin) myAdminProxy; | |
77 | |
78 try { | |
79 System.err.println("Invoking cleanup"); | |
80 myBlitzAdmin.clean(); | |
81 } catch (Exception aE) { | |
82 System.err.println("Failed to cleanup"); | |
83 aE.printStackTrace(System.err); | |
84 System.exit(-1); | |
85 } | |
86 } else { | |
87 System.err.println("No BlitzAdmin interface found - can't be Blitz"); | |
88 } | |
89 } else { | |
90 System.err.println("No admin interface present - can't be Blitz"); | |
91 } | |
92 } | |
93 } catch (InterruptedException anIE) { | |
94 System.err.println("!!! Whoops service not found :( !!!"); | |
95 } | |
96 } catch (ClassNotFoundException aCNFE) { | |
97 System.err.println("ClassNotFound exception"); | |
98 aCNFE.printStackTrace(System.err); | |
99 } catch (RemoteException anRE) { | |
100 System.err.println("Remote exception"); | |
101 anRE.printStackTrace(System.err); | |
102 } catch (IOException anIOE) { | |
103 System.err.println("Failed to configure discovery"); | |
104 anIOE.printStackTrace(System.err); | |
105 } | |
106 } | |
107 } |