From b2df78af58a09c1285e753b05cc344a60622fe54 Mon Sep 17 00:00:00 2001 From: Navarrop Date: Tue, 18 Oct 2011 12:51:09 +0200 Subject: [PATCH 1/1] Add a new example to kill a process. Ping boom ;) --- CMakeLists.txt | 19 +++++-- examples/master_slave_kill/FinalizeTask.java | 16 ++++++ examples/master_slave_kill/Master.java | 52 ++++++++++++++++++++ examples/master_slave_kill/MsKill.java | 38 ++++++++++++++ examples/master_slave_kill/Slave.java | 32 ++++++++++++ examples/master_slave_kill/platform.xml | 29 +++++++++++ 6 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 examples/master_slave_kill/FinalizeTask.java create mode 100644 examples/master_slave_kill/Master.java create mode 100644 examples/master_slave_kill/MsKill.java create mode 100644 examples/master_slave_kill/Slave.java create mode 100644 examples/master_slave_kill/platform.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index c766956524..be2d4bf845 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,10 @@ set(JAVA_EXAMPLES examples/master_slave_bypass/MsBypass.java examples/master_slave_bypass/Slave.java examples/master_slave_bypass/FinalizeTask.java + examples/master_slave_kill/Master.java + examples/master_slave_kill/MsKill.java + examples/master_slave_kill/Slave.java + examples/master_slave_kill/FinalizeTask.java ) set(CMAKE_SRC @@ -149,6 +153,7 @@ set(XML_FILES examples/basic/basicDeployment.xml examples/basic/deploy.xml examples/master_slave_bypass/platform.xml + examples/master_slave_kill/platform.xml ) set(source_to_pack @@ -216,7 +221,9 @@ add_custom_command( COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java ) + add_custom_target(simgrid_java_examples ALL DEPENDS ${JAVA_EXAMPLES_CLASS} ) @@ -252,17 +259,19 @@ java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar ADD_TEST(bypass java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_bypass/MsBypass ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/platform.xml ) - +ADD_TEST(kill +java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_kill/MsKill ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/platform.xml +) ########################################## # Set the DYLD_LIBRARY_PATH for mac # ########################################## if(APPLE) if($ENV{DYLD_LIBRARY_PATH} STREQUAL "") - set_tests_properties(basic pingPong CommTime mutualExclusion + set_tests_properties(basic pingPong CommTime mutualExclusion bypass kill PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:$ENV{SIMGRID_ROOT}/lib") else($ENV{DYLD_LIBRARY_PATH} STREQUAL "") - set_tests_properties(basic pingPong CommTime mutualExclusion + set_tests_properties(basic pingPong CommTime mutualExclusion bypass kill PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:$ENV{SIMGRID_ROOT}/lib") endif($ENV{DYLD_LIBRARY_PATH} STREQUAL "") endif(APPLE) @@ -271,10 +280,10 @@ endif(APPLE) # Set the LD_LIBRARY_PATH for our tests # ########################################## if($ENV{LD_LIBRARY_PATH} STREQUAL "") - set_tests_properties(basic pingPong CommTime mutualExclusion + set_tests_properties(basic pingPong CommTime mutualExclusion bypass kill PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:$ENV{SIMGRID_ROOT}/lib") else($ENV{LD_LIBRARY_PATH} STREQUAL "") - set_tests_properties(basic pingPong CommTime mutualExclusion + set_tests_properties(basic pingPong CommTime mutualExclusion bypass kill PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:$ENV{SIMGRID_ROOT}/lib") endif($ENV{LD_LIBRARY_PATH} STREQUAL "") diff --git a/examples/master_slave_kill/FinalizeTask.java b/examples/master_slave_kill/FinalizeTask.java new file mode 100644 index 0000000000..2b08b4edd1 --- /dev/null +++ b/examples/master_slave_kill/FinalizeTask.java @@ -0,0 +1,16 @@ +/* + * Copyright 2006,2007,2010. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill; +import org.simgrid.msg.Task; + +public class FinalizeTask extends Task { + public FinalizeTask() { + super("finalize",0,0); + } +} + \ No newline at end of file diff --git a/examples/master_slave_kill/Master.java b/examples/master_slave_kill/Master.java new file mode 100644 index 0000000000..f9d16a3ce6 --- /dev/null +++ b/examples/master_slave_kill/Master.java @@ -0,0 +1,52 @@ +/* + * Master of a basic master/slave example in Java + * + * Copyright 2006,2007,2010 The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill; +import org.simgrid.msg.HostNotFoundException; +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.Process; +import org.simgrid.msg.Task; + +import master_slave_kill.FinalizeTask; + +public class Master extends Process { + public Master(String hostname, String name) throws HostNotFoundException { + super(hostname, name); + } + public void main(String[] args) throws MsgException { + Msg.info("Master Hello!"); + Process process2 = null; + //Create a slave on host "alice" + try { + Msg.info("Create process on host 'alice'"); + process2 = new Slave("alice","slave"); + } catch (MsgException e){ + System.out.println("Process2!"); + } + + //Wait for slave "alice" + while(true) + { + Task task = Task.receive("mail1"); + if (task instanceof FinalizeTask) { + Msg.info("Received mail1!"); + break; + } + } + +// FinalizeTask task = new FinalizeTask(); +// Msg.info("Send Mail2!"); +// task.send("mail2"); + + Process.waitFor(10); + Process.kill(process2); + + } +} diff --git a/examples/master_slave_kill/MsKill.java b/examples/master_slave_kill/MsKill.java new file mode 100644 index 0000000000..e4b5f72648 --- /dev/null +++ b/examples/master_slave_kill/MsKill.java @@ -0,0 +1,38 @@ +/* + * Copyright 2006,2007,2010. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ + +package master_slave_kill; + +import org.simgrid.msg.Msg; +import org.simgrid.msg.MsgException; +import org.simgrid.msg.NativeException; + +public class MsKill { + + /* This only contains the launcher. If you do nothing more than than you can run + * java simgrid.msg.Msg + * which also contains such a launcher + */ + + public static void main(String[] args) throws NativeException { + + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + Msg.createEnvironment(args[0]); + + /* bypass deploymemt */ + try { + Master process1 = new Master("bob","master"); + } + catch (MsgException e){ + System.out.println("Create processes failed!"); + } + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/master_slave_kill/Slave.java b/examples/master_slave_kill/Slave.java new file mode 100644 index 0000000000..86fff0bcec --- /dev/null +++ b/examples/master_slave_kill/Slave.java @@ -0,0 +1,32 @@ +/* + * Copyright 2006,2007,2010. The SimGrid Team. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. + */ +package master_slave_kill; +import org.simgrid.msg.HostFailureException; +import org.simgrid.msg.HostNotFoundException; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Task; +import org.simgrid.msg.TimeoutException; +import org.simgrid.msg.TransferFailureException; +import org.simgrid.msg.Process; + +import master_slave_kill.FinalizeTask; + +public class Slave extends Process { + public Slave(String hostname, String name) throws HostNotFoundException { + super(hostname, name); + } + public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { + Msg.info("Slave Hello!"); + + FinalizeTask task = new FinalizeTask(); + Msg.info("Send Mail1!"); + task.send("mail1"); + + Task task2 = Task.receive("mail2"); + Msg.info("Receive Mail2!"); + } +} \ No newline at end of file diff --git a/examples/master_slave_kill/platform.xml b/examples/master_slave_kill/platform.xml new file mode 100644 index 0000000000..310c6e65d2 --- /dev/null +++ b/examples/master_slave_kill/platform.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.20.1