org/objectweb/proactive/core/runtime/rmi/SshRmiRuntimeFactory.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.runtime.rmi;
00032 
00033 import java.rmi.registry.LocateRegistry;
00034 import java.rmi.registry.Registry;
00035 
00036 import org.objectweb.proactive.core.ProActiveException;
00037 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
00038 import org.objectweb.proactive.core.runtime.ProActiveRuntimeAdapterForwarderImpl;
00039 import org.objectweb.proactive.core.runtime.ProActiveRuntimeAdapterImpl;
00040 import org.objectweb.proactive.core.runtime.RemoteProActiveRuntime;
00041 import org.objectweb.proactive.core.ssh.rmissh.SshRMIClientSocketFactory;
00042 import org.objectweb.proactive.core.ssh.rmissh.SshRMIServerSocketFactory;
00043 import org.objectweb.proactive.core.util.UrlBuilder;
00044 
00045 
00049 public class SshRmiRuntimeFactory extends RmiRuntimeFactory {
00050     //    private static RegistryHelper registryHelper = new RegistryHelper();
00051     //    private static ClassServerHelper classServerHelper = new ClassServerHelper();
00052     //    private static ProActiveRuntime defaultRmiRuntime = null;
00053     public SshRmiRuntimeFactory() throws java.io.IOException {
00054         if ((System.getSecurityManager() == null) &&
00055                 !("false".equals(System.getProperty("proactive.securitymanager")))) {
00056             System.setSecurityManager(new java.rmi.RMISecurityManager());
00057         }
00058     }
00059 
00060     // return a Runtime object "skeleton" (ie: a server)
00061     //    protected ProActiveRuntime getProtocolSpecificRuntimeImpl()
00062     //        throws ProActiveException {
00063     //        if (defaultRmiRuntime == null) {
00064     //            try {
00065     //                registryHelper.initializeRegistry();
00066     //            } catch (java.rmi.RemoteException e) {
00067     //                e.printStackTrace();
00068     //            }
00069     //
00070     //            defaultRmiRuntime = createRuntimeAdapter();
00071     //        }
00072     //        return defaultRmiRuntime;
00073     //    }
00074     // return a Runtime object "stub" (ie: a client)
00075     protected ProActiveRuntime getRemoteRuntimeImpl(String s)
00076         throws ProActiveException {
00077         String host;
00078         try {
00079             host = UrlBuilder.getHostNameFromUrl(s);
00080         } catch (java.net.UnknownHostException e) {
00081             throw new ProActiveException("Unknown host: " + s, e);
00082         }
00083         int port = UrlBuilder.getPortFromUrl(s);
00084         try {
00085             Registry registry = LocateRegistry.getRegistry(host, port,
00086                     new SshRMIClientSocketFactory());
00087             RemoteProActiveRuntime runtimeStub = (RemoteProActiveRuntime) registry.lookup(UrlBuilder.getNameFromUrl(
00088                         s));
00089             return createRuntimeAdapter(runtimeStub);
00090         } catch (java.rmi.RemoteException e) {
00091             throw new ProActiveException("Remote", e);
00092         } catch (java.rmi.NotBoundException e) {
00093             throw new ProActiveException("NotBound", e);
00094         }
00095     }
00096 
00100     protected ProActiveRuntimeAdapterImpl createRuntimeAdapter()
00101         throws ProActiveException {
00102         RmiProActiveRuntimeImpl impl;
00103         try {
00104             impl = new SshRmiProActiveRuntimeImpl(new SshRMIClientSocketFactory(),
00105                     new SshRMIServerSocketFactory());
00106         } catch (java.rmi.RemoteException e) {
00107             throw new ProActiveException("Cannot create the RemoteProActiveRuntimeImpl",
00108                 e);
00109         } catch (java.rmi.AlreadyBoundException e) {
00110             throw new ProActiveException("Cannot bind remoteProactiveRuntime", e);
00111         }
00112         return new ProActiveRuntimeAdapterImpl(impl);
00113     }
00114 
00115     protected ProActiveRuntimeAdapterForwarderImpl createRuntimeAdapterForwarder()
00116         throws ProActiveException {
00117         RmiSshProActiveRuntimeForwarder impl;
00118         try {
00119             impl = new RmiSshProActiveRuntimeForwarder(new SshRMIClientSocketFactory(),
00120                     new SshRMIServerSocketFactory());
00121         } catch (java.rmi.RemoteException e) {
00122             throw new ProActiveException("Cannot create the RemoteProActiveRuntimeImpl",
00123                 e);
00124         } catch (java.rmi.AlreadyBoundException e) {
00125             throw new ProActiveException("Cannot bind remoteProactiveRuntime", e);
00126         }
00127         return new ProActiveRuntimeAdapterForwarderImpl(impl);
00128     }
00129 }

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