Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2730] Create MaintainedPeers class #1484

Merged
merged 4 commits into from
May 22, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented May 22, 2019

PR description

Move peer maintenance list management into a new MaintainedPeers class. This change will help facilitate the break up of logic within DefaultP2PNetwork by decoupling the add / remove action from the handling of peers in this list.

This change also makes tests more robust by exposing a public dependency that can be checked directly, rather than having to reach into the DefaultP2PNetwork to check a private field. Some connection-related checks were moved into DefaultP2PNetwork.connect in order to reduce the amount of custom logic executed when a new peer is added to MaintainedPeers.

Copy link
Contributor

@AbdelStark AbdelStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left few optional comments.

peer.getEnodeURL().isListening(),
"Invalid enode url. Enode url must contain a non-zero listening port.");
boolean wasAdded = maintainedPeers.add(peer);
addedSubscribers.forEach(s -> s.onPeerAdded(peer, wasAdded));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not invoking subscribers in parallel ? Since there is no particular check in the foreach loop it is doable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as-is for now because I don't want to get into changing the Subscribers interface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have too.
I was just suggesting to do : addedSubscribers.parallelStream().forEach(s -> s.onPeerAdded(peer, wasAdded)); instead of addedSubscribers.forEach(s -> s.onPeerAdded(peer, wasAdded));


public boolean remove(final Peer peer) {
boolean wasRemoved = maintainedPeers.remove(peer);
removedCallbackSubscribers.forEach(s -> s.onPeerRemoved(peer, wasRemoved));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous.

return maintainedPeers.stream();
}

public interface PeerAddedCallback {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionalInterface ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call - done

@mbaxter mbaxter merged commit 0acea7c into PegaSysEng:master May 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants