use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method set.
/**
* Set the value of an SNMP variable.
*
* <p><b><i>
* You should never need to use this method directly.
* </i></b></p>
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* @return The new value of the variable after the operation.
*
* @exception SnmpStatusException whenever an SNMP exception must be
* raised. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Attribute att = new Attribute(attname, attvalue);
Object result = null;
try {
server.setAttribute(name, att);
result = server.getAttribute(name, attname);
} catch (InvalidAttributeValueException iv) {
throw new SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
} catch (InstanceNotFoundException f) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
return meta.buildSnmpValue(id, result);
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method check.
/**
* Checks whether a SET operation can be performed on a given SNMP
* variable.
*
* @param meta The impacted metadata object
* @param name The ObjectName of the impacted MBean
* @param x The new requested SnmpValue
* @param id The OID arc identifying the variable we're trying to set.
* @param data User contextual data allocated through the
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
*
* <p>
* This method calls checkSetAccess() on the meta object, and then
* tries to invoke the check<i>AttributeName</i>() method on the MBean.
* If this method is not defined then it is assumed that the SET
* won't fail.
* </p>
*
* <p><b><i>
* This method is called internally by <code>mibgen</code> generated
* objects and you should never need to call it directly.
* </i></b></p>
*
* @exception SnmpStatusException if the requested SET operation must
* be rejected. Raising an exception will abort the request. <br>
* Exceptions should never be raised directly, but only by means of
* <code>
* req.registerCheckException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
*
**/
// XXX xxx ZZZ zzz Maybe we should go through the MBeanInfo here?
public void check(SnmpGenericMetaServer meta, ObjectName name, SnmpValue x, long id, Object data) throws SnmpStatusException {
meta.checkSetAccess(x, id, data);
try {
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, x);
final Object[] params = new Object[1];
final String[] signature = new String[1];
params[0] = attvalue;
signature[0] = attvalue.getClass().getName();
server.invoke(name, "check" + attname, params, signature);
} catch (SnmpStatusException e) {
throw e;
} catch (InstanceNotFoundException i) {
throw new SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
} catch (ReflectionException r) {
// checkXXXX() not defined => do nothing
} catch (MBeanException m) {
Exception t = m.getTargetException();
if (t instanceof SnmpStatusException)
throw (SnmpStatusException) t;
throw new SnmpStatusException(SnmpStatusException.noAccess);
} catch (Exception e) {
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method findNextHandlingNode.
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode. The algorithm is very
// largely inspired from the original getNext() method.
//
// ---------------------------------------------------------------------
@Override
final synchronized long[] findNextHandlingNode(SnmpVarBind varbind, long[] oid, int pos, int depth, SnmpRequestTree handlers, AcmChecker checker) throws SnmpStatusException {
int length = oid.length;
if (handlers == null) {
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
final Object data = handlers.getUserData();
final int pduVersion = handlers.getRequestPduVersion();
long var = -1;
//
if (pos >= length) {
// this will have the side effect to set
// oid[pos] = nodeId
// and
// (pos+1) = length
// so we won't fall into the "else if" cases below -
// so using "else if" rather than "if ..." is guaranteed
// to be safe.
//
oid = new long[1];
oid[0] = nodeId;
pos = 0;
length = 1;
} else if (oid[pos] > nodeId) {
//
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
} else if (oid[pos] < nodeId) {
// we must return the first leaf under the first columnar
// object, so we are back to our first case where pos was
// out of bounds... => reset the oid to contain only the
// arc of the xxxEntry object.
//
oid = new long[1];
oid[0] = nodeId;
pos = 0;
length = 0;
} else if ((pos + 1) < length) {
// The arc at the position "pos+1" is the id of the columnar
// object (ie: the id of the variable in the table entry)
//
var = oid[pos + 1];
}
// Now that we've got everything right we can begin.
SnmpOid entryoid;
if (pos == (length - 1)) {
// pos points to the last arc in the oid, and this arc is
// guaranteed to be the xxxEntry id (we have handled all
// the other possibilities before)
//
// We must therefore return the first leaf below the first
// columnar object in the table.
//
// Get the first index. If an exception is raised,
// then it means that the table is empty. We thus do not
// have to catch the exception - we let it propagate to
// the caller.
//
entryoid = getNextOid(data);
var = getNextVarEntryId(entryoid, var, data, pduVersion);
} else if (pos == (length - 2)) {
// In that case we have (pos+1) = (length-1), so pos
// points to the arc of the querried variable (columnar object).
// Since the requested oid stops there, it means we have
// to return the first leaf under this columnar object.
//
// So we first get the first index:
// Note: if this raises an exception, this means that the table
// is empty, so we can let the exception propagate to the caller.
//
entryoid = getNextOid(data);
//
if (skipEntryVariable(entryoid, var, data, pduVersion)) {
var = getNextVarEntryId(entryoid, var, data, pduVersion);
}
} else {
//
try {
entryoid = getNextOid(oid, pos + 2, data);
//
if (skipEntryVariable(entryoid, var, data, pduVersion)) {
throw new SnmpStatusException(SnmpStatusException.noSuchObject);
}
} catch (SnmpStatusException se) {
entryoid = getNextOid(data);
var = getNextVarEntryId(entryoid, var, data, pduVersion);
}
}
return findNextAccessibleOid(entryoid, varbind, oid, depth, handlers, checker, data, var);
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method getNextOid.
/**
* Get the <CODE>SnmpOid</CODE> index of the row that follows
* the given <CODE>oid</CODE> in the table. The given <CODE>
* oid</CODE> does not need to be a valid row OID index.
*
* <p>
* @param oid The OID from which the search will begin.
*
* @param userData A contextual object containing user-data.
* This object is allocated through the <code>
* {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
* for each incoming SNMP request.
*
* @return The next <CODE>SnmpOid</CODE> index.
*
* @exception SnmpStatusException There is no index following the
* specified <CODE>oid</CODE> in the table.
*/
protected SnmpOid getNextOid(SnmpOid oid, Object userData) throws SnmpStatusException {
if (size == 0) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
final SnmpOid resOid = oid;
// Just a simple check to speed up retrieval of last element ...
//
// XX SnmpOid last= (SnmpOid) oids.lastElement();
SnmpOid last = tableoids[tablecount - 1];
if (last.equals(resOid)) {
//
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// First find the oid. This will allow to speed up retrieval process
// during smart discovery of table (using the getNext) as the
// management station will use the valid index returned during a
// previous getNext ...
//
// Returns the position following the position at which resOid
// is found, or the position at which resOid should be inserted.
//
final int newPos = getInsertionPoint(resOid, false);
//
if (newPos > -1 && newPos < size) {
try {
// XX last = (SnmpOid) oids.elementAt(newPos);
last = tableoids[newPos];
} catch (ArrayIndexOutOfBoundsException e) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
} else {
//
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
return last;
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibGroup method findHandlingNode.
// -------------------------------------------------------------------
// see comments in SnmpMibNode
// -------------------------------------------------------------------
@Override
void findHandlingNode(SnmpVarBind varbind, long[] oid, int depth, SnmpRequestTree handlers) throws SnmpStatusException {
int length = oid.length;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
final Object data = handlers.getUserData();
if (depth >= length) {
// Nothing is left... the oid is not valid
throw new SnmpStatusException(SnmpStatusException.noAccess);
}
long arc = oid[depth];
if (isNestedArc(arc)) {
// This arc leads to a subgroup: delegates the search to the
// method defined in SnmpMibOid
super.findHandlingNode(varbind, oid, depth, handlers);
} else if (isTable(arc)) {
// This arc leads to a table: forward the search to the table.
// Gets the table
SnmpMibTable table = getTable(arc);
// Forward the search to the table
table.findHandlingNode(varbind, oid, depth + 1, handlers);
} else {
// If it's not a variable, throws an exception
validateVarId(arc, data);
// The trailing .0 is missing in the OID
if (depth + 2 > length) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// a single trailing .0)
if (depth + 2 < length) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// The last trailing arc is not .0
if (oid[depth + 1] != 0L) {
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
}
// It's one of our variable, register this node.
handlers.add(this, depth, varbind);
}
}
Aggregations