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.process.rsh; 00032 00033 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator; 00034 import org.objectweb.proactive.core.process.ExternalProcess; 00035 import org.objectweb.proactive.core.process.SimpleExternalProcess; 00036 import org.objectweb.proactive.core.process.UniversalProcess; 00037 00038 00060 public class RSHProcess extends AbstractExternalProcessDecorator { 00061 public final static String DEFAULT_RSHPATH = "/usr/bin/rsh "; 00062 public final static String DEFAULT_RSH_COPYPROTOCOL = "rcp"; 00063 00064 // 00065 // -- CONSTRUCTORS ----------------------------------------------- 00066 // 00067 00072 public RSHProcess() { 00073 super(); 00074 00075 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_RSH_COPYPROTOCOL; 00076 this.command_path = DEFAULT_RSHPATH; 00077 } 00078 00084 public RSHProcess(ExternalProcess targetProcess) { 00085 super(targetProcess); 00086 00087 FILE_TRANSFER_DEFAULT_PROTOCOL = DEFAULT_RSH_COPYPROTOCOL; 00088 this.command_path = DEFAULT_RSHPATH; 00089 } 00090 00091 // 00092 // -- PUBLIC METHODS ----------------------------------------------- 00093 // 00094 00098 public String getProcessId() { 00099 return "rsh_" + targetProcess.getProcessId(); 00100 } 00101 00105 public int getNodeNumber() { 00106 return targetProcess.getNodeNumber(); 00107 } 00108 00112 public UniversalProcess getFinalProcess() { 00113 checkStarted(); 00114 return targetProcess.getFinalProcess(); 00115 } 00116 00117 public static void main(String[] args) { 00118 try { 00119 RSHProcess rsh = new RSHProcess(new SimpleExternalProcess("ls -lsa")); 00120 rsh.setHostname("solida"); 00121 rsh.startProcess(); 00122 } catch (Exception e) { 00123 e.printStackTrace(); 00124 } 00125 } 00126 00127 // 00128 // -- PROTECTED METHODS ----------------------------------------------- 00129 // 00130 protected String internalBuildCommand() { 00131 return buildRSHCommand() + buildEnvironmentCommand(); 00132 } 00133 00134 protected String buildRSHCommand() { 00135 if (IS_WINDOWS_SYSTEM) { 00136 return buildWindowsRSHCommand(); 00137 } else { 00138 return buildUnixRSHCommand(); 00139 } 00140 } 00141 00142 protected String buildUnixRSHCommand() { 00143 StringBuilder command = new StringBuilder(); 00144 command.append(DEFAULT_RSHPATH); 00145 // append username 00146 if (username != null) { 00147 command.append(" -l "); 00148 command.append(username); 00149 } 00150 00151 // append host 00152 command.append(" "); 00153 command.append(hostname); 00154 command.append(" "); 00155 return command.toString(); 00156 } 00157 00158 protected String buildWindowsRSHCommand() { 00159 StringBuilder command = new StringBuilder(); 00160 command.append("rsh"); 00161 command.append(" "); 00162 command.append(hostname); 00163 // append username 00164 if (username != null) { 00165 command.append(" -l "); 00166 command.append(username); 00167 } 00168 00169 // append host 00170 command.append(" "); 00171 return command.toString(); 00172 } 00173 00174 // 00175 // -- PRIVATE METHODS ----------------------------------------------- 00176 // 00177 }