org/objectweb/proactive/core/body/ft/servers/StartFTServer.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.body.ft.servers;
00032 
00033 import java.net.InetAddress;
00034 import java.net.MalformedURLException;
00035 import java.net.UnknownHostException;
00036 import java.rmi.Naming;
00037 import java.rmi.RMISecurityManager;
00038 import java.rmi.RemoteException;
00039 
00040 import org.objectweb.proactive.core.body.ft.protocols.cic.servers.CheckpointServerCIC;
00041 import org.objectweb.proactive.core.body.ft.protocols.cic.servers.RecoveryProcessCIC;
00042 import org.objectweb.proactive.core.body.ft.protocols.pmlrb.servers.CheckpointServerPMLRB;
00043 import org.objectweb.proactive.core.body.ft.protocols.pmlrb.servers.RecoveryProcessPMLRB;
00044 import org.objectweb.proactive.core.body.ft.servers.faultdetection.FaultDetector;
00045 import org.objectweb.proactive.core.body.ft.servers.faultdetection.FaultDetectorImpl;
00046 import org.objectweb.proactive.core.body.ft.servers.location.LocationServer;
00047 import org.objectweb.proactive.core.body.ft.servers.location.LocationServerImpl;
00048 import org.objectweb.proactive.core.body.ft.servers.recovery.RecoveryProcess;
00049 import org.objectweb.proactive.core.body.ft.servers.resource.ResourceServer;
00050 import org.objectweb.proactive.core.body.ft.servers.resource.ResourceServerImpl;
00051 import org.objectweb.proactive.core.body.ft.servers.storage.CheckpointServer;
00052 import org.objectweb.proactive.core.rmi.RegistryHelper;
00053 
00054 
00061 public class StartFTServer {
00062     public static void main(String[] args) {
00063         try {
00064             int port = 0;
00065             int fdPeriod = 0;
00066             String name = "";
00067             String proto = "cic";
00068             String p2pServer = null;
00069 
00070             if (args.length == 0) {
00071                 System.out.println(
00072                     "Usage startGlobalFTServer [-proto cic|pml] [-name name] [-port portnumber] [-fdperiod faultDetectionPeriod (sec)] [-p2p serverUrl]");
00073             } else {
00074                 for (int i = 0; i < args.length; i++) {
00075                     if (args[i].equals("-port")) {
00076                         port = Integer.parseInt(args[i + 1]);
00077                     } else if (args[i].equals("-fdperiod")) {
00078                         fdPeriod = Integer.parseInt(args[i + 1]);
00079                     } else if (args[i].equals("-name")) {
00080                         name = args[i + 1];
00081                     } else if (args[i].equals("-proto")) {
00082                         proto = args[i + 1];
00083                     } else if (args[i].equals("-p2p")) {
00084                         p2pServer = args[i + 1];
00085                     }
00086                 }
00087             }
00088 
00089             if (port == 0) {
00090                 port = FTServer.DEFAULT_PORT;
00091             }
00092             if ("".equals(name)) {
00093                 name = FTServer.DEFAULT_SERVER_NAME;
00094             }
00095             if (fdPeriod == 0) {
00096                 fdPeriod = FTServer.DEFAULT_FDETECT_SCAN_PERIOD;
00097             }
00098 
00099             // rmi registry
00100             RegistryHelper registryHelper = new RegistryHelper();
00101             registryHelper.setRegistryPortNumber(port);
00102             registryHelper.initializeRegistry();
00103 
00104             System.setSecurityManager(new RMISecurityManager());
00105 
00106             // server init
00107             FTServer server = new FTServer();
00108             LocationServer ls = new LocationServerImpl(server);
00109             FaultDetector fd = new FaultDetectorImpl(server, fdPeriod);
00110             ResourceServer rs;
00111 
00112             // protocol specific
00113             CheckpointServer cs = null;
00114             RecoveryProcess rp = null;
00115             if (proto.equals("cic")) {
00116                 cs = new CheckpointServerCIC(server);
00117                 rp = new RecoveryProcessCIC(server);
00118             } else if (proto.equals("pml")) {
00119                 cs = new CheckpointServerPMLRB(server);
00120                 rp = new RecoveryProcessPMLRB(server);
00121             } else {
00122                 System.err.println("ERROR: " + proto +
00123                     " is not a valid protocol. Aborting.");
00124                 System.exit(1);
00125             }
00126 
00127             // resource server with p2p or not
00128             if (p2pServer != null) {
00129                 // resource server is launched on p2p network
00130                 rs = new ResourceServerImpl(server, p2pServer);
00131             } else {
00132                 rs = new ResourceServerImpl(server);
00133             }
00134 
00135             // init
00136             server.init(fd, ls, rp, rs, cs);
00137             server.startFailureDetector();
00138 
00139             String host = InetAddress.getLocalHost().getHostName();
00140             Naming.rebind("rmi://" + host + ":" + port + "/" + name, server);
00141             System.out.println("Fault-tolerance server is bound on rmi://" +
00142                 host + ":" + port + "/" + name);
00143         } catch (RemoteException e) {
00144             System.err.println("** ERROR ** Unable to launch FT server : ");
00145             e.printStackTrace();
00146         } catch (MalformedURLException e) {
00147             System.err.println("** ERROR ** Unable to launch FT server : ");
00148             e.printStackTrace();
00149         } catch (UnknownHostException e) {
00150             System.err.println("** ERROR ** Unable to launch FT server : ");
00151             e.printStackTrace();
00152         }
00153     }
00154 }

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1