use SigarNotImplementedException.INSTANCE

This commit is contained in:
Doug MacEachern 2004-08-14 04:45:42 +00:00
parent 61771a1596
commit cfbbf3dfc7
1 changed files with 30 additions and 6 deletions

View File

@ -24,6 +24,9 @@
#define SIGAR_FIND_CLASS(name) \ #define SIGAR_FIND_CLASS(name) \
JENV->FindClass(env, SIGAR_PACKAGE name) JENV->FindClass(env, SIGAR_PACKAGE name)
#define SIGAR_CLASS_SIG(name) \
"L" SIGAR_PACKAGE name ";"
typedef struct { typedef struct {
jclass classref; jclass classref;
jfieldID *ids; jfieldID *ids;
@ -35,6 +38,7 @@ typedef struct {
sigar_t *sigar; sigar_t *sigar;
jsigar_field_cache_t *fields[JSIGAR_FIELDS_MAX]; jsigar_field_cache_t *fields[JSIGAR_FIELDS_MAX];
int open_status; int open_status;
jthrowable not_impl;
} jni_sigar_t; } jni_sigar_t;
#define dSIGAR_GET \ #define dSIGAR_GET \
@ -58,9 +62,11 @@ static void sigar_throw_exception(JNIEnv *env, char *msg)
JENV->ThrowNew(env, errorClass, msg); JENV->ThrowNew(env, errorClass, msg);
} }
#define SIGAR_NOTIMPL_EX "SigarNotImplementedException"
static void sigar_throw_notimpl(JNIEnv *env, char *msg) static void sigar_throw_notimpl(JNIEnv *env, char *msg)
{ {
jclass errorClass = SIGAR_FIND_CLASS("SigarNotImplementedException"); jclass errorClass = SIGAR_FIND_CLASS(SIGAR_NOTIMPL_EX);
JENV->ThrowNew(env, errorClass, msg); JENV->ThrowNew(env, errorClass, msg);
} }
@ -78,8 +84,23 @@ static void sigar_throw_error(JNIEnv *env, jni_sigar_t *jsigar, int err)
/*XXX*/ /*XXX*/
#endif #endif
case SIGAR_ENOTIMPL: case SIGAR_ENOTIMPL:
errorClass = SIGAR_FIND_CLASS("SigarNotImplementedException"); if (jsigar->not_impl == NULL) {
break; jfieldID id;
jthrowable not_impl;
errorClass = SIGAR_FIND_CLASS(SIGAR_NOTIMPL_EX);
id = JENV->GetStaticFieldID(env, errorClass,
"INSTANCE",
SIGAR_CLASS_SIG(SIGAR_NOTIMPL_EX));
not_impl = JENV->GetStaticObjectField(env, errorClass, id);
jsigar->not_impl = JENV->NewGlobalRef(env, not_impl);
}
JENV->Throw(env, jsigar->not_impl);
return;
default: default:
errorClass = SIGAR_FIND_CLASS("SigarException"); errorClass = SIGAR_FIND_CLASS("SigarException");
break; break;
@ -170,6 +191,10 @@ JNIEXPORT jint SIGAR_JNI(Sigar_nativeClose)
JENV->DeleteGlobalRef(env, jsigar->logger); JENV->DeleteGlobalRef(env, jsigar->logger);
} }
if (jsigar->not_impl != NULL) {
JENV->DeleteGlobalRef(env, jsigar->not_impl);
}
for (i=0; i<JSIGAR_FIELDS_MAX; i++) { for (i=0; i<JSIGAR_FIELDS_MAX; i++) {
if (jsigar->fields[i]) { if (jsigar->fields[i]) {
JENV->DeleteGlobalRef(env, JENV->DeleteGlobalRef(env,
@ -218,9 +243,6 @@ static jstring jinet_ntoa(JNIEnv *env, sigar_t *sigar, sigar_uint64_t val) {
#include "javasigar_generated.c" #include "javasigar_generated.c"
#define SIGAR_CLASS_SIG(name) \
"L" SIGAR_PACKAGE name ";"
#define SIGAR_ALLOC_OBJECT(name) \ #define SIGAR_ALLOC_OBJECT(name) \
JENV->AllocObject(env, SIGAR_FIND_CLASS(name)) JENV->AllocObject(env, SIGAR_FIND_CLASS(name))
@ -1124,6 +1146,8 @@ JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
return pid; return pid;
#else #else
dSIGAR(0);
sigar_throw_error(env, jsigar, SIGAR_ENOTIMPL); sigar_throw_error(env, jsigar, SIGAR_ENOTIMPL);
return 0;
#endif #endif
} }