2 * simgrid.msg.ApplicationHandler.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 *(GNU LGPL) which comes with this package.
14 import java.util.Vector;
15 import java.util.Hashtable;
18 * The handler used to parse the deployment file which contains
19 * the description of the application (simulation).
21 * @author Abdelmalek Cherier
22 * @author Martin Quinson
23 * @version 1.00, 07/05/01
30 public final class ApplicationHandler {
33 * This class is used to create the processes descibed in the deployment file.
35 static class ProcessFactory {
37 * The vector which contains the arguments of the main function
38 * of the process object.
42 public Hashtable properties;
45 * The name of the host of the process.
47 private String hostName;
50 * The function of the process.
52 private String function;
56 * Default constructor.
58 public ProcessFactory() {
59 this.args = new Vector();
60 this.properties = new Hashtable();
65 * This method is called by the start element handler.
66 * It sets the host and the function of the process to create,
67 * and clear the vector containing the arguments of the
68 * previouse process function if needed.
70 * @host The host of the process to create.
71 * @function The function of the process to create.
74 public void setProcessIdentity(String hostName, String function) {
75 this.hostName = hostName;
76 this.function = function;
81 if(!properties.isEmpty())
85 * This method is called by the startElement() handler.
86 * It stores the argument of the function of the next
87 * process to create in the vector of arguments.
89 * @arg The argument to add.
91 */ public void registerProcessArg(String arg) {
95 public void setProperty(String id, String value)
97 properties.put(id,value);
100 public String getHostName()
105 public void createProcess() {
108 Class cls = Class.forName(this.function);
110 simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
111 process.name = this.function;
112 process.id = simgrid.msg.Process.nextProcessId++;
113 Host host = Host.getByName(this.hostName);
115 MsgNative.processCreate(process, host);
116 Vector args = processFactory.args;
117 int size = args.size();
119 for (int index = 0; index < size; index++)
120 process.args.add(args.get(index));
122 process.properties = this.properties;
123 this.properties = new Hashtable();
125 } catch(JniException e) {
126 System.out.println(e.toString());
129 } catch(NativeException e) {
130 System.out.println(e.toString());
133 } catch(HostNotFoundException e) {
134 System.out.println(e.toString());
137 } catch(ClassNotFoundException e) {
138 System.out.println(this.function +
139 " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)");
142 } catch(InstantiationException e) {
143 System.out.println("instantiation exception");
145 } catch(IllegalAccessException e) {
146 System.out.println("illegal access exception");
148 } catch(IllegalArgumentException e) {
149 System.out.println("illegal argument exception");
157 * the ProcessFactory object used to create the processes.
159 public static ProcessFactory processFactory;
162 * instanciates the process factory
164 public static void onStartDocument() {
165 processFactory = new ProcessFactory();
168 public static void onBeginProcess(String hostName, String function) {
169 processFactory.setProcessIdentity(hostName, function);
171 public static void onProperty(String id, String value) {
172 processFactory.setProperty(id, value);
175 public static void onProcessArg(String arg) {
176 processFactory.registerProcessArg(arg);
179 public static void onEndProcess() {
180 processFactory.createProcess();
183 public static void onEndDocument() {