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