eebenson / haggle

Automatically exported from code.google.com/p/haggle
Apache License 2.0
0 stars 0 forks source link

unregisterInterest cause problem #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.In PhotoShare,take a picture ,add a attribute ,for example "test", "test" is 
automatically added as interest by PhotoShare.Then PhotoShare will receive and 
show this picture.

2.Delete the interest "test" ,and now PhotoShare can no longer receive any 
picture.You can take some more pictures ,name them any attributes,but 
PhotoShare cannot recieve and show them. 

I guess it is the call h.unregisterInterest() cause problem,so I did something 
to test it.

3.Here is TestApp.java which I've done a little change for my test.When 
unregisterInterest() is called,it seems to caused problem.

Code changed is here :
Attribute[] attrs = new Attribute[num_dataobjects];
DataObject[] dobjs = new DataObject[num_dataobjects];
for (int i = 0; i < num_dataobjects; i++) {
    attrs[i] = new Attribute("num", "" + i, 1);
    h.registerInterest(attrs[i]);
    dobjs[i] = new DataObject();
    dobjs[i].addAttribute("num", "" + i, 1);
    h.publishDataObject(dobjs[i]);
    Thread.sleep(2000);
}

...

public synchronized void onNewDataObject(DataObject dObj) {
    num_dataobjects_received++;
    Attribute attr = dObj.getAttribute("num", 0);
    h.unregisterInterest(attr);
    System.out.println("Got data object " + " filepath="
        + dObj.getFilePath());
    dObj.dispose();
}

What is the expected output? What do you see instead?

If variable num_dataobjects is 10 ,we should receive 10 dataobjects with 
attribute num:0,num:1,num:2...,num:10.
But I only received one dataobject num:0.
OnNewDataObject() was called only once.
I guess it was "h.unregisterInterest()" that caused this problem,so I commented 
it:

public synchronized void onNewDataObject(DataObject dObj) {
    num_dataobjects_received++;
    //Attribute attr = dObj.getAttribute("num", 0);
    //h.unregisterInterest(attr);
    System.out.println("Got data object " + " filepath="
        + dObj.getFilePath());
    dObj.dispose();
}

Program ran correctly,10 dataobjects was received.

When unregisterInterest() was called,you could no longer receive dataobjects.

What version of the product are you using? On what operating system?

Haggle-0.4 on android 2.2

Please provide any additional information below.

Original issue reported on code.google.com by Donzell...@gmail.com on 27 May 2011 at 8:13

Attachments: