ADD_TEST(java-pingPong ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/pingPong/pingpong.tesh)
ADD_TEST(java-priority ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/priority/priority.tesh)
ADD_TEST(java-startKillTime ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/startKillTime/startKillTime.tesh)
+ ADD_TEST(java-surf-plugin ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/surfPlugin/surf_plugin.tesh)
ADD_TEST(java-suspend ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/suspend/suspend.tesh)
if(HAVE_TRACING)
ADD_TEST(java-tracing ${TESH_COMMAND} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/examples/java ${CMAKE_HOME_DIRECTORY}/examples/java/tracing/tracingPingPong.tesh)
find_package(JNI REQUIRED)
message("-- [Java] JNI found: ${JNI_FOUND}")
message("-- [Java] JNI include dirs: ${JNI_INCLUDE_DIRS}")
+ find_package(SWIG REQUIRED)
+ include(UseSWIG)
+ message("-- [Java] Swig found: ${SWIG_FOUND}")
set(HAVE_Java 1)
endif()
if(enable_scala)
)
set(JMSG_JAVA_SRC
+ src/bindings/java/org/simgrid/NativeLib.java
+ #src/bindings/java/org/simgrid/NativeException.java
+
src/bindings/java/org/simgrid/msg/As.java
src/bindings/java/org/simgrid/msg/Comm.java
src/bindings/java/org/simgrid/msg/File.java
src/bindings/java/org/simgrid/msg/Msg.java
src/bindings/java/org/simgrid/msg/MsgException.java
src/bindings/java/org/simgrid/msg/Mutex.java
- src/bindings/java/org/simgrid/msg/NativeException.java
- src/bindings/java/org/simgrid/msg/NativeLib.java
+ src/bindings/java/org/simgrid/msg/NativeException.java
src/bindings/java/org/simgrid/msg/Process.java
src/bindings/java/org/simgrid/msg/ProcessKilledError.java
src/bindings/java/org/simgrid/msg/ProcessNotFoundException.java
src/bindings/java/org/simgrid/msg/TimeoutException.java
src/bindings/java/org/simgrid/msg/TransferFailureException.java
src/bindings/java/org/simgrid/msg/VM.java
+
+ src/bindings/java/org/simgrid/surf/Surf.java
+ src/bindings/java/org/simgrid/surf/SurfJNI.java
+ src/bindings/java/org/simgrid/surf/Plugin.java
+ src/bindings/java/org/simgrid/surf/Model.java
+ src/bindings/java/org/simgrid/surf/Resource.java
+ src/bindings/java/org/simgrid/surf/Action.java
+ src/bindings/java/org/simgrid/surf/Cpu.java
+ src/bindings/java/org/simgrid/surf/CpuAction.java
+ src/bindings/java/org/simgrid/surf/NetworkLink.java
+ src/bindings/java/org/simgrid/surf/NetworkAction.java
+
+ src/bindings/java/org/simgrid/surf/LmmConstraint.java
+ src/bindings/java/org/simgrid/surf/XbtDict.java
)
set(JTRACE_C_SRC
examples/java/cloud/CMakeLists.txt
examples/java/cloud/migration/CMakeLists.txt
examples/java/commTime/CMakeLists.txt
+ examples/java/surfPlugin/CMakeLists.txt
examples/java/io/CMakeLists.txt
examples/java/kademlia/CMakeLists.txt
examples/java/master_slave_bypass/CMakeLists.txt
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/pingPong)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/priority)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/startKillTime)
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/surfPlugin)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/suspend)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/java/tracing)
target_link_libraries(simgrid-java simgrid)
-
-
if(WIN32)
exec_program("java -d32 -version"
OUTPUT_VARIABLE IS_32_BITS_JVM)
libsimgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
set(LIBSIMGRID_JAVA_SO
${CMAKE_SHARED_LIBRARY_PREFIX}simgrid-java${CMAKE_SHARED_LIBRARY_SUFFIX})
+set(LIBSURF_JAVA_SO
+ ${CMAKE_SHARED_LIBRARY_PREFIX}surf-java.so)
## Don't strip libraries if not in release mode
##
set(JAVA_BUNDLE_SO_FILES
${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO}
+ ${CMAKE_BINARY_DIR}/lib/${LIBSURF_JAVA_SO}
)
set(JAVA_BUNDLE_TXT_FILES
${CMAKE_HOME_DIRECTORY}/COPYING
COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
)
add_custom_target(simgrid-java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)
+
+set(CMAKE_SWIG_FLAGS "-package" "org.simgrid.surf")
+set(CMAKE_SWIG_OUTDIR "${CMAKE_HOME_DIRECTORY}/src/bindings/java/org/simgrid/surf")
+
+set(SURF_SWIG_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf.i")
+set_source_files_properties(${SURF_SWIG_FILE} PROPERTIES CPLUSPLUS 1)
+#set_source_files_properties(${SURF_SWIG_FILE} PROPERTIES SWIG_FLAGS "-includeall")
+include_directories(${JNI_INCLUDE_DIRS})
+swig_add_module(surf-java java ${SURF_SWIG_FILE} "${CMAKE_HOME_DIRECTORY}/src/surf/surf_interface.hpp" "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf_swig.hpp" "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf_swig.cpp")
+swig_link_libraries(surf-java simgrid)
+
+add_dependencies(simgrid-java surf-java)
STRIP=$3
shift 3
-JSG_BUNDLE=$("$JAVA" -classpath "$SIMGRID_JAR" org.simgrid.msg.NativeLib)
+JSG_BUNDLE=$("$JAVA" -classpath "$SIMGRID_JAR" org.simgrid.NativeLib)
# sanity check
case "$JSG_BUNDLE" in
--- /dev/null
+cmake_minimum_required(VERSION 2.6)
+
+set(example java_surf_plugin)
+set(sources
+ ${CMAKE_CURRENT_SOURCE_DIR}/TestPlugin.java
+ ${CMAKE_CURRENT_SOURCE_DIR}/TracePlugin.java
+ ${CMAKE_CURRENT_SOURCE_DIR}/Sender.java
+ ${CMAKE_CURRENT_SOURCE_DIR}/Receiver.java
+ )
+
+if(enable_java)
+ add_custom_command(
+ COMMENT "Building ${example}..."
+ OUTPUT ${example}_compiled
+ DEPENDS ${sources} simgrid-java_jar ${SIMGRID_JAR}
+ COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR}
+ -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources}
+ COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled
+ COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
+ )
+ add_custom_target(${example} ALL DEPENDS ${example}_compiled)
+endif()
+
+set(tesh_files
+ ${tesh_files}
+ ${CMAKE_CURRENT_SOURCE_DIR}/surf_plugin.tesh
+ PARENT_SCOPE
+ )
+set(xml_files
+ ${xml_files}
+ ${CMAKE_CURRENT_SOURCE_DIR}/surfPluginDeployment.xml
+ PARENT_SCOPE
+ )
+set(examples_src
+ ${examples_src}
+ ${sources}
+ PARENT_SCOPE
+ )
+set(bin_files
+ ${bin_files}
+ PARENT_SCOPE
+ )
+set(txt_files
+ ${txt_files}
+ ${CMAKE_CURRENT_SOURCE_DIR}/README
+ PARENT_SCOPE
+ )
--- /dev/null
+/* Copyright (c) 2006-2014. 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 surfPlugin;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+
+public class Receiver extends Process {
+ public Receiver(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
+ final double commSizeLat = 1;
+ final double commSizeBw = 100000000;
+
+ public void main(String[] args) throws MsgException {
+
+ Msg.info("helloo!");
+ double communicationTime=0;
+
+ Msg.info("try to get a task");
+
+ Task task = Task.receive(getHost().getName());
+ double timeGot = Msg.getClock();
+
+ Msg.info("Got at time "+ timeGot);
+ task.execute();
+
+ Msg.info("goodbye!");
+ }
+}
--- /dev/null
+/* Copyright (c) 2006-2014. 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 surfPlugin;
+import org.simgrid.msg.Host;
+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;
+
+public class Sender extends Process {
+ public Sender(Host host, String name, String[] args) {
+ super(host,name,args);
+ }
+ private final double commSizeLat = 1;
+ final double commSizeBw = 100000000;
+
+ public void main(String[] args) throws MsgException {
+
+ Msg.info("helloo!");
+
+ int hostCount = args.length;
+
+ Msg.info("host count: " + hostCount);
+ String mailboxes[] = new String[hostCount];
+ double time;
+ double computeDuration = 10000;
+ Task task;
+
+ for(int pos = 0; pos < args.length ; pos++) {
+ try {
+ mailboxes[pos] = Host.getByName(args[pos]).getName();
+ } catch (HostNotFoundException e) {
+ Msg.info("Invalid deployment file: " + e.toString());
+ System.exit(1);
+ }
+ }
+
+ for (int pos = 0; pos < hostCount; pos++) {
+ time = Msg.getClock();
+
+ Msg.info("sender time: " + time);
+
+ task = new Task("no name",computeDuration,commSizeLat);
+
+ task.send(mailboxes[pos]);
+ }
+
+ Msg.info("goodbye!");
+ }
+}
--- /dev/null
+/* Copyright (c) 2006-2014. 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 surfPlugin;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.NativeException;
+import org.simgrid.surf.Surf;
+import org.simgrid.surf.Cpu;
+
+public class TestPlugin {
+
+ /* 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
+ */
+ //static TracePlugin tp = new TracePlugin();
+
+ public static void main(String[] args) throws NativeException {
+ /* initialize the MSG simulation. Must be done before anything else (even logging). */
+ Msg.init(args);
+ if(args.length < 2) {
+ Msg.info("Usage : TestPlugin platform_file deployment_file");
+ Msg.info("example : TestPlugin ping_pong_platform.xml ping_pong_deployment.xml");
+ System.exit(1);
+ }
+ TracePlugin tp = new TracePlugin();
+
+ /* construct the platform and deploy the application */
+ Msg.createEnvironment(args[0]);
+ Msg.deployApplication(args[1]);
+ /* execute the simulation. */
+ Msg.run();
+ }
+}
--- /dev/null
+package surfPlugin;
+
+import org.simgrid.surf.*;
+import org.simgrid.msg.Msg;
+import java.util.HashMap;
+
+public class TracePlugin extends Plugin {
+
+ public TracePlugin() {
+ activateCpuCreatedCallback();
+ //activateCpuDestructedCallback();
+ activateCpuStateChangedCallback();
+ activateCpuActionStateChangedCallback();
+
+ activateNetworkLinkCreatedCallback();
+ //activateCpuDestructedCallback();
+ activateNetworkLinkStateChangedCallback();
+ activateNetworkActionStateChangedCallback();
+ }
+
+ public void cpuCreatedCallback(Cpu cpu) {
+ Msg.info("Trace: Cpu created "+cpu.getName());
+ }
+
+ public void cpuStateChangedCallback(Cpu cpu){
+ Msg.info("Trace: Cpu state changed "+cpu.getName());
+ }
+
+ public void cpuActionStateChangedCallback(CpuAction action){
+ Msg.info("Trace: CpuAction state changed "+action.getModel().getName());
+ }
+
+ public void networkLinkCreatedCallback(NetworkLink link) {
+ Msg.info("Trace: NetworkLink created "+link.getName());
+ }
+
+ public void networkLinkStateChangedCallback(NetworkLink link){
+ Msg.info("Trace: NetworkLink state changed "+link.getName());
+ }
+
+ public void networkActionStateChangedCallback(NetworkAction action){
+ Msg.info("Trace: NetworkAction state changed "+action.getModel().getName());
+ }
+
+}
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+ <process host="Jacquelin" function="surfPlugin.Sender">
+ <argument value="Boivin"/>
+ </process>
+<process host="Boivin" function="surfPlugin.Receiver"/>
+</platform>
--- /dev/null
+<?xml version='1.0'?>
+ <!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+ <platform version="3">
+ <AS id="AS0" routing="Full">
+ <host id="Jacquelin" power="137.333Mf"/>
+ <host id="Boivin" power="98.095Mf"/>
+ <link id="link" bandwidth="1MBps" latency="100ms"/>
+ <route src="Jacquelin" dst="Boivin">
+ <link_ctn id="link"/>
+ </route>
+ </AS>
+ </platform>
--- /dev/null
+#! tesh
+
+$ java -classpath ${classpath:=.} surfPlugin/TestPlugin ${srcdir:=.}/surfPlugin/surfPluginPlatform.xml ${srcdir:=.}/surfPlugin/surfPluginDeployment.xml
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.000000] [jmsg/INFO] Trace: NetworkLink created __loopback__
+> [0.000000] [jmsg/INFO] Trace: NetworkLink state changed __loopback__
+> [0.000000] [jmsg/INFO] Trace: Cpu created Jacquelin
+> [0.000000] [jmsg/INFO] Trace: Cpu state changed Jacquelin
+> [0.000000] [jmsg/INFO] Trace: Cpu created Boivin
+> [0.000000] [jmsg/INFO] Trace: Cpu state changed Boivin
+> [0.000000] [jmsg/INFO] Trace: NetworkLink created link
+> [0.000000] [jmsg/INFO] Trace: NetworkLink state changed link
+> [Jacquelin:surfPlugin.Sender:(1) 0.000000] [jmsg/INFO] helloo!
+> [Jacquelin:surfPlugin.Sender:(1) 0.000000] [jmsg/INFO] host count: 1
+> [Jacquelin:surfPlugin.Sender:(1) 0.000000] [jmsg/INFO] sender time: 0.0
+> [Boivin:surfPlugin.Receiver:(2) 0.000000] [jmsg/INFO] helloo!
+> [Boivin:surfPlugin.Receiver:(2) 0.000000] [jmsg/INFO] try to get a task
+> [1.301001] [jmsg/INFO] Trace: NetworkAction state changed network
+> [Boivin:surfPlugin.Receiver:(2) 1.301001] [jmsg/INFO] Got at time 1.3010010824742269
+> [Jacquelin:surfPlugin.Sender:(1) 1.301001] [jmsg/INFO] goodbye!
+> [1.301103] [jmsg/INFO] Trace: CpuAction state changed cpu
+> [Boivin:surfPlugin.Receiver:(2) 1.301103] [jmsg/INFO] goodbye!
+> [1.301103] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
--- /dev/null
+package org.simgrid;
+
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.File;
+
+public final class NativeLib {
+
+ public static String getPath() {
+ String prefix = "NATIVE";
+ String os = System.getProperty("os.name");
+ String arch = System.getProperty("os.arch");
+
+ if (os.toLowerCase().startsWith("^win"))
+ os = "Windows";
+ else if (os.contains("OS X"))
+ os = "Darwin";
+
+ if (arch.matches("^i[3-6]86$"))
+ arch = "x86";
+ else if (arch.equalsIgnoreCase("amd64"))
+ arch = "x86_64";
+
+ os = os.replace(' ', '_');
+ arch = arch.replace(' ', '_');
+
+ return prefix + "/" + os + "/" + arch + "/";
+ }
+ public static void nativeInit(String name) {
+ try {
+ /* prefer the version on disk, if existing */
+ System.loadLibrary(name);
+ } catch (UnsatisfiedLinkError e) {
+ /* If not found, unpack the one bundled into the jar file and use it */
+ loadLib(name);
+ }
+ }
+
+ private static void loadLib (String name) {
+ String Path = NativeLib.getPath();
+
+ String filename=name;
+ InputStream in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
+
+ if (in == null) {
+ filename = "lib"+name+".so";
+ in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
+ }
+ if (in == null) {
+ filename = name+".dll";
+ in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
+ }
+ if (in == null) {
+ filename = "lib"+name+".dll";
+ in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
+ }
+ if (in == null) {
+ filename = "lib"+name+".dylib";
+ in = NativeLib.class.getClassLoader().getResourceAsStream(Path+filename);
+ }
+ if (in == null) {
+ throw new RuntimeException("Cannot find library "+name+" in path "+Path+". Sorry, but this jar does not seem to be usable on your machine.");
+ }
+ try {
+ // We must write the lib onto the disk before loading it -- stupid operating systems
+ File fileOut = new File(filename);
+ fileOut = File.createTempFile(name+"-", ".tmp");
+ // don't leak the file on disk, but remove it on JVM shutdown
+ Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(fileOut.getAbsolutePath())));
+ OutputStream out = new FileOutputStream(fileOut);
+
+ /* copy the library in position */
+ byte[] buffer = new byte[4096];
+ int bytes_read;
+ while ((bytes_read = in.read(buffer)) != -1) // Read until EOF
+ out.write(buffer, 0, bytes_read);
+
+ /* close all file descriptors, and load that shit */
+ in.close();
+ out.close();
+ System.load(fileOut.getAbsolutePath());
+
+ } catch (Exception e) {
+ System.err.println("Cannot load the bindings to the "+name+" library: ");
+ e.printStackTrace();
+ System.err.println("This jar file does not seem to fit your system, sorry");
+ System.exit(1);
+ }
+ }
+
+ /* A hackish mechanism used to remove the file containing our library when the JVM shuts down */
+ private static class FileCleaner implements Runnable {
+ private String target;
+ public FileCleaner(String name) {
+ target = name;
+ }
+ public void run() {
+ try {
+ new File(target).delete();
+ } catch(Exception e) {
+ System.out.println("Unable to clean temporary file "+target+" during shutdown.");
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ public static void main(String[] args) {
+ System.out.println(getPath());
+ }
+}
* under the terms of the license (GNU LGPL) which comes with this package. */
package org.simgrid.msg;
+import org.simgrid.NativeLib;
import java.io.FileOutputStream;
import java.io.InputStream;
public final class Msg {
/* Statically load the library which contains all native functions used in here */
static private boolean isNativeInited = false;
- public static void nativeInit() {
- if (isNativeInited)
- return;
- try {
- /* prefer the version on disk, if existing */
- System.loadLibrary("simgrid-java");
- } catch (UnsatisfiedLinkError e) {
- /* If not found, unpack the one bundled into the jar file and use it */
- loadLib("simgrid");
- loadLib("simgrid-java");
- }
+ public static void nativeInit() {
+ if (isNativeInited)
+ return;
+ NativeLib.nativeInit("simgrid");
+ NativeLib.nativeInit("simgrid-java");
isNativeInited = true;
+
}
+
static {
- nativeInit();
+ nativeInit();
}
- private static void loadLib (String name) {
- String Path = NativeLib.getPath();
-
- String filename=name;
- InputStream in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
-
- if (in == null) {
- filename = "lib"+name+".so";
- in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = name+".dll";
- in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = "lib"+name+".dll";
- in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- filename = "lib"+name+".dylib";
- in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
- }
- if (in == null) {
- throw new RuntimeException("Cannot find library "+name+" in path "+Path+". Sorry, but this jar does not seem to be usable on your machine.");
- }
-// Caching the file on disk: desactivated because it could fool the users
-// if (new File(filename).isFile()) {
-// // file was already unpacked -- use it directly
-// System.load(new File(".").getAbsolutePath()+File.separator+filename);
-// return;
-// }
- try {
- // We must write the lib onto the disk before loading it -- stupid operating systems
- File fileOut = new File(filename);
-// if (!new File(".").canWrite()) {
-// System.out.println("Cannot write in ."+File.separator+filename+"; unpacking the library into a temporary file instead");
- fileOut = File.createTempFile("simgrid-", ".tmp");
- // don't leak the file on disk, but remove it on JVM shutdown
- Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(fileOut.getAbsolutePath())));
-// }
-// System.out.println("Unpacking SimGrid native library to " + fileOut.getAbsolutePath());
- OutputStream out = new FileOutputStream(fileOut);
-
- /* copy the library in position */
- byte[] buffer = new byte[4096];
- int bytes_read;
- while ((bytes_read = in.read(buffer)) != -1) // Read until EOF
- out.write(buffer, 0, bytes_read);
-
- /* close all file descriptors, and load that shit */
- in.close();
- out.close();
- System.load(fileOut.getAbsolutePath());
- } catch (Exception e) {
- System.err.println("Cannot load the bindings to the simgrid library: ");
- e.printStackTrace();
- System.err.println("This jar file does not seem to fit your system, sorry");
- System.exit(1);
- }
- }
- /* A hackish mechanism used to remove the file containing our library when the JVM shuts down */
- private static class FileCleaner implements Runnable {
- private String target;
- public FileCleaner(String name) {
- target = name;
- }
- public void run() {
- try {
- new File(target).delete();
- } catch(Exception e) {
- System.out.println("Unable to clean temporary file "+target+" during shutdown.");
- e.printStackTrace();
- }
- }
- }
-
+
/** Retrieve the simulation time
* @return The simulation time.
*/
--- /dev/null
+/* File : example.i */
+%module(directors="1") Surf
+
+%pragma(java) jniclassimports=%{
+import org.simgrid.NativeLib;
+
+%}
+%pragma(java) jniclasscode=%{
+ static {
+ NativeLib.nativeInit("surf-java");
+ }
+%}
+
+%{
+#include "src/surf/cpu_interface.hpp"
+#include "src/surf/network_interface.hpp"
+#include "src/bindings/java/surf_swig.hpp"
+#include "src/xbt/dict_private.h"
+typedef struct lmm_constraint *lmm_constraint_t;
+%}
+
+%feature("director") Plugin;
+
+%include "src/bindings/java/surf_swig.hpp"
+
+%nodefaultctor Model;
+class Model {
+public:
+ const char *getName();
+};
+
+class Resource {
+public:
+ Resource();
+ const char *getName();
+ virtual bool isUsed()=0;
+ lmm_constraint *getConstraint();
+ s_xbt_dict *getProperties();
+};
+
+class Cpu : public Resource {
+public:
+ Cpu();
+ ~Cpu();
+ double getCurrentPowerPeak();
+};
+
+class NetworkLink : public Resource {
+public:
+ NetworkLink();
+ ~NetworkLink();
+};
+
+class Action {
+public:
+ Model *getModel();
+};
+
+class CpuAction : public Action {
+public:
+%extend {
+ Cpu *getCpu() {return getActionCpu($self);}
+}
+};
+
+%nodefaultctor NetworkAction;
+class NetworkAction : public Action {
+public:
+%extend {
+ double getLatency() {return $self->m_latency;}
+}
+};
+
+
+%rename lmm_constraint LmmConstraint;
+struct lmm_constraint {
+%extend {
+ double getUsage() {return lmm_constraint_get_usage($self);}
+}
+};
+
+%rename s_xbt_dict XbtDict;
+struct s_xbt_dict {
+%extend {
+ char *getValue(char *key) {return (char*)xbt_dict_get_or_null($self, key);}
+}
+};
+
--- /dev/null
+#include <boost/lambda/bind.hpp>
+#include "src/surf/surf_interface.hpp"
+#include "surf_swig.hpp"
+
+double getClock() {
+ surf_get_clock();
+}
+
+void Plugin::activateCpuCreatedCallback(){
+ surf_callback_connect(cpuCreatedCallbacks, boost::bind(&Plugin::cpuCreatedCallback, this, _1));
+}
+
+void Plugin::activateCpuDestructedCallback(){
+ surf_callback_connect(cpuDestructedCallbacks, boost::bind(&Plugin::cpuDestructedCallback, this, _1));
+}
+
+void Plugin::activateCpuStateChangedCallback(){
+ surf_callback_connect(cpuStateChangedCallbacks, boost::bind(&Plugin::cpuStateChangedCallback, this, _1));
+}
+
+void Plugin::activateCpuActionStateChangedCallback(){
+ surf_callback_connect(cpuActionStateChangedCallbacks, boost::bind(&Plugin::cpuActionStateChangedCallback, this, _1));
+}
+
+
+void Plugin::activateNetworkLinkCreatedCallback(){
+ surf_callback_connect(networkLinkCreatedCallbacks, boost::bind(&Plugin::networkLinkCreatedCallback, this, _1));
+}
+
+void Plugin::activateNetworkLinkDestructedCallback(){
+ surf_callback_connect(networkLinkDestructedCallbacks, boost::bind(&Plugin::networkLinkDestructedCallback, this, _1));
+}
+
+void Plugin::activateNetworkLinkStateChangedCallback(){
+ surf_callback_connect(networkLinkStateChangedCallbacks, boost::bind(&Plugin::networkLinkStateChangedCallback, this, _1));
+}
+
+void Plugin::activateNetworkActionStateChangedCallback(){
+ surf_callback_connect(networkActionStateChangedCallbacks, boost::bind(&Plugin::networkActionStateChangedCallback, this, _1));
+}
+
+
--- /dev/null
+#include <cstdio>
+#include <iostream>
+#include "src/surf/cpu_interface.hpp"
+#include "src/surf/network_interface.hpp"
+#include "src/surf/maxmin_private.hpp"
+
+double getClock();
+
+class Plugin {
+public:
+ virtual ~Plugin() {
+ std::cout << "Plugin::~Plugin()" << std:: endl;
+ }
+
+ void exit() {
+ surf_exit();
+ }
+
+ void activateCpuCreatedCallback();
+ virtual void cpuCreatedCallback(Cpu *cpu) {}
+
+ void activateCpuDestructedCallback();
+ virtual void cpuDestructedCallback(Cpu *cpu) {}
+
+ void activateCpuStateChangedCallback();
+ virtual void cpuStateChangedCallback(Cpu *cpu) {}
+
+ void activateCpuActionStateChangedCallback();
+ virtual void cpuActionStateChangedCallback(CpuAction *action) {}
+
+
+ void activateNetworkLinkCreatedCallback();
+ virtual void networkLinkCreatedCallback(NetworkLink *link) {}
+
+ void activateNetworkLinkDestructedCallback();
+ virtual void networkLinkDestructedCallback(NetworkLink *link) {}
+
+ void activateNetworkLinkStateChangedCallback();
+ virtual void networkLinkStateChangedCallback(NetworkLink *link) {}
+
+ void activateNetworkActionStateChangedCallback();
+ virtual void networkActionStateChangedCallback(NetworkAction *action) {}
+
+};
+
+
s_xbt_swag_hookup_t p_stateHookup;
+ ModelPtr getModel() {return p_model;}
+
protected:
ActionListPtr p_stateSet;
double m_priority; /**< priority (1.0 by default) */
double m_maxDuration; /*< max_duration (may fluctuate until the task is completed) */
double m_finish; /**< finish time : this is modified during the run and fluctuates until the task is completed */
- ModelPtr getModel() {return p_model;}
-
private:
int resourceUsed(void *resource_id);