1 //****************************************************************************** 2 // 3 // File: JobFrontendProxy.java 4 // Package: edu.rit.pj.cluster 5 // Unit: Class edu.rit.pj.cluster.JobFrontendProxy 6 // 7 // This Java source file is copyright (C) 2012 by Alan Kaminsky. All rights 8 // reserved. For further information, contact the author, Alan Kaminsky, at 9 // ark@cs.rit.edu. 10 // 11 // This Java source file is part of the Parallel Java Library ("PJ"). PJ is free 12 // software; you can redistribute it and/or modify it under the terms of the GNU 13 // General Public License as published by the Free Software Foundation; either 14 // version 3 of the License, or (at your option) any later version. 15 // 16 // PJ is distributed in the hope that it will be useful, but WITHOUT ANY 17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 18 // A PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 // 20 // Linking this library statically or dynamically with other modules is making a 21 // combined work based on this library. Thus, the terms and conditions of the GNU 22 // General Public License cover the whole combination. 23 // 24 // As a special exception, the copyright holders of this library give you 25 // permission to link this library with independent modules to produce an 26 // executable, regardless of the license terms of these independent modules, and 27 // to copy and distribute the resulting executable under terms of your choice, 28 // provided that you also meet, for each linked independent module, the terms 29 // and conditions of the license of that module. An independent module is a module 30 // which is not derived from or based on this library. If you modify this library, 31 // you may extend this exception to your version of the library, but you are not 32 // obligated to do so. If you do not wish to do so, delete this exception 33 // statement from your version. 34 // 35 // A copy of the GNU General Public License is provided in the file gpl.txt. You 36 // may also obtain a copy of the GNU General Public License on the World Wide 37 // Web at http://www.gnu.org/licenses/gpl.html. 38 // 39 //****************************************************************************** 40 package edu.rit.pj.cluster; 41 42 import java.io.File; 43 import java.io.IOException; 44 import java.net.InetSocketAddress; 45 46 import edu.rit.mp.ByteBuf; 47 import edu.rit.mp.Channel; 48 import edu.rit.mp.ChannelGroup; 49 import edu.rit.util.Range; 50 51 /** 52 * Class JobFrontendProxy provides a proxy object for sending messages to a PJ 53 * job frontend process. 54 * 55 * @author Alan Kaminsky 56 * @version 20-Jun-2012 57 */ 58 public class JobFrontendProxy 59 extends Proxy 60 implements JobFrontendRef { 61 62 // Exported constructors. 63 /** 64 * Construct a new job frontend proxy. The proxy will use the given channel 65 * in the given channel group to send messages to the job frontend process. 66 * 67 * @param theChannelGroup Channel group. 68 * @param theChannel Channel. 69 */ 70 public JobFrontendProxy(ChannelGroup theChannelGroup, 71 Channel theChannel) { 72 super(theChannelGroup, theChannel); 73 } 74 75 // Exported operations. 76 /** 77 * {@inheritDoc} 78 * 79 * Assign a backend process to the job. 80 * @exception IOException Thrown if an I/O error occurred. 81 */ 82 public void assignBackend(JobSchedulerRef theJobScheduler, 83 String name, 84 String host, 85 String jvm, 86 String classpath, 87 String[] jvmflags, 88 String shellCommand, 89 int Nt) 90 throws IOException { 91 send(JobFrontendMessage.assignBackend(theJobScheduler, name, host, jvm, classpath, jvmflags, 92 shellCommand, Nt)); 93 } 94 95 /** 96 * {@inheritDoc} 97 * 98 * Assign a job number to the job. The host name for the job frontend's 99 * middleware channel group is also specified. 100 * @exception IOException Thrown if an I/O error occurred. 101 */ 102 public void assignJobNumber(JobSchedulerRef theJobScheduler, 103 int jobnum, 104 String pjhost) 105 throws IOException { 106 send(JobFrontendMessage.assignJobNumber(theJobScheduler, jobnum, pjhost)); 107 } 108 109 /** 110 * {@inheritDoc} 111 * 112 * Cancel the job. 113 * @exception IOException Thrown if an I/O error occurred. 114 */ 115 public void cancelJob(JobSchedulerRef theJobScheduler, 116 String errmsg) 117 throws IOException { 118 send(JobFrontendMessage.cancelJob(theJobScheduler, errmsg)); 119 } 120 121 /** 122 * Renew the lease on the job. 123 * 124 * @param theJobScheduler Job Scheduler that is calling this method. 125 * @exception IOException Thrown if an I/O error occurred. 126 * @throws java.io.IOException if any. 127 */ 128 public void renewLease(JobSchedulerRef theJobScheduler) 129 throws IOException { 130 send(JobFrontendMessage.renewLease(theJobScheduler)); 131 } 132 133 /** 134 * {@inheritDoc} 135 * 136 * Report that a backend process has finished executing the job. 137 * @exception IOException Thrown if an I/O error occurred. 138 */ 139 public void backendFinished(JobBackendRef theJobBackend) 140 throws IOException { 141 send(JobFrontendMessage.backendFinished(theJobBackend)); 142 } 143 144 /** 145 * {@inheritDoc} 146 * 147 * Report that a backend process is ready to commence executing the job. 148 * @exception IOException Thrown if an I/O error occurred. 149 */ 150 public void backendReady(JobBackendRef theJobBackend, 151 int rank, 152 InetSocketAddress middlewareAddress, 153 InetSocketAddress worldAddress, 154 InetSocketAddress frontendAddress) 155 throws IOException { 156 send(JobFrontendMessage.backendReady(theJobBackend, rank, middlewareAddress, 157 worldAddress, frontendAddress)); 158 } 159 160 /** 161 * {@inheritDoc} 162 * 163 * Cancel the job. 164 * @exception IOException Thrown if an I/O error occurred. 165 */ 166 public void cancelJob(JobBackendRef theJobBackend, 167 String errmsg) 168 throws IOException { 169 send(JobFrontendMessage.cancelJob(theJobBackend, errmsg)); 170 } 171 172 /** 173 * {@inheritDoc} 174 * 175 * Renew the lease on the job. 176 * @exception IOException Thrown if an I/O error occurred. 177 */ 178 public void renewLease(JobBackendRef theJobBackend) 179 throws IOException { 180 send(JobFrontendMessage.renewLease(theJobBackend)); 181 } 182 183 /** 184 * {@inheritDoc} 185 * 186 * Request the given resource from this job frontend's class loader. 187 * @exception IOException Thrown if an I/O error occurred. 188 */ 189 public void requestResource(JobBackendRef theJobBackend, 190 String resourceName) 191 throws IOException { 192 send(JobFrontendMessage.requestResource(theJobBackend, resourceName)); 193 } 194 195 /** 196 * {@inheritDoc} 197 * 198 * Open the given output file for writing or appending. 199 * @exception IOException Thrown if an I/O error occurred. 200 */ 201 public void outputFileOpen(JobBackendRef theJobBackend, 202 int bfd, 203 File file, 204 boolean append) 205 throws IOException { 206 send(JobFrontendMessage.outputFileOpen(theJobBackend, bfd, file, append)); 207 } 208 209 /** 210 * {@inheritDoc} 211 * 212 * Write the given bytes to the given output file. <code>fd</code> = 1 refers to 213 * the job's standard output stream; <code>fd</code> = 2 refers to the job's 214 * standard error stream; other values refer to a previously opened file. 215 * @exception IOException Thrown if an I/O error occurred. 216 */ 217 public void outputFileWrite(JobBackendRef theJobBackend, 218 int ffd, 219 byte[] buf, 220 int off, 221 int len) 222 throws IOException { 223 send(JobFrontendMessage.outputFileWrite(theJobBackend, ffd, len)); 224 send(ffd, 225 ByteBuf.sliceBuffer(buf, new Range(off, off + len - 1))); 226 } 227 228 /** 229 * {@inheritDoc} 230 * 231 * Flush accumulated bytes to the given output file. 232 * @exception IOException Thrown if an I/O error occurred. 233 */ 234 public void outputFileFlush(JobBackendRef theJobBackend, 235 int ffd) 236 throws IOException { 237 send(JobFrontendMessage.outputFileFlush(theJobBackend, ffd)); 238 } 239 240 /** 241 * {@inheritDoc} 242 * 243 * Close the given output file. 244 * @exception IOException Thrown if an I/O error occurred. 245 */ 246 public void outputFileClose(JobBackendRef theJobBackend, 247 int ffd) 248 throws IOException { 249 send(JobFrontendMessage.outputFileClose(theJobBackend, ffd)); 250 } 251 252 /** 253 * {@inheritDoc} 254 * 255 * Open the given input file for reading. 256 * @exception IOException Thrown if an I/O error occurred. 257 */ 258 public void inputFileOpen(JobBackendRef theJobBackend, 259 int bfd, 260 File file) 261 throws IOException { 262 send(JobFrontendMessage.inputFileOpen(theJobBackend, bfd, file)); 263 } 264 265 /** 266 * {@inheritDoc} 267 * 268 * Read bytes from the given input file. <code>ffd</code> = 1 refers to the 269 * job's standard input stream; other values refer to a previously opened 270 * file. 271 * @exception IOException Thrown if an I/O error occurred. 272 */ 273 public void inputFileRead(JobBackendRef theJobBackend, 274 int ffd, 275 int len) 276 throws IOException { 277 send(JobFrontendMessage.inputFileRead(theJobBackend, ffd, len)); 278 } 279 280 /** 281 * {@inheritDoc} 282 * 283 * Skip bytes from the given input file. 284 * @exception IOException Thrown if an I/O error occurred. 285 */ 286 public void inputFileSkip(JobBackendRef theJobBackend, 287 int ffd, 288 long len) 289 throws IOException { 290 send(JobFrontendMessage.inputFileSkip(theJobBackend, ffd, len)); 291 } 292 293 /** 294 * {@inheritDoc} 295 * 296 * Close the given input file. 297 * @exception IOException Thrown if an I/O error occurred. 298 */ 299 public void inputFileClose(JobBackendRef theJobBackend, 300 int ffd) 301 throws IOException { 302 send(JobFrontendMessage.inputFileClose(theJobBackend, ffd)); 303 } 304 305 /** 306 * {@inheritDoc} 307 * 308 * Report a comment for a process. 309 * @exception IOException Thrown if an I/O error occurred. 310 */ 311 public void reportComment(JobBackendRef theJobBackend, 312 int rank, 313 String comment) 314 throws IOException { 315 send(JobFrontendMessage.reportComment(theJobBackend, rank, comment)); 316 } 317 318 }