2 * These are the upcalls used by the FleXML parser for application files
4 * Copyright 2006,2007,2010 The SimGrid team.
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 /* FIXME: Kill the process factory: that's just a storage of informations, AppHandler can do the work itself */
16 import java.util.Vector;
17 import java.util.Hashtable;
19 public final class ApplicationHandler {
22 * This class is used to create the processes described in the deployment file.
24 static class ProcessFactory {
26 * The vector which contains the arguments of the main function
27 * of the process object.
29 public Vector<String> args;
31 public Hashtable<String,String> properties;
34 * The name of the host of the process.
36 private String hostName;
39 * The function of the process.
41 private String function;
45 * Default constructor.
47 public ProcessFactory() {
48 this.args = new Vector<String>();
49 this.properties = new Hashtable<String,String>();
54 * This method is called by the start element handler.
55 * It sets the host and the function of the process to create,
56 * and clear the vector containing the arguments of the
57 * previouse process function if needed.
59 * @host The host of the process to create.
60 * @function The function of the process to create.
63 public void setProcessIdentity(String hostName, String function) {
64 this.hostName = hostName;
65 this.function = function;
70 if(!properties.isEmpty())
74 * This method is called by the startElement() handler.
75 * It stores the argument of the function of the next
76 * process to create in the vector of arguments.
78 * @arg The argument to add.
80 */ public void registerProcessArg(String arg) {
84 public void setProperty(String id, String value)
86 properties.put(id,value);
89 public String getHostName()
94 @SuppressWarnings("unchecked")
95 public void createProcess() {
97 Class<simgrid.msg.Process> cls = (Class<Process>) Class.forName(this.function);
99 simgrid.msg.Process process = cls.newInstance();
100 process.name = this.function;
101 process.id = simgrid.msg.Process.nextProcessId++;
102 Host host = Host.getByName(this.hostName);
104 MsgNative.processCreate(process, host);
105 Vector<String> args = processFactory.args;
106 int size = args.size();
108 for (int index = 0; index < size; index++)
109 process.args.add(args.get(index));
111 process.properties = this.properties;
112 this.properties = new Hashtable();
114 } catch(NativeException e) {
115 System.out.println(e.toString());
118 } catch(HostNotFoundException e) {
119 System.out.println(e.toString());
122 } catch(ClassNotFoundException e) {
123 System.out.println(this.function +
124 " 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)");
127 } catch(InstantiationException e) {
128 System.out.println("Unable to create the process. I got an instantiation exception");
130 } catch(IllegalAccessException e) {
131 System.out.println("Unable to create the process. I got an illegal access exception");
139 * the ProcessFactory object used to create the processes.
141 public static ProcessFactory processFactory;
144 * instanciates the process factory
146 public static void onStartDocument() {
147 processFactory = new ProcessFactory();
150 public static void onBeginProcess(String hostName, String function) {
151 processFactory.setProcessIdentity(hostName, function);
153 public static void onProperty(String id, String value) {
154 processFactory.setProperty(id, value);
157 public static void onProcessArg(String arg) {
158 processFactory.registerProcessArg(arg);
161 public static void onEndProcess() {
162 processFactory.createProcess();
165 public static void onEndDocument() {