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)
(JNIEnv *env, jobject sigar_obj, jlong port)
(JNIEnv *env, jobject sigar_obj, jint protocol, jlong port)
{
int status;
sigar_pid_t pid;
dSIGAR(0);
status = sigar_proc_port_get(sigar, SIGAR_NETCONN_TCP, /*XXX UDP*/
status = sigar_proc_port_get(sigar, protocol,
(unsigned long)port, &pid);
if (status != SIGAR_OK) {
sigar_throw_error(env, jsigar, status);

View File

@ -465,10 +465,14 @@ public class Sigar implements SigarProxy {
* @return pid of the process.
* @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 {
return getProcPort(Integer.parseInt(port));
public long getProcPort(String protocol, String 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 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;

View File

@ -233,16 +233,16 @@ public class SynchronizedSigar implements SigarProxy {
return this.sigar.getProcModules(pid);
}
public synchronized long getProcPort(long port)
public synchronized long getProcPort(int protocol, long port)
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
{
return this.sigar.getProcPort(port);
return this.sigar.getProcPort(protocol, port);
}
public synchronized FileSystem[] getFileSystemList()

View File

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

View File

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

View File

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