Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New version of the java bindings by Malek, passing all [existing] tests
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 13 Sep 2007 22:26:16 +0000 (22:26 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 13 Sep 2007 22:26:16 +0000 (22:26 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@4629 48e7efb5-ca39-0410-a469-dd3cf9ba447f

29 files changed:
examples/java/basic/Forwarder.java
examples/java/basic/Makefile.am
examples/java/basic/Makefile.in
examples/java/basic/surfxml.dtd [deleted file]
examples/java/comm_time/Makefile.am
examples/java/comm_time/Makefile.in
examples/java/comm_time/surfxml.dtd [deleted file]
examples/java/ping_pong/Makefile.am
examples/java/ping_pong/Makefile.in
examples/java/ping_pong/surfxml.dtd [deleted file]
examples/java/suspend/DreamMaster.java
examples/java/suspend/LazyGuy.java
examples/java/suspend/Makefile.am
examples/java/suspend/Makefile.in
examples/java/suspend/surfxml.dtd [deleted file]
src/Makefile.am
src/Makefile.in
src/java/jmsg.c
src/java/jmsg.h
src/java/jmsg_process.c
src/java/jmsg_process.h
src/java/jxbt_context.c
src/java/jxbt_context.h
src/java/jxbt_utilities.c
src/java/simgrid/msg/ApplicationHandler.java
src/java/simgrid/msg/DTDResolver.java [new file with mode: 0644]
src/java/simgrid/msg/Msg.java
src/java/simgrid/msg/Process.java
src/java/simgrid/msg/Sem.java [new file with mode: 0644]

index 0119c3d..2e08701 100644 (file)
@@ -45,8 +45,8 @@ public class Forwarder extends simgrid.msg.Process {
               forwardedtask.setData(221297);
               
               channel.put(forwardedtask,slaves[cpt]);
-              break;
            }
+           break;
            
         } else {
            
index 055698b..29ae17b 100644 (file)
@@ -1,5 +1,5 @@
 CLASSPATH=../../../src/simgrid.jar
-EXTRA_DIST=basic_deployment.xml basic_platform.xml surfxml.dtd
+EXTRA_DIST=basic_deployment.xml basic_platform.xml
 
 # Declare sources:
 noinst_JAVA= Master.java Forwarder.java Slave.java BasicTest.java BasicTask.java
index 9c6c569..810feaa 100644 (file)
@@ -280,6 +280,7 @@ CTAGS:
 
 check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
+       faillist=""; xpasslist=""; xfaillist=""; skiplist=""; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
        if test -n "$$list"; then \
@@ -293,6 +294,7 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
+               xpasslist="$$xpasslist $$tst"; \
                echo "XPASS: $$tst"; \
              ;; \
              *) \
@@ -304,15 +306,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
+               xfaillist="$$xfaillist $$tst"; \
                echo "XFAIL: $$tst"; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
+               faillist="$$faillist $$tst"; \
                echo "FAIL: $$tst"; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
+             skiplist="$$skiplist $$tst"; \
              echo "SKIP: $$tst"; \
            fi; \
          done; \
@@ -348,6 +353,30 @@ check-TESTS: $(TESTS)
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
          echo "$$dashes"; \
+         if test -n "$$faillist" ; then \
+           echo "Failed tests:";\
+           for tst in $$faillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xpasslist" ; then \
+           echo "Unexpectedly passed tests:";\
+           for tst in $$xpasslist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xfaillist" ; then \
+           echo "Expected failures:";\
+           for tst in $$xfaillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$skiplist" ; then \
+           echo "Skipped tests:";\
+           for tst in $$skiplist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
          test "$$failed" -eq 0; \
        else :; fi
 
diff --git a/examples/java/basic/surfxml.dtd b/examples/java/basic/surfxml.dtd
deleted file mode 100644 (file)
index be3e5ef..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!-- Small DTD for SURF based tools. -->
-<!ELEMENT platform_description ((include|cpu|network_link|route|process)*)>
-<!ATTLIST platform_description version CDATA "0.0">
-
-<!ELEMENT include ((include|cpu|network_link|route|process)*)>
-<!ATTLIST include file CDATA #REQUIRED>
-
-<!ELEMENT cpu EMPTY>
-<!ATTLIST cpu name CDATA #REQUIRED>
-<!ATTLIST cpu power CDATA #REQUIRED>
-<!ATTLIST cpu availability CDATA "1.0">
-<!ATTLIST cpu availability_file CDATA "">
-<!ATTLIST cpu state (ON|OFF) "ON">
-<!ATTLIST cpu state_file CDATA "">
-<!ATTLIST cpu interference_send CDATA "1.0">
-<!ATTLIST cpu interference_recv CDATA "1.0">
-<!ATTLIST cpu interference_send_recv CDATA "1.0">
-<!ATTLIST cpu max_outgoing_rate CDATA "-1.0">
-
-<!ELEMENT network_link EMPTY>
-<!ATTLIST network_link name CDATA #REQUIRED>
-<!ATTLIST network_link bandwidth CDATA  #REQUIRED>
-<!ATTLIST network_link bandwidth_file CDATA "">
-<!ATTLIST network_link latency CDATA "0.0">
-<!ATTLIST network_link latency_file CDATA "">
-<!ATTLIST network_link state (ON|OFF) "ON">
-<!ATTLIST network_link state_file CDATA "">
-<!ATTLIST network_link sharing_policy (SHARED|FATPIPE) "SHARED">
-
-<!ELEMENT route (route_element*)>
-<!ATTLIST route src CDATA #REQUIRED>
-<!ATTLIST route dst CDATA #REQUIRED>
-<!ATTLIST route impact_on_src CDATA "0.0">
-<!ATTLIST route impact_on_dst CDATA "0.0">
-<!ATTLIST route impact_on_src_with_other_recv CDATA "0.0">
-<!ATTLIST route impact_on_dst_with_other_send CDATA "0.0">
-
-<!ELEMENT route_element EMPTY>
-<!ATTLIST route_element name CDATA #REQUIRED>
-
-<!ELEMENT process (argument*)>
-<!ATTLIST process host CDATA #REQUIRED>
-<!ATTLIST process function CDATA #REQUIRED>
-<!ATTLIST process start_time CDATA "-1.0">
-<!ATTLIST process kill_time CDATA "-1.0">
-
-<!ELEMENT argument EMPTY>
-<!ATTLIST argument value CDATA #REQUIRED>
index 2cb867b..d60c632 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST=comm_time_deployment.xml comm_time_platform.xml surfxml.dtd
+EXTRA_DIST=comm_time_deployment.xml comm_time_platform.xml
 
 # Declare sources:
 noinst_JAVA= Master.java Slave.java CommTimeTest.java CommTimeTask.java
index b6cc8f8..c38d1f5 100644 (file)
@@ -277,6 +277,7 @@ CTAGS:
 
 check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
+       faillist=""; xpasslist=""; xfaillist=""; skiplist=""; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
        if test -n "$$list"; then \
@@ -290,6 +291,7 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
+               xpasslist="$$xpasslist $$tst"; \
                echo "XPASS: $$tst"; \
              ;; \
              *) \
@@ -301,15 +303,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
+               xfaillist="$$xfaillist $$tst"; \
                echo "XFAIL: $$tst"; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
+               faillist="$$faillist $$tst"; \
                echo "FAIL: $$tst"; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
+             skiplist="$$skiplist $$tst"; \
              echo "SKIP: $$tst"; \
            fi; \
          done; \
@@ -345,6 +350,30 @@ check-TESTS: $(TESTS)
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
          echo "$$dashes"; \
+         if test -n "$$faillist" ; then \
+           echo "Failed tests:";\
+           for tst in $$faillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xpasslist" ; then \
+           echo "Unexpectedly passed tests:";\
+           for tst in $$xpasslist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xfaillist" ; then \
+           echo "Expected failures:";\
+           for tst in $$xfaillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$skiplist" ; then \
+           echo "Skipped tests:";\
+           for tst in $$skiplist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
          test "$$failed" -eq 0; \
        else :; fi
 
diff --git a/examples/java/comm_time/surfxml.dtd b/examples/java/comm_time/surfxml.dtd
deleted file mode 100644 (file)
index be3e5ef..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!-- Small DTD for SURF based tools. -->
-<!ELEMENT platform_description ((include|cpu|network_link|route|process)*)>
-<!ATTLIST platform_description version CDATA "0.0">
-
-<!ELEMENT include ((include|cpu|network_link|route|process)*)>
-<!ATTLIST include file CDATA #REQUIRED>
-
-<!ELEMENT cpu EMPTY>
-<!ATTLIST cpu name CDATA #REQUIRED>
-<!ATTLIST cpu power CDATA #REQUIRED>
-<!ATTLIST cpu availability CDATA "1.0">
-<!ATTLIST cpu availability_file CDATA "">
-<!ATTLIST cpu state (ON|OFF) "ON">
-<!ATTLIST cpu state_file CDATA "">
-<!ATTLIST cpu interference_send CDATA "1.0">
-<!ATTLIST cpu interference_recv CDATA "1.0">
-<!ATTLIST cpu interference_send_recv CDATA "1.0">
-<!ATTLIST cpu max_outgoing_rate CDATA "-1.0">
-
-<!ELEMENT network_link EMPTY>
-<!ATTLIST network_link name CDATA #REQUIRED>
-<!ATTLIST network_link bandwidth CDATA  #REQUIRED>
-<!ATTLIST network_link bandwidth_file CDATA "">
-<!ATTLIST network_link latency CDATA "0.0">
-<!ATTLIST network_link latency_file CDATA "">
-<!ATTLIST network_link state (ON|OFF) "ON">
-<!ATTLIST network_link state_file CDATA "">
-<!ATTLIST network_link sharing_policy (SHARED|FATPIPE) "SHARED">
-
-<!ELEMENT route (route_element*)>
-<!ATTLIST route src CDATA #REQUIRED>
-<!ATTLIST route dst CDATA #REQUIRED>
-<!ATTLIST route impact_on_src CDATA "0.0">
-<!ATTLIST route impact_on_dst CDATA "0.0">
-<!ATTLIST route impact_on_src_with_other_recv CDATA "0.0">
-<!ATTLIST route impact_on_dst_with_other_send CDATA "0.0">
-
-<!ELEMENT route_element EMPTY>
-<!ATTLIST route_element name CDATA #REQUIRED>
-
-<!ELEMENT process (argument*)>
-<!ATTLIST process host CDATA #REQUIRED>
-<!ATTLIST process function CDATA #REQUIRED>
-<!ATTLIST process start_time CDATA "-1.0">
-<!ATTLIST process kill_time CDATA "-1.0">
-
-<!ELEMENT argument EMPTY>
-<!ATTLIST argument value CDATA #REQUIRED>
index aa5f0df..5b3fede 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST=ping_pong_deployment.xml ping_pong_platform.xml surfxml.dtd
+EXTRA_DIST=ping_pong_deployment.xml ping_pong_platform.xml
 
 # Declare sources:
 noinst_JAVA= Sender.java Receiver.java PingPongTask.java PingPongTest.java
