Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
codefactor: malformed whitespace issues
[simgrid.git] / src / bindings / java / jmsg_vm.cpp
index 25256f7..07f20e3 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to the Virtual Machines.                               */
 
-/* Copyright (c) 2012-2017. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2012-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. */
@@ -8,14 +8,13 @@
 #include "jmsg_vm.h"
 #include "jmsg_host.h"
 #include "jxbt_utilities.hpp"
+#include "simgrid/Exception.hpp"
 #include "simgrid/plugins/live_migration.h"
+#include "src/kernel/context/Context.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
-#include "xbt/ex.hpp"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 
-extern "C" {
-
 extern int JAVA_HOST_LEVEL;
 static jfieldID jvm_field_bind;
 
@@ -92,7 +91,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_VM_all(JNIEnv* env, jclass c
   msg_host_t h;
   xbt_dynar_foreach (hosts, it, h) {
     simgrid::s4u::VirtualMachine* vm = dynamic_cast<simgrid::s4u::VirtualMachine*>(h);
-    if (vm != nullptr && vm->getState() != SURF_VM_STATE_DESTROYED) {
+    if (vm != nullptr && vm->get_state() != simgrid::s4u::VirtualMachine::state::DESTROYED) {
       jobject jvm = static_cast<jobject>(vm->extension(JAVA_HOST_LEVEL));
       vms.push_back(jvm);
     }
@@ -134,9 +133,16 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm)
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm)
 {
   msg_vm_t vm = jvm_get_native(env,jvm);
-  if (vm) {
+  if (vm)
     MSG_vm_shutdown(vm);
-    auto vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
+}
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm)
+{
+  msg_vm_t vm = jvm_get_native(env, jvm);
+  if (vm) {
+    MSG_vm_destroy(vm);
+    auto* vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
     vmList->erase(std::remove(vmList->begin(), vmList->end(), vm), vmList->end());
   }
 }
@@ -145,12 +151,9 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeMigration(JNIEnv* env, jobj
 {
   msg_vm_t vm = jvm_get_native(env,jvm);
   msg_host_t host = jhost_get_native(env, jhost);
-  try {
-    MSG_vm_migrate(vm,host);
-  }
-  catch(xbt_ex& e){
-     XBT_VERB("CATCH EXCEPTION MIGRATION %s",e.what());
-     jxbt_throw_host_failure(env, (char*)"during migration");
+  if (not simgrid::ForcefulKillException::try_n_catch([&vm, &host]() { MSG_vm_migrate(vm, host); })) {
+    XBT_VERB("Caught exception during migration");
+    jxbt_throw_host_failure(env, "during migration");
   }
 }
 
@@ -168,7 +171,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_resume(JNIEnv *env, jobject jvm)
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclass cls, jstring jname)
 {
-
   /* get the C string from the java string */
   if (jname == nullptr) {
     jxbt_throw_null(env, "No VM can have a null name");
@@ -187,4 +189,3 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclas
 
   return static_cast<jobject>(host->extension(JAVA_HOST_LEVEL));
 }
-}