📄 snmptablesupport.java
字号:
* @param index The SnmpIndex identifying the entry from which we * want to build the default ObjectName. * * @return The default ObjectName for the entry identified by * the given index. * * @exception SnmpStatusException if the given index is not valid. **/ public abstract ObjectName buildNameFromIndex(SnmpIndex index) throws SnmpStatusException; //----------------------------------------------------------------- // // Implementation of the SnmpTableEntryFactory interface // //----------------------------------------------------------------- /** * This callback is called by the associated metadata object * when a new table entry has been registered in the * table metadata. * * This method will update the <code>entries</code> list. * * @param pos The position at which the new entry was inserted * in the table. * @param row The row OID of the new entry * @param name The ObjectName of the new entry (as specified by the * factory) * @param entry The new entry (as returned by the factory) * @param meta The table metadata object. * **/ public void addEntryCb(int pos, SnmpOid row, ObjectName name, Object entry, SnmpMibTable meta) throws SnmpStatusException { try { if (entries != null) entries.add(pos,entry); } catch (Exception e) { throw new SnmpStatusException(SnmpStatusException.noSuchName); } } /** * This callback is called by the associated metadata object * when a new table entry has been removed from the * table metadata. * * This method will update the <code>entries</code> list. * * @param pos The position from which the entry was deleted * @param row The row OID of the deleted entry * @param name The ObjectName of the deleted entry (may be null if * ObjectName's were not required) * @param entry The deleted entry (may be null if only ObjectName's * were required) * @param meta The table metadata object. * **/ public void removeEntryCb(int pos, SnmpOid row, ObjectName name, Object entry, SnmpMibTable meta) throws SnmpStatusException { try { if (entries != null) entries.remove(pos); } catch (Exception e) { } } /** * Enables to add an SNMP entry listener to this * <CODE>SnmpMibTable</CODE>. * * @param listener The listener object which will handle the * notifications emitted by the registered MBean. * * @param filter The filter object. If filter is null, no filtering * will be performed before handling notifications. * * @param handback The context to be sent to the listener when a * notification is emitted. * * @exception IllegalArgumentException Listener parameter is null. */ public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) { meta.addNotificationListener(listener,filter,handback); } /** * Enables to remove an SNMP entry listener from this * <CODE>SnmpMibTable</CODE>. * * @param listener The listener object which will handle the * notifications emitted by the registered MBean. * This method will remove all the information related to this * listener. * * @exception ListenerNotFoundException The listener is not registered * in the MBean. */ public synchronized void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException { meta.removeNotificationListener(listener); } /** * Returns a <CODE>NotificationInfo</CODE> object containing the * notification class and the notification type sent by the * <CODE>SnmpMibTable</CODE>. */ public MBeanNotificationInfo[] getNotificationInfo() { return meta.getNotificationInfo(); } //----------------------------------------------------------------- // // Protected Abstract methods // //----------------------------------------------------------------- /** * Builds an SnmpIndex object from the index part of an OID. * * This method is generated by mibgen and used internally. * * @param oid The OID from which to build the index, represented * as an array of long. * @param start The position where to start from in the OID array. * * @return The SnmpOid form of the given entry index. * * @exception SnmpStatusException if the given index is not valid. **/ protected abstract SnmpIndex buildSnmpIndex(long oid[], int start ) throws SnmpStatusException; /** * Returns the metadata object associated with this table. * * This method is generated by mibgen and used internally. * * @param mib The SnmpMib object holding the Metadata corresponding * to this table. * * @return The metadata object associated with this table. * Returns <code>null</code> if this implementation of the * MIB doesn't support this table. **/ protected abstract SnmpMibTable getRegisteredTableMeta(SnmpMib mib); //----------------------------------------------------------------- // // Protected methods // //----------------------------------------------------------------- /** * Allocates an ArrayList for storing table entries. * * This method is called within the constructor at object creation. * Any object implementing the {@link java.util.List} interface can * be used. * * @return A new list in which to store entries. If <code>null</code> * is returned then no entry will be stored in the list * and getEntry() will always return null. **/ protected List allocateTable() { return new ArrayList(); } /** * Add an entry in this table. * * This method registers an entry in the table and perform * synchronization with the associated table metadata object. * * This method assumes that the given entry will not be registered, * or will be registered with its default ObjectName built from the * associated SnmpIndex. * <p> * If the entry is going to be registered, then * {@link com.sun.jmx.snmp.agent.SnmpTableSupport#addEntry(SnmpIndex, ObjectName, Object)} should be prefered. * <br> This function is mainly provided for backward compatibility. * * @param index The SnmpIndex built from the given entry. * @param entry The entry that should be added in the table. * * @exception SnmpStatusException if the entry cannot be registered with * the given index. **/ protected void addEntry(SnmpIndex index, Object entry) throws SnmpStatusException { SnmpOid oid = buildOidFromIndex(index); ObjectName name = null; if (isRegistrationRequired()) { name = buildNameFromIndex(index); } meta.addEntry(oid,name,entry); } /** * Add an entry in this table. * * This method registers an entry in the table and performs * synchronization with the associated table metadata object. * * @param index The SnmpIndex built from the given entry. * @param name The ObjectName with which this entry will be registered. * @param entry The entry that should be added in the table. * * @exception SnmpStatusException if the entry cannot be registered with * the given index. **/ protected void addEntry(SnmpIndex index, ObjectName name, Object entry) throws SnmpStatusException { SnmpOid oid = buildOidFromIndex(index); meta.addEntry(oid,name,entry); } /** * Remove an entry from this table. * * This method unregisters an entry from the table and performs * synchronization with the associated table metadata object. * * @param index The SnmpIndex identifying the entry. * @param entry The entry that should be removed in the table. This * parameter is optional and can be omitted if it doesn't * need to be passed along to the * <code>removeEntryCb()</code> callback defined in the * {@link com.sun.jmx.snmp.agent.SnmpTableCallbackHandler} * interface. * * @exception SnmpStatusException if the entry cannot be unregistered. **/ protected void removeEntry(SnmpIndex index, Object entry) throws SnmpStatusException { SnmpOid oid = buildOidFromIndex(index); meta.removeEntry(oid,entry); } // protected void removeEntry(ObjectName name, Object entry) // throws SnmpStatusException { // meta.removeEntry(name,entry); // } /** * Returns the entries in the table. * * @return An Object[] array containing the entries registered in the * table. **/ protected Object[] getBasicEntries() { if (entries == null) return null; Object[] array= new Object[entries.size()]; entries.toArray(array); return array; } /** * Binds this table with its associated metadata, registering itself * as an SnmpTableEntryFactory. **/ protected void bindWithTableMeta() { if (meta == null) return; registrationRequired = meta.isRegistrationRequired(); meta.registerEntryFactory(this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -