Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The default alias name is now build from the name of the host of the process and...
[simgrid.git] / src / java / simgrid / msg / ApplicationHandler.java
index 16bef1d7a695a5b6a2a41a0fa64b56f962864924..37c6e6628569528734d310970d10651ad0e3b340 100644 (file)
@@ -12,8 +12,7 @@
 package simgrid.msg;
 
 import java.util.Vector;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
+import java.util.Hashtable;
 
 /**
  * The handler used to parse the deployment file which contains 
@@ -28,40 +27,41 @@ import org.xml.sax.helpers.*;
  * @since SimGrid 3.3
  * @since JDK1.5011 
  */
-public final class ApplicationHandler extends DefaultHandler
-{
-       
-       /* 
-        * This class is used to create the processes descibed in the deployment file.
-        */
-       class ProcessFactory
-       {
-               /**
+public final class ApplicationHandler{
+
+  /* 
+   * This class is used to create the processes descibed in the deployment file.
+   */
+  static class ProcessFactory {
+                /**
                 * The vector which contains the arguments of the main function 
                 * of the process object.
                 */
-               public Vector args;
-               
-               /**
+    public Vector args;
+    
+    public Hashtable properties;
+
+                /**
                 * The name of the host of the process.
-                */     
-               private String hostName;
-               
-               /**
+                */
+    private String hostName;
+
+                /**
                 * The function of the process.
                 */
-               private String function;
-               
-               /**
+    private String function;
+    
+
+                /**
                 * Default constructor.
                 */
-               public ProcessFactory(){
-                       this.args = new Vector();
-                       this.hostName = null;
-                       this.function = null;
-               }
-               
-               /**
+    public ProcessFactory() {
+      this.args = new Vector();
+      this.properties = new Hashtable();
+      this.hostName = null;
+      this.function = null;
+    }
+                /**
                 * This method is called by the start element handler.
                 * It sets the host and the function of the process to create,
                 * and clear the vector containing the arguments of the 
@@ -71,123 +71,120 @@ public final class ApplicationHandler extends DefaultHandler
                 * @function                    The function of the process to create.
                 *
                 */
-               public void setProcessIdentity(String hostName, String function){
-                       this.hostName = hostName;
-                       this.function = function;
-               
-                       if(!args.isEmpty())
-                               args.clear();
-               }
-               
-               /**
+      public void setProcessIdentity(String hostName, String function) {
+      this.hostName = hostName;
+      this.function = function;
+
+      if (!args.isEmpty())
+        args.clear();
+        
+      if(!properties.isEmpty())
+       properties.clear();
+    }
+                /**
                 * This method is called by the startElement() handler.
                 * It stores the argument of the function of the next
                 * process to create in the vector of arguments.
                 *
                 * @arg                                 The argument to add.
                 *
-                */
-               public void registerProcessArg(String arg){
-                       this.args.add(arg);     
-               }
-       
-               public void createProcess(){
-                       try {
-                               
-                       Class cls = Class.forName(this.function);
-                       simgrid.msg.Process process = (simgrid.msg.Process)cls.newInstance();
-                       process.name = process.getName(); //this.function;
-                       process.id = simgrid.msg.Process.nextProcessId++;
-                       Host host = Host.getByName(this.hostName);
-                       Msg.processCreate(process,host);
-                       Vector args = processFactory.args;
-                       int size = args.size();
-                       
-                       for(int index = 0; index < size; index++)
-                               process.args.add(args.get(index));
-                               
-               } catch(JniException e)
-               {
-                       System.out.println(e.toString());
-                       e.printStackTrace();    
-                
-               } catch(NativeException e)
-               {
-                       System.out.println(e.toString());
-                       e.printStackTrace();
-               
-               } catch(HostNotFoundException e) {
-                       System.out.println(e.toString());
-                       e.printStackTrace();
-                       
-               } catch(ClassNotFoundException e) {
-                       System.out.println(this.function + " 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)");
-                       e.printStackTrace();
-
-               } catch(InstantiationException e) {
-                        System.out.println("instantiation exception");
-                        e.printStackTrace();
-                       } catch (IllegalAccessException e) {
-                       System.out.println("illegal access exception");
-                       e.printStackTrace();
-               } catch (IllegalArgumentException e) {  
-                        System.out.println("illegal argument exception");
-                        e.printStackTrace();
-               }
-
-       }
-       }
-       
-       /* 
-        * the ProcessFactory object used to create the processes.
-        */
-       private ProcessFactory processFactory;
-    
-    public ApplicationHandler() {
-        super();
+                */ public void registerProcessArg(String arg) {
+      args.add(arg);
     }
-    /**
-     * instanciates the process factory 
-     */
-    public void startDocument(){
-       this.processFactory = new ProcessFactory();     
-    } 
     
-    public void characters(char[] caracteres, int debut, int longueur) {} // NOTHING TODO
-    
-   /**
-    * element handlers
-    */
-    public void startElement(String nameSpace, String localName,String qName,Attributes attr) {
-        if(localName.equals("process"))
-            onProcessIdentity(attr);   
-               else if(localName.equals("argument"))
-            onProcessArg(attr);
+    public void setProperty(String id, String value)
+    {
+       properties.put(id,value);       
     }
     
-     /**
-     * process attributs handler.
-     */
-    public void onProcessIdentity(Attributes attr) {
-               processFactory.setProcessIdentity(attr.getValue(0),attr.getValue(1));
+    public String getHostName()
+    {
+       return hostName;
     }
-       
-       /**
-     * process arguments handler.
-     */
-    public void onProcessArg(Attributes attr) {
-        processFactory.registerProcessArg(attr.getValue(0));      
+
+    public void createProcess() {
+      try {
+
+        Class cls = Class.forName(this.function);
+
+        simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
+        process.name = /*process.getName();*/       this.function;
+        process.id = simgrid.msg.Process.nextProcessId++;
+        Host host = Host.getByName(this.hostName);
+
+        MsgNative.processCreate(process, host);
+        Vector args = processFactory.args;
+        int size = args.size();
+
+        for (int index = 0; index < size; index++)
+          process.args.add(args.get(index));
+          
+        process.properties = this.properties;
+        this.properties = new Hashtable();
+
+      } catch(JniException e) {
+        System.out.println(e.toString());
+        e.printStackTrace();
+
+      } catch(NativeException e) {
+        System.out.println(e.toString());
+        e.printStackTrace();
+
+      } catch(HostNotFoundException e) {
+        System.out.println(e.toString());
+        e.printStackTrace();
+
+      } catch(ClassNotFoundException e) {
+        System.out.println(this.function +
+                           " 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)");
+        e.printStackTrace();
+
+      } catch(InstantiationException e) {
+        System.out.println("instantiation exception");
+        e.printStackTrace();
+      } catch(IllegalAccessException e) {
+        System.out.println("illegal access exception");
+        e.printStackTrace();
+      } catch(IllegalArgumentException e) {
+        System.out.println("illegal argument exception");
+        e.printStackTrace();
+      }
+
     }
-    
+  }
+
+  /* 
+   * the ProcessFactory object used to create the processes.
+   */
+  public static ProcessFactory processFactory;
+
+  public ApplicationHandler() {
+    super();
+  }
     /**
-     * creates the process
+     * instanciates the process factory 
      */
-    public void endElement(String nameSpace, String localName,String qName)  {
-        if(localName.equals("process"))
-{
-               processFactory.createProcess();
-        }      
-    }
-     
-    public void endDocument() {} // NOTHING TODO
+  public static void onStartDocument() {
+    processFactory = new ProcessFactory();
+  }
+  
+   public static void onBeginProcess(String hostName, String function)
+   {
+        processFactory.setProcessIdentity(hostName, function);
+}
+       public static void onProperty(String id, String value) {
+    processFactory.setProperty(id, value);
+  }
+  
+   public static void onProcessArg(String arg) {
+    processFactory.registerProcessArg(arg);
+  }
+  
+  public static void onEndProcess() {
+    
+      processFactory.createProcess();
+  }        
+
+  public static void onEndDocument() {
+  }  // NOTHING TODO
 }