From: Martin Quinson Date: Tue, 21 Mar 2017 08:49:21 +0000 (+0100) Subject: guess what? I hate our java crufty code X-Git-Tag: v3_15~41 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/24904a5d2b3de5c5404f3817e5f01966cbd1a8d2?hp=7310fc0a24abaca645f3f6931b6065c796127f9b guess what? I hate our java crufty code --- diff --git a/examples/java/cloud/migration/Test.java b/examples/java/cloud/migration/Test.java index 83c80449e9..d57582d424 100644 --- a/examples/java/cloud/migration/Test.java +++ b/examples/java/cloud/migration/Test.java @@ -1,5 +1,4 @@ -/* Copyright (c) 2014, 2016. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2014-2017. 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. */ @@ -32,15 +31,8 @@ public class Test extends Process{ } public void main(String[] strings) throws MsgException { - Host host0 = null; - Host host1 = null; - try { - /* get hosts 1 and 2*/ - host0 = Host.getByName("PM0"); - host1 = Host.getByName("PM1"); - }catch (HostNotFoundException e) { - e.printStackTrace(); - } + Host host0 = Host.getByName("PM0"); + Host host1 = Host.getByName("PM1"); List vms = new ArrayList<>(); @@ -65,7 +57,6 @@ public class Test extends Process{ vm1.start(); /* Collocated VMs */ - int collocatedSrc = 6; int[] vmSrcLoad = { 80, 0, @@ -76,7 +67,7 @@ public class Test extends Process{ }; XVM tmp; - for (int i=1 ; i<= collocatedSrc ; i++){ + for (int i=1 ; i<= vmSrcLoad.length ; i++){ tmp = new XVM(host0, "vm"+i, 2048, // Ramsize, 125, // Net bandwidth, @@ -97,8 +88,8 @@ public class Test extends Process{ 80, }; - for (int i=1 ; i <= collocatedDst ; i++){ - tmp = new XVM(host1, "vm"+(i+collocatedSrc), + for (int i=1 ; i <= vmDstLoad.length ; i++){ + tmp = new XVM(host1, "vm"+(i+vmSrcLoad.length), 2048, // Ramsize, 125, // Net bandwidth, dpRate // Memory intensity diff --git a/src/bindings/java/jmsg_task.cpp b/src/bindings/java/jmsg_task.cpp index 8e2c1fc0e7..d3a98fa5e1 100644 --- a/src/bindings/java/jmsg_task.cpp +++ b/src/bindings/java/jmsg_task.cpp @@ -57,7 +57,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create(JNIEnv * env, jobject jtask, jstring jname, jdouble jflopsAmount, jdouble jbytesAmount) { - msg_task_t task; /* the native task to create */ const char *name = nullptr; /* the name of the task */ if (jflopsAmount < 0) { @@ -70,17 +69,14 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create(JNIEnv * env, jobject jt return; } - if (jname) { - /* get the C string from the java string */ + if (jname) name = env->GetStringUTFChars(jname, 0); - } - /* create the task */ - task = MSG_task_create(name, static_cast(jflopsAmount), static_cast(jbytesAmount), nullptr); + msg_task_t task = + MSG_task_create(name, static_cast(jflopsAmount), static_cast(jbytesAmount), nullptr); if (jname) env->ReleaseStringUTFChars(jname, name); - /* sets the task name */ - env->SetObjectField(jtask, jtask_field_Task_name, jname); + /* bind & store the task */ jtask_bind(jtask, task, env); MSG_task_set_data(task, jtask); diff --git a/src/bindings/java/org/simgrid/msg/Task.java b/src/bindings/java/org/simgrid/msg/Task.java index 708978cf78..c6098b32fe 100644 --- a/src/bindings/java/org/simgrid/msg/Task.java +++ b/src/bindings/java/org/simgrid/msg/Task.java @@ -49,6 +49,7 @@ public class Task { */ public Task(String name, double flopsAmount, double bytesAmount) { create(name, flopsAmount, bytesAmount); + this.name = name; this.messageSize = bytesAmount; } /**