KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > process > globus > GlobusProcess


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
32 /**
33  * @author rquilici
34  *
35  * This class represents a Globus Process.
36  */

37 package org.objectweb.proactive.core.process.globus;
38
39 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator;
40 import org.objectweb.proactive.core.process.JVMProcess;
41 import org.objectweb.proactive.core.process.JVMProcessImpl;
42
43
44 /**
45  * @author rquilici
46  *
47  * To change the template for this generated type comment go to
48  * Window>Preferences>Java>Code Generation>Code and Comments
49  */

50 public class GlobusProcess extends AbstractExternalProcessDecorator {
51     protected JVMProcessImpl jvmProcess;
52     private static final String JavaDoc FILE_SEPARATOR = System.getProperty(
53             "file.separator");
54     private static final String JavaDoc DEFAULT_SCRIPT_LOCATION = System.getProperty(
55             "user.home") + FILE_SEPARATOR + "ProActive" + FILE_SEPARATOR +
56         "scripts" + FILE_SEPARATOR + "unix" + FILE_SEPARATOR + "cluster" +
57         FILE_SEPARATOR + "startRuntime.sh ";
58     private String JavaDoc count = "1";
59     private String JavaDoc scriptLocation = DEFAULT_SCRIPT_LOCATION;
60
61     //===========================================================
62
// Constructor
63
//===========================================================
64

65     /**
66      * Creates a new instance of GlobusProcess
67      */

68     public GlobusProcess() {
69         super();
70         setCompositionType(GIVE_COMMAND_AS_PARAMETER);
71         this.hostname = null;
72     }
73
74     /**
75      * Creates a new instance of GlobusProcess. The process given as parameter represents the target process
76      */

77     public GlobusProcess(JVMProcess process) {
78         super(process, GIVE_COMMAND_AS_PARAMETER);
79         this.jvmProcess = (JVMProcessImpl) targetProcess;
80         this.hostname = null;
81     }
82
83     /* (non-Javadoc)
84      * @see org.objectweb.proactive.core.process.AbstractExternalProcessDecorator#internalBuildCommand()
85      */

86     protected String JavaDoc internalBuildCommand() {
87         return buildRSLCommand();
88     }
89
90     public static void main(String JavaDoc[] args) {
91         //String RSL = "& (executable = /bin/ls)(directory=/net/home/rquilici)(arguments=-l)";
92
String JavaDoc RSL = "& (executable = " + DEFAULT_SCRIPT_LOCATION +
93             ")(count=5)";
94         GridJob Job1 = new GridJob("cluster.inria.fr", false);
95
96         String JavaDoc jobOut = Job1.GlobusRun(RSL);
97
98         System.out.println(jobOut);
99     }
100
101     protected void internalStartProcess(String JavaDoc rslCommand)
102         throws java.io.IOException JavaDoc {
103         GridJob Job1 = new GridJob(hostname, true);
104         String JavaDoc jobOut = Job1.GlobusRun(getCommand());
105
106         //Job1.GlobusRun(getCommand());
107
logger.info(jobOut);
108     }
109
110     /**
111      * Method buildRSLCommand.
112      * @return String
113      */

114     private String JavaDoc buildRSLCommand() {
115         String JavaDoc RSLCommand = "& (executable = " + scriptLocation +
116             ")(arguments='" + getTargetProcess().getCommand() + "')(count=" +
117             count + ")(jobType=single)";
118
119         // if (count != null) RSLCommand = RSLCommand+"(count="+count+")";
120
// RSLCommand = RSLCommand+"(jobType=single)";
121
if (environment != null) {
122             RSLCommand = RSLCommand + "(environment=" +
123                 buildEnvironmentCommand() + ")";
124         }
125         return RSLCommand;
126         // String rslCommand ="&(executable=" + ((JVMProcess)targetProcess).getJavaPath()+")" +
127
// "(arguments='-Djava.security.policy="+((JVMProcess)targetProcess).getPolicyFile()+"' '-Dlog4j.configuration="+((JVMProcess)targetProcess).getLog4jFile()+"' "+((JVMProcess)targetProcess).getClassname() + " " + ((JVMProcess)targetProcess).getParameters() +")"+
128
// "(environment=(CLASSPATH "+((JVMProcess)targetProcess).getClasspath()+")"+buildEnvironmentCommand()+")";
129
// if (count != null) rslCommand = rslCommand+"(count="+count+")(jobType=single)";
130
// System.out.println(rslCommand);
131
// return rslCommand;
132
}
133
134     protected String JavaDoc buildEnvironmentCommand() {
135         if (environment == null) {
136             return "";
137         }
138         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
139         String JavaDoc[] globusEnvironment = new String JavaDoc[environment.length];
140         for (int i = 0; i < environment.length; i++) {
141             globusEnvironment[i] = environment[i].replace('=', ' ');
142             sb.append("(");
143             sb.append(globusEnvironment[i]);
144             sb.append(")");
145         }
146         return sb.toString();
147     }
148
149     /**
150      * Returns the count.
151      * @return String
152      */

153     public String JavaDoc getCount() {
154         return count;
155     }
156
157     /**
158      * Sets the count.
159      * @param count The count to set
160      */

161     public void setCount(String JavaDoc count) {
162         this.count = count;
163     }
164
165     /**
166      * Returns the scriptLocation.
167      * @return String
168      */

169     public String JavaDoc getScriptLocation() {
170         return scriptLocation;
171     }
172
173     /**
174      * Sets the scriptLocation.
175      * @param scriptLocation The scriptLocation to set
176      */

177     public void setScriptLocation(String JavaDoc scriptLocation) {
178         this.scriptLocation = scriptLocation;
179     }
180 }
181
Popular Tags