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

[PAN-2588] Create P2PNetwork Builder #1343

Merged
merged 5 commits into from
Apr 29, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Apr 26, 2019

PR description

Create a P2PNetwork builder. Using this builder pattern simplifies tests and should make it simpler to update the P2PNetwork in the future.

This PR also:

  • creates a network package
  • moves the existing netty package to network.netty
  • splits up the existing NettyP2PNetworkTest into two tests: one that depends on the concrete implementation details of the network and one that doesn't
  • rename NettyP2PNetwork to DefaultP2PNework
  • configure PeerRequirement's on the PeerDiscoveryAgent instance rather than passing the requirements to the constructor - this allows us to construct the discovery agent outside of the P2PNetwork and pass it in as a dependency

Reviewer's Notes

To review, it may be easier to look through individual commits in order to view changes without the noise of the file reorganization.

@mbaxter mbaxter force-pushed the PAN-2588/p2p-network-builder branch from cc7baab to 049ed1c Compare April 29, 2019 14:30
@mbaxter mbaxter marked this pull request as ready for review April 29, 2019 14:51
*
* @return A stream of discovered peers on the network.
*/
Stream<DiscoveryPeer> getDiscoveredPeers();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure a Stream should be returned as a property. Streams are single use and have transient state, and mutations are not propagated back into the returning object. Could this be renamed streamDiscoveredPeers? This may need another PR to push this getFoo -> streamFoo done properly, but the name would then reflect reality.

Another option is to return the backing collection, but that looks to be an even deeper refactor to do properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up to now, we haven't used any special naming for streams. But we can discuss offline and maybe create a follow-up PR.

@@ -70,7 +71,7 @@
private static final long PEER_REFRESH_INTERVAL_MS = MILLISECONDS.convert(30, TimeUnit.MINUTES);

protected final List<DiscoveryPeer> bootstrapPeers;
private final PeerRequirement peerRequirement;
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

😄 CopyOnWriteArray is very concurrent friendly.

peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
metricsSystem);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;

metricsSystem.createIntegerGauge(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, is the VertxPeerDiscoveryAgent created once and only once per server? If not the createIntegerGauge call will result in errors on the second and subsequent calls. Not sure there is any way to hedge this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently only created once.

@@ -741,4 +716,140 @@ private void onConnectionEstablished(final PeerConnection connection) {
connections.registerConnection(connection);
connectCallbacks.forEach(callback -> callback.accept(connection));
}

public static class Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but we should consider using a Builder library for these in the future to cut down on busy-work code. Lombok and Guava autoValues both have support for the builder pattern like we use it. Guava has the advantage we use part of it in our code already.

@mbaxter mbaxter merged commit a6003b6 into PegaSysEng:master Apr 29, 2019
notlesh pushed a commit to notlesh/pantheon that referenced this pull request May 4, 2019
notlesh pushed a commit to notlesh/pantheon that referenced this pull request May 14, 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