Package org.jgroups.blocks.cs
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected DataInputStreamprotected final byte[]protected OutputStreamprotected TcpConnection.Receiverprotected final ReentrantLockprotected final Socketprotected final AtomicIntegerFields inherited from class org.jgroups.blocks.cs.Connection
cookie, last_access, peer_addr, 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()voidprotected voidprotected DataInputStreamprotected OutputStreamprotected voiddoSend(byte[] data, int offset, int length) protected voiddoSend(byte[] data, int offset, int length, boolean flush) voidflush()protected StringbooleanisClosed()booleanbooleanprotected AddressreadPeerAddress(Socket client_sock) Reads the peer's address.voidsend(byte[] data, int offset, int length) voidsend(ByteBuffer buf) protected voidsendLocalAddress(Address local_addr) Send the cookie first, then our port number.protected voidsetSocketParameters(Socket client_sock) voidstart()status()toString()Methods inherited from class org.jgroups.blocks.cs.Connection
getTimestamp, isExpired, peerAddress, updateLastAccessed
-
Field Details
-
sock
-
send_lock
-
out
-
in
-
receiver
-
writers
-
connected
protected volatile boolean connected -
length_buf
protected final byte[] length_buf
-
-
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
-
localAddress
- Specified by:
localAddressin classConnection
-
getSockAddress
-
connect
- Specified by:
connectin classConnection- Throws:
Exception
-
connect
- Throws:
Exception
-
start
public void start()- Specified by:
startin classConnection
-
send
- Specified by:
sendin classConnection- Throws:
Exception
-
send
- Specified by:
sendin classConnection- Throws:
Exception
-
doSend
- Throws:
Exception
-
doSend
- Throws:
Exception
-
flush
public void flush()- Specified by:
flushin classConnection
-
createDataOutputStream
-
createDataInputStream
-
setSocketParameters
- Throws:
SocketException
-
sendLocalAddress
Send the cookie first, then our port number. If the cookie doesn't match the receiver's cookie, the receiver will reject the connection and close it.- Throws:
Exception
-
readPeerAddress
Reads the peer's address. First a cookie has to be sent which has to match my own cookie, otherwise the connection will be refused- Throws:
Exception
-
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
-