move getServicePid to the Sigar class so we get caching via SigarProxy

This commit is contained in:
Doug MacEachern 2004-08-14 00:40:37 +00:00
parent 0d2c62af41
commit 2896feb983
4 changed files with 16 additions and 10 deletions

View File

@ -1054,8 +1054,8 @@ typedef BOOL (CALLBACK *QueryServiceStatusExFunc)(SC_HANDLE,
LPDWORD); LPDWORD);
#endif #endif
JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid) JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
(JNIEnv *env, jclass classinstance, jstring jname) (JNIEnv *env, jobject sigar_obj, jstring jname)
{ {
#ifdef WIN32 #ifdef WIN32
const char *name; const char *name;
@ -1063,6 +1063,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid)
jlong pid = 0; jlong pid = 0;
DWORD err = ERROR_SUCCESS; DWORD err = ERROR_SUCCESS;
SC_HANDLE mgr; SC_HANDLE mgr;
dSIGAR(0);
name = JENV->GetStringUTFChars(env, jname, &is_copy); name = JENV->GetStringUTFChars(env, jname, &is_copy);
@ -1118,10 +1119,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid)
} }
if (err != ERROR_SUCCESS) { if (err != ERROR_SUCCESS) {
/* XXX need sigar for sigar_strerror */ sigar_throw_error(env, sigar, err);
char msg[256];
sprintf(msg, "error=%d", err);
sigar_throw_exception(env, msg);
} }
return pid; return pid;

View File

@ -125,6 +125,14 @@ public class Sigar implements SigarProxy {
*/ */
public native long getPid(); public native long getPid();
/**
* Get pid for the Windows service with the given name.
* This method is implemented on Windows only as a helper
* for PTQL.
*/
public native long getServicePid(String name);
/** /**
* Send a signal to a process. * Send a signal to a process.
* *

View File

@ -13,6 +13,8 @@ public interface SigarProxy {
public long getPid(); public long getPid();
public long getServicePid(String name);
public Mem getMem() throws SigarException; public Mem getMem() throws SigarException;
public Swap getSwap() throws SigarException; public Swap getSwap() throws SigarException;

View File

@ -8,8 +8,6 @@ public class WindowsServiceQuery implements ProcessQuery {
private String name; private String name;
public static native long getServicePid(String name);
public WindowsServiceQuery(String name) { public WindowsServiceQuery(String name) {
this.name = name; this.name = name;
} }
@ -17,11 +15,11 @@ public class WindowsServiceQuery implements ProcessQuery {
public boolean match(SigarProxy sigar, long pid) public boolean match(SigarProxy sigar, long pid)
throws SigarException { throws SigarException {
return pid == getServicePid(this.name); return pid == sigar.getServicePid(this.name);
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Sigar sigar = new Sigar(); //load the .dll Sigar sigar = new Sigar(); //load the .dll
System.out.println(getServicePid(args[0])); System.out.println(sigar.getServicePid(args[0]));
} }
} }