⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 handlernettinfo.java

📁 监控大型网络的软件。能够自动发现拓扑结构
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
				sysnameMap.put(boksid, sysname);				katMap.put(boksid, rs.getString("catid"));			}			topologiMap = new HashMap[] { portMap, rootMap, sysnameMap, katMap };			cachedTopologi = new Object[] { new Long(System.currentTimeMillis()), topologiMap };			com.getContext().setAttribute(TOPOLOGI_MAP, cachedTopologi);		}		topologiMap = (HashMap[])cachedTopologi[1];		return topologiMap;	}	private static final int SORT_SYSNAME = 0;	private static final int SORT_IFINDEX = 10;	private static final int SORT_PORT = 20;	private Collection sort(Collection c, final int sortOn) {		List l = new ArrayList(c);		Collections.sort(l,	new Comparator() {					public int compare(Object o1, Object o2) {						if (!(o1 instanceof HashMap) || !(o2 instanceof HashMap)) return 0;						HashMap m1 = (HashMap)o1;						HashMap m2 = (HashMap)o2;						switch (sortOn) {						case SORT_SYSNAME: {							String s1 = (String)sysnameMap.get(m1.containsKey("to_netboxid") ? m1.get("to_netboxid") : "");							String s2 = (String)sysnameMap.get(m2.containsKey("to_netboxid") ? m2.get("to_netboxid") : "");							return s1.compareTo(s2);						}						case SORT_IFINDEX: {							String if1 = (String)m1.get("ifindex");							String if2 = (String)m2.get("ifindex");							Integer i1 = new Integer(if1 != null && !"null".equals(if1) ? if1 : "0");							Integer i2 = new Integer(if2 != null && !"null".equals(if2) ? if2 : "0");							int cmp = i1.compareTo(i2);							if (cmp != 0) return cmp;						}						case SORT_PORT: {							String p1 = (String)m1.get("port");							String p2 = (String)m2.get("port");							try {								Integer i1 = new Integer(p1 != null && !"null".equals(p1) ? p1 : "0");								Integer i2 = new Integer(p2 != null && !"null".equals(p2) ? p2 : "0");								return i1.compareTo(i2);							} catch (NumberFormatException exp) {								return p1 == null ? 0 : p1.compareTo(p2);							}						}						}						return 0;					}			});		return l;	}	private boolean showdetails = false;	/* [/ni.visTopologi]	 *	 */	private boolean firstSearchHit = false;	private void visTopologi() throws SQLException	{		if (s.length > 2) {			if (s[2].equals("showdetails")) {				com.out( com.get("ni.visTopologi.showdetails") );			}			if (s[2].equals("showempty")) {				com.out( com.get("ni.visTopologi.showempty") );			}			if (s[2].equals("searchexact")) {				com.out( com.get("ni.visTopologi.searchexact") );			}			if (s[2].equals("showpath")) {				com.out( com.get("ni.visTopologi.showpath") );			}			if (s[2].equals("searchblocked")) {				com.out( com.get("ni.visTopologi.searchblocked") );			}			if (s.length > 3 && s[2].equals("searchField")) {				String num = s[3];				com.out( (num.equals(com.get("ni.visTopologi.searchFieldNum")) ? " selected" : "") );			}			if (s[2].equals("searchFor")) {				//com.out( (com.get("ni.visTopologi.searchFor") != null) ? com.get("ni.visTopologi.searchFor") : "" );				com.out( (com.getp("searchFor") != null ? com.getp("searchFor") : "") );			}			return;		}		showdetails = false;		{			String s = com.get("ni.visTopologi.showdetails");			if (s != null && s.equals("checked")) showdetails = true;		}		boolean showempty = false;		{			String s = com.get("ni.visTopologi.showempty");			if (s != null && s.equals("checked")) showempty = true;		}		boolean searchexact = false;		{			String s = com.get("ni.visTopologi.searchexact");			if (s != null && s.equals("checked")) searchexact = true;		}		boolean showpath = false;		{			String s = com.get("ni.visTopologi.showpath");			if (s != null && s.equals("checked")) showpath = true;		}		boolean searchblocked = false;		{			String s = com.get("ni.visTopologi.searchblocked");			if (s != null && s.equals("checked")) searchblocked = true;		}		String name = "<b>Network&nbsp;</b>";		String imgRoot = "<img border=0 src=\"" + gfxRoot + "/";		String ntnuImg = imgRoot + "ntnunet.gif" + "\">";		String expandIcon = imgRoot + "expand.gif" + "\" alt=\"Expand entire branch\">";		String label = "<a name=\"0:0\"></a>";		com.out("<table border=0 cellspacing=0 cellpadding=0 style=\"font-size: 13\">\n");		com.outl("  <tr>");		com.outl("    <td>");		com.outl("      " + label + ntnuImg);		com.outl("    </td>");		com.outl("    <td colspan=50 style=\"font-size: 13\">");		com.outl("      <font color=black>" + name + "</font>");		com.outl("    </td>");		com.outl("  </tr>");		long begin = System.currentTimeMillis();		HashMap portMap;		Map rootMap;		HashMap katMap;		{			HashMap[] hmA = getPortMap();			portMap = hmA[0];			rootMap = hmA[1];			sysnameMap = hmA[2];			katMap = hmA[3];		}		long p1 = System.currentTimeMillis();		HashMap travMap = (HashMap)com.getUser().getData("traverseList");		if (travMap == null) {			travMap = new HashMap();			//com.outl("no trav list found<br>");		}		com.getUser().setData("traverseList", travMap);		// sjekk om vi skal traverese hele ntnunet		boolean expandRoot = false;		{			Boolean b = (Boolean)travMap.get("0");			if (b != null) expandRoot = b.booleanValue();		}		HashMap rootRec = new HashMap();		rootRec.put("to_netboxid", "0");		rootRec.put("vlan", "0");		rootRec.put("rootRec", null);		Set visitSet = new HashSet();		HashSet searchHitSet = new HashSet();		if (com.getp("searchField") != null && com.getp("searchFor").length() > 0) {			String searchF = com.getp("searchField");			String searchFor = com.getp("searchFor");			if (searchFor != null) searchFor = searchFor.trim();			// Remove leading number in searchField			searchF = searchF.substring(searchF.indexOf(".")+1, searchF.length());			// Convert MAC			if ("mac".equals(searchF)) { 				if (searchFor != null) {					if (searchFor.split(":").length == 6) searchFor = util.remove(searchFor, ":");					if (searchFor.split("\\.").length == 6) searchFor = util.remove(searchFor, ".");				}				searchF = "portname";			}			StringTokenizer st = new StringTokenizer(searchF, "|");			String[] searchField = new String[st.countTokens()];			for (int i=0; i < searchField.length; i++) searchField[i] = st.nextToken();			for (Iterator iter=rootMap.values().iterator(); iter.hasNext();) {				HashMap swrec = (HashMap)iter.next();				swportExpand(swrec, rootRec, 0, !iter.hasNext(), expandRoot, showempty, searchexact, showpath, searchblocked, searchField, searchFor, searchHitSet, portMap, travMap, sysnameMap, katMap, visitSet);			}			visitSet.clear();		}		com.out("<table border=0 cellspacing=0 cellpadding=0>\n");		for (Iterator iter=sort(rootMap.values(), SORT_SYSNAME).iterator(); iter.hasNext();) {			HashMap swrec = (HashMap)iter.next();			swportExpand(swrec, rootRec, 0, !iter.hasNext(), expandRoot, showempty, false, showpath, searchblocked, null, null, searchHitSet, portMap, travMap, sysnameMap, katMap, visitSet);		}		long p2 = System.currentTimeMillis();		com.out("</table>\n");		com.outl("<div style=\"font-size: 13\">");		com.outl("<br>Fetch from DB/cache: " + (p1-begin) + " ms. Output HTML: " + (p2-p1) + " ms.");		com.outl("</div>");		firstSearchHit = false;	}	private boolean swportExpand(HashMap swrec, HashMap parentSwrec, int depth, boolean lastPort, boolean expand, boolean showempty, boolean searchexact, boolean showpath, boolean searchblocked, String[] searchField, String searchFor, HashSet searchHitSet, HashMap portMap, HashMap travMap, HashMap sysnameMap, HashMap katMap, Set visitSet)	{		int strekType = (lastPort ? BOXOPEN_BOTTOM : BOXOPEN_BOTH);		if (depth > 24) {			com.outl("<tr><td colspan=50 style=\"font-size: 13\">ERROR, depth too large, return.</td></tr>");			return false;		}		String boksid = (String)swrec.get("netboxid");		String boksbak = (String)swrec.get("to_netboxid");		String kat = (String)swrec.get("catid");		String vlan = (String)swrec.get("vlan");		String key = boksid+":"+vlan;		String keyBak = boksbak+":"+vlan;		String direction = (String)swrec.get("direction");		boolean dirDown = direction == null || !(direction.equals("b") || direction.equals("o"));		boolean searchFound = false;		// sjekk om vi skal traverse videre		boolean traverse = expand;		if (!traverse) {			Boolean b = (Boolean)travMap.get(keyBak);			if (b != null) {				traverse = true;				expand = b.booleanValue();			}		}		List portList = (List)portMap.get(keyBak);		boolean expandable = portList != null && !visitSet.contains(boksbak);		if (searchField == null) {			if (!showempty) {				String bb = (String)swrec.get("to_netboxid");				String portname = (String)swrec.get("portname");				if (bb == null && (portname == null || portname.length() == 0)) return false;			}			// Skriv ut denne noden			if (!expandable) strekType = (lastPort ? STREK_BOTTOM : STREK_BOTH);			else if (!traverse) strekType = (lastPort ? BOXCLOSED_BOTTOM : BOXCLOSED_BOTH);			String searchKey = ((boksbak==null||boksbak.length()==0)?swrec.get("swportid"):boksbak)+":"+vlan;			boolean searchHit = searchHitSet.contains(searchKey);			printNode(swrec, parentSwrec, depth, strekType, searchHit, sysnameMap, katMap);			if (!traverse) return false;		} else {			for (int i=0; i < searchField.length && !searchFound; i++) {				String s = (String)swrec.get(searchField[i]);				if (searchexact) {					if (s != null && s.equalsIgnoreCase(searchFor)) searchFound = true;				} else {					if (s != null && s.toLowerCase().indexOf(searchFor.toLowerCase()) != -1) searchFound = true;				}			}		}		if (searchField != null && searchFound) {			String parentKey = boksid+":"+vlan;			if (swrec.containsKey("parentKey")) parentKey = (String)swrec.get("parentKey");			travMap.put(parentKey, new Boolean(false) );			String searchKey = ((boksbak==null||boksbak.length()==0)?swrec.get("swportid"):boksbak)+":"+vlan;			searchHitSet.add(searchKey);		}		if (depth == 0 && kat != null && kat.equals("GSW")) {			// Vi legger ikke til i visitSet i først rekursjon da vi treffer på samme enhet ett nivå ned		} else		// Pass på at vi ikke går i løkke		if (!visitSet.add(boksbak)) {			return searchFound;		}		if (!dirDown && searchField != null && !searchblocked) {			visitSet.remove(boksbak);			return searchFound;		}		// Hent ut listen over porter tilhørende denne enheten		if (portList == null)		{			visitSet.remove(boksbak);			return searchFound;		}		for (Iterator it=sort(portList, SORT_IFINDEX).iterator(); it.hasNext();) {			HashMap port = (HashMap)it.next();			boolean b = swportExpand(port, swrec, depth+1, it.hasNext(), expand, showempty, searchexact, showpath, searchblocked, searchField, searchFor, searchHitSet, portMap, travMap, sysnameMap, katMap, visitSet);			if (searchField != null && b) searchFound = true;		}		visitSet.remove(boksbak);		if (searchField != null && searchFound) {			key = boksid+":"+vlan;			travMap.put(key, new Boolean(false) );		}		return searchFound;	}	private void printNode(HashMap swrec, HashMap parentrec, int depth, int strekType, boolean searchHit, HashMap sysnameMap, HashMap katMap)	{		String imgRoot = "<img border=0 src=\"" + gfxRoot + "/";		String expandIcon = imgRoot + "expand.gif" + "\" alt=\"Expand entire branch\">";		String expandGrayIcon = imgRoot + "expand-gray.gif" + "\" alt=\"No branches to expand\">";		String portIcon = imgRoot + "porticon" + ("t".equals(swrec.get("trunk"))?"-trunk":"") + ".gif" + "\">";		String redCross = imgRoot + "redcross.gif" + "\">";		String strekVertical = imgRoot + "strek.gif" + "\">";		String strekBoth = imgRoot + "strek_both.gif" + "\">";		String strekBottom = imgRoot + "strek_bottom.gif" + "\">";		String boxOpenBoth = imgRoot + "boxopen_both.gif" + "\">";		String boxOpenBottom = imgRoot + "boxopen_bottom.gif" + "\">";		String boxClosedBoth = imgRoot + "boxclosed_both.gif" + "\">";		String boxClosedBottom = imgRoot + "boxclosed_bottom.gif" + "\">";		String hubImg = imgRoot + "hub.gif" + "\">";		String dumhubImg = imgRoot + "dumhub.gif" + "\">";		String switchImg = imgRoot + "switch.gif" + "\">";		String routerImg = imgRoot + "router.gif" + "\">";		String serverImg = imgRoot + "server.gif" + "\">";		String maskinImg = imgRoot + "maskin.gif" + "\">";		String undefImg = imgRoot + "undef.gif" + "\">";		String arrowIcon = imgRoot + "arrow.gif" + "\">";		String arrowUpIcon = imgRoot + "arrow-up.gif" + "\">";		String arrowDownIcon = imgRoot + "arrow-down.gif" + "\">";		String arrowBlockIcon = imgRoot + "arrow-block.gif" + "\">";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -