本文整理汇总了Java中com.sun.jmx.snmp.SnmpStatusException.noAccess方法的典型用法代码示例。如果您正苦于以下问题:Java SnmpStatusException.noAccess方法的具体用法?Java SnmpStatusException.noAccess怎么用?Java SnmpStatusException.noAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jmx.snmp.SnmpStatusException
的用法示例。
在下文中一共展示了SnmpStatusException.noAccess方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: set
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
/**
* 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);
}
示例2: findHandlingNode
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
@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);
}
// There are too many arcs left in the OID (there should remain
// 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);
}
}
示例3: mapGetException
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
public static int mapGetException(int errorStatus, int version)
throws SnmpStatusException {
final int errorCode = errorStatus;
if (version == SnmpDefinitions.snmpVersionOne)
return errorCode;
int mappedErrorCode = errorCode;
// Now take care of V2 errorCodes that can be stored
// in the varbind itself:
if (errorCode ==
SnmpStatusException.noSuchObject)
// noSuchObject => noSuchObject
mappedErrorCode = errorCode;
else if (errorCode ==
SnmpStatusException.noSuchInstance)
// noSuchInstance => noSuchInstance
mappedErrorCode = errorCode;
// Now we're going to try to transform every other
// global code in either noSuchInstance or noSuchObject,
// so that the get can return a partial result.
//
// Only noSuchInstance or noSuchObject can be stored
// in the varbind itself.
//
// According to RFC 1905: noAccess is emitted when the
// the access is denied because it is not in the MIB view...
//
else if (errorCode ==
SnmpStatusException.noAccess)
// noAccess => noSuchInstance
mappedErrorCode = SnmpStatusException.noSuchInstance;
// According to RFC 1905: (my interpretation because it is not
// really clear) The specified variable name exists - but the
// variable does not exists and cannot be created under the
// present circumstances (probably because the request specifies
// another variable/value which is incompatible, or because the
// value of some other variable in the MIB prevents the creation)
//
// Note that this error should never be raised in a GET context
// but who knows?
//
else if (errorCode == SnmpStatusException.snmpRspInconsistentName)
// inconsistentName => noSuchInstance
mappedErrorCode = SnmpStatusException.noSuchInstance;
// All the errors comprised between snmpRspWrongType and
// snmpRspInconsistentValue concern values: so we're going
// to assume the OID was correct, and reply with noSuchInstance.
//
// Note that this error should never be raised in a GET context
// but who knows?
//
else if ((errorCode >= SnmpStatusException.snmpRspWrongType) &&
(errorCode <= SnmpStatusException.snmpRspInconsistentValue))
mappedErrorCode = SnmpStatusException.noSuchInstance;
// We're going to assume the OID was correct, and reply
// with noSuchInstance.
//
else if (errorCode == SnmpStatusException.readOnly)
mappedErrorCode = SnmpStatusException.noSuchInstance;
// For all other errors but genErr, we're going to reply with
// noSuchObject
//
else if (errorCode != SnmpStatusException.snmpRspAuthorizationError &&
errorCode != SnmpStatusException.snmpRspGenErr)
mappedErrorCode = SnmpStatusException.noSuchObject;
// Only genErr will abort the GET and be returned as global
// error.
//
return mappedErrorCode;
}
示例4: findHandlingNode
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
@Override
final synchronized void findHandlingNode(SnmpVarBind varbind,
long[] oid, int depth,
SnmpRequestTree handlers)
throws SnmpStatusException {
final int length = oid.length;
if (handlers == null)
throw new SnmpStatusException(SnmpStatusException.snmpRspGenErr);
if (depth >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (oid[depth] != nodeId)
throw new SnmpStatusException(SnmpStatusException.noAccess);
if (depth+2 >= length)
throw new SnmpStatusException(SnmpStatusException.noAccess);
// Checks that the oid is valid
// validateOid(oid,depth);
// Gets the part of the OID that identifies the entry
final SnmpOid entryoid = new SnmpEntryOid(oid, depth+2);
// Finds the entry: false means that the entry does not exists
final Object data = handlers.getUserData();
final boolean hasEntry = contains(entryoid, data);
// Fails if the entry is not found and the table does not
// not support creation.
// We know that the entry does not exists if (isentry == false).
if (!hasEntry) {
if (!handlers.isCreationAllowed()) {
// we're not doing a set
throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
} else if (!isCreationEnabled())
// we're doing a set but creation is disabled.
throw new
SnmpStatusException(SnmpStatusException.snmpRspNoAccess);
}
final long var = oid[depth+1];
// Validate the entry id
if (hasEntry) {
// The entry already exists - validate the id
validateVarEntryId(entryoid,var,data);
}
// Registers this node for the identified entry.
//
if (handlers.isSetRequest() && isRowStatus(entryoid,var,data))
// We only try to identify the RowStatus for SET operations
//
handlers.add(this,depth,entryoid,varbind,(!hasEntry),varbind);
else
handlers.add(this,depth,entryoid,varbind,(!hasEntry));
}
示例5: set
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
/**
* Generic handling of the <CODE>set</CODE> operation.
*
* <p> This method should be overridden in subclasses.
* <p>
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
@Override
public void set(SnmpMibSubRequest req, int depth)
throws SnmpStatusException {
for (Enumeration<SnmpVarBind> e= req.getElements(); e.hasMoreElements();) {
SnmpVarBind var= e.nextElement();
SnmpStatusException x =
new SnmpStatusException(SnmpStatusException.noAccess);
req.registerSetException(var,x);
}
}
示例6: check
import com.sun.jmx.snmp.SnmpStatusException; //导入方法依赖的package包/类
/**
* Generic handling of the <CODE>check</CODE> operation.
*
* <p> This method should be overridden in subclasses.
* <p>
*
* @param req The sub-request that must be handled by this node.
*
* @param depth The depth reached in the OID tree.
*
* @exception SnmpStatusException The default implementation (if not
* overridden) is to generate a SnmpStatusException.
*/
@Override
public void check(SnmpMibSubRequest req, int depth)
throws SnmpStatusException {
for (Enumeration<SnmpVarBind> e= req.getElements(); e.hasMoreElements();) {
SnmpVarBind var= e.nextElement();
SnmpStatusException x =
new SnmpStatusException(SnmpStatusException.noAccess);
req.registerCheckException(var,x);
}
}