pass protocol param to ProcPort method

This commit is contained in:
Doug MacEachern 2005-03-16 03:24:26 +00:00
parent 4291d52164
commit 807c8af462
7 changed files with 40 additions and 16 deletions

View File

@ -862,13 +862,13 @@ JNIEXPORT void SIGAR_JNI(FileInfo_gatherLink)
} }
JNIEXPORT jlong SIGAR_JNI(Sigar_getProcPort) JNIEXPORT jlong SIGAR_JNI(Sigar_getProcPort)
(JNIEnv *env, jobject sigar_obj, jlong port) (JNIEnv *env, jobject sigar_obj, jint protocol, jlong port)
{ {
int status; int status;
sigar_pid_t pid; sigar_pid_t pid;
dSIGAR(0); dSIGAR(0);
status = sigar_proc_port_get(sigar, SIGAR_NETCONN_TCP, /*XXX UDP*/ status = sigar_proc_port_get(sigar, protocol,
(unsigned long)port, &pid); (unsigned long)port, &pid);
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
sigar_throw_error(env, jsigar, status); sigar_throw_error(env, jsigar, status);

View File

@ -465,10 +465,14 @@ public class Sigar implements SigarProxy {
* @return pid of the process. * @return pid of the process.
* @exception SigarException on failure. * @exception SigarException on failure.
*/ */
public native long getProcPort(long port) throws SigarException; public native long getProcPort(int protocol, long port)
throws SigarException;
public long getProcPort(String port) throws SigarException { public long getProcPort(String protocol, String port)
return getProcPort(Integer.parseInt(port)); throws SigarException {
return getProcPort(NetFlags.getConnectionProtocol(protocol),
Integer.parseInt(port));
} }
/** /**

View File

@ -83,9 +83,9 @@ public interface SigarProxy {
public List getProcModules(String pid) throws SigarException; public List getProcModules(String pid) throws SigarException;
public long getProcPort(long port) throws SigarException; public long getProcPort(int protocol, long port) throws SigarException;
public long getProcPort(String port) throws SigarException; public long getProcPort(String protocol, String port) throws SigarException;
public FileSystem[] getFileSystemList() throws SigarException; public FileSystem[] getFileSystemList() throws SigarException;

View File

@ -233,16 +233,16 @@ public class SynchronizedSigar implements SigarProxy {
return this.sigar.getProcModules(pid); return this.sigar.getProcModules(pid);
} }
public synchronized long getProcPort(long port) public synchronized long getProcPort(int protocol, long port)
throws SigarException throws SigarException
{ {
return this.sigar.getProcPort(port); return this.sigar.getProcPort(protocol, port);
} }
public synchronized long getProcPort(String port) public synchronized long getProcPort(String protocol, String port)
throws SigarException throws SigarException
{ {
return this.sigar.getProcPort(port); return this.sigar.getProcPort(protocol, port);
} }
public synchronized FileSystem[] getFileSystemList() public synchronized FileSystem[] getFileSystemList()

View File

@ -9,6 +9,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.hyperic.sigar.NetFlags;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarProxy; import net.hyperic.sigar.SigarProxy;
import org.apache.bcel.Constants; import org.apache.bcel.Constants;
@ -411,7 +413,8 @@ public class ProcessQueryBuilder {
} }
//special case //special case
public void appendProcPortOp(String flags, String op, long val) public void appendProcPortOp(String flags, String op,
int protocol, long val)
throws MalformedQueryException { throws MalformedQueryException {
//XXX flags current unused; could be used to narrow search scope. //XXX flags current unused; could be used to narrow search scope.
@ -419,12 +422,17 @@ public class ProcessQueryBuilder {
loadSigarArg(); loadSigarArg();
this.qi.append(new PUSH(this.pool, protocol));
this.qi.append(new PUSH(this.pool, val)); //port this.qi.append(new PUSH(this.pool, val)); //port
this.qi.append(this.factory.createInvoke(PROXY_CLASS, this.qi.append(this.factory.createInvoke(PROXY_CLASS,
"getProcPort", "getProcPort",
Type.LONG, Type.LONG,
new Type[] { Type.LONG }, new Type[] {
Type.INT,
Type.LONG
},
Constants.INVOKEINTERFACE)); Constants.INVOKEINTERFACE));
loadPidArg(); loadPidArg();
@ -693,6 +701,7 @@ public class ProcessQueryBuilder {
} }
} }
else if (attrClass.equals("Port")) { else if (attrClass.equals("Port")) {
int protocol;
long port; long port;
try { try {
port = Long.parseLong(val); port = Long.parseLong(val);
@ -700,7 +709,13 @@ public class ProcessQueryBuilder {
String msg = "Port value '" + val + "' is not a number"; String msg = "Port value '" + val + "' is not a number";
throw new MalformedQueryException(msg); throw new MalformedQueryException(msg);
} }
appendProcPortOp(attr, op, port); try {
protocol = NetFlags.getConnectionProtocol(attr);
} catch (SigarException e) {
throw new MalformedQueryException(e.getMessage());
}
appendProcPortOp(attr, op, protocol, port);
} }
else if (attrClass.equals("Pid")) { else if (attrClass.equals("Pid")) {
appendPidOp(op, val); appendPidOp(op, val);

View File

@ -247,8 +247,12 @@ public class Proxy {
objArgs = new Object[] { arg }; objArgs = new Object[] { arg };
break; break;
case 2: case 2:
//XXX assume ProcEnv for now. if (type.equals("ProcEnv")) {
objArgs = new Object[] { arg, "SHELL" }; objArgs = new Object[] { arg, "SHELL" };
}
else if (type.equals("ProcPort")) {
objArgs = new Object[] { "tcp", "80" };
}
break; break;
} }
} }

View File

@ -66,6 +66,7 @@ public class TestPTQL extends SigarTestCase {
"Pid.Pid.eq=foo", "Pid.Pid.eq=foo",
"Pid.Service.ne=Eventlog", "Pid.Service.ne=Eventlog",
"Cpu.Percent.ge=x", "Cpu.Percent.ge=x",
"Port.foo.eq=8080",
"", "",
null null
}; };