当前位置: 首页>>代码示例>>Java>>正文


Java NetConnection类代码示例

本文整理汇总了Java中org.hyperic.sigar.NetConnection的典型用法代码示例。如果您正苦于以下问题:Java NetConnection类的具体用法?Java NetConnection怎么用?Java NetConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NetConnection类属于org.hyperic.sigar包,在下文中一共展示了NetConnection类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNetStats

import org.hyperic.sigar.NetConnection; //导入依赖的package包/类
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;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:35,代码来源:Host.java

示例2: getCount

import org.hyperic.sigar.NetConnection; //导入依赖的package包/类
private int getCount(final int flags) throws SigarException {
    final NetConnection[] connections = sigar.getNetConnectionList(flags);
    if (connections == null) {
        return 0;
    }

    return connections.length;
}
 
开发者ID:vosmann,项目名称:flechette,代码行数:9,代码来源:SystemMetricsService.java

示例3: output

import org.hyperic.sigar.NetConnection; //导入依赖的package包/类
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);
    }
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:67,代码来源:Netstat.java


注:本文中的org.hyperic.sigar.NetConnection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。