Java Dynamic Management Kit 5.0 Tutorial

Implementing a New SnmpPduFactory Class

Java DMK expects decodeSnmpPdu to behave as follows:

Java DMK expects encodeSnmpPdu to behave as follows:

Because SnmpPdu and SnmpMsg are abstract classes, you should delegate their creation and initialization to an instance of SnmpPduFactoryBER and work on the result returned.

You can change the SnmpPduFactory object used by the SNMP adaptor by using the setPduFactory method, shown in Example 20–15.

Example 20–15 Changing the SnmpPduFactory object Using setPduFactory

       myAdaptor.setPduFactory(new MyFireWallPduFactory()) ;

In Java DMK 4.2, the SnmpPduFactory was attached to the SnmpPeer object. In Java DMK 5.0, the SnmpPduFactory is attached to the SnmpSession. Factories set via the deprecated SnmpPeer API are reused in Java DMK 5.0. They can be changed using the setPduFactory method, as shown in Example 20–16:

Example 20–16 Updating Deprecated SnmpPeer Factories Using setPduFactory

SnmpSession mySession = new SnmpSession() ;
mySession.setPduFactory(new MyFireWallPduFactory()) ;
mySession.snmpGet(myPeer, this, myVarBindList) ;

Caution – Caution –

Setting two different factories in the peer and in the session can lead to unpredictable behavior. Use the same factory at both levels.