KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > process > rsh > RSHProcess


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.process.rsh;
32
33 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator;
34 import org.objectweb.proactive.core.process.SimpleExternalProcess;
35 import org.objectweb.proactive.core.process.ExternalProcess;
36
37 /**
38  * <p>
39  * The RSHProcess class is able to start any class, of the ProActive library,
40  * using rsh protocol.
41  * </p><p>
42  * For instance:
43  * </p><pre>
44  * ..........
45  * RSHProcess rsh = new RSHProcess(new SimpleExternalProcess("ls -lsa"));
46  * rsh.setHostname("hostname.domain.fr");
47  * rsh.startProcess();
48  * .......... or
49  * RSHProcess rsh = new RSHProcess(new JVMProcessImpl(new StandardOutputMessageLogger()));
50  * ssh.setHostname("hostname.domain.fr");
51  * ssh.startProcess();
52  * .....
53  * </pre>
54  * @author ProActive Team
55  * @version 1.0, 2002/09/20
56  * @since ProActive 0.9.4
57  */

58  
59 public class RSHProcess extends AbstractExternalProcessDecorator {
60   
61   //
62
// -- CONSTRUCTORS -----------------------------------------------
63
//
64
/**
65    * Creates a new RSHProcess
66    * Used with XML Descriptors
67    */

68   public RSHProcess() {
69     super();
70   }
71   
72   
73   /**
74    * Creates a new RSHProcess
75    * @param targetProcess The target process associated to this process. The target process
76    * represents the process that will be launched after logging remote host with rsh protocol
77    */

78   public RSHProcess(ExternalProcess targetProcess) {
79     super(targetProcess);
80   }
81     
82
83   //
84
// -- PUBLIC METHODS -----------------------------------------------
85
//
86

87   public static void main(String JavaDoc[] args) {
88     try {
89       RSHProcess rsh = new RSHProcess(new SimpleExternalProcess("ls -lsa"));
90       rsh.setHostname("solida");
91       rsh.startProcess();
92     } catch (Exception JavaDoc e) {
93       e.printStackTrace();
94     }
95   }
96
97
98   //
99
// -- PROTECTED METHODS -----------------------------------------------
100
//
101

102   protected String JavaDoc internalBuildCommand() {
103     return buildRSHCommand()+buildEnvironmentCommand();
104   }
105   
106   
107   protected String JavaDoc buildRSHCommand() {
108     if (IS_WINDOWS_SYSTEM) {
109       return buildWindowsRSHCommand();
110     } else {
111       return buildUnixRSHCommand();
112     }
113   }
114   
115   
116   protected String JavaDoc buildUnixRSHCommand() {
117     StringBuffer JavaDoc command = new StringBuffer JavaDoc();
118     command.append("rsh");
119     // append username
120
if (username != null) {
121       command.append(" -l ");
122       command.append(username);
123     }
124     // append host
125
command.append(" ");
126     command.append(hostname);
127     command.append(" ");
128     return command.toString();
129   }
130   
131   
132   protected String JavaDoc buildWindowsRSHCommand() {
133     StringBuffer JavaDoc command = new StringBuffer JavaDoc();
134     command.append("rsh");
135     command.append(" ");
136     command.append(hostname);
137     // append username
138
if (username != null) {
139       command.append(" -l ");
140       command.append(username);
141     }
142     // append host
143
command.append(" ");
144     return command.toString();
145   }
146   
147   
148   //
149
// -- PRIVATE METHODS -----------------------------------------------
150
//
151

152 }
153
Popular Tags