Class TcpConnection
java.lang.Object
org.jgroups.blocks.cs.Connection
org.jgroups.blocks.cs.TcpConnection
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
TcpConnectionNonBlocking
Blocking IO (BIO) connection. Starts 1 reader thread for the peer socket and blocks until data is available.
Calls
BaseServer.receive(Address,byte[],int,int) when data has been received.- Since:
- 3.6.5
- Author:
- Bela Ban
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected DataInputStreamprotected final byte[]protected DataOutputStreamprotected TcpConnection.Receiverprotected final Socketprotected booleanprotected final AtomicIntegerFields inherited from class Connection
closed_gracefully, cookie, GRACEFUL_CLOSE, last_access, peer_addr, send_lock, server -
Constructor Summary
ConstructorsConstructorDescriptionTcpConnection(Socket s, TcpServer server) Called byTcpServer.Acceptor.handleAccept(Socket)TcpConnection(Address peer_addr, TcpBaseServer server) Creates a connection to a remote peer, useconnect(Address)to connect -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidclose(boolean graceful) protected voidvoidprotected voidprotected DataInputStreamprotected DataOutputStreamprotected voiddoClose()protected voiddoSend(byte[] data, int offset, int length, boolean flush) voidflush()protected Stringprotected voidPerforms the TLS handshake, bounded bytimeoutms, which is what is left ofsock_conn_timeoutafter the TCP connect, so that the connection setup as a whole is bounded by it.booleanisClosed()booleanbooleanvoidlocklessSend(byte[] data, int offset, int length) protected AddressreadPeerAddress(Socket client_sock) Reads the peer's address.voidsend(byte[] data, int offset, int length) voidsend(ByteBuffer buf) voidsend(ByteBuffer[] bufs) protected voidsendLocalAddress(Address local_addr) Send the cookie first, then our port number.protected voidsetSocketParameters(Socket client_sock) voidstart()status()toString()boolean<T extends Connection>
TuseLockToSend(boolean u) Methods inherited from class Connection
getTimestamp, isClosedGracefully, isExpired, peerAddress, setClosedGracefully, updateLastAccessed
-
Field Details
-
sock
-
out
-
in
-
receiver
-
writers
-
connected
protected volatile boolean connected -
length_buf
protected final byte[] length_buf -
use_lock_to_send
protected boolean use_lock_to_send
-
-
Constructor Details
-
TcpConnection
Creates a connection to a remote peer, useconnect(Address)to connect- Throws:
Exception
-
TcpConnection
Called byTcpServer.Acceptor.handleAccept(Socket)- Throws:
Exception
-
-
Method Details
-
useLockToSend
public boolean useLockToSend() -
useLockToSend
-
localAddress
- Specified by:
localAddressin classConnection
-
getSockAddress
-
connect
- Specified by:
connectin classConnection- Throws:
Exception
-
connect
-
handshake
Performs the TLS handshake, bounded bytimeoutms, which is what is left ofsock_conn_timeoutafter the TCP connect, so that the connection setup as a whole is bounded by it. If the server has a timer, the handshake as a whole is bounded: a watchdog closes the socket when the deadline expires, which makes the blocked handshake fail. Without a timer, SO_TIMEOUT is used, which only bounds each single read of the handshake.- Throws:
IOException
-
start
public void start()- Specified by:
startin classConnection
-
send
- Specified by:
sendin classConnection- Throws:
Exception
-
send
- Specified by:
sendin classConnection- Throws:
Exception
-
send
- Specified by:
sendin classConnection- Throws:
Exception
-
locklessSend
-
doSend
-
flush
public void flush()- Specified by:
flushin classConnection
-
createDataOutputStream
-
createDataInputStream
-
setSocketParameters
- Throws:
SocketException
-
sendLocalAddress
-
readPeerAddress
-
toString
-
status
- Specified by:
statusin classConnection
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin classConnection
-
isConnectionPending
public boolean isConnectionPending()- Specified by:
isConnectionPendingin classConnection
-
isClosed
public boolean isClosed()- Specified by:
isClosedin classConnection
-
close
- Throws:
IOException
-
close
- Specified by:
closein classConnection- Throws:
IOException
-
closeGracefully
protected void closeGracefully() -
doClose
protected void doClose()
-