Maybe I should add:
If a managedobject without context(null) will be unregistered the result of the 
comperator is:
public int compare(MOScope o1, MOScope o2) {
    if (o1==o2) {
      return 0; // ensure identity is equal
    }......
Because the instance of the scope is the same (mo.getscope()).

Register or unregister of a mo with context will always use a new instance of 
DefaultMOContextScope:
new DefaultMOContextScope(context, mo.getScope());

so o1==o2 in the comperator is false and the rest of the comperator will never 
result in 0 if the mo is the same.
If you change the comperator to:
public int compare(MOScope o1, MOScope o2) {
    if (o1.equals(o2)) {
      return 0; // ensure identity is equal
    }.....
It will work with the DefaultMOContextScope too (it will compare the content 
instead of the instance).
Now registry.remove(key); will remove the mo from registry

Is this the correct fix for this bug?

Best regards
Dave

-----Previous Message-----
Subject: [SNMP4J] Unregister MO with context doesnt work

Unregister a managed object will call "public void unregister(ManagedObject mo, 
OctetString context)" (DefaultMOServer.java).
This will remove the mo from registry (treemap) with "registry.remove(key);"

The problem is the comperator from the treemap registry will call: 
"compareContextScope(MOScope scope, MOContextScope scope2)"
In this function it will compare first the upperbound and if it is the same it 
will do:
if (result == 0) {
          result = scope.getUpperBound().compareTo(scope2.getLowerBound());

and this is always 1 so the result is always -1 or 1 even if it is exact the 
same scope. So it will never be removed from registry.

If you unregister without context (context==null) the compare function:
result = o1.getLowerBound().compareTo(o2.getLowerBound());
will return 0 and it will be removed from registry.

_______________________________________________
SNMP4J mailing list
[email protected]
http://oosnmp.net/mailman/listinfo/snmp4j
_______________________________________________
SNMP4J mailing list
[email protected]
http://oosnmp.net/mailman/listinfo/snmp4j

Reply via email to