* @exception HostNotFoundException if the name of the host is not valid.
* NativeException if the native version of this method failed.
*/
- public static Host getByName(String name)
- throws HostNotFoundException {
- if (name==null)
- throw new NullPointerException("No host can have a null name");
- return MsgNative.hostGetByName(name);
- }
-
+ public native static Host getByName(String name)
+ throws HostNotFoundException, NullPointerException;
/**
* This static method returns the count of the installed hosts.
*
* @return The count of the installed hosts.
- *
+ * FIXME: Not implemented... ?
*/
- public static int getCount() {
- return MsgNative.hostGetCount();
- }
+ public native static int getCount();
/**
* This static method return an instance to the host of the current process.
*
* @return The host on which the current process is executed.
*/
- public static Host currentHost() {
- return MsgNative.hostSelf();
- }
+ public native static Host currentHost();
/**
* This static method returns all of the hosts of the installed platform.
* @return The name of the host.
*
*/
- public String getName() {
- return MsgNative.hostGetName(this);
- }
-
+ public native String getName();
/**
* Sets the data of the host.
*
*
* @return The number of tasks currently running on a host.
*/
- public int getLoad() {
- return MsgNative.hostGetLoad(this);
- }
+ public native int getLoad();
/**
* This method returns the speed of the processor of a host,
* @return The speed of the processor of the host in flops.
*
*/
- public double getSpeed() {
- return MsgNative.hostGetSpeed(this);
- }
+ public native double getSpeed();
/** This method tests if a host is avail.
* @return
*/
- public boolean isAvail() {
- return MsgNative.hostIsAvail(this);
- }
+ public native boolean isAvail();
+
+
}
* The natively implemented methods connected to the MSG host *
******************************************************************/
- /**
- * The natively implemented method to get an host from his name.
- *
- * @param name The name of the host to get.
- *
- * @return The host having the specified name.
- *
- * @exception HostNotFoundException if there is no such host
- *
- *
- * @see Host.getByName()
- */
- final static native Host hostGetByName(String name) throws HostNotFoundException;
-
- /**
- * The natively implemented method to get the name of an MSG host.
- *
- * @param host The host (valid) to get the name.
- *
- * @return The name of the specified host.
- *
- * @see Host.getName()
- */
- final static native String hostGetName(Host host);
-
- /**
- * The natively implemented method to get the number of hosts of the simulation.
- *
- * @return The number of hosts of the simulation.
- *
- * @see Host.getNumber()
- */
- final static native int hostGetCount();
-
- /**
- * The natively implemented method to get the host of the current runing process.
- *
- * @return The host of the current running process.
- *
- * @see Host.currentHost()
- */
- final static native Host hostSelf();
-
- /**
- * The natively implemented method to get the speed of a MSG host.
- *
- * @param host The host to get the host.
- *
- * @return The speed of the specified host.
- *
- * @see Host.getSpeed()
- */
-
- final static native double hostGetSpeed(Host host);
-
- /**
- * The natively implemented native method to test if an host is avail.
- *
- * @param host The host to test.
- *
- * @return If the host is avail the method returns true.
- * Otherwise the method returns false.
- *
- * @see Host.isAvail()
- */
- final static native boolean hostIsAvail(Host host);
-
/**
* The natively implemented native method to get all the hosts of the simulation.
*
final static native Host[] allHosts();
- /**
- * The natively implemented native method to get the number of running tasks on a host.
- *
- * @param The host concerned by the operation.
- *
- * @return The number of running tasks.
- */
- final static native int hostGetLoad(Host host);
}
* @throws HostFailureException
* @throws TransferFailureException
*/
- public void send(String mailbox) throws NativeException, TransferFailureException, HostFailureException, TimeoutException {
+ public void send(String mailbox) throws TransferFailureException, HostFailureException, TimeoutException {
send(mailbox, -1);
}
* @throws HostFailureException
* @throws TransferFailureException
*/
- public native void send(String mailbox, double timeout) throws NativeException, TransferFailureException, HostFailureException, TimeoutException;
+ public native void send(String mailbox, double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
/**
* Sends the task on the mailbox identified by the specified alias (capping the sending rate to \a maxrate)
*
* The MSG host connected functions implementation. *
***************************************************************************************/
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls,
- jstring jname)
-{
- m_host_t host; /* native host */
- jobject jhost; /* global reference to the java host instance returned */
-
- /* get the C string from the java string */
- const char *name = (*env)->GetStringUTFChars(env, jname, 0);
- XBT_DEBUG("Looking for host '%s'",name);
- /* get the host by name (the hosts are created during the grid resolution) */
- host = MSG_get_host_by_name(name);
- XBT_DEBUG("MSG gave %p as native host", host);
-
- if (!host) { /* invalid name */
- jxbt_throw_host_not_found(env, name);
- (*env)->ReleaseStringUTFChars(env, jname, name);
- return NULL;
- }
- (*env)->ReleaseStringUTFChars(env, jname, name);
-
- if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */
-
- /* Instantiate a new java host */
- jhost = jhost_new_instance(env);
-
- if (!jhost) {
- jxbt_throw_jni(env, "java host instantiation failed");
- return NULL;
- }
-
- /* get a global reference to the newly created host */
- jhost = jhost_ref(env, jhost);
-
- if (!jhost) {
- jxbt_throw_jni(env, "new global ref allocation failed");
- return NULL;
- }
-
- /* bind the java host and the native host */
- jhost_bind(jhost, host, env);
-
- /* the native host data field is set with the global reference to the
- * java host returned by this function
- */
- MSG_host_set_data(host, (void *) jhost);
- }
-
- /* return the global reference to the java host instance */
- return (jobject) MSG_host_get_data(host);
-}
-
-JNIEXPORT jstring JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetName(JNIEnv * env, jclass cls,
- jobject jhost)
-{
- m_host_t host = jhost_get_native(env, jhost);
- const char* name;
-
- if (!host) {
- jxbt_throw_notbound(env, "host", jhost);
- return NULL;
- }
-
- name = MSG_host_get_name(host);
- if (!name)
- xbt_die("This host has no name...");
-
- return (*env)->NewStringUTF(env, name);
-}
-
-JNIEXPORT jint JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetNumber(JNIEnv * env, jclass cls)
-{
- xbt_dynar_t hosts = MSG_hosts_as_dynar();
- int nb_host = xbt_dynar_length(hosts);
- xbt_dynar_free(&hosts);
- return (jint) nb_host;
-}
-
-JNIEXPORT jobject JNICALL
-Java_org_simgrid_msg_MsgNative_hostSelf(JNIEnv * env, jclass cls)
-{
- jobject jhost;
-
- m_host_t host = MSG_host_self();
-
- if (!MSG_host_get_data(host)) {
- /* the native host not yet associated with the java host instance */
-
- /* instanciate a new java host instance */
- jhost = jhost_new_instance(env);
-
- if (!jhost) {
- jxbt_throw_jni(env, "java host instantiation failed");
- return NULL;
- }
-
- /* get a global reference to the newly created host */
- jhost = jhost_ref(env, jhost);
-
- if (!jhost) {
- jxbt_throw_jni(env, "global ref allocation failed");
- return NULL;
- }
-
- /* Bind & store it */
- jhost_bind(jhost, host, env);
- MSG_host_set_data(host, (void *) jhost);
- } else {
- jhost = (jobject) MSG_host_get_data(host);
- }
-
- return jhost;
-}
-
-JNIEXPORT jdouble JNICALL
-Java_org_simgrid_msg_MsgNative_hostGetSpeed(JNIEnv * env, jclass cls,
- jobject jhost)
-{
- m_host_t host = jhost_get_native(env, jhost);
-
- if (!host) {
- jxbt_throw_notbound(env, "host", jhost);
- return -1;
- }
-
- return (jdouble) MSG_get_host_speed(host);
-}
-
JNIEXPORT jint JNICALL
Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
jobject jhost)
}
-JNIEXPORT jboolean JNICALL
-Java_org_simgrid_msg_MsgNative_hostIsAvail(JNIEnv * env, jclass cls,
- jobject jhost)
-{
- m_host_t host = jhost_get_native(env, jhost);
-
- if (!host) {
- jxbt_throw_notbound(env, "host", jhost);
- return 0;
- }
-
- return (jboolean) MSG_host_is_avail(host);
-}
-
/***************************************************************************************
* Unsortable functions *
***************************************************************************************/
jname = (*env)->NewStringUTF(env, MSG_host_get_name(host));
jhost =
- Java_org_simgrid_msg_MsgNative_hostGetByName(env, cls_arg, jname);
+ Java_org_simgrid_msg_Host_getByName(env, cls_arg, jname);
/* FIXME: leak of jname ? */
}
JNIEXPORT void JNICALL Java_org_simgrid_msg_MsgNative_processWaitFor
(JNIEnv *, jclass, jdouble);
-/*
- * Class simgrid_msg_Msg
- * Method hostGetByName
- * Signature (Ljava/lang/String;)Lsimgrid/msg/Host;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_hostGetByName
- (JNIEnv *, jclass, jstring);
-
-/*
- * Class simgrid_msg_Msg
- * Method hostGetName
- * Signature (Lsimgrid/msg/Host;)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_org_simgrid_msg_MsgNative_hostGetName
- (JNIEnv *, jclass, jobject);
-
-/*
- * Class simgrid_msg_Msg
- * Method hostGetNumber
- * Signature ()I
- */
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_MsgNative_hostGetNumber
- (JNIEnv *, jclass);
-
-/*
- * Class simgrid_msg_Msg
- * Method hostSelf
- * Signature ()Lsimgrid/msg/Host;
- */
-JNIEXPORT jobject JNICALL Java_org_simgrid_msg_MsgNative_hostSelf
- (JNIEnv *, jclass);
-
-/*
- * Class simgrid_msg_Msg
- * Method hostGetSpeed
- * Signature (Lsimgrid/msg/Host;)D
- */
-JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_MsgNative_hostGetSpeed
- (JNIEnv *, jclass, jobject);
-
JNIEXPORT jint JNICALL
Java_org_simgrid_msg_MsgNative_hostGetLoad(JNIEnv * env, jclass cls,
jobject jhost);
-/*
- * Class simgrid_msg_Msg
- * Method hostIsAvail
- * Signature (Lsimgrid/msg/Host;)Z
- */
-JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_MsgNative_hostIsAvail
- (JNIEnv *, jclass, jobject);
-
/*
* Class simgrid_msg_Msg
* Method getClock
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls,
jstring jplatformFile);
-
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Msg_deployApplication(JNIEnv * env, jclass cls,
jstring jdeploymentFile);
#include "jmsg_host.h"
#include "jxbt_utilities.h"
-jobject jhost_new_instance(JNIEnv * env)
-{
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+
+jobject jhost_new_instance(JNIEnv * env) {
jclass cls = jxbt_get_class(env, "org/simgrid/msg/Host");
jmethodID constructor = jxbt_get_jmethod(env, cls, "<init>", "()V");
return (*env)->NewObject(env, cls, constructor);
}
-jobject jhost_ref(JNIEnv * env, jobject jhost)
-{
+jobject jhost_ref(JNIEnv * env, jobject jhost) {
return (*env)->NewGlobalRef(env, jhost);
}
-void jhost_unref(JNIEnv * env, jobject jhost)
-{
+void jhost_unref(JNIEnv * env, jobject jhost) {
(*env)->DeleteGlobalRef(env, jhost);
}
-void jhost_bind(jobject jhost, m_host_t host, JNIEnv * env)
-{
+void jhost_bind(jobject jhost, m_host_t host, JNIEnv * env) {
jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Host", "bind", "J");
if (!id)
(*env)->SetLongField(env, jhost, id, (jlong) (long) (host));
}
-m_host_t jhost_get_native(JNIEnv * env, jobject jhost)
-{
+m_host_t jhost_get_native(JNIEnv * env, jobject jhost) {
jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Host", "bind", "J");
if (!id)
return (m_host_t) (long) (*env)->GetLongField(env, jhost, id);
}
-const char *jhost_get_name(jobject jhost, JNIEnv * env)
-{
+const char *jhost_get_name(jobject jhost, JNIEnv * env) {
m_host_t host = jhost_get_native(env, jhost);
return MSG_host_get_name(host);
}
-jboolean jhost_is_valid(jobject jhost, JNIEnv * env)
-{
+jboolean jhost_is_valid(jobject jhost, JNIEnv * env) {
jfieldID id = jxbt_get_sfield(env, "org/simgrid/msg/Host", "bind", "J");
if (!id)
return JNI_FALSE;
}
}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls,
+ jstring jname) {
+ m_host_t host; /* native host */
+ jobject jhost; /* global reference to the java host instance returned */
+
+ /* get the C string from the java string */
+ const char *name = (*env)->GetStringUTFChars(env, jname, 0);
+ if (name == NULL) {
+ jxbt_throw_null(env,bprintf("No host can have a null name"));
+ return NULL;
+ }
+ XBT_DEBUG("Looking for host '%s'",name);
+ /* get the host by name (the hosts are created during the grid resolution) */
+ host = MSG_get_host_by_name(name);
+ XBT_DEBUG("MSG gave %p as native host", host);
+
+ if (!host) { /* invalid name */
+ jxbt_throw_host_not_found(env, name);
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+ return NULL;
+ }
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+
+ if (!MSG_host_get_data(host)) { /* native host not associated yet with java host */
+
+ /* Instantiate a new java host */
+ jhost = jhost_new_instance(env);
+
+ if (!jhost) {
+ jxbt_throw_jni(env, "java host instantiation failed");
+ return NULL;
+ }
+
+ /* get a global reference to the newly created host */
+ jhost = jhost_ref(env, jhost);
+
+ if (!jhost) {
+ jxbt_throw_jni(env, "new global ref allocation failed");
+ return NULL;
+ }
+
+ /* bind the java host and the native host */
+ jhost_bind(jhost, host, env);
+
+ /* the native host data field is set with the global reference to the
+ * java host returned by this function
+ */
+ MSG_host_set_data(host, (void *) jhost);
+ }
+
+ /* return the global reference to the java host instance */
+ return (jobject) MSG_host_get_data(host);
+}
+
+JNIEXPORT jobject JNICALL
+Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) {
+ jobject jhost;
+
+ m_host_t host = MSG_host_self();
+
+ if (!MSG_host_get_data(host)) {
+ /* the native host not yet associated with the java host instance */
+
+ /* instanciate a new java host instance */
+ jhost = jhost_new_instance(env);
+
+ if (!jhost) {
+ jxbt_throw_jni(env, "java host instantiation failed");
+ return NULL;
+ }
+
+ /* get a global reference to the newly created host */
+ jhost = jhost_ref(env, jhost);
+
+ if (!jhost) {
+ jxbt_throw_jni(env, "global ref allocation failed");
+ return NULL;
+ }
+
+ /* Bind & store it */
+ jhost_bind(jhost, host, env);
+ MSG_host_set_data(host, (void *) jhost);
+ } else {
+ jhost = (jobject) MSG_host_get_data(host);
+ }
+
+ return jhost;
+}
+
+JNIEXPORT jstring JNICALL
+Java_org_simgrid_msg_Host_getName(JNIEnv * env,
+ jobject jhost) {
+ m_host_t host = jhost_get_native(env, jhost);
+ const char* name;
+
+ if (!host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return NULL;
+ }
+
+ name = MSG_host_get_name(host);
+ if (!name)
+ xbt_die("This host has no name...");
+
+ return (*env)->NewStringUTF(env, name);
+}
+
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Host_getCount(JNIEnv * env, jclass cls) {
+ xbt_dynar_t hosts = MSG_hosts_as_dynar();
+ int nb_host = xbt_dynar_length(hosts);
+ xbt_dynar_free(&hosts);
+ return (jint) nb_host;
+}
+
+JNIEXPORT jdouble JNICALL
+Java_org_simgrid_msg_Host_getSpeed(JNIEnv * env,
+ jobject jhost) {
+ m_host_t host = jhost_get_native(env, jhost);
+
+ if (!host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return -1;
+ }
+
+ return (jdouble) MSG_get_host_speed(host);
+}
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Host_getLoad(JNIEnv * env, jobject jhost) {
+ m_host_t host = jhost_get_native(env, jhost);
+
+ if (!host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return -1;
+ }
+
+ return (jint) MSG_get_host_msgload(host);
+}
+JNIEXPORT jboolean JNICALL
+Java_org_simgrid_msg_Host_isAvail(JNIEnv * env, jobject jhost) {
+ m_host_t host = jhost_get_native(env, jhost);
+
+ if (!host) {
+ jxbt_throw_notbound(env, "host", jhost);
+ return 0;
+ }
+
+ return (jboolean) MSG_host_is_avail(host);
+}
*/
jboolean jhost_is_valid(jobject jhost, JNIEnv * env);
+/*
+ * Class simgrid_msg_Host
+ * Method getByName
+ * Signature (Ljava/lang/String;)Lsimgrid/msg/Host;
+ */
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName
+ (JNIEnv *, jclass, jstring);
+
+/*
+ * Class simgrid_msg_Host
+ * Method currentHost
+ * Signature ()Lsimgrid/msg/Host;
+ */
+JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_currentHost
+ (JNIEnv *, jclass);
+
+/*
+ * Class simgrid_msg_Host
+ * Method getName
+ * Signature ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_simgrid_msg_Host_getName
+ (JNIEnv *, jobject);
+/*
+ * Class simgrid_msg_Host
+ * Method getCount
+ * Signature ()I
+ */
+JNIEXPORT jint JNICALL Java_org_simgrid_msg_Host_getCount
+ (JNIEnv *, jclass);
+
+/*
+ * Class simgrid_msg_Host
+ * Method getSpeed
+ * Signature ()D
+ */
+JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Host_getSpeed
+ (JNIEnv *, jobject);
+/*
+ * Class simgrid_msg_Host
+ * Method getLoad
+ * Signature ()I
+ */
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Host_getLoad(JNIEnv * env,
+ jobject jhost);
+
+/*
+ * Class simgrid_msg_Msg
+ * Method isAvail
+ * Signature ()Z
+ */
+JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Host_isAvail
+ (JNIEnv *, jobject);
+
#endif /*!MSG_JHOST_H */