[jboss-cvs] JBossAS SVN: r111655 - branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 22 17:05:51 EDT 2011


Author: thauser at redhat.com
Date: 2011-06-22 17:05:51 -0400 (Wed, 22 Jun 2011)
New Revision: 111655

Modified:
   branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
Log:
added rudimentary check for wildcard support in the attributes.xml

Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2011-06-22 18:46:01 UTC (rev 111654)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java	2011-06-22 21:05:51 UTC (rev 111655)
@@ -27,6 +27,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.SortedMap;
 import java.util.SortedSet;
 import java.util.TreeMap;
@@ -625,22 +626,61 @@
 
 		addAttributeMappings(mappings);
    }
+	
+	/**
+	 * hacked together method that iterates through a list of object names and adds metrics to the 
+	 * bind entry set 
+	 * @param mbeanNames Set of ObjectNames associated with a wildcard ObjectName
+	 * @param attrs List of attributes that we want to know about for each entry in mbeanNames
+	 * @param oidPrefix the oidPrefix for each of these, because Ideally we are creating a table.
+	 */
+	
+	private void createTableRows(Set<ObjectName> mbeanNames, List<MappedAttribute> attrs, String tableOid){
+		ArrayList<String> onameStrings = new ArrayList<String>(1);
+		for (ObjectName oname : mbeanNames){
+			onameStrings.add(oname.toString());
+		}
+		for (String mbeanRealName : onameStrings){
+			for (MappedAttribute ma : attrs){
+				String oid;
+				if (tableOid != null){
+					oid = tableOid + ma.getOid();
+					addObjectEntry(new OID(tableOid));
+				}else{
+					oid = ma.getOid();
+					OID objectOID = new OID(oid);
+					addObjectEntry(objectOID.trim());
+				}
+				addBindEntry(oid, mbeanRealName, ma.getName(), ma.isReadWrite());
+			}
+		}
+	}
 
 	/**
 	 * @param mappings
 	 */
 	public void addAttributeMappings(List<ManagedBean> mappings) {
 		Iterator<ManagedBean> it = mappings.iterator();
+		ObjectName oname = null;
 		while (it.hasNext()) {
+			// here we add a check for the mbean name being a pattern. if it is, we need to 
+			// do some additional operations
 			ManagedBean mmb = it.next();
+			try{
+				oname = new ObjectName(mmb.getName());
+			} catch (Exception e) {}
+			if (oname.isPattern()){ //it is a pattern. the mat
+				Set<ObjectName> mbeanNames = server.queryNames(oname, null); // get all ObjectNames of MBeans matched by the given name. they should be treated
+				// as Rows of the table defined which will have the oid oidPrefix.
+				createTableRows(mbeanNames, mmb.getAttributes(), mmb.getOidPrefix());
+			}
+			else {
 			String oidPrefix = mmb.getOidPrefix();
 			List attrs = mmb.getAttributes();
 			Iterator aIt = attrs.iterator();
 			while (aIt.hasNext()) {
 				Object check = aIt.next();
-
 				MappedAttribute ma = (MappedAttribute) check;
-
 				String oid;
 				if (oidPrefix != null) {
 					oid = oidPrefix + ma.getOid();
@@ -650,10 +690,10 @@
 					OID objectOID = new OID(oid);
 					addObjectEntry(objectOID.trim());
 				}
+						addBindEntry(oid, mmb.getName(), ma.getName(), ma.isReadWrite());
+				}//end while
+			}
 
-				addBindEntry(oid, mmb.getName(), ma.getName(), ma.isReadWrite());
-
-			}
 		}
 	}
 	



More information about the jboss-cvs-commits mailing list