public class TcpConnection extends java.lang.Object implements Connection<Address>
TcpServer#receive(Object,byte[],int,int) when data has been received.| Modifier and Type | Class and Description |
|---|---|
protected class |
TcpConnection.Receiver |
protected class |
TcpConnection.Sender |
| Modifier and Type | Field and Description |
|---|---|
protected static byte[] |
cookie |
protected java.io.DataInputStream |
in |
protected long |
last_access |
protected java.io.DataOutputStream |
out |
protected Address |
peer_addr |
protected TcpConnection.Receiver |
receiver |
protected java.util.concurrent.locks.ReentrantLock |
send_lock |
protected TcpConnection.Sender |
sender |
protected TcpServer |
server |
protected java.net.Socket |
sock |
| Constructor and Description |
|---|
TcpConnection(Address peer_addr,
TcpServer server)
Creates a connection stub and binds it, use
connect(Address) to connect |
TcpConnection(java.net.Socket s,
TcpServer server) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
_send(byte[] data,
int offset,
int length,
boolean acquire_lock,
boolean flush)
Sends data using the 'out' output stream of the socket
|
void |
close() |
void |
connect(Address dest)
Called after
TcpConnection#TcpConnection(Address, SocketFactory) |
protected void |
doSend(byte[] data,
int offset,
int length,
boolean acquire_lock,
boolean flush) |
protected void |
flush() |
protected Address |
getPeerAddress() |
protected java.lang.String |
getSockAddress() |
protected long |
getTimestamp() |
boolean |
isConnected() |
boolean |
isExpired(long now) |
boolean |
isOpen() |
protected boolean |
isSenderUsed() |
protected boolean |
matchCookie(byte[] input) |
protected Address |
readPeerAddress(java.net.Socket client_sock)
Reads the peer's address.
|
void |
send(byte[] data,
int offset,
int length) |
void |
send(java.nio.ByteBuffer buf) |
protected void |
sendLocalAddress(Address local_addr)
Send the cookie first, then the our port number.
|
protected void |
setSocketParameters(java.net.Socket client_sock) |
void |
start() |
java.lang.String |
toString() |
protected void |
updateLastAccessed() |
protected final java.net.Socket sock
protected final java.util.concurrent.locks.ReentrantLock send_lock
protected static final byte[] cookie
protected java.io.DataOutputStream out
protected java.io.DataInputStream in
protected Address peer_addr
protected long last_access
protected volatile TcpConnection.Sender sender
protected volatile TcpConnection.Receiver receiver
protected final TcpServer server
public TcpConnection(Address peer_addr, TcpServer server) throws java.lang.Exception
connect(Address) to connectjava.lang.Exceptionpublic TcpConnection(java.net.Socket s,
TcpServer server)
throws java.lang.Exception
java.lang.Exceptionprotected long getTimestamp()
protected Address getPeerAddress()
protected boolean isSenderUsed()
protected java.lang.String getSockAddress()
protected void updateLastAccessed()
public void connect(Address dest) throws java.lang.Exception
TcpConnection#TcpConnection(Address, SocketFactory)connect in interface Connection<Address>java.lang.Exceptionpublic void start()
start in interface Connection<Address>public void send(byte[] data,
int offset,
int length)
throws java.lang.Exception
send in interface Connection<Address>data - Guaranteed to be non nulloffset - length - java.lang.Exceptionpublic void send(java.nio.ByteBuffer buf)
throws java.lang.Exception
send in interface Connection<Address>java.lang.Exceptionprotected void _send(byte[] data,
int offset,
int length,
boolean acquire_lock,
boolean flush)
throws java.lang.Exception
data - offset - length - acquire_lock - java.lang.Exceptionprotected void doSend(byte[] data,
int offset,
int length,
boolean acquire_lock,
boolean flush)
throws java.lang.Exception
java.lang.Exceptionprotected void flush()
throws java.lang.Exception
java.lang.Exceptionprotected void setSocketParameters(java.net.Socket client_sock)
throws java.net.SocketException
java.net.SocketExceptionprotected Address readPeerAddress(java.net.Socket client_sock) throws java.lang.Exception
java.lang.Exceptionprotected void sendLocalAddress(Address local_addr) throws java.lang.Exception
java.lang.Exceptionprotected boolean matchCookie(byte[] input)
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean isExpired(long now)
isExpired in interface Connection<Address>public boolean isConnected()
isConnected in interface Connection<Address>public boolean isOpen()
isOpen in interface Connection<Address>public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionCopyright © 1998-2020 Red Hat. All Rights Reserved.