public class NetworkNode
extends java.lang.Object
implements java.io.Serializable
MessageDispatcher
on a networked computer. The NetworkNode is used identify senders and receivers
of messages. For scenarios with multiple nodes per peer that shares the top-level
message dispatcher, there is a sub-ID identification.MessageDispatcher
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected java.net.InetAddress |
host
IP address of this network node
|
protected static java.util.Map<java.lang.Integer,MessageDispatcher> |
messageDispMappingTable
Mapping table for translating parent message dispatchers - key is port and value is a top-level dispatcher for that port
|
protected static java.util.Map<java.net.InetAddress,java.util.Map<java.lang.Integer,NetworkNode>> |
netnodeMappingTable
Mapping table for translating original host names (optionally plus ports) to new ones
|
protected java.lang.Integer |
nodeID
Identification of a specific node, when several logical nodes are running on one physical peer.
|
protected int |
port
TCP/UDP port of this network node
|
Constructor and Description |
---|
NetworkNode(java.net.InetAddress host,
int port)
Creates a new instance of NetworkNode for the specified host/port pair.
|
NetworkNode(java.net.InetAddress host,
int port,
java.lang.Integer nodeID)
Creates a new instance of NetworkNode for the specified host, port and nodeID.
|
NetworkNode(NetworkNode node)
Creates a copy of the provided NetworkNode.
|
NetworkNode(NetworkNode node,
boolean copyNodeID)
Creates a copy of the provided NetworkNode.
|
NetworkNode(NetworkNode node,
java.lang.Integer nodeID)
Creates a copy of the provided NetworkNode.
|
NetworkNode(java.lang.String host,
int port)
Creates a new instance of NetworkNode for the specified host/port pair.
|
NetworkNode(java.lang.String host,
int port,
java.lang.Integer nodeID)
Creates a new instance of NetworkNode for the specified host, port and nodeID.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Compares this network node with another object.
|
boolean |
equalsIgnoreNodeID(NetworkNode node)
Compare the address and port of actual network node with other network node's host and port.
|
java.net.InetAddress |
getHost()
Returns the IP address of this network node.
|
java.lang.Integer |
getNodeID()
Returns the sub-ID of this network node.
|
int |
getPort()
Returns the TCP/UDP port of this network node.
|
int |
hashCode()
Returns a hash code value for this network node.
|
boolean |
hasNodeID()
Returns true if the nodeID was set.
|
static void |
loadHostMappingTable(java.lang.String fileName)
Load the mapping table from the specified file.
|
static void |
resetHostMappingTable()
Reset the mapping table - it will no longer provide any remapping.
|
static void |
setHostMappingTable(java.util.Map<java.net.InetAddress,java.util.Map<java.lang.Integer,NetworkNode>> netnodeMappingTable,
java.util.Map<java.lang.Integer,MessageDispatcher> messageDispMappingTable)
Setter method for the mapping table.
|
java.lang.String |
toString()
Returns the string representation of this network node.
|
static NetworkNode |
valueOf(java.lang.String hostPortNode)
Creates a new instance of NetworkNode from string "host:port#node".
|
protected java.net.InetAddress host
protected int port
protected final java.lang.Integer nodeID
protected static java.util.Map<java.net.InetAddress,java.util.Map<java.lang.Integer,NetworkNode>> netnodeMappingTable
protected static java.util.Map<java.lang.Integer,MessageDispatcher> messageDispMappingTable
public NetworkNode(java.net.InetAddress host, int port, java.lang.Integer nodeID)
host
- the IP address of the network nodeport
- the TCP/UDP port of the network nodenodeID
- the sub-ID of the network nodepublic NetworkNode(java.lang.String host, int port, java.lang.Integer nodeID) throws java.net.UnknownHostException
host
- the FQDN address of the network nodeport
- the TCP/UDP port of the network nodenodeID
- the sub-ID of the network nodejava.net.UnknownHostException
- if the provided FQDN address cannot be resolved to IP addresspublic NetworkNode(java.net.InetAddress host, int port)
host
- the IP address of the network nodeport
- the TCP/UDP port of the network nodepublic NetworkNode(java.lang.String host, int port) throws java.net.UnknownHostException
host
- the FQDN address of the network nodeport
- the TCP/UDP port of the network nodejava.net.UnknownHostException
- if the provided FQDN address cannot be resolved to IP addresspublic NetworkNode(NetworkNode node)
node
- the source NetworkNode to copy frompublic NetworkNode(NetworkNode node, boolean copyNodeID)
node
- the source NetworkNode to copy fromcopyNodeID
- if true, the sub-ID attribute is copied, otherwise, it is set to nullpublic NetworkNode(NetworkNode node, java.lang.Integer nodeID)
node
- the source NetworkNode to copy fromnodeID
- the sub-ID of the network nodepublic final java.net.InetAddress getHost()
public final int getPort()
public final java.lang.Integer getNodeID()
public final boolean hasNodeID()
public static NetworkNode valueOf(java.lang.String hostPortNode) throws java.net.UnknownHostException
hostPortNode
- the string to parse the NetworkNode from - its format should be "host", "host:port" or "host:port#node"java.net.UnknownHostException
- if the host name cannot be resolved to IP addresspublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the object to compare withobj
argument; false
otherwise.public boolean equalsIgnoreNodeID(NetworkNode node)
node
- the other network node to compare this network node withtrue
if host and port of this network node is equal to the host and port of the netNode argument;
false
is returned otherwisepublic int hashCode()
hashCode
in class java.lang.Object
public static void setHostMappingTable(java.util.Map<java.net.InetAddress,java.util.Map<java.lang.Integer,NetworkNode>> netnodeMappingTable, java.util.Map<java.lang.Integer,MessageDispatcher> messageDispMappingTable)
resetHostMappingTable()
should be used to disable remapping.netnodeMappingTable
- the new host names mapping table or null to disable it.messageDispMappingTable
- mapping table for translating parent message dispatchers - key is port and value is a top-level dispatcher for that portpublic static void loadHostMappingTable(java.lang.String fileName) throws java.net.UnknownHostException, java.io.IOException
resetHostMappingTable()
should be used to disable remapping.fileName
- the file to load mapping table fromjava.net.UnknownHostException
- if a host specified in mapping cannot be resolved (mappings loaded before the exception occurred are kept loaded)java.io.IOException
- if there was a problem loading the file (mappings loaded before the exception occurred are kept loaded)public static void resetHostMappingTable()
public java.lang.String toString()
toString
in class java.lang.Object