org/objectweb/proactive/core/process/rlogin/RLoginProcess.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.process.rlogin;
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 import org.objectweb.proactive.core.process.lsf.LSFBSubProcess;
00038 
00039 
00058 public class RLoginProcess extends AbstractExternalProcessDecorator {
00059     public final static String DEFAULT_RLOGINPATH = "/usr/bin/rlogin ";
00060     private boolean exitAfterCommand;
00061     private String username;
00062     //
00063     // -- CONSTRUCTORS -----------------------------------------------
00064     //
00065 
00070     public RLoginProcess() {
00071         super();
00072         setCompositionType(SEND_TO_OUTPUT_STREAM_COMPOSITION);
00073         this.command_path = DEFAULT_RLOGINPATH;
00074     }
00075 
00081     public RLoginProcess(ExternalProcess targetProcess) {
00082         this(targetProcess, false);
00083     }
00084 
00091     public RLoginProcess(ExternalProcess targetProcess, boolean exitAfterCommand) {
00092         super(targetProcess, SEND_TO_OUTPUT_STREAM_COMPOSITION);
00093         this.exitAfterCommand = exitAfterCommand;
00094         this.command_path = DEFAULT_RLOGINPATH;
00095     }
00096 
00097     //
00098     // -- PUBLIC METHODS -----------------------------------------------
00099     //
00100 
00104     public String getProcessId() {
00105         return "rlogin_" + targetProcess.getProcessId();
00106     }
00107 
00111     public int getNodeNumber() {
00112         return targetProcess.getNodeNumber();
00113     }
00114 
00118     public UniversalProcess getFinalProcess() {
00119         checkStarted();
00120         return targetProcess.getFinalProcess();
00121     }
00122 
00127     public void setExitAfterCommand(boolean b) {
00128         exitAfterCommand = b;
00129     }
00130 
00136     public boolean getExitAfterCommand() {
00137         return exitAfterCommand;
00138     }
00139 
00140     public static void main(String[] args) {
00141         try {
00142             LSFBSubProcess lsf = new LSFBSubProcess(new SimpleExternalProcess(
00143                         "ls -lsa"));
00144             RLoginProcess p = new RLoginProcess(lsf, false);
00145             p.setHostname("galere1");
00146             p.startProcess();
00147         } catch (Exception e) {
00148             e.printStackTrace();
00149         }
00150     }
00151 
00152     //
00153     // -- PROTECTED METHODS -----------------------------------------------
00154     //
00155     protected String internalBuildCommand() {
00156         return buildEnvironmentCommand() + buildRLoginCommand();
00157     }
00158 
00159     protected String buildRLoginCommand() {
00160         String command;
00161         if(this.username == null) {
00162                 command = DEFAULT_RLOGINPATH + hostname + " ";
00163         }else {
00164                 command = DEFAULT_RLOGINPATH + "-l " + username + " " + hostname + " ";
00165         }
00166         return command;
00167     }
00168 
00169     protected void internalStartProcess(String command)
00170         throws java.io.IOException {
00171         super.internalStartProcess(command);
00172         if (exitAfterCommand) {
00173             outputMessageSink.setMessage(null);
00174         }
00175     }
00176 
00177         public String getUsername() {
00178                 return username;
00179         }
00180 
00181         public void setUsername(String username) {
00182                 this.username = username;
00183         }
00184 
00185     //
00186     // -- PRIVATE METHODS -----------------------------------------------
00187     //
00188 }

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