Eliminate BootstrapNodes#DIGITAL_OCEAN_1_DEV

Instead of including testing-related bootstrap nodes in the
BootstrapNodes class, this change introduces a Node#withPort method that
allows for obtaining a copy of an existing bootstrap node (e.g.
DIGITAL_OCEAN_1) with a modified port value.

This approach to `with*` methods allows for convenient customization of
value types without sacrificing immutability. See [1] for details.

[1]: http://blog.joda.org/2014/03/valjos-value-java-objects.html
This commit is contained in:
Chris Beams 2014-11-10 13:52:12 +01:00
parent 5ab837658b
commit adfd8b2ac4
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
3 changed files with 8 additions and 2 deletions

View File

@ -23,7 +23,6 @@ import java.util.List;
public interface BootstrapNodes {
Node DIGITAL_OCEAN_1 = Node.at("digitalocean1.bitsquare.io", "188.226.179.109");
Node DIGITAL_OCEAN_1_DEV = Node.at("digitalocean1.bitsquare.io", "188.226.179.109", 7367);
/**
* Alias to the default bootstrap node.

View File

@ -68,6 +68,13 @@ public final class Node {
return String.valueOf(port);
}
/**
* Return a copy of this node with the port updated to the given value.
*/
public Node withPort(int newPort) {
return Node.at(this.name, this.ip, newPort);
}
@Override
public boolean equals(Object object) {
if (this == object)

View File

@ -89,7 +89,7 @@ public class TomP2PTests {
// Typically you run the bootstrap node on localhost to test direct connection.
// If you have a setup where you are not behind a router you can also use a WAN bootstrap node.
private static final Node BOOTSTRAP_NODE = (FORCED_CONNECTION_TYPE == ConnectionType.DIRECT) ?
BootstrapNodes.LOCALHOST : BootstrapNodes.DIGITAL_OCEAN_1_DEV;
BootstrapNodes.LOCALHOST : BootstrapNodes.DIGITAL_OCEAN_1.withPort(7367);
private static final PeerAddress BOOTSTRAP_NODE_ADDRESS;