index 6df5cd1..9487bba 100644 (file)
@@ -280,6 +280,7 @@ CTAGS:
 
 check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
+       faillist=""; xpasslist=""; xfaillist=""; skiplist=""; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
        if test -n "$$list"; then \
@@ -293,6 +294,7 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
+               xpasslist="$$xpasslist $$tst"; \
                echo "XPASS: $$tst"; \
              ;; \
              *) \
@@ -304,15 +306,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
+               xfaillist="$$xfaillist $$tst"; \
                echo "XFAIL: $$tst"; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
+               faillist="$$faillist $$tst"; \
                echo "FAIL: $$tst"; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
+             skiplist="$$skiplist $$tst"; \
              echo "SKIP: $$tst"; \
            fi; \
          done; \
@@ -348,6 +353,30 @@ check-TESTS: $(TESTS)
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
          echo "$$dashes"; \
+         if test -n "$$faillist" ; then \
+           echo "Failed tests:";\
+           for tst in $$faillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xpasslist" ; then \
+           echo "Unexpectedly passed tests:";\
+           for tst in $$xpasslist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xfaillist" ; then \
+           echo "Expected failures:";\
+           for tst in $$xfaillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$skiplist" ; then \
+           echo "Skipped tests:";\
+           for tst in $$skiplist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
          test "$$failed" -eq 0; \
        else :; fi
 
diff --git a/examples/java/ping_pong/surfxml.dtd b/examples/java/ping_pong/surfxml.dtd
deleted file mode 100644 (file)
index be3e5ef..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!-- Small DTD for SURF based tools. -->
-<!ELEMENT platform_description ((include|cpu|network_link|route|process)*)>
-<!ATTLIST platform_description version CDATA "0.0">
-
-<!ELEMENT include ((include|cpu|network_link|route|process)*)>
-<!ATTLIST include file CDATA #REQUIRED>
-
-<!ELEMENT cpu EMPTY>
-<!ATTLIST cpu name CDATA #REQUIRED>
-<!ATTLIST cpu power CDATA #REQUIRED>
-<!ATTLIST cpu availability CDATA "1.0">
-<!ATTLIST cpu availability_file CDATA "">
-<!ATTLIST cpu state (ON|OFF) "ON">
-<!ATTLIST cpu state_file CDATA "">
-<!ATTLIST cpu interference_send CDATA "1.0">
-<!ATTLIST cpu interference_recv CDATA "1.0">
-<!ATTLIST cpu interference_send_recv CDATA "1.0">
-<!ATTLIST cpu max_outgoing_rate CDATA "-1.0">
-
-<!ELEMENT network_link EMPTY>
-<!ATTLIST network_link name CDATA #REQUIRED>
-<!ATTLIST network_link bandwidth CDATA  #REQUIRED>
-<!ATTLIST network_link bandwidth_file CDATA "">
-<!ATTLIST network_link latency CDATA "0.0">
-<!ATTLIST network_link latency_file CDATA "">
-<!ATTLIST network_link state (ON|OFF) "ON">
-<!ATTLIST network_link state_file CDATA "">
-<!ATTLIST network_link sharing_policy (SHARED|FATPIPE) "SHARED">
-
-<!ELEMENT route (route_element*)>
-<!ATTLIST route src CDATA #REQUIRED>
-<!ATTLIST route dst CDATA #REQUIRED>
-<!ATTLIST route impact_on_src CDATA "0.0">
-<!ATTLIST route impact_on_dst CDATA "0.0">
-<!ATTLIST route impact_on_src_with_other_recv CDATA "0.0">
-<!ATTLIST route impact_on_dst_with_other_send CDATA "0.0">
-
-<!ELEMENT route_element EMPTY>
-<!ATTLIST route_element name CDATA #REQUIRED>
-
-<!ELEMENT process (argument*)>
-<!ATTLIST process host CDATA #REQUIRED>
-<!ATTLIST process function CDATA #REQUIRED>
-<!ATTLIST process start_time CDATA "-1.0">
-<!ATTLIST process kill_time CDATA "-1.0">
-
-<!ELEMENT argument EMPTY>
-<!ATTLIST argument value CDATA #REQUIRED>
index 221250a..368e16b 100644 (file)
@@ -17,16 +17,33 @@ public class DreamMaster extends simgrid.msg.Process {
        
        Msg.info("Let's create a lazy guy.");
        
-       Host currentHost = Host.currentHost();
-       Msg.info("Current host  name : " + currentHost.getName());
-               
-       LazyGuy lazy = new LazyGuy();
-//       lazy.migrate(currentHost);
+       try
+       {
+                         Host currentHost = Host.currentHost();
+                         
+                         Msg.info("Current host  name : " + currentHost.getName());
+
+                       LazyGuy lazy = new LazyGuy(currentHost,"LazyGuy");
+                       
+                        Msg.info("Let's wait a little bit...");
+
+                       simgrid.msg.Process.waitFor(10.0);
+
+                       Msg.info("Let's wake the lazy guy up! >:) ");
+
+                       lazy.restart();
+
+
+       }
+       catch(HostNotFoundException e)
+       {
+               System.err.println(e.toString());
+               System.exit(1);
+       }
+       
+        //lazy.migrate(currentHost);
         
-       Msg.info("Let's wait a little bit...");
-       simgrid.msg.Process.waitFor(10.0);
-       Msg.info("Let's wake the lazy guy up! >:) ");
-       lazy.restart();
+      
                
        Msg.info("OK, goodbye now.");
     }
