mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-19 13:45:48 +00:00
Make adding/removing event listeners lock PeerGroup. Take out use of synchronizedList as it's redundant. Resolves issue 148.
This commit is contained in:
parent
31463c506f
commit
32a2be53c4
@ -121,7 +121,7 @@ public class PeerGroup {
|
|||||||
// peerEventListeners get a subset of events seen by the group. We add our own internal listener to this so
|
// peerEventListeners get a subset of events seen by the group. We add our own internal listener to this so
|
||||||
// when we download a transaction, we can distribute it to each Peer in the pool so they can update the
|
// when we download a transaction, we can distribute it to each Peer in the pool so they can update the
|
||||||
// transactions confidence level if they've seen it be announced/when they see it be announced.
|
// transactions confidence level if they've seen it be announced/when they see it be announced.
|
||||||
peerEventListeners = Collections.synchronizedList(new ArrayList<PeerEventListener>());
|
peerEventListeners = new ArrayList<PeerEventListener>();
|
||||||
addEventListener(new AbstractPeerEventListener() {
|
addEventListener(new AbstractPeerEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTransaction(Peer peer, Transaction t) {
|
public void onTransaction(Peer peer, Transaction t) {
|
||||||
@ -224,13 +224,13 @@ public class PeerGroup {
|
|||||||
* <p>The listener will be locked during callback execution, which in turn will cause network message processing
|
* <p>The listener will be locked during callback execution, which in turn will cause network message processing
|
||||||
* to stop until the listener returns.</p>
|
* to stop until the listener returns.</p>
|
||||||
*/
|
*/
|
||||||
public void addEventListener(PeerEventListener listener) {
|
public synchronized void addEventListener(PeerEventListener listener) {
|
||||||
assert listener != null;
|
assert listener != null;
|
||||||
peerEventListeners.add(listener);
|
peerEventListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The given event listener will no longer be called with events. */
|
/** The given event listener will no longer be called with events. */
|
||||||
public boolean removeEventListener(PeerEventListener listener) {
|
public synchronized boolean removeEventListener(PeerEventListener listener) {
|
||||||
return peerEventListeners.remove(listener);
|
return peerEventListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -569,7 +569,7 @@ public class PeerGroup {
|
|||||||
needHandleDeath = peers.remove(peer);
|
needHandleDeath = peers.remove(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is unsynchronized since it can take awhile
|
// This is unsynchronized since it can take a while.
|
||||||
if (needHandleDeath)
|
if (needHandleDeath)
|
||||||
handlePeerDeath(peer);
|
handlePeerDeath(peer);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user