simplify process finder exceptions
This commit is contained in:
parent
10d50d8916
commit
439f1eab1c
|
@ -1255,7 +1255,7 @@ JNIEXPORT jlong SIGAR_JNI(ptql_SigarProcessQuery_findProcess)
|
||||||
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
sigar_throw_ptql_malformed(env, sigar->errbuf);
|
sigar_throw_exception(env, sigar->errbuf);
|
||||||
}
|
}
|
||||||
else if (status != SIGAR_OK) {
|
else if (status != SIGAR_OK) {
|
||||||
sigar_throw_error(env, jsigar, status);
|
sigar_throw_error(env, jsigar, status);
|
||||||
|
@ -1288,7 +1288,7 @@ JNIEXPORT jlongArray SIGAR_JNI(ptql_SigarProcessQuery_findProcesses)
|
||||||
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
sigar_throw_ptql_malformed(env, sigar->errbuf);
|
sigar_throw_exception(env, sigar->errbuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (status != SIGAR_OK) {
|
else if (status != SIGAR_OK) {
|
||||||
|
|
|
@ -18,11 +18,13 @@
|
||||||
|
|
||||||
package org.hyperic.sigar.ptql;
|
package org.hyperic.sigar.ptql;
|
||||||
|
|
||||||
|
import org.hyperic.sigar.SigarException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception for malformed process queries which cannot
|
* Exception for malformed process queries which cannot
|
||||||
* be parsed.
|
* be parsed.
|
||||||
*/
|
*/
|
||||||
public class MalformedQueryException extends Exception {
|
public class MalformedQueryException extends SigarException {
|
||||||
|
|
||||||
public MalformedQueryException() {
|
public MalformedQueryException() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,20 +39,15 @@ public class ProcessFinder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long findSingleProcess(String query)
|
public long findSingleProcess(String query)
|
||||||
throws SigarException, SigarNotImplementedException {
|
throws SigarException {
|
||||||
|
|
||||||
try {
|
ProcessQuery processQuery =
|
||||||
ProcessQuery processQuery =
|
ProcessQueryFactory.getInstance(query);
|
||||||
ProcessQueryFactory.getInstance(query);
|
return findSingleProcess(processQuery);
|
||||||
return findSingleProcess(processQuery);
|
|
||||||
} catch (MalformedQueryException e) {
|
|
||||||
throw new SigarException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long findSingleProcess(ProcessQuery query)
|
public long findSingleProcess(ProcessQuery query)
|
||||||
throws SigarException, SigarNotImplementedException,
|
throws SigarException {
|
||||||
MalformedQueryException {
|
|
||||||
|
|
||||||
if (query instanceof SigarProcessQuery) {
|
if (query instanceof SigarProcessQuery) {
|
||||||
return ((SigarProcessQuery)query).findProcess(getSigar());
|
return ((SigarProcessQuery)query).findProcess(getSigar());
|
||||||
|
@ -75,25 +70,17 @@ public class ProcessFinder {
|
||||||
|
|
||||||
ProcessFinder finder = new ProcessFinder(sigar);
|
ProcessFinder finder = new ProcessFinder(sigar);
|
||||||
|
|
||||||
try {
|
return finder.find(ProcessQueryFactory.getInstance(query));
|
||||||
return finder.find(ProcessQueryFactory.getInstance(query));
|
|
||||||
} catch (MalformedQueryException e) {
|
|
||||||
throw new SigarException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] find(String query)
|
public long[] find(String query)
|
||||||
throws SigarException, SigarNotImplementedException {
|
throws SigarException {
|
||||||
|
|
||||||
try {
|
return find(ProcessQueryFactory.getInstance(query));
|
||||||
return find(ProcessQueryFactory.getInstance(query));
|
|
||||||
} catch (MalformedQueryException e) {
|
|
||||||
throw new SigarException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] find(ProcessQuery query)
|
public long[] find(ProcessQuery query)
|
||||||
throws SigarException, SigarNotImplementedException {
|
throws SigarException {
|
||||||
|
|
||||||
if (query instanceof SigarProcessQuery) {
|
if (query instanceof SigarProcessQuery) {
|
||||||
return ((SigarProcessQuery)query).findProcesses(getSigar());
|
return ((SigarProcessQuery)query).findProcesses(getSigar());
|
||||||
|
|
|
@ -47,10 +47,10 @@ public class SigarProcessQuery implements ProcessQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
public native long findProcess(Sigar sigar)
|
public native long findProcess(Sigar sigar)
|
||||||
throws SigarException, SigarNotImplementedException, MalformedQueryException;
|
throws SigarException;
|
||||||
|
|
||||||
public native long[] findProcesses(Sigar sigar)
|
public native long[] findProcesses(Sigar sigar)
|
||||||
throws SigarException, SigarNotImplementedException;
|
throws SigarException;
|
||||||
|
|
||||||
static boolean re(String haystack, String needle) {
|
static boolean re(String haystack, String needle) {
|
||||||
if (haystack == null) {
|
if (haystack == null) {
|
||||||
|
|
Loading…
Reference in New Issue