novitski / bitcoinj

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

[Pull Request] PeerGroup.clearEventListeners #426

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I added a convenience method to PeerGroup in order to be able to clear all 
event listeners at once instead of doing explicit calls for each of them. 
Nothing fancy, just a two liner. 

You can check it here:
 https://code.google.com/r/alexanderlolis-bitcoinj/source/detail?r=5ac94ea3d01799bcd7676579efcc83e7836ce7ea&name=clear_event_listeners

Original issue reported on code.google.com by alexande...@gmail.com on 8 Jul 2013 at 8:43

GoogleCodeExporter commented 9 years ago
I wonder if that might accidently clear listeners that the framework has set 
internally.

Perhaps only allow clearing of listeners of a specific type, like

peerGroup.clearEventListeners(MyListener.class);

Original comment by andreas....@gmail.com on 8 Jul 2013 at 8:52

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The reason I added this is because I am restarting PeerGroup when something   
blows up so before i call stopAndWait method, I clear all listeners from it 
first.

Original comment by alexande...@gmail.com on 8 Jul 2013 at 9:23

GoogleCodeExporter commented 9 years ago
Clearing all listeners before it's stopped might cause weirdness, I'm thinking 
maybe what Andreas suggested is better.

What do you mean by "blows up", exactly? Perhaps we can fix this issue with 
better exception handling?

Original comment by hearn@google.com on 9 Jul 2013 at 12:51

GoogleCodeExporter commented 9 years ago
I have implemented PeerEventListener.onException and inside there whenever an 
exception from my app is get caught i restart peer group (by creating a new 
object) but I remove the event listeners first in order to ensure that I won't 
create any memory leaks.

Maybe i am wrong thought and calling stopAndWait() and then creating a new 
PeerGroup will be just fine :)

Original comment by alexande...@gmail.com on 9 Jul 2013 at 1:43

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 2c26f8802b01.

Original comment by hearn@google.com on 11 Jul 2013 at 2:35