//******************************************************************************
//
// File: JobBackendMessage.java
// Package: edu.rit.pj.cluster
// Unit: Class edu.rit.pj.cluster.JobBackendMessage
//
// This Java source file is copyright (C) 2007 by Alan Kaminsky. All rights
// reserved. For further information, contact the author, Alan Kaminsky, at
// ark@cs.rit.edu.
//
// This Java source file is part of the Parallel Java Library ("PJ"). PJ is free
// software; you can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// PJ is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// A copy of the GNU General Public License is provided in the file gpl.txt. You
// may also obtain a copy of the GNU General Public License on the World Wide
// Web at http://www.gnu.org/licenses/gpl.html.
//
//******************************************************************************
package edu.rit.pj.cluster;
import edu.rit.util.ByteSequence;
import java.io.IOException;
import java.io.Externalizable;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;
/**
* Class JobBackendMessage provides a message sent to a Job Backend process
* (interface {@linkplain JobBackendRef}) in the PJ cluster middleware.
*
* @author Alan Kaminsky
* @version 02-Jul-2007
*/
public abstract class JobBackendMessage
extends Message
implements Externalizable
{
// Hidden data members.
private static final long serialVersionUID = 3747140854797048519L;
// Exported constructors.
/**
* Construct a new job backend message.
*/
public JobBackendMessage()
{
}
/**
* Construct a new job backend message with the given message tag.
*
* @param theTag Message tag to use when sending this message.
*/
public JobBackendMessage
(int theTag)
{
super (theTag);
}
// Exported operations.
/**
* Construct a new "cancel job" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param errmsg Error message string.
*
* @return "Cancel job" message.
*/
public static JobBackendMessage cancelJob
(JobFrontendRef theJobFrontend,
String errmsg)
{
return new CancelJobMessage (theJobFrontend, errmsg);
}
/**
* Construct a new "commence job" message.
*
* @param theJobFrontend
* Job Frontend that is calling this method.
* @param middlewareAddress
* Array of hosts/ports for middleware messages. The first K
* elements are for the job backend processes in rank order, the
* K+1st element is for the job frontend process. If the
* @param worldAddress
* Array of hosts/ports for the world communicator. The K
* elements are for the job backend processes in rank order.
* @param frontendAddress
* Array of hosts/ports for the frontend communicator. The first
* K elements are for the job backend processes in rank order,
* the K+1st element is for the job frontend process. If the
* frontend communicator does not exist, frontendAddress is
* null.
* @param properties
* Java system properties.
* @param mainClassName
* Fully qualified class name of the Java main program class to execute.
* @param args
* Array of 0 or more Java command line arguments.
*
* @return "Commence job" message.
*/
public static JobBackendMessage commenceJob
(JobFrontendRef theJobFrontend,
InetSocketAddress[] middlewareAddress,
InetSocketAddress[] worldAddress,
InetSocketAddress[] frontendAddress,
Properties properties,
String mainClassName,
String[] args)
{
return new CommenceJobMessage
(theJobFrontend, middlewareAddress, worldAddress, frontendAddress,
properties, mainClassName, args);
}
/**
* Construct a new "job finished" message.
*
* @param theJobFrontend Job frontend that is calling this method.
*
* @return "Job finished" message.
*/
public static JobBackendMessage jobFinished
(JobFrontendRef theJobFrontend)
{
return new JobFinishedMessage (theJobFrontend);
}
/**
* Construct a new "renew lease" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
*
* @return "Renew lease" message.
*/
public static JobBackendMessage renewLease
(JobFrontendRef theJobFrontend)
{
return new RenewLeaseMessage (theJobFrontend);
}
/**
* Construct a new "report resource" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param resourceName Resource name.
* @param content Resource content, or null if resource not found.
*
* @return "Report resource" message.
*/
public static JobBackendMessage reportResource
(JobFrontendRef theJobFrontend,
String resourceName,
byte[] content)
{
return new ReportResourceMessage
(theJobFrontend, resourceName, content);
}
/**
* Construct a new "report resource" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param resourceName Resource name.
* @param content Resource content, or null if resource not found.
*
* @return "Report resource" message.
*/
public static JobBackendMessage reportResource
(JobFrontendRef theJobFrontend,
String resourceName,
ByteSequence content)
{
return new ReportResourceMessage
(theJobFrontend, resourceName, content);
}
/**
* Construct a new "output file open result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param bfd Backend file descriptor.
* @param ffd Frontend file descriptor if success.
* @param exc Null if success, exception if failure.
*
* @return "Output file open result" message.
*/
public static JobBackendMessage outputFileOpenResult
(JobFrontendRef theJobFrontend,
int bfd,
int ffd,
IOException exc)
{
return new OutputFileOpenResultMessage (theJobFrontend, bfd, ffd, exc);
}
/**
* Construct a new "output file write result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param exc Null if success, exception if failure.
*
* @return "Output file write result" message.
*/
public static JobBackendMessage outputFileWriteResult
(JobFrontendRef theJobFrontend,
int ffd,
IOException exc)
{
return new OutputFileWriteResultMessage (theJobFrontend, ffd, exc);
}
/**
* Construct a new "output file flush result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param exc Null if success, exception if failure.
*
* @return "Output file flush result" message.
*/
public static JobBackendMessage outputFileFlushResult
(JobFrontendRef theJobFrontend,
int ffd,
IOException exc)
{
return new OutputFileFlushResultMessage (theJobFrontend, ffd, exc);
}
/**
* Construct a new "output file close result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param exc Null if success, exception if failure.
*
* @return "Output file close result" message.
*/
public static JobBackendMessage outputFileCloseResult
(JobFrontendRef theJobFrontend,
int ffd,
IOException exc)
{
return new OutputFileCloseResultMessage (theJobFrontend, ffd, exc);
}
/**
* Construct a new "input file open result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param bfd Backend file descriptor.
* @param ffd Frontend file descriptor if success.
* @param exc Null if success, exception if failure.
*
* @return "Input file open result" message.
*/
public static JobBackendMessage inputFileOpenResult
(JobFrontendRef theJobFrontend,
int bfd,
int ffd,
IOException exc)
{
return new InputFileOpenResultMessage (theJobFrontend, bfd, ffd, exc);
}
/**
* Construct a new "input file read result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param len Number of bytes read, or -1 if EOF.
* @param exc Null if success, exception if failure.
*
* @return "Input file read result" message.
*/
public static JobBackendMessage inputFileReadResult
(JobFrontendRef theJobFrontend,
int ffd,
int len,
IOException exc)
{
return new InputFileReadResultMessage (theJobFrontend, ffd, len, exc);
}
/**
* Construct a new "input file skip result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param len Number of bytes skipped.
* @param exc Null if success, exception if failure.
*
* @return "Input file skip result" message.
*/
public static JobBackendMessage inputFileSkipResult
(JobFrontendRef theJobFrontend,
int ffd,
long len,
IOException exc)
{
return new InputFileSkipResultMessage (theJobFrontend, ffd, len, exc);
}
/**
* Construct a new "input file close result" message.
*
* @param theJobFrontend Job Frontend that is calling this method.
* @param ffd Frontend file descriptor.
* @param exc Null if success, exception if failure.
*
* @return "Input file close result" message.
*/
public static JobBackendMessage inputFileCloseResult
(JobFrontendRef theJobFrontend,
int ffd,
IOException exc)
{
return new InputFileCloseResultMessage (theJobFrontend, ffd, exc);
}
/**
* Invoke the method corresponding to this job backend message on the
* given Job Backend object. The method arguments come from the fields of
* this job backend message object.
*
* @param theJobBackend Job Backend on which to invoke the method.
* @param theJobFrontend Job Frontend that is calling the method.
*
* @exception IOException
* Thrown if an I/O error occurred.
*/
public void invoke
(JobBackendRef theJobBackend,
JobFrontendRef theJobFrontend)
throws IOException
{
throw new UnsupportedOperationException();
}
/**
* Write this job backend message to the given object output stream.
*
* @param out Object output stream.
*
* @exception IOException
* Thrown if an I/O error occurred.
*/
public void writeExternal
(ObjectOutput out)
throws IOException
{
}
/**
* Read this job backend message from the given object input stream.
*
* @param in Object input stream.
*
* @exception IOException
* Thrown if an I/O error occurred.
* @exception ClassNotFoundException
* Thrown if a class needed to read this job backend message could not
* be found.
*/
public void readExternal
(ObjectInput in)
throws IOException, ClassNotFoundException
{
}
// Hidden subclasses.
/**
* Class CancelJobMessage provides the Job Backend "cancel job" message in
* the PJ cluster middleware.
*
* @author Alan Kaminsky
* @version 25-Oct-2006
*/
private static class CancelJobMessage
extends JobBackendMessage
{
private static final long serialVersionUID = -1706674774429384654L;
private String errmsg;
public CancelJobMessage()
{
}
public CancelJobMessage
(JobFrontendRef theJobFrontend,
String errmsg)
{
super (Message.FROM_JOB_FRONTEND);
this.errmsg = errmsg;
}
public void invoke
(JobBackendRef theJobBackend,
JobFrontendRef theJobFrontend)
throws IOException
{
theJobBackend.cancelJob (theJobFrontend, errmsg);
}
public void writeExternal
(ObjectOutput out)
throws IOException
{
out.writeUTF (errmsg);
}
public void readExternal
(ObjectInput in)
throws IOException
{
errmsg = in.readUTF();
}
}
/**
* Class CommenceJobMessage provides the Job Backend "commence job" message
* in the PJ cluster middleware.
*
* @author Alan Kaminsky
* @version 25-Oct-2006
*/
private static class CommenceJobMessage
extends JobBackendMessage
{
private static final long serialVersionUID = -8262872991140404870L;
private InetSocketAddress[] middlewareAddress;
private InetSocketAddress[] worldAddress;
private InetSocketAddress[] frontendAddress;
private Properties properties;
private String mainClassName;
private String[] args;
public CommenceJobMessage()
{
}
public CommenceJobMessage
(JobFrontendRef theJobFrontend,
InetSocketAddress[] middlewareAddress,
InetSocketAddress[] worldAddress,
InetSocketAddress[] frontendAddress,
Properties properties,
String mainClassName,
String[] args)
{
super (Message.FROM_JOB_FRONTEND);
this.middlewareAddress = middlewareAddress;
this.worldAddress = worldAddress;
this.frontendAddress = frontendAddress;
this.properties = properties;
this.mainClassName = mainClassName;
this.args = args;
}
public void invoke
(JobBackendRef theJobBackend,
JobFrontendRef theJobFrontend)
throws IOException
{
theJobBackend.commenceJob
(theJobFrontend, middlewareAddress, worldAddress,
frontendAddress, properties, mainClassName, args);
}
public void writeExternal
(ObjectOutput out)
throws IOException
{
out.writeInt (properties.size());
for (Map.Entry
Ads help maintain this website.