index 19288e1..225e6f6 100644 (file)
 import simgrid.msg.*;
 
 public class LazyGuy extends simgrid.msg.Process {
+       
+       
+       public LazyGuy() {
+       super();
+    }
     
+     public LazyGuy(Host host,String name) 
+     throws NullPointerException, HostNotFoundException, JniException, NativeException
+     {
+               super(host,name,null);
+       }
+       
+        
     public void main(String[] args) throws JniException, NativeException {
        Msg.info("Hello !");
         
index 349ef8a..5e83d6f 100644 (file)
@@ -1,11 +1,10 @@
-EXTRA_DIST=suspend_deployment.xml suspend_platform.xml surfxml.dtd
+EXTRA_DIST=suspend_deployment.xml suspend_platform.xml
 
 # Declare sources:
 noinst_JAVA= DreamMaster.java LazyGuy.java SuspendTest.java
 
 # Declare test class 
 TESTS=SuspendTest.class
-XFAIL_TESTS=SuspendTest.class
 
 include $(srcdir)/../java_test.mk
 
index 234bc76..54a11e7 100644 (file)
@@ -204,7 +204,6 @@ noinst_JAVA = DreamMaster.java LazyGuy.java SuspendTest.java
 
 # Declare test class 
 TESTS = SuspendTest.class
-XFAIL_TESTS = SuspendTest.class
 JAVAROOT = .
 AM_JAVACFLAGS = -classpath $(top_srcdir)/src/simgrid.jar
 
@@ -280,6 +279,7 @@ CTAGS:
 
 check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
+       faillist=""; xpasslist=""; xfaillist=""; skiplist=""; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
        if test -n "$$list"; then \
@@ -293,6 +293,7 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
+               xpasslist="$$xpasslist $$tst"; \
                echo "XPASS: $$tst"; \
              ;; \
              *) \
@@ -304,15 +305,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
+               xfaillist="$$xfaillist $$tst"; \
                echo "XFAIL: $$tst"; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
+               faillist="$$faillist $$tst"; \
                echo "FAIL: $$tst"; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
+             skiplist="$$skiplist $$tst"; \
              echo "SKIP: $$tst"; \
            fi; \
          done; \
@@ -348,6 +352,30 @@ check-TESTS: $(TESTS)
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
          echo "$$dashes"; \
+         if test -n "$$faillist" ; then \
+           echo "Failed tests:";\
+           for tst in $$faillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xpasslist" ; then \
+           echo "Unexpectedly passed tests:";\
+           for tst in $$xpasslist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xfaillist" ; then \
+           echo "Expected failures:";\
+           for tst in $$xfaillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$skiplist" ; then \
+           echo "Skipped tests:";\
+           for tst in $$skiplist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
          test "$$failed" -eq 0; \
        else :; fi
 
diff --git a/examples/java/suspend/surfxml.dtd b/examples/java/suspend/surfxml.dtd
deleted file mode 100644 (file)
index be3e5ef..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<!-- Small DTD for SURF based tools. -->
-<!ELEMENT platform_description ((include|cpu|network_link|route|process)*)>
-<!ATTLIST platform_description version CDATA "0.0">
-
-<!ELEMENT include ((include|cpu|network_link|route|process)*)>
-<!ATTLIST include file CDATA #REQUIRED>
-
-<!ELEMENT cpu EMPTY>
-<!ATTLIST cpu name CDATA #REQUIRED>
-<!ATTLIST cpu power CDATA #REQUIRED>
-<!ATTLIST cpu availability CDATA "1.0">
-<!ATTLIST cpu availability_file CDATA "">
-<!ATTLIST cpu state (ON|OFF) "ON">
-<!ATTLIST cpu state_file CDATA "">
-<!ATTLIST cpu interference_send CDATA "1.0">
-<!ATTLIST cpu interference_recv CDATA "1.0">
-<!ATTLIST cpu interference_send_recv CDATA "1.0">
-<!ATTLIST cpu max_outgoing_rate CDATA "-1.0">
-
-<!ELEMENT network_link EMPTY>
-<!ATTLIST network_link name CDATA #REQUIRED>
-<!ATTLIST network_link bandwidth CDATA  #REQUIRED>
-<!ATTLIST network_link bandwidth_file CDATA "">
-<!ATTLIST network_link latency CDATA "0.0">
-<!ATTLIST network_link latency_file CDATA "">
-<!ATTLIST network_link state (ON|OFF) "ON">
-<!ATTLIST network_link state_file CDATA "">
-<!ATTLIST network_link sharing_policy (SHARED|FATPIPE) "SHARED">
-
-<!ELEMENT route (route_element*)>
-<!ATTLIST route src CDATA #REQUIRED>
-<!ATTLIST route dst CDATA #REQUIRED>
-<!ATTLIST route impact_on_src CDATA "0.0">
-<!ATTLIST route impact_on_dst CDATA "0.0">
-<!ATTLIST route impact_on_src_with_other_recv CDATA "0.0">
-<!ATTLIST route impact_on_dst_with_other_send CDATA "0.0">
-
-<!ELEMENT route_element EMPTY>
-<!ATTLIST route_element name CDATA #REQUIRED>
-
-<!ELEMENT process (argument*)>
-<!ATTLIST process host CDATA #REQUIRED>
-<!ATTLIST process function CDATA #REQUIRED>
-<!ATTLIST process start_time CDATA "-1.0">
-<!ATTLIST process kill_time CDATA "-1.0">
-
-<!ELEMENT argument EMPTY>
-<!ATTLIST argument value CDATA #REQUIRED>
index 18e4b3f..f694bbf 100644 (file)
@@ -213,12 +213,16 @@ JMSG_JAVA_SRC = \
   java/simgrid/msg/ProcessNotFoundException.java     \
   \
   java/simgrid/msg/Process.java                      \
+  java/simgrid/msg/DTDResolver.java                  \
   java/simgrid/msg/ApplicationHandler.java           \
   java/simgrid/msg/Channel.java                      \
   java/simgrid/msg/Host.java                         \
   java/simgrid/msg/Msg.java                          \
   java/simgrid/msg/Task.java                         \
-  java/simgrid/msg/ParallelTask.java                 
+  java/simgrid/msg/ParallelTask.java                 \
+  \
+  java/simgrid/msg/Sem.java
+
 
 SIMDAG_SRC= simdag/sd_global.c simdag/sd_link.c simdag/sd_task.c simdag/sd_workstation.c
 
@@ -333,10 +337,10 @@ clean-local:
 jardir = $(prefix)/jar 
 jar_DATA =  simgrid.jar
 
-simgrid.jar: $(JMSG_JAVA_SRC)
+simgrid.jar: $(JMSG_JAVA_SRC) ./surf/surfxml.dtd
        [ -e .classes ] || mkdir .classes
-       $(JAVAC) -sourcepath java -d .classes $(JMSG_JAVA_SRC)
-       $(JAR) cvf simgrid.jar -C .classes .;
+       $(JAVAC) -sourcepath java -d .classes $(JMSG_JAVA_SRC) 
+       $(JAR) cvf simgrid.jar -C .classes . ./surf/surfxml.dtd;
 else
 EXTRA_DIST += $(JCTX_SRC) $(JMSG_C_SRC) $(MSG_SRC)
 endif
index 7beacbd..11473d3 100644 (file)
@@ -592,12 +592,15 @@ JMSG_JAVA_SRC = \
   java/simgrid/msg/ProcessNotFoundException.java     \
   \
   java/simgrid/msg/Process.java                      \
+  java/simgrid/msg/DTDResolver.java                  \
   java/simgrid/msg/ApplicationHandler.java           \
   java/simgrid/msg/Channel.java                      \
   java/simgrid/msg/Host.java                         \
   java/simgrid/msg/Msg.java                          \
   java/simgrid/msg/Task.java                         \
-  java/simgrid/msg/ParallelTask.java                 
+  java/simgrid/msg/ParallelTask.java                 \
+  \
+  java/simgrid/msg/Sem.java
 
 SIMDAG_SRC = simdag/sd_global.c simdag/sd_link.c simdag/sd_task.c simdag/sd_workstation.c
 GRAS_COMMON_SRC = \
@@ -2041,6 +2044,7 @@ distclean-tags:
 
 check-TESTS: $(TESTS)
        @failed=0; all=0; xfail=0; xpass=0; skip=0; ws='[        ]'; \
+       faillist=""; xpasslist=""; xfaillist=""; skiplist=""; \
        srcdir=$(srcdir); export srcdir; \
        list=' $(TESTS) '; \
        if test -n "$$list"; then \
@@ -2054,6 +2058,7 @@ check-TESTS: $(TESTS)
              *$$ws$$tst$$ws*) \
                xpass=`expr $$xpass + 1`; \
                failed=`expr $$failed + 1`; \
+               xpasslist="$$xpasslist $$tst"; \
                echo "XPASS: $$tst"; \
              ;; \
              *) \
@@ -2065,15 +2070,18 @@ check-TESTS: $(TESTS)
              case " $(XFAIL_TESTS) " in \
              *$$ws$$tst$$ws*) \
                xfail=`expr $$xfail + 1`; \
+               xfaillist="$$xfaillist $$tst"; \
                echo "XFAIL: $$tst"; \
              ;; \
              *) \
                failed=`expr $$failed + 1`; \
+               faillist="$$faillist $$tst"; \
                echo "FAIL: $$tst"; \
              ;; \
              esac; \
            else \
              skip=`expr $$skip + 1`; \
+             skiplist="$$skiplist $$tst"; \
              echo "SKIP: $$tst"; \
            fi; \
          done; \
@@ -2109,6 +2117,30 @@ check-TESTS: $(TESTS)
          test -z "$$skipped" || echo "$$skipped"; \
          test -z "$$report" || echo "$$report"; \
          echo "$$dashes"; \
+         if test -n "$$faillist" ; then \
+           echo "Failed tests:";\
+           for tst in $$faillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xpasslist" ; then \
+           echo "Unexpectedly passed tests:";\
+           for tst in $$xpasslist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$xfaillist" ; then \
+           echo "Expected failures:";\
+           for tst in $$xfaillist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
+         if test -n "$$skiplist" ; then \
+           echo "Skipped tests:";\
+           for tst in $$skiplist ; do \
+             echo "  "$$tst;\
+           done;\
+         fi;\
          test "$$failed" -eq 0; \
        else :; fi
 
@@ -2265,10 +2297,10 @@ uninstall-am: uninstall-binSCRIPTS uninstall-jarDATA \
 @HAVE_JAVA_TRUE@clean-local:
 @HAVE_JAVA_TRUE@       -rm -rf .classes
 
-@HAVE_JAVA_TRUE@simgrid.jar: $(JMSG_JAVA_SRC)
+@HAVE_JAVA_TRUE@simgrid.jar: $(JMSG_JAVA_SRC) ./surf/surfxml.dtd
 @HAVE_JAVA_TRUE@       [ -e .classes ] || mkdir .classes
-@HAVE_JAVA_TRUE@       $(JAVAC) -sourcepath java -d .classes $(JMSG_JAVA_SRC)
-@HAVE_JAVA_TRUE@       $(JAR) cvf simgrid.jar -C .classes .;
+@HAVE_JAVA_TRUE@       $(JAVAC) -sourcepath java -d .classes $(JMSG_JAVA_SRC) 
+@HAVE_JAVA_TRUE@       $(JAR) cvf simgrid.jar -C .classes . ./surf/surfxml.dtd;
 
 @GRAMINE_MODE_FALSE@@MAINTAINER_MODE_TRUE@@builddir@/cunit_unit.c: xbt/cunit.c
 @GRAMINE_MODE_FALSE@@MAINTAINER_MODE_TRUE@     @top_srcdir@/tools/sg_unit_extractor.pl $^
index ce812ae..0063f41 100644 (file)
@@ -11,6 +11,7 @@
  */
 #include "msg/msg.h"
 #include "msg/private.h"
+#include "simix/private.h"
 #include "java/jxbt_context.h"
 
 #include "jmsg_process.h"
@@ -31,6 +32,8 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg,"MSG for Java(TM)");
 
 #include "jmsg.h"
 
+static JavaVM * __java_vm = NULL;
+
 
 #ifdef WIN32
   static DWORD __current_thread_id = 0;
