[SNMP4J] Some notes to Class MOScalar

Frank Fock fock at agentpp.com
Tue Jul 3 23:21:18 CEST 2007


Hi Bernhard,

Please find my comments inline below:

bernhard.kling at sdm.de wrote:
> 
> Hi,
> 
> I am using a subclass of MOScalar, which overrides the 'getValue' and 'setValue' Methods.
> 
> The 'getValue' Method of the subclass determins it's return value online, by acessing an application via TCP.
> The 'setValue' Method passes the new value online to an application, also via TCP.

If getting a value causes noticeable overhead then
I recommend overwriting the "get" and "prepare"/"commit"
methods instead of getValue and setValue.

As you noticed, getValue and to some minor extend also setValue
are also internally used which could cause performance problems
when these methods take too much time for execution.

> 
> Requesting the managed objekts value by a SNMP GET Request works fine.
> Setting the managed objekt's value by a SNMP SET Request also works, but shows some noticable points (problems).
> 
> 1.
> During processing of the SET Request the 'getValue' Method was called multiple times.
> (If Log-Level was DEBUG: 6 times, otherwise: 2 times).
>  
> 	a: This 'getValue' are additional load for the application accesed via TCP
> 	b. if 'getValue' failed (throws an exception) 'setValue' also failed.
> 		Log Snippet (after Failed 'getValue'): 'Failed to process SET request, trying to clean it up...'
> 	  
> 
> Is there any possibility to avoid this coupling of 'setValue' and 'getValue' ?

Not really, please think about the approach I described above.

> Is it possible to replace 'getValue()' by 'value' in MoScalar's 'toString' Method ?

This is an option, however, the toString() will then not work correctly
for MOScalar that do not use the internally cached "value".

> Is it possible to replace other occurrences of 'getValue()' by 'value' in MoScalar ?
> Especially
> 	request.setUndoValue(getValue());
> may cause undefined results, when 'getValue' determines its result dynamically.
> Anyway, the value returned by 'getvalue', need not be the same as before processing the SNMP GET Request. 
> 

This should not impose any problems when overwriting the "get" and
"commit" methods. Again, "getValue" is called to support
MOScalars that do not use the "value" member for caching values.

> 	
> 2. 
> If 'setValue' failed and returned SnmpConstants.SNMP_ERROR_GENERAL_ERROR, this was ignored.
> (Message of Command line tool: Response received with requestID=663712947, errorIndex=0, errorStatus=Success(0)).
> This is caused by the following code snippet:
> ------------------------------------------------------------------------------------------------
>  public void commit(SubRequest request) {
> 	...
>     request.setUndoValue(getValue());
>     setValue(vb.getVariable());
>     status.setPhaseComplete(true);
>     ...
>   }
> --------------------------------------------------------------------------------------------------
> 
> Is it intended, that the 'commit' Method does not evaluat the result of 'setValue' ?

Yes, this is intended. SNMP requires that the same value
is returned by a set request response as in the request
on success and on failure at the commit phase, only
commitFail and genErr are allowed to be returned.

Best regards,
Frank

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list