use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.
the class SnmpSubNextRequestHandler method updateResult.
/**
* The method updates a given var bind list with the result of a
* previsouly invoked operation.
* Prior to calling the method, one must make sure that the operation was
* successful. As such the method getErrorIndex or getErrorStatus should be
* called.
*/
protected void updateResult(SnmpVarBind[] result) {
final int max = varBind.size();
for (int i = 0; i < max; i++) {
// May be we should control the position ...
//
final int index = translation[i];
final SnmpVarBind elmt = (SnmpVarBind) ((NonSyncVector) varBind).elementAtNonSync(i);
final SnmpVarBind vb = result[index];
if (vb == null) {
result[index] = elmt;
/* end of NPCTE fix for bugid 4381195 */
continue;
}
final SnmpValue val = vb.value;
if ((val == null) || (val == SnmpVarBind.endOfMibView)) {
/* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
if ((elmt != null) && (elmt.value != SnmpVarBind.endOfMibView))
result[index] = elmt;
// vb.value = SnmpVarBind.endOfMibView;
continue;
/* end of NPCTE fix for bugid 4381195 */
}
/* NPCTE fix for bugid 4381195 esc 0. <J.C.> < 17-Oct-2000> */
if (elmt == null)
continue;
if (elmt.value == SnmpVarBind.endOfMibView)
continue;
// Now we need to take the smallest oid ...
//
int comp = elmt.oid.compareTo(vb.oid);
if (comp < 0) {
// Take the smallest (lexicographically)
//
result[index] = elmt;
} else {
if (comp == 0) {
// Take the deeper within the reply
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", " oid overlapping. Oid : " + elmt.oid + "value :" + elmt.value);
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Already present varBind : " + vb);
}
SnmpOid oid = vb.oid;
SnmpMibAgent deeperAgent = server.getAgentMib(oid);
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "Deeper agent : " + deeperAgent);
}
if (deeperAgent == agent) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "updateResult", "The current agent is the deeper one. Update the value with the current one");
}
result[index].value = elmt.value;
}
/*
Vector v = new Vector();
SnmpMibRequest getReq = createMibRequest(v,
version,
null);
SnmpVarBind realValue = new SnmpVarBind(oid);
getReq.addVarBind(realValue);
try {
deeperAgent.get(getReq);
} catch(SnmpStatusException e) {
e.printStackTrace();
}
if(isDebugOn())
trace("updateResult", "Biggest priority value is : " +
realValue.value);
result[index].value = realValue.value;
*/
}
}
}
}
use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method endRowAction.
/**
* This method takes care of final RowStatus handling during the
* set() phase of a SET request.
*
* In particular it will:
* <ul><li>either call <code>setRowStatus(<i>active</i>)</code>
* (<code> rowAction = <i>createAndGo</i> or <i>active</i>
* </code>),</li>
* <li>or call <code>setRowStatus(<i>notInService</i> or <i>
* notReady</i>)</code> depending on the result of <code>
* isRowReady()</code> (<code>rowAction = <i>createAndWait</i>
* </code>),</li>
* <li>or call <code>setRowStatus(<i>notInService</i>)</code>
* (<code> rowAction = <i>notInService</i></code>),
* <li>or call <code>removeTableRow()</code> (<code>
* rowAction = <i>destroy</i></code>),</li>
* <li>or generate a SnmpStatusException if the passed <code>
* rowAction</code> is not correct. This should be avoided
* since it would break SET request atomicity</li>
* </ul>
* <p>
* In principle, you should not need to redefine this method.
* <p>
* <code>endRowAction()</code> is called during the set() phase
* of a SET request, after the actual set() on the varbind list
* has been performed. The varbind containing the control variable
* is updated with the value returned by setRowStatus() (if it is
* not <code>null</code>).
*
* <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.
*
* @param rowAction The requested action as returned by <code>
* getRowAction()</code>: one of the RowStatus codes defined in
* {@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.
*
* @exception SnmpStatusException if the specified <code>rowAction</code>
* is not valid.
*
* @see com.sun.jmx.snmp.EnumRowStatus
**/
protected void endRowAction(SnmpMibSubRequest req, SnmpOid rowOid, int depth, int rowAction) throws SnmpStatusException {
final boolean isnew = req.isNewEntry();
final SnmpOid oid = rowOid;
final int action = rowAction;
final Object data = req.getUserData();
SnmpValue value = null;
switch(action) {
case EnumRowStatus.unspecified:
break;
case EnumRowStatus.createAndGo:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndGo");
}
value = setRowStatus(oid, EnumRowStatus.active, data);
break;
case EnumRowStatus.createAndWait:
if (isRowReady(oid, data)) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = createAndWait");
}
value = setRowStatus(oid, EnumRowStatus.notInService, data);
} else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notReady' " + "for row[" + rowOid + "] : requested RowStatus = " + "createAndWait");
}
value = setRowStatus(oid, EnumRowStatus.notReady, data);
}
break;
case EnumRowStatus.destroy:
if (isnew) {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Warning: requested RowStatus = destroy, " + "but row[" + rowOid + "] does not exist");
}
} else {
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Destroying row[" + rowOid + "] : requested RowStatus = destroy");
}
}
removeTableRow(req, oid, depth);
break;
case EnumRowStatus.active:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'active' for row[" + rowOid + "] : requested RowStatus = active");
}
value = setRowStatus(oid, EnumRowStatus.active, data);
break;
case EnumRowStatus.notInService:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Setting RowStatus to 'notInService' for row[" + rowOid + "] : requested RowStatus = notInService");
}
value = setRowStatus(oid, EnumRowStatus.notInService, data);
break;
case EnumRowStatus.notReady:
default:
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMibTable.class.getName(), "endRowAction", "Invalid RowStatus value for row[" + rowOid + "] : specified RowStatus = " + action);
}
setRowStatusFail(req, SnmpStatusException.snmpRspInconsistentValue);
}
if (value != null) {
final SnmpVarBind vb = req.getRowStatusVarBind();
if (vb != null)
vb.value = value;
}
}
use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method get.
// ---------------------------------------------------------------------
//
// Implements the method defined in SnmpMibNode.
//
// ---------------------------------------------------------------------
/**
* Generic handling of the <CODE>get</CODE> operation.
* <p> The default implementation of this method is to
* <ul>
* <li> check whether the entry exists, and if not register an
* exception for each varbind in the list.
* <li> call the generated
* <CODE>get(req,oid,depth+1)</CODE> method. </li>
* </ul>
* <p>
* <pre>
* public void get(SnmpMibSubRequest req, int depth)
* throws SnmpStatusException {
* boolean isnew = req.isNewEntry();
*
* // if the entry does not exists, then registers an error for
* // each varbind involved (nb: this should not happen, since
* // the error should already have been detected earlier)
* //
* if (isnew) {
* SnmpVarBind var = null;
* for (Enumeration e= req.getElements(); e.hasMoreElements();) {
* var = (SnmpVarBind) e.nextElement();
* req.registerGetException(var,noSuchNameException);
* }
* }
*
* final SnmpOid oid = req.getEntryOid();
* get(req,oid,depth+1);
* }
* </pre>
* <p> You should not need to override this method in any cases, because
* it will eventually call
* <CODE>get(SnmpMibSubRequest req, int depth)</CODE> on the generated
* derivative of <CODE>SnmpMibEntry</CODE>. If you need to implement
* specific policies for minimizing the accesses made to some remote
* underlying resources, or if you need to implement some consistency
* checks between the different values provided in the varbind list,
* you should then rather override
* <CODE>get(SnmpMibSubRequest req, int depth)</CODE> on the generated
* derivative of <CODE>SnmpMibEntry</CODE>.
* <p>
*
*/
@Override
public void get(SnmpMibSubRequest req, int depth) throws SnmpStatusException {
final boolean isnew = req.isNewEntry();
final SnmpMibSubRequest r = req;
// should have been registered earlier)
if (isnew) {
SnmpVarBind var;
for (Enumeration<SnmpVarBind> e = r.getElements(); e.hasMoreElements(); ) {
var = e.nextElement();
r.registerGetException(var, new SnmpStatusException(SnmpStatusException.noSuchInstance));
}
}
final SnmpOid oid = r.getEntryOid();
// SnmpIndex index = buildSnmpIndex(oid.longValue(false), 0);
// get(req,index,depth+1);
//
get(req, oid, depth + 1);
}
use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method removeEntry.
/**
* Remove the specified entry from the table.
* Also triggers the removeEntryCB() callback of the
* {@link com.sun.jmx.snmp.agent.SnmpTableEntryFactory} interface
* if this node is bound to a factory.
*
* <p>
* @param pos The position of the entry in the table.
*
* @param entry The entry to be removed. This parameter is not used
* internally, it is simply passed along to the
* removeEntryCB() callback.
*
* @exception SnmpStatusException if the specified entry couldn't
* be removed.
*/
public synchronized void removeEntry(int pos, Object entry) throws SnmpStatusException {
if (pos == -1)
return;
if (pos >= size)
return;
Object obj = entry;
if (entries != null && entries.size() > pos) {
obj = entries.elementAt(pos);
entries.removeElementAt(pos);
}
ObjectName name = null;
if (entrynames != null && entrynames.size() > pos) {
name = entrynames.elementAt(pos);
entrynames.removeElementAt(pos);
}
final SnmpOid rowOid = tableoids[pos];
removeOid(pos);
size--;
if (obj == null)
obj = entry;
if (factory != null)
factory.removeEntryCb(pos, rowOid, name, obj, this);
sendNotification(SnmpTableEntryNotification.SNMP_ENTRY_REMOVED, (new Date()).getTime(), obj, name);
}
use of com.sun.jmx.snmp.SnmpOid 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);
}
Aggregations