View Javadoc
1   //******************************************************************************
2   //
3   // File:    JobBackendProxy.java
4   // Package: edu.rit.pj.cluster
5   // Unit:    Class edu.rit.pj.cluster.JobBackendProxy
6   //
7   // This Java source file is copyright (C) 2006 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.IOException;
43  import java.net.InetSocketAddress;
44  import java.util.Properties;
45  
46  import edu.rit.mp.ByteBuf;
47  import edu.rit.mp.Channel;
48  import edu.rit.mp.ChannelGroup;
49  import edu.rit.util.ByteSequence;
50  import edu.rit.util.Range;
51  
52  /**
53   * Class JobBackendProxy provides a proxy object for sending messages to a PJ
54   * job backend process.
55   *
56   * @author Alan Kaminsky
57   * @version 20-Nov-2006
58   */
59  public class JobBackendProxy
60          extends Proxy
61          implements JobBackendRef {
62  
63  // Exported constructors.
64      /**
65       * Construct a new job backend proxy. The proxy will use the given channel
66       * in the given channel group to send messages to the job backend process.
67       *
68       * @param theChannelGroup Channel group.
69       * @param theChannel Channel.
70       */
71      public JobBackendProxy(ChannelGroup theChannelGroup,
72              Channel theChannel) {
73          super(theChannelGroup, theChannel);
74      }
75  
76  // Exported operations.
77      /**
78       * {@inheritDoc}
79       *
80       * Cancel the job.
81       * @exception IOException Thrown if an I/O error occurred.
82       */
83      public void cancelJob(JobFrontendRef theJobFrontend,
84              String errmsg)
85              throws IOException {
86          send(JobBackendMessage.cancelJob(theJobFrontend, errmsg));
87      }
88  
89      /**
90       * Commence the job.
91       *
92       * @param theJobFrontend Job Frontend that is calling this method.
93       * @param middlewareAddress Array of hosts/ports for middleware messages.
94       * The first <I>K</I>
95       * elements are for the job backend processes in rank order, the
96       * <I>K</I>+1st element is for the job frontend process. If the
97       * @param worldAddress Array of hosts/ports for the world communicator. The
98       * <I>K</I>
99       * elements are for the job backend processes in rank order.
100      * @param frontendAddress Array of hosts/ports for the frontend
101      * communicator. The first
102      * <I>K</I> elements are for the job backend processes in rank order, the
103      * <I>K</I>+1st element is for the job frontend process. If the frontend
104      * communicator does not exist, <code>frontendAddress</code> is null.
105      * @param properties Java system properties.
106      * @param mainClassName Fully qualified class name of the Java main program
107      * class to execute.
108      * @param args Array of 0 or more Java command line arguments.
109      * @exception IOException Thrown if an I/O error occurred.
110      * @throws java.io.IOException if any.
111      */
112     public void commenceJob(JobFrontendRef theJobFrontend,
113             InetSocketAddress[] middlewareAddress,
114             InetSocketAddress[] worldAddress,
115             InetSocketAddress[] frontendAddress,
116             Properties properties,
117             String mainClassName,
118             String[] args)
119             throws IOException {
120         send(JobBackendMessage.commenceJob(theJobFrontend, middlewareAddress, worldAddress,
121                 frontendAddress, properties, mainClassName, args));
122     }
123 
124     /**
125      * {@inheritDoc}
126      *
127      * Report that the job finished.
128      * @exception IOException Thrown if an I/O error occurred.
129      */
130     public void jobFinished(JobFrontendRef theJobFrontend)
131             throws IOException {
132         send(JobBackendMessage.jobFinished(theJobFrontend));
133     }
134 
135     /**
136      * {@inheritDoc}
137      *
138      * Renew the lease on the job.
139      * @exception IOException Thrown if an I/O error occurred.
140      */
141     public void renewLease(JobFrontendRef theJobFrontend)
142             throws IOException {
143         send(JobBackendMessage.renewLease(theJobFrontend));
144     }
145 
146     /**
147      * Report the content for a previously-requested resource.
148      *
149      * @param theJobFrontend Job Frontend that is calling this method.
150      * @param resourceName Resource name.
151      * @param content Resource content, or null if resource not found.
152      * @exception IOException Thrown if an I/O error occurred.
153      * @throws java.io.IOException if any.
154      */
155     public void reportResource(JobFrontendRef theJobFrontend,
156             String resourceName,
157             byte[] content)
158             throws IOException {
159         send(JobBackendMessage.reportResource(theJobFrontend, resourceName, content));
160     }
161 
162     /**
163      * {@inheritDoc}
164      *
165      * Report the content for a previously-requested resource.
166      *
167      * @exception IOException Thrown if an I/O error occurred.
168      * @param theJobFrontend a {@link edu.rit.pj.cluster.JobFrontendRef} object
169      * @param resourceName a {@link java.lang.String} object
170      * @param content a {@link edu.rit.util.ByteSequence} object
171      * @throws java.io.IOException if any.
172      */
173     public void reportResource(JobFrontendRef theJobFrontend,
174             String resourceName,
175             ByteSequence content)
176             throws IOException {
177         send(JobBackendMessage.reportResource(theJobFrontend, resourceName, content));
178     }
179 
180     /**
181      * {@inheritDoc}
182      *
183      * Report the result of opening the given output file.
184      * @exception IOException Thrown if an I/O error occurred.
185      */
186     public void outputFileOpenResult(JobFrontendRef theJobFrontend,
187             int bfd,
188             int ffd,
189             IOException exc)
190             throws IOException {
191         send(JobBackendMessage.outputFileOpenResult(theJobFrontend, bfd, ffd, exc));
192     }
193 
194     /**
195      * {@inheritDoc}
196      *
197      * Report the result of writing the given output file.
198      * @exception IOException Thrown if an I/O error occurred.
199      */
200     public void outputFileWriteResult(JobFrontendRef theJobFrontend,
201             int ffd,
202             IOException exc)
203             throws IOException {
204         send(JobBackendMessage.outputFileWriteResult(theJobFrontend, ffd, exc));
205     }
206 
207     /**
208      * {@inheritDoc}
209      *
210      * Report the result of flushing the given output file.
211      * @exception IOException Thrown if an I/O error occurred.
212      */
213     public void outputFileFlushResult(JobFrontendRef theJobFrontend,
214             int ffd,
215             IOException exc)
216             throws IOException {
217         send(JobBackendMessage.outputFileFlushResult(theJobFrontend, ffd, exc));
218     }
219 
220     /**
221      * {@inheritDoc}
222      *
223      * Report the result of closing the given output file.
224      * @exception IOException Thrown if an I/O error occurred.
225      */
226     public void outputFileCloseResult(JobFrontendRef theJobFrontend,
227             int ffd,
228             IOException exc)
229             throws IOException {
230         send(JobBackendMessage.outputFileCloseResult(theJobFrontend, ffd, exc));
231     }
232 
233     /**
234      * {@inheritDoc}
235      *
236      * Report the result of opening the given input file.
237      * @exception IOException Thrown if an I/O error occurred.
238      */
239     public void inputFileOpenResult(JobFrontendRef theJobFrontend,
240             int bfd,
241             int ffd,
242             IOException exc)
243             throws IOException {
244         send(JobBackendMessage.inputFileOpenResult(theJobFrontend, bfd, ffd, exc));
245     }
246 
247     /**
248      * {@inheritDoc}
249      *
250      * Report the result of reading the given input file.
251      * @exception IOException Thrown if an I/O error occurred.
252      */
253     public void inputFileReadResult(JobFrontendRef theJobFrontend,
254             int ffd,
255             byte[] buf,
256             int len,
257             IOException exc)
258             throws IOException {
259         send(JobBackendMessage.inputFileReadResult(theJobFrontend, ffd, len, exc));
260         if (len > 0) {
261             send(ffd, ByteBuf.sliceBuffer(buf, new Range(0, len - 1)));
262         }
263     }
264 
265     /**
266      * {@inheritDoc}
267      *
268      * Report the result of skipping the given input file.
269      * @exception IOException Thrown if an I/O error occurred.
270      */
271     public void inputFileSkipResult(JobFrontendRef theJobFrontend,
272             int ffd,
273             long len,
274             IOException exc)
275             throws IOException {
276         send(JobBackendMessage.inputFileSkipResult(theJobFrontend, ffd, len, exc));
277     }
278 
279     /**
280      * {@inheritDoc}
281      *
282      * Report the result of closing the given input file.
283      * @exception IOException Thrown if an I/O error occurred.
284      */
285     public void inputFileCloseResult(JobFrontendRef theJobFrontend,
286             int ffd,
287             IOException exc)
288             throws IOException {
289         send(JobBackendMessage.inputFileCloseResult(theJobFrontend, ffd, exc));
290     }
291 
292 }