NodeIDType - This class is a simple utility to quickly set up a simple node
config object when port numbers can take "don't care" values. It
is also especially convenient for a local (single-machine) setup.
This class is mainly useful for quick testing.public class SampleNodeConfig<NodeIDType> extends java.lang.Object implements NodeConfig<NodeIDType>
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_START_PORT
The default starting port number beyond which nodes automatically get
port numbers assigned.
|
| Constructor and Description |
|---|
SampleNodeConfig() |
SampleNodeConfig(int defaultPort) |
SampleNodeConfig(int defaultPort,
int startNodeID,
int numLocalNodes) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(NodeIDType id,
java.net.InetAddress IP)
Add node with id mapped to IP and an auto-selected port number.
|
void |
addLocal(NodeIDType id) |
void |
clear() |
java.net.InetAddress |
getBindAddress(NodeIDType ID) |
static java.net.InetAddress |
getLocalAddress() |
java.net.InetAddress |
getNodeAddress(NodeIDType ID) |
java.util.Set<NodeIDType> |
getNodeIDs() |
int |
getNodePort(NodeIDType ID)
Maps each node ID to a port number.
|
java.util.Set<NodeIDType> |
getNodes() |
static int |
getPort(int ID) |
java.util.Set<NodeIDType> |
getValuesFromJSONArray(org.json.JSONArray array) |
java.util.Set<NodeIDType> |
getValuesFromStringSet(java.util.Set<java.lang.String> strNodes)
Converts a set of string node ids using valueOf.
|
void |
localSetup(int nNodes) |
void |
localSetup(int startNodeID,
int nNodes)
The caller can either specify the number of nodes, nNodes, or specify a
set of integer node IDs explicitly.
|
void |
localSetup(java.util.Set<NodeIDType> members)
Maps each element in members to the local IP address.
|
boolean |
nodeExists(NodeIDType ID) |
java.lang.String |
toString()
Pretty prints this node config information.
|
NodeIDType |
valueOf(java.lang.String nodeAsString)
Converts a string representation of a node id into the appropriate node
id type.
|
public static final int DEFAULT_START_PORT
public SampleNodeConfig(int defaultPort)
defaultPort - Assigns port numbers to nodes starting from defaultPortpublic SampleNodeConfig(int defaultPort,
int startNodeID,
int numLocalNodes)
defaultPort - startNodeID - numLocalNodes - public SampleNodeConfig()
public void localSetup(java.util.Set<NodeIDType> members)
members - public void localSetup(int startNodeID,
int nNodes)
startNodeID - nNodes - Number of nodes created.public void localSetup(int nNodes)
nNodes - public boolean nodeExists(NodeIDType ID)
nodeExists in interface NodeConfig<NodeIDType>public java.util.Set<NodeIDType> getNodeIDs()
getNodeIDs in interface NodeConfig<NodeIDType>public java.net.InetAddress getNodeAddress(NodeIDType ID)
getNodeAddress in interface NodeConfig<NodeIDType>id.public java.net.InetAddress getBindAddress(NodeIDType ID)
getBindAddress in interface NodeConfig<NodeIDType>id.public int getNodePort(NodeIDType ID)
defaultport + ID, else it is
defaultPort + ID.hashCode(). The port calculated above modulo
65536 is returned in order to ensure legitimate port numbers.getNodePort in interface NodeConfig<NodeIDType>id.public static int getPort(int ID)
ID - public java.util.Set<NodeIDType> getNodes()
public void add(NodeIDType id, java.net.InetAddress IP)
id - Node id.IP - IP address.public void addLocal(NodeIDType id)
id - public java.lang.String toString()
toString in class java.lang.Objectpublic NodeIDType valueOf(java.lang.String nodeAsString)
StringifiablevalueOf in interface Stringifiable<NodeIDType>public java.util.Set<NodeIDType> getValuesFromStringSet(java.util.Set<java.lang.String> strNodes)
StringifiablegetValuesFromStringSet in interface Stringifiable<NodeIDType>public java.util.Set<NodeIDType> getValuesFromJSONArray(org.json.JSONArray array) throws org.json.JSONException
getValuesFromJSONArray in interface Stringifiable<NodeIDType>org.json.JSONExceptionpublic static java.net.InetAddress getLocalAddress()
public void clear()