[SNMP4J] Issue with AgentX casting in AgentXProtocol

Frank Fock fock at agentpp.com
Thu Sep 11 23:18:04 CEST 2008


Andrew,

Your fix is OK. I have added it to the next release.
Thanks.

Best regards,
Frank

Andrew Baptist wrote:
> I am attempting to write code that will have dynamically updated variables within a table. To accomplish this I am using VariantVariable as wrapper around the Variable that I pass in. 
> 
> However when I try to run this from within an AgentX agent, I get an class cast exception in AgentXProtocol. Specifically in the method encodeVariableData, the code is attempting to get the value based on the syntax by casting to the correct type. However since a VariantVariable can't be cast to different types this fails. 
> 
> The code can be fixed by the following changes:
> 169c169
> <         buf.putInt((int) (((AssignableFromLong) v).toLong() & 0xFFFFFFFFL));
>>         buf.putInt((int)(((UnsignedInteger32)v).getValue() & 0xFFFFFFFFL));
> 173c173
> <         buf.putInt(((AssignableFromInteger) v).toInt());
>>         buf.putInt(((Integer32)v).getValue());
> 177c177
> <         buf.putLong(((AssignableFromLong) v).toLong());
>>         buf.putLong(((Counter64)v).getValue());
> 
> For reference I have the following sample class that I use as the variable within my table when I add a row:
> 
>    public static class RandomCounterCallback extends ReadonlyVariableCallback
>    {
>       long value = 0;
> 
>       @Override
>       public void updateVariable(final VariantVariable variable)
>       {
>          this.value += (long) (Math.random() * 20);
>          variable.setValue(this.value);
>       }
>    }
> 
> final MOTable table = DefaultMOFactory.getInstance().createTable(oid, null, columns);
> table.addRow(DefaultMOFactory.createRow(new OID("1"), new Variable[]{new VariantVariable(new Counter64(0), new RandomCounterCallback())}));
> 
> 
> I am using this change locally within my system and am wondering if other people have hit this issue and if so if there is a different way of doing this.
> 
> Thanks,
> Andrew
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

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




More information about the SNMP4J mailing list