本文整理汇总了Java中org.hyperic.sigar.NetFlags.CONN_CLIENT属性的典型用法代码示例。如果您正苦于以下问题:Java NetFlags.CONN_CLIENT属性的具体用法?Java NetFlags.CONN_CLIENT怎么用?Java NetFlags.CONN_CLIENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.hyperic.sigar.NetFlags
的用法示例。
在下文中一共展示了NetFlags.CONN_CLIENT属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNetStats
public static List<JSON> getNetStats() throws SigarException {
_init();
int flags = NetFlags.CONN_CLIENT | NetFlags.CONN_SERVER | NetFlags.CONN_TCP | NetFlags.CONN_UDP
| NetFlags.CONN_PROTOCOLS;
NetConnection[] nn = sigar.getNetConnectionList(flags);
List<JSON> l1 = new ArrayList<JSON>();
for (NetConnection n : nn) {
if (n.getRemotePort() == 0 && n.getLocalPort() == 0)
continue;
JSON jo = JSON.create().append("remoteaddress", n.getRemoteAddress())
.append("remoteport", n.getRemotePort()).append("localaddress", n.getLocalAddress())
.append("localport", n.getLocalPort()).append("recvqueue", n.getReceiveQueue())
.append("sendqueue", n.getSendQueue()).append("state", n.getState()).append("type", n.getType())
.append("typename", n.getTypeString());
if (n.getType() != NetFlags.CONN_UDP) {
jo.append("statename", n.getStateString());
}
try {
long pid = sigar.getProcPort(n.getType(), n.getLocalPort());
if (pid != 0) {
ProcState p = sigar.getProcState(pid);
if (p != null) {
jo.append("pid", pid + "/" + p.getName());
}
}
} catch (Exception e) {
// ignore
log.warn("get pid error, type=" + n.getType() + ", port=" + n.getLocalPort());
}
l1.add(jo);
}
return l1;
}
示例2: getFlags
public static int getFlags(String[] args, int flags) {
int proto_flags = 0;
isNumeric = false;
wantPid = false;
isStat = false;
for (int i=0; i<args.length; i++) {
String arg = args[i];
int j = 0;
while (j<arg.length()) {
switch (arg.charAt(j++)) {
case '-':
continue;
case 'l':
flags &= ~NetFlags.CONN_CLIENT;
flags |= NetFlags.CONN_SERVER;
break;
case 'a':
flags |= NetFlags.CONN_SERVER | NetFlags.CONN_CLIENT;
break;
case 'n':
isNumeric = true;
break;
case 'p':
wantPid = true;
break;
case 's':
isStat = true;
break;
case 't':
proto_flags |= NetFlags.CONN_TCP;
break;
case 'u':
proto_flags |= NetFlags.CONN_UDP;
break;
case 'w':
proto_flags |= NetFlags.CONN_RAW;
break;
case 'x':
proto_flags |= NetFlags.CONN_UNIX;
break;
default:
System.err.println("unknown option");
}
}
}
if (proto_flags != 0) {
flags &= ~NetFlags.CONN_PROTOCOLS;
flags |= proto_flags;
}
return flags;
}
示例3: output
public void output(String[] args) throws SigarException {
//default
int flags = NetFlags.CONN_CLIENT | NetFlags.CONN_PROTOCOLS;
if (args.length > 0) {
flags = getFlags(args, flags);
if (isStat) {
outputStats(flags);
return;
}
}
NetConnection[] connections = this.sigar.getNetConnectionList(flags);
printf(HEADER);
for (int i=0; i<connections.length; i++) {
NetConnection conn = connections[i];
String proto = conn.getTypeString();
String state;
if (conn.getType() == NetFlags.CONN_UDP) {
state = "";
}
else {
state = conn.getStateString();
}
ArrayList items = new ArrayList();
items.add(proto);
items.add(formatAddress(conn.getType(),
conn.getLocalAddress(),
conn.getLocalPort(),
LADDR_LEN));
items.add(formatAddress(conn.getType(),
conn.getRemoteAddress(),
conn.getRemotePort(),
RADDR_LEN));
items.add(state);
String process = null;
if (wantPid &&
//XXX only works w/ listen ports
(conn.getState() == NetFlags.TCP_LISTEN))
{
try {
long pid =
this.sigar.getProcPort(conn.getType(),
conn.getLocalPort());
if (pid != 0) { //XXX another bug
String name =
this.sigar.getProcState(pid).getName();
process = pid + "/" + name;
}
} catch (SigarException e) {
}
}
if (process == null) {
process = "";
}
items.add(process);
printf(items);
}
}