[jboss-cvs] JBossAS SVN: r111654 - 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 14:46:01 EDT 2011
Author: thauser at redhat.com
Date: 2011-06-22 14:46:01 -0400 (Wed, 22 Jun 2011)
New Revision: 111654
Modified:
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
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/RequestHandlerSupport.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
Log:
remove refactoring. begin trying to get wildcards working.
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2011-06-22 18:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandler.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -22,7 +22,6 @@
package org.jboss.jmx.adaptor.snmp.agent;
import java.util.List;
-import java.util.SortedMap;
import javax.management.MBeanServer;
@@ -50,10 +49,8 @@
*/
void initialize(String resourceName, MBeanServer server, Logger loggger, Clock uptime)
throws Exception;
-
- SortedMap getBindings();
+
void addAttributeMappings(List<ManagedBean> mappings);
void removeAttributeMappings(List<ManagedBean> mappings);
-
} // RequestHandler
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:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -102,11 +102,6 @@
oidKeys = new TreeSet();
objectKeys = new TreeSet();
}
-
- // expose the bindings map, for use by the TrapFactory
- public SortedMap getBindings(){
- return this.bindings;
- }
// RequestHandler Implementation ---------------------------------
@@ -301,8 +296,7 @@
* error indications. Both the error type (ErrorStatus) and error index (the binding in the
* PDU being processed that caused the error are returned.)
*/
- public PDU snmpReceivedGet (PDU pdu)
- {
+ public PDU snmpReceivedGet (PDU pdu) {
PDU response;
// this counts the number of VariableBindings and indicates which one caused a problem, if any
int errorIndex = 1;
@@ -347,12 +341,10 @@
newVB = new VariableBinding(noid);
try {
var = getValueFor(noid);
- }
- catch (NoSuchInstanceException e) {
+ } catch (NoSuchInstanceException e) {
log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
var = Null.noSuchInstance;
- }
- catch (VariableTypeException e) {
+ } catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GETNEXT operation could not convert the returned value for " + noid + " into an appropriate type.");
makeErrorPdu(response, pdu, errorIndex, PDU.genErr);
return response;
@@ -367,17 +359,15 @@
if (checkObject(oid)){
try {
var = getValueFor(oid);
- }
- catch (NoSuchInstanceException e) {
+ } catch (NoSuchInstanceException e) {
log.debug("snmpReceivedGet: GET operation returned null. No such Instance.");
var = Null.noSuchInstance;
- }
- catch (VariableTypeException e) {
+ } catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GET operation could not convert the returned value for " + oid + " into an appropriate type.");
makeErrorPdu(response, pdu, errorIndex, PDU.genErr);
return response;
- }
+ }
}
// if we get here, there's no such object.
@@ -723,7 +713,7 @@
private void addBindEntry(String oid, String mmb, String ma, boolean rw){
BindEntry be = new BindEntry(oid, mmb, ma);
- be.setReadWrite(rw);
+ be.isReadWrite = rw;
OID coid = new OID(oid);
if (log.isTraceEnabled())
@@ -776,14 +766,14 @@
log.debug("getValueFor: Found entry " + be.toString() + " for oid " + oid);
try {
- Object val = server.getAttribute(be.getMbean(), be.getAttr().getName());
+ Object val = server.getAttribute(be.mbean, be.attr.getName());
ssy = prepForPdu(val);
} catch (VariableTypeException e){
log.debug("getValueFor: didn't find a suitable data type for the requested data");
throw e;
} catch (Exception e) {
- log.warn("getValueFor: (" + be.getMbean().toString() + ", "
- + be.getAttr().getName() + ": " + e.toString());
+ log.warn("getValueFor: (" + be.mbean.toString() + ", "
+ + be.attr.getName() + ": " + e.toString());
}
} else {
log.debug("getValueFor: " + NO_ENTRY_FOUND_FOR_OID + oid);
@@ -904,7 +894,7 @@
if (trace)
log.trace("setValueFor: " + be.toString());
- if (be.isReadWrite() == false)
+ if (be.isReadWrite == false)
{
if (trace)
log.trace("setValueFor: this is marked read only");
@@ -913,7 +903,7 @@
}
try
{
- Object other = server.getAttribute(be.getMbean(), be.getAttr().getName());
+ Object other = server.getAttribute(be.mbean, be.attr.getName());
Object val = convertVariableToValue(newVal, other);
if (other != null && val.getClass() != other.getClass() ){
@@ -921,8 +911,8 @@
ssy = newVal;
}
- Attribute at = new Attribute(be.getAttr().getName(), val);
- server.setAttribute(be.getMbean(), at);
+ Attribute at = new Attribute(be.attr.getName(), val);
+ server.setAttribute(be.mbean, at);
if (trace)
log.trace("setValueFor: set attribute in mbean server");
@@ -1071,9 +1061,9 @@
/** This utility method is used to construct an error PDU. This code
* was repeated so many times it was prudent to give it it's own method.
* @param response This PDU is the one being modified into an error PDU.
- * @param pdu The Offending PDU, to grab VariableBinding list from it
- * @param errIndex the VariableBinding in the PDU that caused the error.
- * @param errNo The error number defined in the PDU class that indicates a given failure
+ * @param oid The OID to contain the error Null instance.
+ * @param errIndex the VariableBinding in the PDU that caused the error.
+ * @param errNo The error number defined in the PDU class that indicates a given failure
*/
private void makeErrorPdu(PDU response, PDU pdu, int errIndex, int errNo){
response.clear();
@@ -1081,5 +1071,121 @@
response.setErrorIndex(errIndex);
response.setErrorStatus(errNo);
}
+
+ // Inner Class ---------------------------------------------------
+
+ /**
+ * An entry containing the mapping between oid and mbean/attribute
+ *
+ * @author <a href="mailto:pilhuhn at user.sf.net>">Heiko W. Rupp</a>
+ */
+ private class BindEntry implements Comparable {
+ private final OID oid;
+
+ private ObjectName mbean;
+ private Attribute attr;
+ private String mName;
+ private String aName;
+ private boolean isReadWrite = false;
+
+ /**
+ * Constructs a new BindEntry
+ *
+ * @param oid
+ * The SNMP-oid, this entry will use.
+ * @param mbName
+ * The name of an MBean with attribute to query
+ * @param attrName
+ * The name of the attribute to query
+ */
+ BindEntry(final String oidString, final String mbName, final String attrName) {
+ this(new OID(oidString),
+ mbName,
+ attrName);
+ }
+
+ /**
+ * Constructs a new BindEntry.
+ * @param coid The SNMP-oid, this entry will use.
+ * @param mbName The name of an MBean with attribute to query
+ * @param attrName The name of the attribute to query
+ */
+ BindEntry(final OID coid, final String mbName, final String attrName) {
+ oid = coid;
+ this.mName = mbName;
+ this.aName = attrName;
+ try
+ {
+ mbean = new ObjectName(mbName);
+ attr = new Attribute(attrName, null);
+
+ }
+ catch (Exception e)
+ {
+ log.warn(e.toString());
+ mName = "-unset-";
+ aName = "-unset-";
+ }
+ }
+
+ /**
+ * A string representation of this BindEntry
+ */
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("[oid=");
+ buf.append(oid).append(", mbean=");
+ buf.append(mName).append(", attr=");
+ buf.append(aName).append(", rw=");
+ buf.append(isReadWrite).append("]");
+
+ return buf.toString();
+ }
+
+ public Attribute getAttr() {
+ return attr;
+ }
+
+ public ObjectName getMbean()
+ {
+ return mbean;
+ }
+
+ public OID getOid()
+ {
+ return oid;
+ }
+
+
+ /**
+ * Compare two BindEntries. Ordering is defined at oid-level.
+ *
+ * @param other
+ * The BindEntry to compare to.
+ * @return 0 on equals, 1 if this is bigger than other
+ */
+ public int compareTo(Object other)
+ {
+ if (other == null)
+ throw new NullPointerException("Can't compare to NULL");
+
+ if (!(other instanceof BindEntry))
+ throw new ClassCastException("Parameter is no BindEntry");
+
+ // trivial case
+ if (this.equals(other))
+ return 0;
+
+ BindEntry obe = (BindEntry) other;
+// if (getOid().equals(obe.getOid()))
+// return 0;
+
+ int res =oid.compareTo(obe.getOid());
+ return res;
+ }
+
+ }
+
+
}
\ No newline at end of file
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2011-06-22 18:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -29,7 +29,6 @@
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.smi.OctetString;
-import java.util.SortedMap;
/**
* Implement RequestHandler with simple tracing of incoming requests.
@@ -56,7 +55,6 @@
/** the agent clock */
protected Clock clock;
-
// Constructors --------------------------------------------------
/**
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-06-22 18:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapEmitter.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -130,9 +130,7 @@
// Initialise
this.trapFactory.set(this.snmpAgentService.getClock(),
- this.snmpAgentService.getTrapCounter(),
- this.snmpAgentService.getRequestHandler().getBindings(),
- this.snmpAgentService.getServer());
+ this.snmpAgentService.getTrapCounter());
// Start the trap factory
this.trapFactory.start();
@@ -407,11 +405,8 @@
} catch (Exception e) {
log.error("Accessing resource '" + snmpAgentService.getNotificationMapResName() + "'");
throw e;
- }
- finally
- {
- if (is != null)
- {
+ } finally {
+ if (is != null) {
// close the XML stream
is.close();
}
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-06-22 18:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactory.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -72,7 +72,7 @@
* Sets the name of the file containing the notification/trap mappings,
* the uptime clock and the trap counter
**/
- public void set(Clock uptime, Counter count, SortedMap bindings, MBeanServer server);
+ public void set(Clock uptime, Counter count);
/**
* Performs all the required initialisation in order for the mapper to
Modified: branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java
===================================================================
--- branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-06-22 18:44:20 UTC (rev 111653)
+++ branches/snmp4j-int/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/TrapFactorySupport.java 2011-06-22 18:46:01 UTC (rev 111654)
@@ -94,10 +94,10 @@
private Counter trapCount = null;
/** attributes gathered from attributes.xml, used for bindings **/
- private SortedMap bindings = null;
+// private SortedMap bindings = null;
/** MBeanServer instance to query about BindEntry objects contained in the bindings map**/
- private MBeanServer server = null;
+// private MBeanServer server = null;
/**
* Create TrapFactorySupport
@@ -111,12 +111,12 @@
* Sets the name of the file containing the notification/trap mappings,
* the uptime clock and the trap counter
**/
- public void set(Clock clock, Counter count, SortedMap bindings, MBeanServer server)
+ public void set(Clock clock, Counter count)
{
this.clock = clock;
this.trapCount = count;
- this.bindings = bindings;
- this.server = server;
+// this.bindings = bindings;
+// this.server = server;
}
/**
More information about the jboss-cvs-commits
mailing list