Package biz.onixs.util.network
Interface TcpConnection
-
public interface TcpConnectionThe interface provides methods for sending and receiving data via TCP connection. Also methods to start and stop the sending and receiving data, send and receive data, set timeouts, set maximum queue size, set thread names and set a listener to listen for events.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceTcpConnection.ListenerThe interface represents a listener for the TCP connection events
-
Field Summary
Fields Modifier and Type Field Description static TcpConnection.ListenerNULL_LISTENERThis field represents a dummy implementation of theTcpConnection.Listenerinterface.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes the connection.longgetOutQueueBytes()Returns the number of bytes in the out queue to be send.intgetTcpSendingChunkSize()Returns TCP sending chunk size, in bytes.booleanisClosed()Returns true if the connection is closed, false otherwise.booleanisSenderStillInactive()Returns true if no data is sent and it remains inactive, false otherwise.voidsend(ByteBuffer byteBuffer)Sends the givenByteBufferthrough the connection.voidsetListener(TcpConnection.Listener listener)Sets the listener to listen for events.voidsetReceiverSpinningTimeout(long timeout, TimeUnit timeUnit)Sets the receiving data spinning timeout.voidsetReceiverThreadName(String name)Sets the name for the receiver thread if the connection useConnectionMode.DEDICATED_THREADSmode.voidsetReceiverTimeout(long timeout, TimeUnit timeUnit)Sets the timeout for the receiving data.voidsetSenderSpinningTimeout(long timeout, TimeUnit timeUnit)Sets the sending data spinning timeout.voidsetSenderTimeout(long timeout, TimeUnit timeUnit)Sets the timeout for the sending data.voidsetSendQueueMaxSize(int size)Sets the maximum size for the send queue.voidsetTcpSendingChunkSize(int size)TCP sending chunk size, in bytes.voidstartReceiver()Starts the receiving data.voidstartSender()Starts the sending data.
-
-
-
Field Detail
-
NULL_LISTENER
static final TcpConnection.Listener NULL_LISTENER
This field represents a dummy implementation of theTcpConnection.Listenerinterface.
-
-
Method Detail
-
startSender
void startSender()
Starts the sending data.
-
startReceiver
void startReceiver() throws IOExceptionStarts the receiving data.- Throws:
IOException- if an I/O error occurs.
-
send
void send(ByteBuffer byteBuffer)
Sends the givenByteBufferthrough the connection.- Parameters:
byteBuffer- the buffer to be sent.
-
setListener
void setListener(TcpConnection.Listener listener)
Sets the listener to listen for events.- Parameters:
listener- the listener to be set.
-
close
void close()
Closes the connection.
-
isClosed
boolean isClosed()
Returns true if the connection is closed, false otherwise.- Returns:
- true if the connection is closed, false otherwise.
-
isSenderStillInactive
boolean isSenderStillInactive()
Returns true if no data is sent and it remains inactive, false otherwise.- Returns:
- true if no data is sent and it remains inactive, false otherwise.
-
getOutQueueBytes
long getOutQueueBytes()
Returns the number of bytes in the out queue to be send.- Returns:
- the number of bytes in the out queue to be send.
-
setSenderTimeout
void setSenderTimeout(long timeout, TimeUnit timeUnit)Sets the timeout for the sending data.- Parameters:
timeout- the timeout value, in case it is 0, the timeout will never elapse.timeUnit- the time unit for the timeout value.
-
setReceiverTimeout
void setReceiverTimeout(long timeout, TimeUnit timeUnit)Sets the timeout for the receiving data.- Parameters:
timeout- the timeout value, in case it is 0, the timeout will never elapse.timeUnit- the time unit for the timeout value.
-
setSenderSpinningTimeout
void setSenderSpinningTimeout(long timeout, TimeUnit timeUnit)Sets the sending data spinning timeout.- Parameters:
timeout- the timeout value.timeUnit- the time unit for the timeout value.
-
setReceiverSpinningTimeout
void setReceiverSpinningTimeout(long timeout, TimeUnit timeUnit)Sets the receiving data spinning timeout.- Parameters:
timeout- the timeout value.timeUnit- the time unit for the timeout value.
-
setSendQueueMaxSize
void setSendQueueMaxSize(int size)
Sets the maximum size for the send queue.If the max size of the sending queue is reached the
send(ByteBuffer)method call will throw an exception- Parameters:
size- the maximum size for the send queue.
-
setReceiverThreadName
void setReceiverThreadName(String name)
Sets the name for the receiver thread if the connection useConnectionMode.DEDICATED_THREADSmode.- Parameters:
name- the name of the receiver thread.
-
setTcpSendingChunkSize
void setTcpSendingChunkSize(int size)
TCP sending chunk size, in bytes.Limits the amount of data that can be sent in a single send operation. The default value 0 (zero) means no such limit.
- Parameters:
size- The limit.
-
getTcpSendingChunkSize
int getTcpSendingChunkSize()
Returns TCP sending chunk size, in bytes.- Returns:
- TCP sending chunk size, in bytes.
-
-