/* Functions related to the java host instances. */
-/* Copyright (c) 2007-2018. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2007-2019. 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. */
+#include "simgrid/Exception.hpp"
#include "simgrid/plugins/energy.h"
+#include "simgrid/plugins/load.h"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Storage.hpp"
+#include "JavaContext.hpp"
#include "jmsg.hpp"
#include "jmsg_host.h"
#include "jmsg_storage.h"
"Native initialization of msg/Host failed. Please report that bug");
}
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, jstring jname) {
-
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv* env, jclass cls, jstring jname)
+{
/* get the C string from the java string */
if (jname == nullptr) {
jxbt_throw_null(env, "No host can have a null name");
if (not host->extension(JAVA_HOST_LEVEL)) {
/* the native host not yet associated with the java host instance */
- /* instanciate a new java host instance */
+ /* instantiate a new java host instance */
jhost = jhost_new_instance(env);
if (not jhost) {
JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_off(JNIEnv *env, jobject jhost) {
msg_host_t host = jhost_get_native(env, jhost);
- MSG_host_off(host);
+ if (not simgrid::ForcefulKillException::try_n_catch([host]() { MSG_host_off(host); }))
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Host turned off");
}
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
}
const char *name = env->GetStringUTFChars((jstring) jname, 0);
const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0);
- char *value = xbt_strdup(value_java);
+ const char* value = xbt_strdup(value_java);
MSG_host_set_property_value(host, name, value);
JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg)
{
-
xbt_dynar_t table = MSG_hosts_as_dynar();
int count = xbt_dynar_length(table);
}
for (int index = 0; index < count; index++) {
- msg_host_t host = xbt_dynar_get_as(table, index, msg_host_t);
+ auto const* host = xbt_dynar_get_as(table, index, msg_host_t);
jobject jhost = static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
if (not jhost) {
msg_host_t host = jhost_get_native(env, jhost);
return MSG_host_get_power_peak_at(host, pstate);
}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getLoad(JNIEnv* env, jobject jhost)
+{
+ msg_host_t host = jhost_get_native(env, jhost);
+ return MSG_host_get_load(host);
+}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getCurrentLoad (JNIEnv *env, jobject jhost)
+{
+ msg_host_t host = jhost_get_native(env, jhost);
+
+ if (not host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return 0;
+ }
+
+ return MSG_host_get_current_load(host);
+}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getComputedFlops (JNIEnv *env, jobject jhost)
+{
+ msg_host_t host = jhost_get_native(env, jhost);
+
+ if (not host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return 0;
+ }
+
+ return MSG_host_get_computed_flops(host);
+}
+
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getAvgLoad (JNIEnv *env, jobject jhost)
+{
+ msg_host_t host = jhost_get_native(env, jhost);
+
+ if (not host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return 0;
+ }
+
+ return MSG_host_get_avg_load(host);
+}