mibgen
, there is one which extends SnmpMib
* for representing a whole MIB.
* This generated class can be subclassed in your code in order to * plug in your own specific behaviour. *
* *This API is a Sun Microsystems internal API and is subject * to change without notice.
*/ public abstract class SnmpMib extends SnmpMibAgent implements Serializable { /** * Default constructor. * Initializes the OID tree. */ public SnmpMib() { root= new SnmpMibOid(); } // -------------------------------------------------------------------- // POLYMORHIC METHODS // -------------------------------------------------------------------- /** *
* This callback should return the OID associated to the group
* identified by the given groupName
.
*
* This method is provided as a hook to plug-in some custom * specific behavior. Although doing so is discouraged you might * want to subclass this method in order to store & provide more metadata * information (mapping OID <-> symbolic name) within the agent, * or to "change" the root of the MIB OID by prefixing the * defaultOid by an application dependant OID string, for instance. *
* *
* The default implementation of this method is to return the given
* defaultOid
*
groupName
,
* in dot-notation.
*/
protected String getGroupOid(String groupName, String defaultOid) {
return defaultOid;
}
/**
*
* This callback should return the ObjectName associated to the
* group identified by the given groupName
.
*
* This method is provided as a hook to plug-in some custom
* specific behavior. You might want to override this method
* in order to provide a different object naming scheme than
* that proposed by default by mibgen
.
*
* This method is only meaningful if the MIB is registered * in the MBeanServer, otherwise, it will not be called. *
* *
* The default implementation of this method is to return an ObjectName
* built from the given defaultName
.
*
* mibgen
*
* @return The ObjectName of the group identified by name
*/
protected ObjectName getGroupObjectName(String name, String oid,
String defaultName)
throws MalformedObjectNameException {
return new ObjectName(defaultName);
}
/**
* * Register an SNMP group and its metadata node in the MIB. *
* ** This method is provided as a hook to plug-in some custom * specific behavior. You might want to override this method * if you want to set special links between the MBean, its metadata * node, its OID or ObjectName etc.. *
* *
* If the MIB is not registered in the MBeanServer, the
* server
and groupObjName
parameters will be
* null
.
* If the given group MBean is not null
, and if the
* server
and groupObjName
parameters are
* not null, then this method will also automatically register the
* group MBean with the given MBeanServer server
.
*
null
if the
* MIB is not registered in the MBeanServer.
* @param node The metadata node, as returned by the metadata
* factory method for this group.
* @param group The MBean for this group, as returned by the
* MBean factory method for this group.
* @param server The MBeanServer in which the groups are to be
* registered. This parameter will be null
* if the MIB is not registered, otherwise it is a
* reference to the MBeanServer in which the MIB is
* registered.
*
*/
protected void registerGroupNode(String groupName, String groupOid,
ObjectName groupObjName, SnmpMibNode node,
Object group, MBeanServer server)
throws NotCompliantMBeanException, MBeanRegistrationException,
InstanceAlreadyExistsException, IllegalAccessException {
root.registerNode(groupOid,node);
if (server != null && groupObjName != null && group != null)
server.registerMBean(group,groupObjName);
}
/**
* * Register an SNMP Table metadata node in the MIB. *
* *
*
* This method is used internally and you should never need to
* call it directly.
It is used to establish the link
* between an SNMP table metadata node and its bean-like counterpart.
*
* The group metadata nodes will create and register their
* underlying table metadata nodes in the MIB using this
* method.
* The metadata nodes will be later retrieved from the MIB by the
* bean-like table objects using the getRegisterTableMeta() method.
*
mibgen
generated
* object.
*/
public abstract void registerTableMeta(String name, SnmpMibTable table);
/**
* Returns a registered SNMP Table metadata node.
*
* * This method is used internally and you should never need to * call it directly. *
* */ public abstract SnmpMibTable getRegisteredTableMeta(String name); // -------------------------------------------------------------------- // PUBLIC METHODS // -------------------------------------------------------------------- /** * Processes aget
operation.
*
**/
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
public void get(SnmpMibRequest req) throws SnmpStatusException {
// Builds the request tree: creation is not allowed, operation
// is not atomic.
final int reqType = SnmpDefinitions.pduGetRequestPdu;
SnmpRequestTree handlers = getHandlers(req,false,false,reqType);
SnmpRequestTree.Handler h = null;
SnmpMibNode meta = null;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
"get", "Processing handlers for GET... ");
}
// For each sub-request stored in the request-tree, invoke the
// get() method.
for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {
h = (SnmpRequestTree.Handler) eh.nextElement();
// Gets the Meta node. It can be either a Group Meta or a
// Table Meta.
//
meta = handlers.getMetaNode(h);
// Gets the depth of the Meta node in the OID tree
final int depth = handlers.getOidDepth(h);
for (Enumeration rqs=handlers.getSubRequests(h);
rqs.hasMoreElements();) {
// Invoke the get() operation.
meta.get((SnmpMibSubRequest)rqs.nextElement(),depth);
}
}
}
/**
* Processes a set
operation.
*
*/
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
public void set(SnmpMibRequest req) throws SnmpStatusException {
SnmpRequestTree handlers = null;
// Optimization: we're going to get the whole SnmpRequestTree
// built in the "check" method, so that we don't have to rebuild
// it here.
//
if (req instanceof SnmpMibRequestImpl)
handlers = ((SnmpMibRequestImpl)req).getRequestTree();
// Optimization didn't work: we have to rebuild the tree.
//
// Builds the request tree: creation is not allowed, operation
// is atomic.
//
final int reqType = SnmpDefinitions.pduSetRequestPdu;
if (handlers == null) handlers = getHandlers(req,false,true,reqType);
handlers.switchCreationFlag(false);
handlers.setPduType(reqType);
SnmpRequestTree.Handler h = null;
SnmpMibNode meta = null;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
"set", "Processing handlers for SET... ");
}
// For each sub-request stored in the request-tree, invoke the
// get() method.
for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {
h = (SnmpRequestTree.Handler) eh.nextElement();
// Gets the Meta node. It can be either a Group Meta or a
// Table Meta.
//
meta = handlers.getMetaNode(h);
// Gets the depth of the Meta node in the OID tree
final int depth = handlers.getOidDepth(h);
for (Enumeration rqs=handlers.getSubRequests(h);
rqs.hasMoreElements();) {
// Invoke the set() operation
meta.set((SnmpMibSubRequest)rqs.nextElement(),depth);
}
}
}
/**
* Checks if a set
operation can be performed.
* If the operation cannot be performed, the method will raise a
* SnmpStatusException
.
*
*/
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
public void check(SnmpMibRequest req) throws SnmpStatusException {
final int reqType = SnmpDefinitions.pduWalkRequest;
// Builds the request tree: creation is allowed, operation
// is atomic.
SnmpRequestTree handlers = getHandlers(req,true,true,reqType);
SnmpRequestTree.Handler h = null;
SnmpMibNode meta = null;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
"check", "Processing handlers for CHECK... ");
}
// For each sub-request stored in the request-tree, invoke the
// check() method.
for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {
h = (SnmpRequestTree.Handler) eh.nextElement();
// Gets the Meta node. It can be either a Group Meta or a
// Table Meta.
//
meta = handlers.getMetaNode(h);
// Gets the depth of the Meta node in the OID tree
final int depth = handlers.getOidDepth(h);
for (Enumeration rqs=handlers.getSubRequests(h);
rqs.hasMoreElements();) {
// Invoke the check() operation
meta.check((SnmpMibSubRequest)rqs.nextElement(),depth);
}
}
// Optimization: we're going to pass the whole SnmpRequestTree
// to the "set" method, so that we don't have to rebuild it there.
//
if (req instanceof SnmpMibRequestImpl) {
((SnmpMibRequestImpl)req).setRequestTree(handlers);
}
}
/**
* Processes a getNext
operation.
*
*/
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
public void getNext(SnmpMibRequest req) throws SnmpStatusException {
// Build the request tree for the operation
// The subrequest stored in the request tree are valid GET requests
SnmpRequestTree handlers = getGetNextHandlers(req);
SnmpRequestTree.Handler h = null;
SnmpMibNode meta = null;
if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
"getNext", "Processing handlers for GET-NEXT... ");
}
// Now invoke get() for each subrequest of the request tree.
for (Enumeration eh=handlers.getHandlers();eh.hasMoreElements();) {
h = (SnmpRequestTree.Handler) eh.nextElement();
// Gets the Meta node. It can be either a Group Meta or a
// Table Meta.
//
meta = handlers.getMetaNode(h);
// Gets the depth of the Meta node in the OID tree
int depth = handlers.getOidDepth(h);
for (Enumeration rqs=handlers.getSubRequests(h);
rqs.hasMoreElements();) {
// Invoke the get() operation
meta.get((SnmpMibSubRequest)rqs.nextElement(),depth);
}
}
}
/**
* Processes a getBulk
operation.
* The method implements the getBulk
operation by calling
* appropriately the getNext
method.
*
*/
// Implements the method defined in SnmpMibAgent. See SnmpMibAgent
// for java-doc
//
public void getBulk(SnmpMibRequest req, int nonRepeat, int maxRepeat)
throws SnmpStatusException {
getBulkWithGetNext(req, nonRepeat, maxRepeat);
}
/**
* Gets the root object identifier of the MIB.
* In order to be accurate, the method should be called once the
* MIB is fully initialized (that is, after a call to init
* or preRegister
).
*
* @return The root object identifier.
*/
public long[] getRootOid() {
if( rootOid == null) {
Vector