use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpGenericObjectServer method set.
/**
* Execute an SNMP SET request.
*
* <p>
* This method first builds the list of attributes that need to be
* set on the MBean and then calls setAttributes() on the
* MBean server. Then it updates the SnmpMibSubRequest with the new
* values retrieved from the MBean.
* </p>
*
* <p>
* The SNMP metadata information is obtained through the given
* <code>meta</code> object, which usually is an instance of a
* <code>mibgen</code> generated class.
* </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>
*
* @param meta The metadata object impacted by the subrequest
* @param name The ObjectName of the MBean impacted by this subrequest
* @param req The SNMP subrequest to execute on the MBean
* @param depth The depth of the SNMP object in the OID tree.
*
* @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.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
* </code>
**/
public void set(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final int size = req.getSize();
final AttributeList attList = new AttributeList(size);
final String[] nameList = new String[size];
final SnmpVarBind[] varList = new SnmpVarBind[size];
final long[] idList = new long[size];
int i = 0;
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
final long id = var.oid.getOidArc(depth);
final String attname = meta.getAttributeName(id);
final Object attvalue = meta.buildAttributeValue(id, var.value);
final Attribute att = new Attribute(attname, attvalue);
attList.add(att);
nameList[i] = attname;
varList[i] = var;
idList[i] = id;
i++;
} catch (SnmpStatusException x) {
req.registerSetException(var, x);
}
}
AttributeList result;
int errorCode = SnmpStatusException.noAccess;
try {
result = server.setAttributes(name, attList);
} catch (InstanceNotFoundException f) {
result = new AttributeList();
errorCode = SnmpStatusException.snmpRspInconsistentName;
} catch (ReflectionException r) {
errorCode = SnmpStatusException.snmpRspInconsistentName;
result = new AttributeList();
} catch (Exception x) {
result = new AttributeList();
}
final Iterator<?> it = result.iterator();
for (int j = 0; j < i; j++) {
if (!it.hasNext()) {
final SnmpStatusException x = new SnmpStatusException(errorCode);
req.registerSetException(varList[j], x);
continue;
}
final Attribute att = (Attribute) it.next();
while ((j < i) && (!nameList[j].equals(att.getName()))) {
final SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
req.registerSetException(varList[j], x);
j++;
}
if (j == i)
break;
try {
varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
} catch (SnmpStatusException x) {
req.registerSetException(varList[j], x);
}
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpStandardObjectServer method get.
/**
* Generic handling of the <CODE>get</CODE> operation.
* <p> The default implementation of this method is to loop over the
* varbind list associated with the sub-request and to call
* <CODE>get(var.oid.getOidArc(depth), data);</CODE>
* <pre>
* public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
* int depth)
* throws SnmpStatusException {
*
* final Object data = req.getUserData();
*
* for (Enumeration e= req.getElements(); e.hasMoreElements();) {
*
* final SnmpVarBind var= (SnmpVarBind) e.nextElement();
*
* try {
* // This method will generate a SnmpStatusException
* // if `depth' is out of bounds.
* //
* final long id = var.oid.getOidArc(depth);
* var.value = meta.get(id, data);
* } catch(SnmpStatusException x) {
* req.registerGetException(var,x);
* }
* }
* }
* </pre>
* <p> You can override this method if you need to implement some
* specific policies for minimizing the accesses made to some remote
* underlying resources.
* <p>
*
* @param meta A pointer to the generated meta-data object which
* implements the <code>SnmpStandardMetaServer</code>
* interface.
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException An error occurred while accessing
* the MIB node.
*/
public void get(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final Object data = req.getUserData();
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
final SnmpVarBind var = e.nextElement();
try {
final long id = var.oid.getOidArc(depth);
var.value = meta.get(id, data);
} catch (SnmpStatusException x) {
req.registerGetException(var, x);
}
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpStandardObjectServer method set.
/**
* Generic handling of the <CODE>set</CODE> operation.
* <p> The default implementation of this method is to loop over the
* varbind list associated with the sub-request and to call
* <CODE>set(var.value, var.oid.getOidArc(depth), data);</CODE>
* <pre>
* public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req,
* int depth)
* throws SnmpStatusException {
*
* final Object data = req.getUserData();
*
* for (Enumeration e= req.getElements(); e.hasMoreElements();) {
*
* final SnmpVarBind var= (SnmpVarBind) e.nextElement();
*
* try {
* // This method will generate a SnmpStatusException
* // if `depth' is out of bounds.
* //
* final long id = var.oid.getOidArc(depth);
* var.value = meta.set(var.value, id, data);
* } catch(SnmpStatusException x) {
* req.registerSetException(var,x);
* }
* }
* }
* </pre>
* <p> You can override this method if you need to implement some
* specific policies for minimizing the accesses made to some remote
* underlying resources.
* <p>
*
* @param meta A pointer to the generated meta-data object which
* implements the <code>SnmpStandardMetaServer</code>
* interface.
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException An error occurred while accessing
* the MIB node.
*/
public void set(SnmpStandardMetaServer meta, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final Object data = req.getUserData();
for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
SnmpVarBind var = e.nextElement();
try {
// This method will generate a SnmpStatusException
// if `depth' is out of bounds.
//
final long id = var.oid.getOidArc(depth);
var.value = meta.set(var.value, id, data);
} catch (SnmpStatusException x) {
req.registerSetException(var, x);
}
}
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method getRowAction.
/**
* Return the RowStatus code value specified in this request.
* <p>
* The RowStatus code value should be one of the values defined
* by {@link com.sun.jmx.snmp.EnumRowStatus}. These codes correspond
* to RowStatus codes as defined in RFC 2579, plus the <i>unspecified</i>
* value which is SNMP Runtime specific.
* <p>
*
* @param req The sub-request that must be handled by this node.
*
* @param rowOid The <CODE>SnmpOid</CODE> identifying the table
* row involved in the operation.
*
* @param depth The depth reached in the OID tree.
*
* @return The RowStatus code specified in this request, if any:
* <ul>
* <li>If the specified row does not exist and this table do
* not use any variable to control creation/deletion of
* rows, then default creation mechanism is assumed and
* <i>createAndGo</i> is returned</li>
* <li>Otherwise, if the row exists and this table do not use any
* variable to control creation/deletion of rows,
* <i>unspecified</i> is returned.</li>
* <li>Otherwise, if the request does not contain the control variable,
* <i>unspecified</i> is returned.</li>
* <li>Otherwise, mapRowStatus() is called to extract the RowStatus
* code from the SnmpVarBind that contains the control variable.</li>
* </ul>
*
* @exception SnmpStatusException if the value of the control variable
* could not be mapped to a RowStatus code.
*
* @see com.sun.jmx.snmp.EnumRowStatus
**/
protected int getRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth) throws SnmpStatusException {
final boolean isnew = req.isNewEntry();
final SnmpVarBind vb = req.getRowStatusVarBind();
if (vb == null) {
if (isnew && !hasRowStatus())
return EnumRowStatus.createAndGo;
else
return EnumRowStatus.unspecified;
}
try {
return mapRowStatus(rowOid, vb, req.getUserData());
} catch (SnmpStatusException x) {
checkRowStatusFail(req, x.getStatus());
}
return EnumRowStatus.unspecified;
}
use of com.sun.jmx.snmp.SnmpStatusException in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method getInsertionPoint.
/**
* Search the position at which the given oid should be inserted
* in the OID table (tableoids).
*
* <p>
* @param oid The OID we would like to insert.
*
* @param fail Tells whether a SnmpStatusException must be generated
* if the given OID is already present in the table.
*
* @return The position at which the OID should be inserted in
* the table. When the OID is found, it returns the next
* position. Note that it is not valid to insert twice the
* same OID. This feature is only an optimization to improve
* the getNextOid() behaviour.
*
* @exception SnmpStatusException if the OID is already present in the
* table and <code>fail</code> is <code>true</code>.
*
**/
private int getInsertionPoint(SnmpOid oid, boolean fail) throws SnmpStatusException {
final int failStatus = SnmpStatusException.snmpRspNotWritable;
int low = 0;
int max = size - 1;
SnmpOid pos;
int comp;
int curr = low + (max - low) / 2;
while (low <= max) {
// XX pos= (SnmpOid) oids.elementAt(curr);
pos = tableoids[curr];
// never know ...we might find something ...
//
comp = oid.compareTo(pos);
if (comp == 0) {
if (fail)
throw new SnmpStatusException(failStatus, curr);
else
return curr + 1;
}
if (comp > 0) {
low = curr + 1;
} else {
max = curr - 1;
}
curr = low + (max - low) / 2;
}
return curr;
}
Aggregations