@@ -48,6 +51,20 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg,"MSG for Java(TM)");
   }
 #endif
 
+JavaVM *
+get_java_VM(void) {
+       return __java_vm;
+}
+
+JNIEnv *
+get_current_thread_env(void) {
+       JNIEnv *env;
+
+    (*__java_vm)->AttachCurrentThread(__java_vm, (void **)&env, NULL);
+
+        return env;
+}
+
 
 /*
  * The MSG process connected functions implementation.                                 
@@ -85,7 +102,7 @@ Java_simgrid_msg_Msg_processCreate(JNIEnv* env, jclass cls, jobject jprocess_arg
     return;
   }
        
-  /* bind the java process instance to the native host */
+  /* bind the java process instance to the native process */
   jprocess_bind(jprocess,process,env);
        
   /* build the C name of the process */
@@ -113,7 +130,7 @@ Java_simgrid_msg_Msg_processCreate(JNIEnv* env, jclass cls, jobject jprocess_arg
   SIMIX_jprocess_create(process->name,
                        process->simdata->m_host->simdata->s_host, 
                        /*data*/ (void*)process,
-                       jprocess_arg,env,
+                       jprocess,env,
                        &process->simdata->s_process);
   DEBUG1("context created (s_process=%p)",process->simdata->s_process);
 
@@ -468,7 +485,7 @@ Java_simgrid_msg_Msg_taskCreate(JNIEnv* env, jclass cls, jobject jtask, jstring
                                jdouble jcomputeDuration, jdouble jmessageSize) {
   m_task_t task;       /* the native task to create                            */
   const char* name;    /* the name of the task                                 */
-       
+
   if(jcomputeDuration < 0) {
     jxbt_throw_illegal(env,bprintf("Task ComputeDuration (%f) cannot be negative",
                                    (double)jcomputeDuration));
@@ -502,6 +519,7 @@ Java_simgrid_msg_Msg_taskCreate(JNIEnv* env, jclass cls, jobject jtask, jstring
 
   if ( ! task->data )
     jxbt_throw_jni(env,"global ref allocation failed");
+
 }
 
 JNIEXPORT void JNICALL 
@@ -925,7 +943,7 @@ Java_simgrid_msg_Msg_channelGetHostWaitingTasks(JNIEnv* env, jclass cls,
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_Msg_channelPut(JNIEnv* env, jclass cls, 
                                jobject jchannel, jobject jtask, jobject jhost) {
-
+       
   if(MSG_OK != MSG_task_put(jtask_to_native_task(jtask,env),
                            jhost_get_native(env,jhost),
                            (int)jchannel_get_id(jchannel,env)))
@@ -948,7 +966,7 @@ Java_simgrid_msg_Msg_channelPutWithTimeout(JNIEnv* env, jclass cls,
     jxbt_throw_notbound(env,"task",jtask);
     return;
   }
-       
+   
   if(MSG_OK != MSG_task_put_with_timeout(task,host,id,(double)jtimeout))
     jxbt_throw_native(env, xbt_strdup("MSG_task_put_with_timeout() failed"));
 }
@@ -1048,6 +1066,8 @@ Java_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jobjectArray jargs) {
 #else
   __current_thread_id = pthread_self();
 #endif
+
+(*env)->GetJavaVM(env,&__java_vm);
        
 }
 
@@ -1059,20 +1079,19 @@ JNICALL Java_simgrid_msg_Msg_run(JNIEnv* env, jclass cls) {
 
   /* Run everything */
   if(MSG_OK != MSG_main())
-    jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
-
+         jxbt_throw_native(env, xbt_strdup("MSG_main() failed"));
+       
   DEBUG0("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
-  SIMIX_display_process_status();   
-  exit(0); /* FIXME */
-   
+  
   DEBUG0("Clean java world");
   /* Cleanup java hosts */
   xbt_fifo_foreach(msg_global->host,item,host,m_host_t) {
     jhost = (jobject)host->data;
        
     if(jhost)
-      jhost_unref(env,jhost);  
+      jhost_unref(env,jhost);
   }
+       
   DEBUG0("Clean native world");
   /* cleanup native stuff */
   if(MSG_OK != MSG_clean())
@@ -1097,49 +1116,26 @@ Java_simgrid_msg_Msg_createEnvironment(JNIEnv* env, jclass cls,jstring jplatform
 
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_Msg_waitSignal(JNIEnv* env, jclass cls, jobject jprocess) {
-  m_process_t m_process = jprocess_to_native_process(jprocess,env);
-  smx_process_t s_process;
-
-  xbt_os_mutex_t ctx_mutex, creation_mutex;
-  xbt_os_cond_t ctx_cond, creation_cond;
-
-  DEBUG3("Msg_waitSignal(m_process=%p %s/%s)",
-        m_process,m_process->name,m_process->simdata->m_host->name);
-  if (!m_process){
-    jxbt_throw_notbound(env,"process",jprocess);
-    return;
-  }
-
-  s_process = m_process->simdata->s_process;
-
-  if (s_process == NULL) {
-    jxbt_throw_notbound(env,"SIMIX process",jprocess);
-    return;
-  }
-
-  ctx_mutex = SIMIX_process_get_jmutex(s_process);
-  ctx_cond = SIMIX_process_get_jcond(s_process);
-
-  creation_mutex = xbt_creation_mutex_get();
-  creation_cond = xbt_creation_cond_get();
 
+  xbt_os_mutex_t creation_mutex = xbt_creation_mutex_get();
+  xbt_os_cond_t creation_cond = xbt_creation_cond_get();
   xbt_os_mutex_lock(creation_mutex);
-  xbt_os_mutex_lock(ctx_mutex);
   xbt_os_cond_signal( creation_cond );
   xbt_os_mutex_unlock( creation_mutex );
-  xbt_os_cond_wait(ctx_cond, ctx_mutex);
-  xbt_os_mutex_unlock(ctx_mutex);
+
 }
 
 JNIEXPORT void JNICALL 
 Java_simgrid_msg_Msg_processExit(JNIEnv* env, jclass cls, jobject jprocess) {
+
   m_process_t process = jprocess_to_native_process(jprocess,env);
 
   if (!process){
     jxbt_throw_notbound(env,"process",jprocess);
     return;
   }
-  MSG_process_kill(process);
+
+  jcontext_exit(process->simdata->s_process->simdata->context,0,get_current_thread_env());
 }
 
 JNIEXPORT void JNICALL 
index 4454901..34b8e72 100644 (file)
 int
 is_main_thread(void);
 
+JavaVM *
+get_java_VM(void);
+
+JNIEnv *
+get_current_thread_env(void);
+
 /*
  * Class               simgrid_msg_Msg
  * Method              processCreate
index f4abf58..da34ddc 100644 (file)
  * process instance. 
  */
  
-#include "jmsg.h"
 #include "jmsg_process.h"
+#include "jmsg.h"
 #include "jxbt_utilities.h"
 
+#define JAVA_SIMGRID
+#include "xbt/context_private.h"
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 
@@ -112,7 +115,7 @@ jprocess_wait_cond(jobject jprocess,JNIEnv* env) {
 void
 jprocess_start(jobject jprocess,JNIEnv* env) {
   jmethodID id = jxbt_get_smethod(env,"simgrid/msg/Process","start", "()V");
-    
+
   if(!id)
     return;
 
@@ -174,3 +177,37 @@ jprocess_is_valid(jobject jprocess,JNIEnv* env) {
 
   return (*env)->GetLongField(env,jprocess,id) ? JNI_TRUE : JNI_FALSE; 
 }
+
+void
+jprocess_schedule(xbt_context_t context) {
+       JNIEnv * env;
+       jmethodID id;
+       
+       env = get_current_thread_env();
+
+       id = jxbt_get_smethod(env,"simgrid/msg/Process","schedule", "()V");
+       
+       if(!id)
+               return;
+       
+       (*env)->CallVoidMethod(env,context->jprocess,id);
+}
+
+
+
+void
+jprocess_unschedule(xbt_context_t context) {
+       JNIEnv * env;
+       jmethodID id;
+
+       env = get_current_thread_env();
+
+       
+       id = jxbt_get_smethod(env,"simgrid/msg/Process","unschedule", "()V");
+       
+       if(!id)
+               return;
+       
+       (*env)->CallVoidMethod(env,context->jprocess,id);
+}
+
index 0971301..85bb943 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <jni.h>
 #include "msg/msg.h"
+#include "xbt/context.h"
 
 /**
  * This function returns a global reference to the  java process instance 
@@ -253,5 +254,11 @@ jprocess_signal_cond(jobject jprocess,JNIEnv* env);
 void
 jprocess_wait_cond(jobject jprocess,JNIEnv* env);
 
+void
+jprocess_schedule(xbt_context_t context);
+
+void
+jprocess_unschedule(xbt_context_t context);
+
 
 #endif /* !MSG_JPROCESS_H */
index 54a87e9..a92d136 100644 (file)
 #include "java/jmsg.h"
 #include "java/jmsg_process.h"
 
-#define JAVA_SIMGRID /* get the right definition of the xbt_ctx with all we need here */
+/* get the right definition of the xbt_ctx with all we need here */
+#ifndef JAVA_SIMGRID
+#define JAVA_SIMGRID
+#endif 
+
 #include "xbt/context_private.h"
 
+pfn_schedule_t __process_schedule= NULL;
+pfn_schedule_t __process_unschedule= NULL;
+
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_ctx, xbt, "Context");
 
@@ -33,16 +40,34 @@ static xbt_os_cond_t creation_cond;              /* For syncronization during pr
 static xbt_os_mutex_t master_mutex;            /* For syncronization during process scheduling*/
 static xbt_os_cond_t master_cond;              /* For syncronization during process scheduling*/
 
+
+static void
+__xbt_process_schedule(xbt_context_t context);
+
+static void
+__xbt_process_unschedule(xbt_context_t context);
+
 static void 
 __xbt_context_yield(xbt_context_t context);
 
+static void
+__xbt_process_schedule(xbt_context_t context) {
+       (*(__process_schedule))(context);
+}
+
+static void
+__xbt_process_unschedule(xbt_context_t context) {
+       (*(__process_unschedule))(context);
+}
 
 static void 
 __xbt_context_yield(xbt_context_t context) {
+
   if(context) {
+
     /* save the current context */
     xbt_context_t self = current_context;
-    
+
     if(is_main_thread()) {
       /* the main thread has called this function
        * - update the current context
@@ -50,18 +75,15 @@ __xbt_context_yield(xbt_context_t context) {
        * - wait on its condition
        * - restore thr current contex
        */
-      
       xbt_os_mutex_lock(master_mutex);
-      xbt_os_mutex_lock(context->mutex);
-                       
       /* update the current context */
       current_context = context;
-      xbt_os_cond_signal(context->cond);
-      xbt_os_mutex_unlock(context->mutex);
+        __xbt_process_schedule(context);
       xbt_os_cond_wait(master_cond, master_mutex);
       xbt_os_mutex_unlock(master_mutex);
       /* retore the current context */
       current_context = self;
+         
                        
     } else {
        /* a java thread has called this function
@@ -70,55 +92,57 @@ __xbt_context_yield(xbt_context_t context) {
         * - wait on its condition
         * - restore thr current contex
         */
-
        xbt_os_mutex_lock(master_mutex);
-       xbt_os_mutex_lock(context->mutex);
        /* update the current context */
        current_context = context;
        xbt_os_cond_signal(master_cond);
        xbt_os_mutex_unlock(master_mutex);
-       xbt_os_cond_wait(context->cond, context->mutex);
-       xbt_os_mutex_unlock(context->mutex);
+       __xbt_process_unschedule(context);
        /* retore the current context */
        current_context = self;
       }
   }
+  
        
-  if(current_context->iwannadie) {
+  if(current_context->iwannadie)
     __context_exit(current_context, 1);
-  }
+  
 }
 
 
 
 static void 
 xbt_context_free(xbt_context_t context) {
-  if(context) {
-    if(context->jprocess) {
-      jobject jprocess = context->jprocess;
-      context->jprocess = NULL;
-                       
-      /* if the java process is alive join it */
-      if(jprocess_is_alive(jprocess,context->jenv)) {
-       jprocess_join(jprocess,context->jenv);
-      }
-    }
-       
-    /* destroy the mutex of the process */
-    xbt_os_mutex_destroy(context->mutex);
 
-    /* destroy the condition of the process */
-    xbt_os_cond_destroy(context->cond);
+       if(context) 
+       {
+               if(context->jprocess) 
+               {
+                       jobject jprocess = context->jprocess;
+                       context->jprocess = NULL;
 
-    context->mutex = NULL;
-    context->cond = NULL;
-    
-    if(context->exception) 
-      free(context->exception);
-    
-    free(context->name);
-    free(context);
-    context = NULL;
+                       /* if the java process is alive join it */
+                       if(jprocess_is_alive(jprocess,get_current_thread_env())) 
+                       {
+                               jprocess_join(jprocess,get_current_thread_env());
+                       }
+               }
+
+               /* destroy the mutex of the process */
+               xbt_os_mutex_destroy(context->mutex);
+
+               /* destroy the condition of the process */
+               xbt_os_cond_destroy(context->cond);
+
+               context->mutex = NULL;
+               context->cond = NULL;
+
+               if(context->exception) 
+                       free(context->exception);
+
+               free(context->name);
+               free(context);
+               context = NULL;
   }
 }
 /*
@@ -127,31 +151,35 @@ xbt_context_free(xbt_context_t context) {
 void 
 __context_exit(xbt_context_t context ,int value) {
   /* call the cleanup function of the context */
-  if(context->cleanup_func)
-    context->cleanup_func(context->cleanup_arg);
        
-  /* remove the context from the list of the contexts in use. */
-  xbt_swag_remove(context, context_living);
+       if(context->cleanup_func)
+               context->cleanup_func(context->cleanup_arg);
        
-  /* insert the context in the list of contexts to destroy. */ 
-  xbt_swag_insert(context, context_to_destroy);
+       /* remove the context from the list of the contexts in use. */
+       xbt_swag_remove(context, context_living);
        
-  /*
-   * signal the condition of the java process 
-   */
-  xbt_os_mutex_lock(master_mutex);
-  xbt_os_mutex_lock(context->mutex);
-  xbt_os_cond_signal(context->cond);
-  xbt_os_mutex_unlock(context->mutex);
+       /* insert the context in the list of contexts to destroy. */ 
+       xbt_swag_insert(context, context_to_destroy);
+       
+       /*
+       * signal the condition of the java process 
+       */
+
+       xbt_os_mutex_lock(master_mutex);
+
+       if (context->jprocess) 
+       {
+               if (jprocess_is_alive(context->jprocess,get_current_thread_env())) 
+               {
+                       jobject jprocess;
+                       __xbt_process_schedule(context);
+                       jprocess = context->jprocess;
+                       context->jprocess = NULL;
+                       jprocess_exit(jprocess,get_current_thread_env());
+               }
+       }
+
        
-  if (context->jprocess) {
-    /* if the java process is alive, stop it */
-    if (jprocess_is_alive(context->jprocess,context->jenv)) {
-      jobject jprocess = context->jprocess;
-      context->jprocess = NULL;
-      jprocess_exit(jprocess,context->jenv);
-    }
-  }
 }
 
 /*
@@ -175,13 +203,12 @@ jcontext_exit(xbt_context_t context ,int value,JNIEnv* env) {
    * signal the condition of the main thread.
    */
   xbt_os_mutex_lock(master_mutex);
-  xbt_os_mutex_lock(context->mutex);
   xbt_os_cond_signal(master_cond);
   xbt_os_mutex_unlock(master_mutex);
        
        
   /* the global reference to the java process instance is deleted */
-  jprocess_delete_global_ref(__jprocess,env);
+  jprocess_delete_global_ref(__jprocess,get_current_thread_env());
 }
 
 /* callback: context fetching */
@@ -234,6 +261,9 @@ xbt_context_init(void) {
     master_mutex = xbt_os_mutex_init();
     /* this mutex is used to synchronize the scheduling of the java process */
     master_cond = xbt_os_cond_init();
+    
+    __process_schedule = jprocess_schedule;
+       __process_unschedule = jprocess_unschedule;
   }
 }
 
@@ -253,13 +283,13 @@ void xbt_context_empty_trash(void) {
 void 
 xbt_context_start(xbt_context_t context)  {
   DEBUG3("xbt_context_start of %p (jproc=%p, jenv=%p)",
-        context, context->jprocess, context->jenv);
+        context, context->jprocess, get_current_thread_env());
 
   /* the main thread locks the mutex used to create all the process    */
   xbt_os_mutex_lock(creation_mutex);
 
   /* the main thread starts the java process                           */
-  jprocess_start(context->jprocess,context->jenv);
+  jprocess_start(context->jprocess,get_current_thread_env());
 
   /* the main thread waits the startup of the java process             */
   xbt_os_cond_wait(creation_cond, creation_mutex);
@@ -353,6 +383,7 @@ void xbt_context_exit(void)  {
  * This function simply kills \a context... scarry isn't it ?
  */
 void xbt_context_kill(xbt_context_t context) {
+
   context->iwannadie=1;
   __xbt_context_yield(context);
 }
@@ -392,8 +423,9 @@ void  xbt_context_set_jenv(xbt_context_t context,void* je)      {
    context->jenv = je;
 }
 void* xbt_context_get_jenv(xbt_context_t context)               { 
-   return context->jenv;
+   return get_current_thread_env();
 }
 
 
+
 /* @} */
index 0797a9e..99f90cb 100644 (file)
 
 SG_BEGIN_DECL()
 
+
+/* pointers to schedule and unschedule functions */
+typedef void (*pfn_schedule_t)(xbt_context_t);
+typedef pfn_schedule_t pfn_unschedule_t;
+
 /**
  * This function gets the context of a java process instance.
  * 
index 2ef04a3..6b9b7d1 100644 (file)
@@ -64,11 +64,15 @@ jmethodID jxbt_get_jmethod(JNIEnv* env, jclass cls,
 
 jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname, 
                          const char *name,const char *signature) { 
-  jclass cls = jxbt_get_class(env,classname);
-  jmethodID id;
+  
+       jclass cls;
+
+       jmethodID id;
+       cls = jxbt_get_class(env,classname);
 
   if (!cls)
     return 0;
+
   id = (*env)->GetMethodID(env, cls, name,signature);
        
   if(!id) {
@@ -79,7 +83,6 @@ jmethodID jxbt_get_smethod(JNIEnv* env, const char *classname,
     free(m);
     return 0;
   }
-
   return id;
 }
 
index e5fd30d..b81ab29 100644 (file)
@@ -11,9 +11,9 @@
 
 package simgrid.msg;
 
+import java.util.Vector;
 import org.xml.sax.*;
 import org.xml.sax.helpers.*;
-import java.lang.reflect.*;
 
 /**
  * The handler used to parse the deployment file which contains 
@@ -30,68 +30,150 @@ import java.lang.reflect.*;
  */
 public final class ApplicationHandler extends DefaultHandler
 {
-       /* the current process. */
-    public simgrid.msg.Process process;
+       
+       /* 
+        * This class is used to create the processes descibed in the deployment file.
+        */
+       class ProcessFactory
+       {
+               /**
+                * The vector which contains the arguments of the main function 
+                * of the process object.
+                */
+               public Vector args;
+               
+               /**
+                * The name of the host of the process.
+                */     
+               private String hostName;
+               
+               /**
+                * The function of the process.
+                */
+               private String function;
+               
+               /**
+                * Default constructor.
+                */
+               public ProcessFactory(){
+                       this.args = new Vector();
+                       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 
+                * previouse process function if needed.
+                *
+                * @host                                The host of the process to create.
+                * @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();
+               }
+               
+               /**
+                * 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 {
+                               
+                               System.out.println("Create process " + function + " on the host " + hostName);
+                       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.addArg((String)args.get(index)); 
+               
+               } 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(Exception e) {
+                        System.out.println("Unexpected exception");
+                        e.printStackTrace();
+               }
+
+       }
+       }
+       
+       /* 
+        * the ProcessFactory object used to create the processes.
+        */
+       private ProcessFactory processFactory;
     
     public ApplicationHandler() {
         super();
     }
+    /**
+     * instanciates the process factory 
+     */
+    public void startDocument(){
+       this.processFactory = new ProcessFactory();     
+    } 
     
-    public void startDocument() {} // NOTHING TODO
-    public void endDocument() {}   // NOTHING TODO
-    
-    public void characters(char[] chars, int beg, int lgr) {}   // NOTHING TODO
+    public void characters(char[] caracteres, int debut, int longueur) {} // NOTHING TODO
     
    /**
     * element handlers
     */
-    public void startElement(String nameSpace, String localName,String qName,Attributes attr)  {
+    public void startElement(String nameSpace, String localName,String qName,Attributes attr) {
         if(localName.equals("process"))
-            onStartProcess(attr);   
-       else if(localName.equals("argument"))
-            onArgument(attr);
-    }
-    public void endElement(String nameSpace, String localName,String qName)  {
-        if(localName.equals("process"))
-            onEndProcess();   
+            onProcessIdentity(attr);   
+               else if(localName.equals("argument"))
+            onProcessArg(attr);
     }
     
-    /**
-     * process element handler.
+     /**
+     * process attributs handler.
      */
-    public void onStartProcess(Attributes attr) {
-        String hostName = attr.getValue(0);
-        String className = attr.getValue(1);
-               
-        try {
-               
-           Class cls = Class.forName(className);
-               
-           process = (simgrid.msg.Process)cls.newInstance();
-           process.name = className;
-           process.id = simgrid.msg.Process.nextProcessId++;
-           
-           Host host = Host.getByName(hostName);
-               
-           Msg.processCreate(process,host);
-               
-       } catch(Exception e) {
-           e.printStackTrace();
-        } 
+    public void onProcessIdentity(Attributes attr) {
+               processFactory.setProcessIdentity(attr.getValue(0),attr.getValue(1));
+    }
+       
+       /**
+     * process arguments handler.
+     */
+    public void onProcessArg(Attributes attr) {
+        processFactory.registerProcessArg(attr.getValue(0));      
     }
-    
-    public void onEndProcess() {} // NOTHING TODO   
     
     /**
-     * function arguments handler.
+     * creates the process
      */
-    public void onArgument(Attributes attr) {
-       //Msg.info("Add "+attr.getValue(0)+" as argument to "+process.msgName());
-        process.addArg(attr.getValue(0));      
+    public void endElement(String nameSpace, String localName,String qName)  {
+        if(localName.equals("process"))
+{
+               processFactory.createProcess();
+        }      
     }
-    
-   /**
-    * end of element handler.
-    */
-    
+     
+    public void endDocument() {} // NOTHING TODO
 }
diff --git a/src/java/simgrid/msg/DTDResolver.java b/src/java/simgrid/msg/DTDResolver.java
new file mode 100644 (file)
index 0000000..1726880
--- /dev/null
@@ -0,0 +1,63 @@
+/*\r
+ * simgrid.msg.DTDResolver.java    1.00 07/05/01\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ */\r
+\r
\r
+\r
+package simgrid.msg;\r
+\r
+import java.io.InputStream;\r
+import org.xml.sax.EntityResolver;\r
+import org.xml.sax.InputSource;\r
+import org.xml.sax.SAXException;\r
+\r
+public class DTDResolver implements EntityResolver {\r
+    \r
+       public InputSource resolveEntity(String publicID, String systemID)\r
+       throws SAXException {\r
+       \r
+       \r
+       if(!systemID.endsWith("surfxml.dtd")){\r
+       System.out.println("\n MSG - Warning - the platform used seams invalid\n");\r
+       return null;\r
+       }\r
+               \r
+       /* try to get the DTD from the classpath */\r
+       InputStream in = getClass().getResourceAsStream("/surfxml.dtd"); \r
+       \r
+       if(null == in)  \r
+               /* try to get the DTD from the surf dir in the jar */\r
+               in = getClass().getResourceAsStream("/surf/surfxml.dtd"); \r
+       if(null == in)  \r
+               /* try to get the DTD from the directory Simgrid */\r
+               in = getClass().getResourceAsStream("/Simgrid/surfxml.dtd"); \r
+       \r
+       if(null == in)\r
+               /* try to get the DTD from the directory Simgrid/msg */\r
+               in = getClass().getResourceAsStream("/Simgrid/msg/surfxml.dtd"); \r
+       \r
+       if(null == in) {\r
+                       System.err.println("\nMSG - XML DTD not found (" + systemID.toString() + ").\n\nPlease put this file in one of the following destinations :\n\n"+\r
+                       "   - classpath;\n"+\r
+                       "   - the directory Simgrid;\n"+\r
+                       "   - the directory Simgrid/msg;\n"+\r
+                       "   - the directory of you simulation.\n\n"+\r
+                       "Once the DTD puted in one of the previouse destinations, retry you simulation.\n");\r
+                       \r
+                       /* \r
+                        * If not founded, returning null makes process continue normally (try to get \r
+                        * the DTD from the current directory \r
+                        */\r
+                       return null;\r
+       }\r
+       \r
+       return new InputSource(in);  \r
+       }\r
+}\r
index 241eb28..d9a13d4 100644 (file)
@@ -11,9 +11,7 @@
  
 package simgrid.msg;
 
-import java.lang.*;
 import org.xml.sax.*;
-import org.xml.sax.helpers.*;
 
 /** 
  * MSG was the first distributed programming environment 
@@ -41,7 +39,7 @@ public final class Msg {
      *
      * @return     The last error code of the simulation.
      */
-    public final static native int getErrCode();
+    final static native int getErrCode();
     
     /**
      * Errors returned by the method Msg.getErrCode().
@@ -110,7 +108,7 @@ public final class Msg {
      *
      * @see  Process constructors.
      */
-    public final static native 
+    final static native 
        void processCreate(Process process, Host host) throws JniException;
      
     /**
@@ -122,7 +120,7 @@ public final class Msg {
      *
      * @return                The function returns the PID of the next created process.
      */
-    public final static native int processKillAll(int resetPID);
+    final static native int processKillAll(int resetPID);
        
     /**
      * The natively implemented method to suspend an MSG process.
@@ -134,7 +132,7 @@ public final class Msg {
      *
      * @see                 Process.pause()
      */
-    public final static native void processSuspend(Process process) 
+    final static native void processSuspend(Process process) 
        throws JniException, NativeException;
      
     /**
@@ -144,7 +142,7 @@ public final class Msg {
      *
      * @see                 Process.kill()
      */
-    public final static native void processKill(Process process)
+    final static native void processKill(Process process)
        throws JniException;
      
     /**
@@ -157,7 +155,7 @@ public final class Msg {
      *
      * @see                 Process.restart()
      */
-    public final static native void processResume(Process process)
+    final static native void processResume(Process process)
        throws JniException, NativeException;
      
     /**
@@ -172,7 +170,7 @@ public final class Msg {
      *
      * @see                 Process.isSuspended()
      */
-    public final static native boolean processIsSuspended(Process process) throws JniException;
+    final static native boolean processIsSuspended(Process process) throws JniException;
      
     /**
      * The natively implemented method to get the host of a MSG process.
@@ -186,7 +184,7 @@ public final class Msg {
      *
      * @see                 Process.getHost()
      */
-    public final static native Host processGetHost(Process process)
+    final static native Host processGetHost(Process process)
        throws JniException, NativeException;
      
     /**
@@ -200,7 +198,7 @@ public final class Msg {
      *
      * @see                 Process.getFromPID()
      */
-    public final static native Process processFromPID(int PID) throws NativeException;
+    final static native Process processFromPID(int PID) throws NativeException;
      
     /**
      * The natively implemented method to get the PID of a MSG process.
@@ -213,7 +211,7 @@ public final class Msg {
      *
      * @see                 Process.getPID()
      */
-    public final static native int processGetPID(Process process) throws NativeException;
+    final static native int processGetPID(Process process) throws NativeException;
      
     /**
      * The natively implemented method to get the PPID of a MSG process.
@@ -226,7 +224,7 @@ public final class Msg {
      *
      * @see                 Process.getPPID()
      */
-    public final static native int processGetPPID(Process process) throws NativeException;
+    final static native int processGetPPID(Process process) throws NativeException;
      
     /**
      * The natively implemented method to get the current running process.
@@ -237,7 +235,7 @@ public final class Msg {
 
      * @see                Process.currentProcess()
      */
-    public final static native Process processSelf() throws NativeException;
+    final static native Process processSelf() throws NativeException;
      
     /**
      * The natively implemented method to get the current running process PID.
@@ -246,7 +244,7 @@ public final class Msg {
      *
      * @see                Process.currentProcessPID()
      */
-    public final static native int processSelfPID();
+    final static native int processSelfPID();
      
     /**
      * The natively implemented method to get the current running process PPID.
@@ -255,7 +253,7 @@ public final class Msg {
      *
      * @see                Process.currentProcessPPID()
      */
-    public final static native int processSelfPPID();
+    final static native int processSelfPPID();
      
     /**
      * The natively implemented method to migrate a process from his currnet host to a new host.
@@ -269,7 +267,7 @@ public final class Msg {
      * @see                Process.migrate()
      * @see                Host.getByName()
      */
-    public final static native void processChangeHost(Process process,Host host) 
+    final static native void processChangeHost(Process process,Host host) 
        throws JniException, NativeException;
      
     /**
@@ -277,7 +275,7 @@ public final class Msg {
      * 
      * @exception            JniException if something goes wrong with JNI
      */
-    public final static native void waitSignal(Process process) throws JniException;
+    final static native void waitSignal(Process process) throws JniException;
      
     /**
      * The natively implemented native to request the current process to sleep 
@@ -289,7 +287,7 @@ public final class Msg {
      *
      * @see                 Process.waitFor()
      */
-    public final static native void processWaitFor(double seconds) throws NativeException;
+    final static native void processWaitFor(double seconds) throws NativeException;
      
     /**
      * The natively implemented native method to exit a process.
@@ -298,7 +296,7 @@ public final class Msg {
      *
      * @see                Process.exit()
      */
-    public final static native void processExit(Process process) throws JniException;
+    final static native void processExit(Process process) throws JniException;
       
      
     /******************************************************************
@@ -318,7 +316,7 @@ public final class Msg {
      *
      * @see                Host.getByName()
      */
-    public final static native Host hostGetByName(String name) 
+    final static native Host hostGetByName(String name) 
        throws JniException, HostNotFoundException, NativeException;
      
     /**
@@ -332,7 +330,7 @@ public final class Msg {
      *
      * @see                Host.getName()
      */
-    public final static native String hostGetName(Host host) throws JniException;
+    final static native String hostGetName(Host host) throws JniException;
      
     /**
      * The natively implemented method to get the number of hosts of the simulation.
@@ -341,7 +339,7 @@ public final class Msg {
      *
      * @see                Host.getNumber()
      */
-    public final static native int hostGetNumber();
+    final static native int hostGetNumber();
      
     /**
      * The natively implemented method to get the host of the current runing process.
@@ -352,7 +350,7 @@ public final class Msg {
      *
      * @see                Host.currentHost()
      */
-    public final static native Host hostSelf() throws JniException;
+    final static native Host hostSelf() throws JniException;
      
     /**
      * The natively implemented method to get the speed of a MSG host.
@@ -366,7 +364,7 @@ public final class Msg {
      * @see                Host.getSpeed()
      */
       
-    public final static native double hostGetSpeed(Host host) throws JniException;
+    final static native double hostGetSpeed(Host host) throws JniException;
      
     /**
      * The natively implemented native method to test if an host is avail.
@@ -380,7 +378,7 @@ public final class Msg {
      *
      * @see                Host.isAvail()
      */
-    public final static native boolean hostIsAvail(Host host) throws JniException;
+    final static native boolean hostIsAvail(Host host) throws JniException;
      
     /**
      * The natively implemented native method to get all the hosts of the simulation.
@@ -390,7 +388,7 @@ public final class Msg {
      * @return                A array which contains all the hosts of simulation.
      */
      
-    public final static native Host[] allHosts() throws JniException;
+    final static native Host[] allHosts() throws JniException;
      
     /**
      * The natively implemented native method to get the number of running tasks on a host.
@@ -402,7 +400,7 @@ public final class Msg {
      * @exception            JniException if something goes wrong with JNI
      *
      */
-    public final static native int hostGetLoad(Host host) throws JniException;
+    final static native int hostGetLoad(Host host) throws JniException;
      
     /******************************************************************
      * The natively implemented methods connected to the MSG task     *
@@ -427,7 +425,7 @@ public final class Msg {
      *
      * @see                    Task.create()
      */
-    public final static native void taskCreate(Task task,String name,double computeDuration, double messageSize)
+    final static native void taskCreate(Task task,String name,double computeDuration, double messageSize)
        throws JniException, NullPointerException, IllegalArgumentException;
       
     /**
@@ -442,7 +440,7 @@ public final class Msg {
      *
      * @see                    Task.getSender()
      */
-    public final static native Process taskGetSender(Task task) throws JniException;
+    final static native Process taskGetSender(Task task) throws JniException;
       
     /**
      * The natively implementd method to get the source of a task.
@@ -456,7 +454,7 @@ public final class Msg {
      *
      * @see                    Task.getSource()
      */
-    public final static native Host taskGetSource(Task task) throws JniException, NativeException;
+    final static native Host taskGetSource(Task task) throws JniException, NativeException;
       
     /**
      * The natively implemented method to get the name of the task.
@@ -470,7 +468,7 @@ public final class Msg {
      *
      * @see                    Task.getName()
      */
-    public final static native String taskGetName(Task task) throws JniException;
+    final static native String taskGetName(Task task) throws JniException;
       
     /**
      * The natively implemented method to cancel a task.
@@ -483,7 +481,7 @@ public final class Msg {
      *
      * @see                    Task.cancel().
      */
-    public final static native void taskCancel(Task task) throws JniException, NativeException;
+    final static native void taskCancel(Task task) throws JniException, NativeException;
       
     /**
      * The natively implemented method to get the computing amount of the task.
@@ -498,7 +496,7 @@ public final class Msg {
      *
      * @see                    Task.getComputeDuration()
      */
-    public final static native double taskGetComputeDuration(Task task) throws JniException;
+    final static native double taskGetComputeDuration(Task task) throws JniException;
       
     /**
      * The natively implemented method to get the remaining computation
@@ -513,7 +511,7 @@ public final class Msg {
      *
      * @see                    Task.getRemainingDuration()
      */
-    public final static native double taskGetRemainingDuration(Task task) throws JniException;
+    final static native double taskGetRemainingDuration(Task task) throws JniException;
       
     /**
      * The natively implemented method to set the priority of a task.
@@ -528,7 +526,7 @@ public final class Msg {
      *
      * @see                    Task.setPriority()
      */
-    public final static native void taskSetPriority(Task task,double priority) throws JniException;
+    final static native void taskSetPriority(Task task,double priority) throws JniException;
       
     /**
      * The natively implemented method to destroy a MSG task.
@@ -541,7 +539,7 @@ public final class Msg {
      *
      * @see                    Task.destroy()
      */
-    public final static native void taskDestroy(Task task) throws JniException, NativeException;
+    final static native void taskDestroy(Task task) throws JniException, NativeException;
       
     /**
      * The natively implemented method to execute a MSG task.
@@ -554,7 +552,7 @@ public final class Msg {
      *
      * @see                    Task.execute()
      */
-    public final static native void taskExecute(Task task) throws JniException, NativeException;
+    final static native void taskExecute(Task task) throws JniException, NativeException;
       
       
      
@@ -573,7 +571,7 @@ public final class Msg {
      *
      * @see                        ParallelTask.create()
      */
-    public final static native void parallelTaskCreate(ParallelTask parallelTask, String name, 
+    final static native void parallelTaskCreate(ParallelTask parallelTask, String name, 
                                                       Host[] hosts, double[] computeDurations, double[] messageSizes)
        throws JniException, NullPointerException, IllegalArgumentException;
       
@@ -586,7 +584,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.getSender()
      */
-    public final static native Process parallelTaskGetSender(ParallelTask parallelTask) throws JniException;
+    final static native Process parallelTaskGetSender(ParallelTask parallelTask) throws JniException;
       
     /**
      * The natively implementd method to get the source of a parallel task.
@@ -597,7 +595,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.getSource()
      */
-    public final static native Host parallelTaskGetSource(ParallelTask parallelTask) throws JniException;
+    final static native Host parallelTaskGetSource(ParallelTask parallelTask) throws JniException;
       
     /**
      * The natively implemented method to get the name of the parallel task.
@@ -608,7 +606,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.getName()
      */
-    public final static native String parallelTaskGetName(ParallelTask parallelTask) throws JniException;
+    final static native String parallelTaskGetName(ParallelTask parallelTask) throws JniException;
       
     /**
      * The natively implemented method to cancel a parallel task.
@@ -617,7 +615,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.cancel().
      */
-    public final static native void parallelTaskCancel(ParallelTask parallelTask) throws JniException,NativeException;
+    final static native void parallelTaskCancel(ParallelTask parallelTask) throws JniException,NativeException;
       
     /**
      * The natively implemented method to get the computing amount of the task.
@@ -628,7 +626,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.getComputeDuration()
      */
-    public final static native double parallelTaskGetComputeDuration(ParallelTask parallelTask) throws JniException;
+    final static native double parallelTaskGetComputeDuration(ParallelTask parallelTask) throws JniException;
       
     /**
      * The natively implemented method to get the remaining computation
@@ -639,7 +637,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.getRemainingDuration()
      */
-    public final static native double parallelTaskGetRemainingDuration(ParallelTask parallelTask) throws JniException;
+    final static native double parallelTaskGetRemainingDuration(ParallelTask parallelTask) throws JniException;
       
     /**
      * The natively implemented method to set the priority of a parallel task.
@@ -650,7 +648,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.setPriority()
      */
-    public final static native void parallelTaskSetPriority(ParallelTask parallelTask,double priority) throws JniException;
+    final static native void parallelTaskSetPriority(ParallelTask parallelTask,double priority) throws JniException;
       
     /**
      * The natively implemented method to destroy a MSG parallel task.
@@ -659,7 +657,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.destroy()
      */
-    public final static native void parallelTaskDestroy(ParallelTask parallelTask) throws JniException,NativeException;
+    final static native void parallelTaskDestroy(ParallelTask parallelTask) throws JniException,NativeException;
       
     /**
      * The natively implemented method to execute a MSG parallel task.
@@ -668,7 +666,7 @@ public final class Msg {
      *
      * @see                    ParallelTask.execute()
      */
-    public final static native void parallelTaskExecute(ParallelTask parallelTask) throws JniException, NativeException;
+    final static native void parallelTaskExecute(ParallelTask parallelTask) throws JniException, NativeException;
       
     /******************************************************************
      * The natively implemented methods connected to the MSG channel  *
@@ -685,7 +683,7 @@ public final class Msg {
      *
      * @see                    Channel.get()
      */
-    public final static native Task channelGet(Channel channel) throws JniException,NativeException;
+    final static native Task channelGet(Channel channel) throws JniException,NativeException;
       
     /**
      * The natively implemented method to listen on the channel and wait for receiving a task with a timeout.
@@ -700,7 +698,7 @@ public final class Msg {
      * @see                    Channel.getWithTimeout()
      *
      */ 
-    public final static native Task channelGetWithTimeout(Channel channel,double timeout) throws JniException,NativeException;
+    final static native Task channelGetWithTimeout(Channel channel,double timeout) throws JniException,NativeException;
       
       
     /**
@@ -717,7 +715,7 @@ public final class Msg {
      *
      * @see                    Channel.getFromHost()
      */    
-    public final static native Task channelGetFromHost(Channel channel,Host host) throws JniException,NativeException;
+    final static native Task channelGetFromHost(Channel channel,Host host) throws JniException,NativeException;
       
     /**
      * The natively implemented method to test whether there is a pending communication on the channel.
@@ -729,7 +727,7 @@ public final class Msg {
      *
      * @see                    Channel.hasPendingCommunication()
      */                
-    public final static native boolean channelHasPendingCommunication(Channel channel) throws JniException;
+    final static native boolean channelHasPendingCommunication(Channel channel) throws JniException;
       
     /**
      * The natively implemented method to test whether there is a pending communication on a 
@@ -742,7 +740,7 @@ public final class Msg {
      *
      * @see                    Channel.getCummunicatingProcess()
      */
-    public final static native int channelGetCommunicatingProcess(Channel channel) throws JniException;
+    final static native int channelGetCommunicatingProcess(Channel channel) throws JniException;
       
     /**
      * The natively implemented method to get the number of tasks waiting to be received on a
@@ -759,7 +757,7 @@ public final class Msg {
      *
      * @see                    Channel.getHostWaiting()
      */
-    public final static native int channelGetHostWaitingTasks(Channel channel,Host host) throws JniException;
+    final static native int channelGetHostWaitingTasks(Channel channel,Host host) throws JniException;
       
     /**
      * The natively implemented method to put a task on the channel of an host.
@@ -774,7 +772,7 @@ public final class Msg {
      *
      * @see                    Channel.put()
      */                
-    public final static native void channelPut(Channel channel,Task task,Host host) throws JniException,NativeException;
+    final static native void channelPut(Channel channel,Task task,Host host) throws JniException,NativeException;
       
     /**
      * The natively implemented method to put a task on a channel of an  host (with a timeout 
@@ -791,7 +789,7 @@ public final class Msg {
      *
      * @see                    Channel.putWithTimeout()
      */
-    public final static native void channelPutWithTimeout(Channel channel,Task task,Host host,double timeout) throws JniException,NativeException;
+    final static native void channelPutWithTimeout(Channel channel,Task task,Host host,double timeout) throws JniException,NativeException;
       
     /**
      * The natively implemented method to put a task on channel with a bounded transmition
@@ -808,7 +806,7 @@ public final class Msg {
      *
      * @see                    Channel.putBounded()
      */
-    public final static native void channelPutBounded(Channel channel,Task task,Host host,double max_rate) throws JniException,NativeException;
+    final static native void channelPutBounded(Channel channel,Task task,Host host,double max_rate) throws JniException,NativeException;
       
     /**
      * The natively implemented method to wait for at most timeout seconds for a task reception
@@ -822,7 +820,7 @@ public final class Msg {
      *
      * @see                    Channel.wait()
      */
-    public final static native int channelWait(Channel channel, double timeout) throws JniException,NativeException;
+    final static native int channelWait(Channel channel, double timeout) throws JniException,NativeException;
       
     /**
      * The natively implemented method to set the number of channel used by all the process
@@ -832,7 +830,7 @@ public final class Msg {
      *
      * @see                    Channel.setNumber()
      */
-    public final static native void channelSetNumber(int channelNumber);
+    final static native void channelSetNumber(int channelNumber);
       
     /**
      * The natively implemented method to get the number of channel of the process of the simulation.
@@ -841,7 +839,7 @@ public final class Msg {
      *
      * @see                    Channel.getNumber()
      */
-    public final static native int channelGetNumber();
+    final static native int channelGetNumber();
              
     /*********************************************************************************
      * Additional native methods                                                      *
@@ -902,6 +900,7 @@ public final class Msg {
        try {
            Class c = Class.forName("com.sun.org.apache.xerces.internal.parsers.SAXParser");
            XMLReader reader = (XMLReader)c.newInstance();
+           reader.setEntityResolver(new DTDResolver());
            ApplicationHandler handler = new ApplicationHandler();
            reader.setContentHandler(handler);
            reader.setFeature("http://xml.org/sax/features/validation", false);
index a3921e6..ac30cf6 100644 (file)
@@ -56,7 +56,7 @@ import java.util.*;
  * @since JDK1.5011
  */
  
-public class Process extends Thread
+public abstract class Process extends Thread
 {
     /**
      * This attribute represents a bind between a java process object and
@@ -90,6 +90,9 @@ public class Process extends Thread
      * The arguments of the method function of the process.    
      */
     public Vector args;
+    
+    /* Used to schedule the process */
+    protected Sem sem;
        
     /**
      * Default constructor. (used in ApplicationHandler to initialize it)
@@ -100,6 +103,7 @@ public class Process extends Thread
        this.name = null;
        this.bind = 0;
        this.args = new Vector();
+       sem = new Sem(0); /* suspend the thread first */
     }
 
        
@@ -170,10 +174,17 @@ public class Process extends Thread
 
        if (name==null)
            throw new NullPointerException("Process name cannot be NULL");
-
-       this.args.addAll(Arrays.asList(args));
+       
+       
+       this.args = new Vector();
+       
+       if(null != args)
+               this.args.addAll(Arrays.asList(args));
+               
        this.name = name;
        this.id = nextProcessId++;
+       
+       sem = new Sem(0); /* suspend the thread first */
                
        Msg.processCreate(this,host);
     }
@@ -359,14 +370,17 @@ public class Process extends Thread
     public synchronized void run() {
                
        try {
-           String[] args; /* do not fill it before the signal or this.args will be empty */
+           String[] args = null; /* do not fill it before the signal or this.args will be empty */
            
            waitSignal(); /* wait for other people to fill the process in */
+               
+               if(this.args.size() > 0)
+               {
+               
+               args = new String[this.args.size()];
+                       this.args.toArray(args);
+               }
 
-           args = new String[this.args.size()];
-           this.args.toArray(args);
-
-           Msg.info("["+this.name+"/"+this.getHost().getName()+"] Start");
            this.main(args);
            Msg.processExit(this);
        } catch (MsgException e) {
@@ -382,17 +396,27 @@ public class Process extends Thread
      * @exception                      JniException on JNI madness
      */
     private void waitSignal() throws JniException{
-        Msg.waitSignal(this);        
+        Msg.waitSignal(this);
+        unschedule();        
     }
   
     /**
-     * The main function of the process (to override).
-     */
-
-    public void main(String[] args) throws MsgException {
-       
-       // TODO
-       // ALL DERIVED CLASS OF THIS CLASS MUST OVERRIDE THIS METHOD
+        * The main function of the process (to implement).
+        */
+    public abstract void main(String[] args) 
+    throws JniException, NativeException;
+    
+   
+    public void unschedule() {
+        try {        
+                       sem.acquire();
+               } catch(InterruptedException e)
+               {
+                       // todo
+               }
     }
     
+     public void schedule() { 
+        sem.release(); 
+    }
 }
diff --git a/src/java/simgrid/msg/Sem.java b/src/java/simgrid/msg/Sem.java
new file mode 100644 (file)
index 0000000..ea386d1
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * $Id$\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ */\r
+package simgrid.msg;\r
+\r
+public class Sem { \r
+       private int permits_;\r
+       \r
+       public Sem(int i) {\r
+               permits_ = i;\r
+       }\r
+       \r
+       public void acquire() throws InterruptedException {\r
+               \r
+               if (Thread.interrupted()) \r
+                       throw new InterruptedException();\r
+               \r
+               synchronized(this) {\r
+               \r
+                       try {\r
+                                       while (permits_ <= 0) \r
+                                               wait();\r
+                                       \r
+                                       --permits_;\r
+                       }\r
+                       catch (InterruptedException ex) {\r
+                               notify();\r
+                               throw ex;\r
+                       }\r
+               }\r
+       }\r
+\r
+       public synchronized void release() {\r
+               ++permits_;\r
+               notify();\r
+       }\r
+}\r