/* Functions related to the java process instances. */
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2007-2020. 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 "jmsg_host.h"
#include "jxbt_utilities.hpp"
#include "simgrid/Exception.hpp"
-#include "src/simix/ActorImpl.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
jfieldID jprocess_field_Process_pid;
jfieldID jprocess_field_Process_ppid;
-jobject jprocess_from_native(msg_process_t process)
+jobject jprocess_from_native(const_sg_actor_t process)
{
- simgrid::kernel::context::JavaContext* context =
- (simgrid::kernel::context::JavaContext*)process->get_impl()->context_;
+ const simgrid::kernel::context::JavaContext* context =
+ static_cast<simgrid::kernel::context::JavaContext*>(process->get_impl()->context_.get());
return context->jprocess_;
}
return (msg_process_t)(intptr_t)env->GetLongField(jprocess, jprocess_field_Process_bind);
}
-void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env)
+void jprocess_bind(jobject jprocess, const_sg_actor_t process, JNIEnv* env)
{
env->SetLongField(jprocess, jprocess_field_Process_bind, (intptr_t)process);
}
simgrid::simix::ActorCode function = [jprocess]() { simgrid::kernel::context::java_main_jprocess(jprocess); };
smx_actor_t self = SIMIX_process_self();
sg_host_t host = jhost_get_native(env, jhost);
- smx_actor_t actor = simgrid::simix::simcall([name, function, host, self] {
+ smx_actor_t actor = simgrid::kernel::actor::simcall([name, function, host, self] {
return simgrid::kernel::actor::ActorImpl::create(std::move(name), std::move(function), nullptr, host, nullptr, self)
.get();
});
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls, jint pid)
{
- msg_process_t process = MSG_process_from_PID(pid);
+ auto const* process = MSG_process_from_PID(pid);
if (not process) {
jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast<int>(pid)));
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess)
{
- msg_process_t process = jprocess_to_native(jprocess, env);
+ const_sg_actor_t process = jprocess_to_native(jprocess, env);
return MSG_process_get_PID(process);
}
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) {
- msg_process_t process = jprocess_to_native(jprocess, env);
+ const_sg_actor_t process = jprocess_to_native(jprocess, env);
if (not process) {
jxbt_throw_notbound(env, "process", jprocess);
process->resume();
}
-JNIEXPORT void
-JNICALL Java_org_simgrid_msg_Process_setAutoRestart (JNIEnv *env, jobject jprocess, jboolean jauto_restart) {
-
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart(JNIEnv* env, jobject jprocess,
+ jboolean jauto_restart)
+{
msg_process_t process = jprocess_to_native(jprocess, env);
if (not process) {
jxbt_throw_notbound(env, "process", jprocess);
{
double time = ((double)jmillis) / 1000 + ((double)jnanos) / 1000000000;
msg_error_t rv = MSG_OK;
- if (not simgrid::kernel::context::ForcefulKillException::try_n_catch(
- [&time]() { simgrid::s4u::this_actor::sleep_for(time); })) {
+ if (not simgrid::ForcefulKillException::try_n_catch([&time]() { simgrid::s4u::this_actor::sleep_for(time); })) {
rv = MSG_HOST_FAILURE;
}
if (rv != MSG_OK) {
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess, jdouble jseconds)
{
msg_error_t rv = MSG_OK;
- if (not simgrid::kernel::context::ForcefulKillException::try_n_catch(
+ if (not simgrid::ForcefulKillException::try_n_catch(
[&jseconds]() { simgrid::s4u::this_actor::sleep_for((double)jseconds); })) {
rv = MSG_HOST_FAILURE;
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
jxbt_throw_notbound(env, "process", jprocess);
return;
}
- if (not simgrid::kernel::context::ForcefulKillException::try_n_catch([&process]() { MSG_process_kill(process); })) {
+ if (not simgrid::ForcefulKillException::try_n_catch([&process]() { MSG_process_kill(process); })) {
jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", "Process killed");
}
}
}
/* change the host of the process */
- process->migrate(host);
+ process->set_host(host);
/* change the host java side */
env->SetObjectField(jprocess, jprocess_field_Process_host, jhost);