move getServicePid to the Sigar class so we get caching via SigarProxy
This commit is contained in:
parent
0d2c62af41
commit
2896feb983
|
@ -1054,8 +1054,8 @@ typedef BOOL (CALLBACK *QueryServiceStatusExFunc)(SC_HANDLE,
|
|||
LPDWORD);
|
||||
#endif
|
||||
|
||||
JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid)
|
||||
(JNIEnv *env, jclass classinstance, jstring jname)
|
||||
JNIEXPORT jlong SIGAR_JNI(Sigar_getServicePid)
|
||||
(JNIEnv *env, jobject sigar_obj, jstring jname)
|
||||
{
|
||||
#ifdef WIN32
|
||||
const char *name;
|
||||
|
@ -1063,6 +1063,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid)
|
|||
jlong pid = 0;
|
||||
DWORD err = ERROR_SUCCESS;
|
||||
SC_HANDLE mgr;
|
||||
dSIGAR(0);
|
||||
|
||||
name = JENV->GetStringUTFChars(env, jname, &is_copy);
|
||||
|
||||
|
@ -1118,10 +1119,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_WindowsServiceQuery_getServicePid)
|
|||
}
|
||||
|
||||
if (err != ERROR_SUCCESS) {
|
||||
/* XXX need sigar for sigar_strerror */
|
||||
char msg[256];
|
||||
sprintf(msg, "error=%d", err);
|
||||
sigar_throw_exception(env, msg);
|
||||
sigar_throw_error(env, sigar, err);
|
||||
}
|
||||
|
||||
return pid;
|
||||
|
|
|
@ -125,6 +125,14 @@ public class Sigar implements SigarProxy {
|
|||
*/
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -13,6 +13,8 @@ public interface SigarProxy {
|
|||
|
||||
public long getPid();
|
||||
|
||||
public long getServicePid(String name);
|
||||
|
||||
public Mem getMem() throws SigarException;
|
||||
|
||||
public Swap getSwap() throws SigarException;
|
||||
|
|
|
@ -8,8 +8,6 @@ public class WindowsServiceQuery implements ProcessQuery {
|
|||
|
||||
private String name;
|
||||
|
||||
public static native long getServicePid(String name);
|
||||
|
||||
public WindowsServiceQuery(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -17,11 +15,11 @@ public class WindowsServiceQuery implements ProcessQuery {
|
|||
public boolean match(SigarProxy sigar, long pid)
|
||||
throws SigarException {
|
||||
|
||||
return pid == getServicePid(this.name);
|
||||
return pid == sigar.getServicePid(this.name);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Sigar sigar = new Sigar(); //load the .dll
|
||||
System.out.println(getServicePid(args[0]));
|
||||
System.out.println(sigar.getServicePid(args[0]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue