org/objectweb/proactive/core/rmi/ClassServerHelper.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.rmi;
00032 
00033 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00034 import org.objectweb.proactive.core.ssh.SshParameters;
00035 
00036 
00037 public class ClassServerHelper {
00038 
00042     protected ClassServer currentClassServer;
00043     protected String classpath;
00044     protected boolean shouldCreateClassServer = true;
00045 
00046     //
00047     // -- Constructors -----------------------------------------------
00048     //
00049     public ClassServerHelper() {
00050         if ((System.getSecurityManager() == null) &&
00051                 !("false".equals(System.getProperty("proactive.securitymanager")))) {
00052             System.setSecurityManager(new java.rmi.RMISecurityManager());
00053         }
00054         if (ProActiveConfiguration.osgiServletEnabled()) {
00055             this.shouldCreateClassServer = false;
00056         }
00057     }
00058 
00059     //
00060     // -- PUBLIC METHODS -----------------------------------------------
00061     //
00062     public String getClasspath() {
00063         return classpath;
00064     }
00065 
00066     public void setClasspath(String v) {
00067         classpath = v;
00068     }
00069 
00070     public int getClassServerPortNumber() {
00071         if (currentClassServer == null) {
00072             return -1;
00073         }
00074         return ClassServer.getServerSocketPort();
00075     }
00076 
00077     public boolean shouldCreateClassServer() {
00078         return shouldCreateClassServer;
00079     }
00080 
00081     public void setShouldCreateClassServer(boolean v) {
00082         shouldCreateClassServer = v;
00083     }
00084 
00085     public synchronized String initializeClassServer()
00086         throws java.io.IOException {
00087 
00088         if (ProActiveConfiguration.osgiServletEnabled()) {
00089                 return this.getCodebase();
00090         }
00091         
00092         if (!shouldCreateClassServer) {
00093             return null; // don't bother
00094         }
00095         if (currentClassServer != null) {
00096             return this.getCodebase(); // already created for this VM
00097         }
00098         if (classpath == null) {
00099             currentClassServer = new ClassServer();
00100         } else {
00101             currentClassServer = new ClassServer(classpath);
00102         }
00103         String codebase = this.getCodebase();
00104         System.setProperty("java.rmi.server.codebase", codebase);
00105 
00106         return codebase;
00107     }
00108 
00109     //
00110     // -- PRIVATE METHODS -----------------------------------------------
00111     // 
00112     private String getCodebase() {
00113         String codebase;
00114         if (SshParameters.getSshTunneling()) {
00115             codebase = "httpssh://" + currentClassServer.getHostname() + ":" +
00116                 ClassServer.getServerSocketPort() + "/";
00117         } else if (ProActiveConfiguration.osgiServletEnabled()) {
00118             codebase = ClassServerServlet.getUrl() + "doc";
00119         } else {
00120             codebase = "http://" + currentClassServer.getHostname() + ":" +
00121                 ClassServer.getServerSocketPort() + "/";
00122         }
00123         
00124         return codebase;
00125     }
00126 }

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