public class TcpConnection extends Connection
BaseServer.receive(Address,byte[],int,int)
when data has been received.Modifier and Type | Class and Description |
---|---|
protected class |
TcpConnection.Receiver |
Modifier and Type | Field and Description |
---|---|
protected DataInputStream |
in |
protected DataOutputStream |
out |
protected TcpConnection.Receiver |
receiver |
protected ReentrantLock |
send_lock |
protected TcpBaseServer |
server |
protected Socket |
sock |
protected AtomicInteger |
writers |
cookie, last_access, peer_addr
Constructor and Description |
---|
TcpConnection(Address peer_addr,
TcpBaseServer server)
Creates a connection stub and binds it, use
connect(Address) to connect |
TcpConnection(Socket s,
TcpServer server) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
connect(Address dest) |
protected void |
connect(Address dest,
boolean send_local_addr) |
protected BufferedInputStream |
createBufferedInputStream(InputStream in) |
protected BufferedOutputStream |
createBufferedOutputStream(OutputStream out) |
protected void |
doSend(byte[] data,
int offset,
int length) |
protected void |
flush() |
protected String |
getSockAddress() |
protected long |
getTimestamp() |
boolean |
isConnected() |
boolean |
isExpired(long now) |
boolean |
isOpen() |
Address |
localAddress() |
Address |
peerAddress() |
protected Address |
readPeerAddress(Socket client_sock)
Reads the peer's address.
|
void |
send(byte[] data,
int offset,
int length) |
void |
send(ByteBuffer buf) |
protected void |
sendLocalAddress(Address local_addr)
Send the cookie first, then the our port number.
|
protected void |
setSocketParameters(Socket client_sock) |
void |
start() |
protected String |
status() |
String |
toString() |
protected void |
updateLastAccessed() |
protected final Socket sock
protected final ReentrantLock send_lock
protected DataOutputStream out
protected DataInputStream in
protected volatile TcpConnection.Receiver receiver
protected final TcpBaseServer server
protected final AtomicInteger writers
public TcpConnection(Address peer_addr, TcpBaseServer server) throws Exception
connect(Address)
to connectException
public Address localAddress()
localAddress
in class Connection
public Address peerAddress()
peerAddress
in class Connection
protected long getTimestamp()
protected String getSockAddress()
protected void updateLastAccessed()
public void connect(Address dest) throws Exception
connect
in class Connection
Exception
protected void connect(Address dest, boolean send_local_addr) throws Exception
Exception
public void start()
start
in class Connection
public void send(byte[] data, int offset, int length) throws Exception
send
in class Connection
data
- Guaranteed to be non nulloffset
- length
- Exception
public void send(ByteBuffer buf) throws Exception
send
in class Connection
Exception
protected void doSend(byte[] data, int offset, int length) throws Exception
Exception
protected void flush()
protected BufferedOutputStream createBufferedOutputStream(OutputStream out)
protected BufferedInputStream createBufferedInputStream(InputStream in)
protected void setSocketParameters(Socket client_sock) throws SocketException
SocketException
protected void sendLocalAddress(Address local_addr) throws Exception
Exception
protected Address readPeerAddress(Socket client_sock) throws Exception
Exception
protected String status()
public boolean isExpired(long now)
isExpired
in class Connection
public boolean isConnected()
isConnected
in class Connection
public boolean isOpen()
isOpen
in class Connection
public void close() throws IOException
IOException
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.