[SNMP4J] integrating SNMP4J with code from AgentPro

Frank Fock fock at agentpp.com
Fri May 13 17:42:56 CEST 2005


Hi Brian,

In general there are two approaches to instrument your MIB:

(1) On demand
(2) By caching

You described (2) in your posting, which is only useful in seldom
cases, where accessing the data takes too long for (1).
If you want to implement a thread that updates your data, then
you need no synchronization if you replace the value objects
(pointer changes are atomic in Java). However if you need to
add or remove rows things are a bit more complex, but in general
SNMP4J-Agent uses synchronized collection classes, so this
should also work in most cases without special synchronization.

The recommended approach however is (1), where an objects
value is determined on demand which means while its
ManagedObject.get(SubRequest sreq) method is being called.

For example: You have a device X which reports its temperature
by method getTemperature() as an int. You then have a scalar MyTemp
which extends MOScalar as follows:

public class MyTemp extends MOScalar {
private X x;
// Overwrite Constructor here
...
public Variable getValue() {
   Integer32 currentTemperature = new Integer32(x.getTemperature());
   super.value = currentTemperature;
   return super.getValue();
}

}

Similarly you could also overwrite the get(SubRequest) and next(SubRequest)
methods.

For writable objects you have the choice to implement 2-phase-commit or not.
The SNMP standard requires 2PC, so I strongly recommend to implement
it via overwriting thr ManagedObject.prepare, .commit, .cleanup, and .undo
methods.

Hope this helps.

Best regards,
Frank

Brian Kirwan wrote:

>Hi Frank,
>
>Thanks very much for your response.
>
>OK - I have successfully generated basic code for my custom MIB using
>AgentPro (very straightforward to do) and registered it with my test agent
>and can access objects in this new custom MIB from my manager.  Great!
>
>Obviously, my next step is to integrate my custom MIB variables with the
>actual backend resources they represent and to be able to generate traps
>from my agent also.  Is there any example of this anywhere I can refer to?
>I see there is, for example, a setValue() method on the MOScalar class - am
>I expected to create a new thread of my own that will invoke this method
>locally (based on changes detected in the backend)  to update the value of
>the SNMP variable?  If so, are there issues with synchronizing access to the
>MOs?  Or is there some other mechanism to synchronize the MIB with the
>backend?
>
>Thanks for your help,
>Brian.
>
>  
>





More information about the SNMP4J mailing list