in src/main/c/org_apache_activemq_artemis_nativo_jlibaio_LibaioContext.c [298:385]
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env;
if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6) != JNI_OK) {
return JNI_ERR;
} else {
int res = pthread_mutex_init(&oneMegaMutex, 0);
if (res) {
fprintf(stderr, "could not initialize mutex on on_load, %d", res);
return JNI_ERR;
}
sprintf (dumbPath, "%s/artemisJLHandler_XXXXXX", P_tmpdir);
dumbWriteHandler = mkstemp (dumbPath);
#ifdef DEBUG
fprintf (stdout, "Creating temp file %s for dumb writes\n", dumbPath);
fflush(stdout);
#endif
if (dumbWriteHandler < 0) {
fprintf (stderr, "couldn't create stop file handler %s\n", dumbPath);
return JNI_ERR;
}
//
// Accordingly to previous experiences we must hold Global Refs on Classes
// And
//
// Accordingly to IBM recommendations here:
// We don't need to hold a global reference on methods:
// http://www.ibm.com/developerworks/java/library/j-jni/index.html#notc
// Which actually caused core dumps
jclass localRuntimeExceptionClass = (*env)->FindClass(env, "java/lang/RuntimeException");
if (localRuntimeExceptionClass == NULL) {
// pending exception...
return JNI_ERR;
}
runtimeExceptionClass = (jclass) (*env)->NewGlobalRef(env, localRuntimeExceptionClass);
if (runtimeExceptionClass == NULL) {
// out-of-memory!
throwOutOfMemoryError(env);
return JNI_ERR;
}
jclass localIoExceptionClass = (*env)->FindClass(env, "java/io/IOException");
if (localIoExceptionClass == NULL) {
// pending exception...
return JNI_ERR;
}
ioExceptionClass = (jclass) (*env)->NewGlobalRef(env, localIoExceptionClass);
if (ioExceptionClass == NULL) {
// out-of-memory!
throwOutOfMemoryError(env);
return JNI_ERR;
}
submitClass = (*env)->FindClass(env, "org/apache/activemq/artemis/nativo/jlibaio/SubmitInfo");
if (submitClass == NULL) {
return JNI_ERR;
}
submitClass = (jclass)(*env)->NewGlobalRef(env, (jobject)submitClass);
errorMethod = (*env)->GetMethodID(env, submitClass, "onError", "(ILjava/lang/String;)V");
if (errorMethod == NULL) {
return JNI_ERR;
}
doneMethod = (*env)->GetMethodID(env, submitClass, "done", "()V");
if (doneMethod == NULL) {
return JNI_ERR;
}
libaioContextClass = (*env)->FindClass(env, "org/apache/activemq/artemis/nativo/jlibaio/LibaioContext");
if (libaioContextClass == NULL) {
return JNI_ERR;
}
libaioContextClass = (jclass)(*env)->NewGlobalRef(env, (jobject)libaioContextClass);
libaioContextDone = (*env)->GetMethodID(env, libaioContextClass, "done", "(Lorg/apache/activemq/artemis/nativo/jlibaio/SubmitInfo;)V");
if (libaioContextDone == NULL) {
return JNI_ERR;
}
return JNI_VERSION_1_6;
}
}