|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectme.edwards.des.net.Connection
public class Connection
Data structure to handle the connection between Nodes
. A
Connection tracks the ping and status of a connection between Nodes and
ensures that connection stay alive.
Created on: Oct 17, 2015 at 10:21:02 AM
Field Summary | |
---|---|
private java.net.InetAddress |
address
|
private static int |
CONNECT_TIMEOUT
|
private boolean |
connected
|
static int |
CONNECTION_BOTH
The connection is agreed upon by both nodes |
static int |
CONNECTION_NODE_ONLY
A connection was initiated by this node |
static int |
CONNECTION_PEER_ONLY
A connection was initiated by a peer node |
private int |
connectionStatus
|
private static java.util.logging.Logger |
logger
|
private java.lang.String |
name
|
private Node |
node
|
private long |
ping
|
private static int |
PING_TIMEOUT
|
private boolean |
pingSent
|
private long |
pingValue
|
private int |
port
|
private java.net.Socket |
socket
|
Constructor Summary | |
---|---|
Connection(Node node,
java.net.Socket socket)
Creates new Connection using the local Node and the socket
connecting to the remote Node. |
Method Summary | |
---|---|
void |
connect()
Connects the local Node to the remote Node through this Connection. |
void |
disconnect()
Disconnects the local and remote Nodes, closes the connection socket and closes node communication. |
java.net.InetAddress |
getAddress()
Returns the destination address of this connection. |
int |
getConnectionStatus()
Returns the current connection status. CONNECTION_NODE_ONLY
A connection was initiated by this node
CONNECTION_PEER_ONLY
A connection was initiated by a peer node
CONNECTION_BOTH
The connection is agreed upon by both nodes
|
java.lang.String |
getHostName()
Returns this connection's host name in the format "/ADDRESS:PORT". |
java.lang.String |
getName()
Returns this connection's common name (if any). |
int |
getPort()
Returns the destination port of this connection. |
java.net.Socket |
getSocket()
Returns the socket used by this connection. |
boolean |
isConnected()
Returns true if the connection is currently connected. |
void |
pong(long pong)
Notifies the connection that the Pong was received. |
void |
send(Packet packet)
Sends a Packet through this connection to the remote
Node . |
void |
setConnectionStatus(int status)
Sets the current connection status. CONNECTION_NODE_ONLY
A connection was initiated by this node
CONNECTION_PEER_ONLY
A connection was initiated by a peer node
CONNECTION_BOTH
The connection is agreed upon by both nodes
|
void |
setName(java.lang.String name)
Sets this connection's common name. |
void |
setPort(int port)
Sets the port of this connection. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static int CONNECTION_NODE_ONLY
public static int CONNECTION_PEER_ONLY
public static int CONNECTION_BOTH
private static final java.util.logging.Logger logger
private static final int CONNECT_TIMEOUT
private static final int PING_TIMEOUT
private Node node
private java.net.Socket socket
private java.lang.String name
private java.net.InetAddress address
private int port
private boolean connected
private int connectionStatus
private long ping
private long pingValue
private boolean pingSent
Constructor Detail |
---|
public Connection(Node node, java.net.Socket socket)
Node
and the socket
connecting to the remote Node.
node
- Local Node which owns this connectionsocket
- Socket to remote Node which is used by this connectionMethod Detail |
---|
public java.net.Socket getSocket()
Node
public java.lang.String getName()
public void setName(java.lang.String name)
name
- Human-readable common name of this connectionpublic java.lang.String getHostName()
public java.net.InetAddress getAddress()
public int getPort()
public void setPort(int port)
port
- Port of remote Nodepublic boolean isConnected()
public int getConnectionStatus()
CONNECTION_NODE_ONLY |
A connection was initiated by this node |
CONNECTION_PEER_ONLY |
A connection was initiated by a peer node |
CONNECTION_BOTH |
The connection is agreed upon by both nodes |
public void setConnectionStatus(int status)
CONNECTION_NODE_ONLY |
A connection was initiated by this node |
CONNECTION_PEER_ONLY |
A connection was initiated by a peer node |
CONNECTION_BOTH |
The connection is agreed upon by both nodes |
status
- New connection statuspublic java.lang.String toString()
toString
in class java.lang.Object
public void send(Packet packet)
Packet
through this connection to the remote
Node
.
packet
- Packet to sendpublic void pong(long pong)
Pong
was received.
This method is used by Node.parse(byte[], Connection).
pong
- Payload of the Pong received (Must be one more than the sent
Ping value to be valid)public void connect()
public void disconnect()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |