[jboss-cvs] JBossAS SVN: r110356 - branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 13 15:19:55 EST 2011
Author: thauser at redhat.com
Date: 2011-01-13 15:19:54 -0500 (Thu, 13 Jan 2011)
New Revision: 110356
Modified:
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
Log:
remove the passing of exceptions out of the agent. instead use PDUs with error codes, as should be done.
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-01-13 19:31:17 UTC (rev 110355)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerImpl.java 2011-01-13 20:19:54 UTC (rev 110356)
@@ -305,7 +305,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) throws NoSuchOidException, EndOfMibViewException
+ public PDU snmpReceivedGet (PDU pdu)
{
PDU response;
// this counts the number of VariableBindings and indicates which one caused a problem, if any
@@ -342,20 +342,17 @@
// we get the lexically next OID from the given one.
try{
noid = getNextOid(oid);
-
}
catch(NoSuchOidException e){
log.debug("snmpReceivedGet: GETNEXT operation couldn't find given oid.");
- throw e;
-/* makeErrorPdu(noid,PDU.noSuchName,counter,response);
- return response;*/
+ makeErrorPdu(noid,PDU.noSuchName,counter,response);
+ return response;
}
// if this OID is the last one possible, we throw this exception.
catch(EndOfMibViewException e){
log.debug("snmpReceivedGet: GETNEXT operation left the OID subtree");
- throw e;
- /*response.add(new VariableBinding(noid,Null.endOfMibView));
- continue;*/
+ makeErrorPdu(oid,PDU.noAccess, counter,response);
+ return response;
}
/* if (noid == null){
// this reaction should be factored out.
@@ -371,13 +368,11 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GETNEXT operation returned null. No such OID.");
- throw e;/*
makeErrorPdu(noid, PDU.noSuchName, counter,response);
- return response;*/
+ return response;
}
catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GETNEXT operation could not convert the returned value for " + noid + " into an appropriate type.");
- // throw e;
makeErrorPdu(noid,PDU.badValue, counter,response);
return response;
@@ -393,29 +388,14 @@
}
catch (NoSuchOidException e) {
log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
- throw e;
- //response.setErrorIndex(counter);
- //response.setErrorStatus(PDU.noSuchName);
- //response.add(new VariableBinding(oid,Null.noSuchObject));
- /*makeErrorPdu(oid, PDU.noSuchName, counter, response);
- return response;*/
- //return makeErrorPdu(oid, PDU.noSuchName, counter);
+ makeErrorPdu(oid, PDU.noSuchName, counter, response);
+ return response;
}
catch (VariableTypeException e) {
log.debug("snmpReceivedGet: GET operation could not convert the returned value for " + oid + " into an appropriate type.");
makeErrorPdu(oid, PDU.badValue, counter,response);
return response;
}
- // the OID we are looking for has no BindEntry. Indicate this in the returned pdu.
- // and abort immediately.
- //* probably no longer needed *//
-/* if (var instanceof Null){
- log.debug("snmpReceivedGet: GET operation returned null. No such OID.");
- response.setErrorStatus(PDU.noSuchName);
- response.setErrorIndex(counter);
- response.add(new VariableBinding(oid, Null.noSuchObject));
- return response;
- }*/
}
newVB.setVariable(var);
response.add(newVB);
@@ -440,7 +420,7 @@
* or a PDU with an empty VB List and an error status indicating why the operation failed,
* and which PDU was problematic.
*/
- public PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException
+ public PDU snmpReceivedSet(PDU pdu)
{
PDU response;
// the modified OID entries so far.
@@ -467,13 +447,13 @@
if (pdu != null){
//iterate through the VB in this PDU
- Iterator it = pdu.getVariableBindings().iterator();
+ Iterator<VariableBinding> it = pdu.getVariableBindings().iterator();
while (it.hasNext()){
// if any set fails for any reason, changes must be undone.
// so changes that pass all tests should be stored, and all applied
// after each VB has been checked.
- VariableBinding vb = (VariableBinding)it.next();
+ VariableBinding vb = it.next();
OID oid = vb.getOid();
Variable newVal = vb.getVariable();
//setup the new variable binding to put into the response pdu
@@ -489,20 +469,16 @@
catch (NoSuchOidException e){
log.debug("snmpReceivedSet: attempt to set a non-existent OID " + oid);
undoSets(modified);
- throw e;
-/* makeErrorPdu(oid, PDU.noSuchName,counter,response);
- return response;*/
- //maybe factor out later: pdu = makeErrorPdu(oid, errorIndex, errorStatus, vb);
+ makeErrorPdu(oid, PDU.noSuchName,counter,response);
+ return response;
}
catch (VariableTypeException e){
log.debug("snmpReceievedSet: could not convert the given value into an appropriate type: " +newVal);
undoSets(modified);
- throw e;
- /*makeErrorPdu(oid, PDU.badValue, counter, response);
- return response;*/
+ makeErrorPdu(oid, PDU.badValue, counter, response);
+ return response;
}
catch (ReadOnlyException e){
- // this reaction needs to be turned into an exception in all cases.
log.debug("snmpReceivedSet: attempt to set a read-only attribute: " + newVB);
undoSets(modified);
makeErrorPdu(oid, PDU.readOnly, counter, response);
@@ -708,6 +684,8 @@
else{
oid = mat.getOid();
}
+ // we shouldn't be using this, because we aren't mapping a table row to a JMX attribute.
+ // we should just be storing the name of the table, since it's just a conceptual ordering anyways.
addBindEntry(oid,mmb.getName(),mat.getName(),mat.isReadWrite());
}
}
@@ -729,6 +707,14 @@
}
}
+ /**
+ *
+ * @param oid The OID bound to this particular attribute
+ * @param mmb the name of the MBean server
+ * @param ma the name of the MBeam attribute the OID is concerning
+ * @param rw indicates whether this Attribute is read-write or not (readonly if false)
+ */
+
private void addBindEntry(String oid, String mmb, String ma, boolean rw){
BindEntry be = new BindEntry(oid, mmb, ma);
be.isReadWrite = rw;
@@ -811,7 +797,7 @@
private Variable prepForPdu(final Object val) throws VariableTypeException{
Variable result = null;
- //TODO: all types managed by the PDU
+ //TODO: all types managed by the PDU
if (val instanceof Long)
{
result = new Counter32((Long)val);
@@ -981,8 +967,7 @@
/**
- * Lookup a BindEntry on the given oid. If the oid ends in .0,
- * then the .0 will be stripped of before the search.
+ * Lookup a BindEntry on the given oid.
*
* @param oid The oid look up.
* @return a bind entry or null.
@@ -1026,7 +1011,6 @@
/**
* Return the next oid that is larger than ours.
* @param oid the starting oid
- * @param stayInSubtree if true, the next oid will not have a different prefix than the one of oid.
* @return the next oid or null if none found.
* @throws NoSuchOidException if request is given an OID that doesn't exist in the first place
* @throws EndOfMibViewException if there is no greater OID than the given, valid, oid.
@@ -1078,7 +1062,7 @@
}
// Check if still in subtree if requested to stay within
-
+ // THIS SHOULD BE A MANAGER FUNCTION, NOT AGENT.
/* if (stayInSubtree && roid != null)
{
//OID parent = coid.removeLast();
@@ -1094,11 +1078,14 @@
/** 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
- *
+ * @param response This PDU is the one being modified into an error PDU.
+ * @param oid The OID to contain the error Null instance.
+ * @param errNo The error number defined in the PDU class that indicates a given failure
+ * @param errInd the VariableBinding in the PDU that caused the error.
*/
private void makeErrorPdu(OID oid, int errNo, int errInd, PDU response){
OID retOID;
+ response.clear(); // prep PDU for being an error PDU
if (oid == null){
retOID=new OID("");
}
@@ -1117,10 +1104,11 @@
case PDU.wrongValue:
response.add(new VariableBinding(retOID, Null.noSuchInstance));
break;
+ case PDU.noAccess:
+ response.add(new VariableBinding(retOID, Null.endOfMibView));
case PDU.readOnly:
case PDU.tooBig:
case PDU.genErr:
- case PDU.noAccess:
case PDU.wrongType:
case PDU.wrongLength:
case PDU.wrongEncoding:
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2011-01-13 19:31:17 UTC (rev 110355)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/RequestHandlerSupport.java 2011-01-13 20:19:54 UTC (rev 110356)
@@ -102,7 +102,7 @@
public PDU snmpReceivedGetBulk(PDU pdu){
return null;
}
- public PDU snmpReceivedGet(PDU pdu) throws NoSuchOidException, EndOfMibViewException
+ public PDU snmpReceivedGet(PDU pdu)
{return null;
// SnmpPduRequest response = null;
// int pduLength = pdu.getLength();
@@ -163,7 +163,7 @@
* @return SnmpPduRequest filled in with the proper response, or null if cannot process
* NOTE: this might be changed to throw an exception.
*/
- public PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException
+ public PDU snmpReceivedSet(PDU pdu)
{
return null;
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java 2011-01-13 19:31:17 UTC (rev 110355)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpAgentRequestHandler.java 2011-01-13 20:19:54 UTC (rev 110356)
@@ -48,7 +48,7 @@
*
* NOTE: this might be changed to throw an exception.
*/
-PDU snmpReceivedGet(PDU pdu) throws NoSuchOidException, EndOfMibViewException;
+PDU snmpReceivedGet(PDU pdu);
/**
* <P> This method handles SNMP Get Bulk requests received by the session
@@ -74,7 +74,7 @@
* @return PDU filled in with the proper response, or null if cannot process
* NOTE: this might be changed to throw an exception.
*/
-PDU snmpReceivedSet(PDU pdu) throws NoSuchOidException, VariableTypeException;
+PDU snmpReceivedSet(PDU pdu);
//ResponseEvent maybe
///**
Modified: branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java
===================================================================
--- branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java 2011-01-13 19:31:17 UTC (rev 110355)
+++ branches/snmp4j-integration-1.11.1/varia/src/main/java/org/jboss/jmx/adaptor/snmp/agent/SnmpRequest.java 2011-01-13 20:19:54 UTC (rev 110356)
@@ -47,27 +47,14 @@
//switch based on pdu.getType() == ___
switch (type) {
case PDU.GET:
- // TODO: this needs to catch NoSuchOidException, VariableTypeException, and EndOfMibViewException
case PDU.GETNEXT:
- try{
response = requestHandler.snmpReceivedGet(pdu);
- }
- catch(Exception e){
- log.debug("processPDU caugh Exception " + e + " in GETNEXT code.");
- return;
- }
break;
case PDU.GETBULK:
response = requestHandler.snmpReceivedGetBulk(pdu);
break;
case PDU.SET:
- // TODO: this needs to catch NoSuchOidException, and VariableTypeException
- try{
response = requestHandler.snmpReceivedSet(pdu);
- }
- catch(Exception e){
- log.debug("processPDU caught Exception " + e + " in SET code.");
- }
break;
default:
log.warn("Cannot process request PDU of type: " +
More information about the jboss-cvs-commits
mailing list