import java.util.Vector;

import org.simgrid.msg.Msg;
import org.simgrid.msg.Task;
import org.simgrid.msg.MsgException;
import org.simgrid.msg.HostFailureException;
import org.simgrid.msg.TaskCancelledException;

public class SEMessage extends Task {
	public enum Type{
		DOWNLOAD_REQUEST,
		SEND_FILE,
		UPLOAD_FILE,
		UPLOAD_ACK
	};

	private Type type;
	private String logicalName = null;
	private long size = 0;
	private Vector<LogicalFile> fileList = null;

	public Type getType() {
		return type;
	}

	public String getSenderMailbox(){
		return getSender().getPID()+ "@" + getSource().getName();
	}

	public String getLogicalName() {
		return logicalName;
	}

	public long getSize() {
		return size;
	}

	public LogicalFile getFile() {
		return fileList.firstElement();
	}

	public Vector<LogicalFile> getFileList() {
		return fileList;
	}

	public SEMessage(Type type, String logicalName, long size, 
			Vector<LogicalFile> files) {
		super(type.toString(), 1e6, 100);
		this.type = type;
		this.logicalName=logicalName;
		this.size = size;
		this.fileList = files;
	}

	/**
	 * Constructor, builds a new UPLOAD_REQUEST/SEND_FILE message
	 */
	public SEMessage(Type type, long size){
		super(type.toString(), 0, size);
		this.type = type;
		this.size = size;
	}

	public void execute() throws  HostFailureException,TaskCancelledException{
		super.execute();
	}

	public static SEMessage getFrom (String mailbox) {
		SEMessage message = null;
		try {
			message = (SEMessage) Task.receive(mailbox);
			Msg.debug("Received a '" + message.type.toString() + 
					"' message from " + mailbox);
			// Simulate the cost of the local processing of the request.
			// Depends on the value set when the Message was created
			message.execute();
		} catch (MsgException e) {
			e.printStackTrace();
		}

		return message;
	}

	public static void sendTo (String destination, Type type, 
			String logicalName, long size, Vector<LogicalFile> fileList) {
		SEMessage m = new SEMessage (type, logicalName, size, fileList);
		try{
			Msg.debug("Send a '" + type.toString() + "' message to " +
					destination);
			m.send(destination);
		} catch (MsgException e) {
			Msg.error("Something went wrong when emitting a '" + 
				type.toString() +"' message to '" + destination + "'");
			e.printStackTrace();
		}
	}

	/**
	 * Specialized send of a UPLOAD_ACK
	 * message
	 */
	public static void sendTo (String destination, Type type) {
		sendTo(destination, type, null, 0, null);
	}

	/**
	 *  Specialized send of a DOWNLOAD_REQUEST message
	 */
	public static void sendTo (String destination, Type type, 
			String logicalName, long size) {
		sendTo(destination, type, logicalName, size, null);
	}

	public static void sendAsynchronouslyTo (String destination, Type type, 
			long payload) {
		SEMessage m = new SEMessage (type, payload);
		m.isend(destination);
	}
}

@@ -1,30 +1,4 @@
-import java.util.Vector;%0A%0A
 impo
@@ -386,54 +386,8 @@
 = 0;
-%0A%09private Vector%3CLogicalFile%3E fileList = null;
 %0A%0A%09p
@@ -635,145 +635,8 @@
 %09%7D%0A%0A
-%09public LogicalFile getFile() %7B%0A%09%09return fileList.firstElement();%0A%09%7D%0A%0A%09public Vector%3CLogicalFile%3E getFileList() %7B%0A%09%09return fileList;%0A%09%7D%0A%0A
 %09pub
@@ -693,39 +693,8 @@
 size
-, %0A%09%09%09Vector%3CLogicalFile%3E files
 ) %7B%0A
@@ -805,33 +805,8 @@
 ze;%0A
-%09%09this.fileList = files;%0A
 %09%7D%0A%0A
@@ -1547,24 +1547,86 @@
 essage;%0A%09%7D%0A%0A
+%09/**%0A%09 *  Specialized send of a DOWNLOAD_REQUEST message%0A%09 */%0A
 %09public stat
@@ -1709,38 +1709,8 @@
 size
-, Vector%3CLogicalFile%3E fileList
 ) %7B%0A
@@ -1767,18 +1767,8 @@
 size
-, fileList
 );%0A%09
@@ -2215,230 +2215,8 @@
 l, 0
-, null);%0A%09%7D%0A%0A%09/**%0A%09 *  Specialized send of a DOWNLOAD_REQUEST message%0A%09 */%0A%09public static void sendTo (String destination, Type type, %0A%09%09%09String logicalName, long size) %7B%0A%09%09sendTo(destination, type, logicalName, size, null
 );%0A%09

remove useless stuff that belonged to LFCMessage