Class ChannelBase
java.lang.Object
cl.netswitch.lib.aio.ChannelBase
- Direct Known Subclasses:
ClientChannel, ServerChannel
Asynchronous bidirectional communication channel with NetSwitch server.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this channel, relinquishing any underlying resources.final voidConnects this channel to remote address.final voidLogs a fine message with supplied format and arguments.final intReturns the size of the writer queue (messages).final InetSocketAddressReturns the local address ornullif not connected.final LoggerReturns the logger of this channel.final StringReturns the logger header of this channel.final intReturns the free size of the reader buffer (bytes).final intReturns the maximum size of the reader buffer (bytes).final intReturns the minimum size of the reader buffer (bytes).final intReturns the warning size of the reader buffer (bytes).final longReturns the total number of bytes read by this channel.final intReturns the total number of messages read by this channel.final InetSocketAddressReturns the remote address ornullif not connected.final booleanReturnstrueif the SO_KEEPALIVE socket option is enabled.final intReturns the maximum time for an SSL handshake (milliseconds).final StringgetTag()Returns the connection tag ornullif not connected.final booleanReturnstrueif the TCP_NODELAY socket option is enabled.final StringReturns the trust store file ornullif none defined.final longReturns the total number of bytes written by this channel.final intReturns the total number of messages written by this channel.final intReturns the size of the writer queue (messages).protected abstract voidhandleInbound(Message inbound) Handles an inbound message received by this channel.final voidGenerate an information entry with message and args.final booleanisClosed()Returnstrueif this channel is closed.final booleanReturnstrueif this channel is connected.final booleanisLoggable(Level level) Returnstrueif the given message level is being logged.final booleanisSecure()Returnstrueif this channel is secure.final booleanReturnstrueif tracing inbound and outbound messages.final voidsetCompressionThreshold(int compressionThreshold) Changes the value of the propertycompressionThreshold.protected final voidChanges the logger of this channel.protected final voidsetLoggerHeader(String header) Changes the logger header of this channel.final voidsetReaderBufferFreeSize(int readerBufferFreeSize) Changes the free size of the reader buffer (bytes).final voidsetReaderBufferMaxSize(int readerBufferMaxSize) Changes the maximum size of the reader buffer (bytes).final voidsetReaderBufferMinSize(int readerBufferMinSize) Changes the minimum size of the reader buffer (bytes).final voidsetReaderBufferWarnSize(int readerBufferWarnSize) Changes the warning size of the reader buffer (bytes).final voidsetSoKeepAlive(boolean value) Enables or disables the SO_KEEPALIVE socket option.final voidsetSslHandshakeTimeout(int sslHandshakeTimeout) Changes the maximum time for an SSL handshake (milliseconds).final voidsetTcpNoDelay(boolean value) Enables or disables the TCP_NODELAY socket option.final voidsetTracing(boolean value) Enables or disables tracing of inbound and outbound messages.final voidsetTrustStoreFile(String trustStore) Changes the trust store file of this channel.final voidsetWriterQueueSize(int writerQueueSize) Changes the value of the propertywriterQueueSize.final voidGenerate a severe error entry with message and args.final voidGenerate a severe error entry with message, args and throwable.final voidGenerate a warning entry with message and args.final voidwriteMessage(Message outbound) Writes the supplied outbound message to this channel.final voidwriteMessage(Message outbound, WriteHandler handler) Writes the supplied outbound message with optional write handler.
-
Constructor Details
-
ChannelBase
protected ChannelBase()Constructs a newChannelBaseinstance.
-
-
Method Details
-
getLogger
Returns the logger of this channel.- Returns:
- the logger of this channel.
-
setLogger
Changes the logger of this channel.- Parameters:
logger- the new logger (can be null).
-
getLoggerHeader
Returns the logger header of this channel.- Returns:
- the logger header of this channel.
-
setLoggerHeader
Changes the logger header of this channel.- Parameters:
header- the new logger header (can be null).
-
isClosed
public final boolean isClosed()Returnstrueif this channel is closed.- Returns:
trueif this channel is closed.
-
isConnected
public final boolean isConnected()Returnstrueif this channel is connected.- Returns:
trueif this channel is connected.
-
isSecure
public final boolean isSecure()Returnstrueif this channel is secure.- Returns:
trueif this channel is secure.
-
getTag
Returns the connection tag ornullif not connected.- Returns:
- the connection tag or
nullif not connected.
-
getLocalAddress
Returns the local address ornullif not connected.- Returns:
- the local address or
nullif not connected.
-
getRemoteAddress
Returns the remote address ornullif not connected.- Returns:
- the remote address or
nullif not connected.
-
getSoKeepAlive
public final boolean getSoKeepAlive()Returnstrueif the SO_KEEPALIVE socket option is enabled.- Returns:
trueif the SO_KEEPALIVE socket option is enabled.
-
setSoKeepAlive
public final void setSoKeepAlive(boolean value) Enables or disables the SO_KEEPALIVE socket option.- Parameters:
value- the new value of the property.
-
getTcpNoDelay
public final boolean getTcpNoDelay()Returnstrueif the TCP_NODELAY socket option is enabled.- Returns:
trueif the TCP_NODELAY socket option is enabled.
-
setTcpNoDelay
public final void setTcpNoDelay(boolean value) Enables or disables the TCP_NODELAY socket option.- Parameters:
value- the new value of the property.
-
getTrustStoreFile
Returns the trust store file ornullif none defined.- Returns:
- the trust store file or
nullif none defined.
-
setTrustStoreFile
Changes the trust store file of this channel.- Parameters:
trustStore- the trust store file (can be null).
-
getSslHandshakeTimeout
public final int getSslHandshakeTimeout()Returns the maximum time for an SSL handshake (milliseconds).- Returns:
- the maximum time for an SSL handshake (milliseconds).
-
setSslHandshakeTimeout
public final void setSslHandshakeTimeout(int sslHandshakeTimeout) Changes the maximum time for an SSL handshake (milliseconds).- Parameters:
sslHandshakeTimeout- the new value of the property.
-
getReaderBufferMinSize
public final int getReaderBufferMinSize()Returns the minimum size of the reader buffer (bytes).- Returns:
- the minimum size of the reader buffer (bytes).
-
setReaderBufferMinSize
public final void setReaderBufferMinSize(int readerBufferMinSize) Changes the minimum size of the reader buffer (bytes).- Parameters:
readerBufferMinSize- the minimum size of the reader buffer (bytes).
-
getReaderBufferFreeSize
public final int getReaderBufferFreeSize()Returns the free size of the reader buffer (bytes).- Returns:
- the free size of the reader buffer (bytes).
-
setReaderBufferFreeSize
public final void setReaderBufferFreeSize(int readerBufferFreeSize) Changes the free size of the reader buffer (bytes).- Parameters:
readerBufferFreeSize- the free size of the reader buffer (bytes).
-
getReaderBufferWarnSize
public final int getReaderBufferWarnSize()Returns the warning size of the reader buffer (bytes).- Returns:
- the warning size of the reader buffer (bytes).
-
setReaderBufferWarnSize
public final void setReaderBufferWarnSize(int readerBufferWarnSize) Changes the warning size of the reader buffer (bytes).- Parameters:
readerBufferWarnSize- the warning size of the reader buffer (bytes).
-
getReaderBufferMaxSize
public final int getReaderBufferMaxSize()Returns the maximum size of the reader buffer (bytes).- Returns:
- the maximum size of the reader buffer (bytes).
-
setReaderBufferMaxSize
public final void setReaderBufferMaxSize(int readerBufferMaxSize) Changes the maximum size of the reader buffer (bytes).- Parameters:
readerBufferMaxSize- the maximum size of the reader buffer (bytes).
-
getCompressionThreshold
public final int getCompressionThreshold()Returns the size of the writer queue (messages).- Returns:
- the size of the writer queue (messages).
-
setCompressionThreshold
public final void setCompressionThreshold(int compressionThreshold) Changes the value of the propertycompressionThreshold.- Parameters:
compressionThreshold- the new value of the property.
-
getWriterQueueSize
public final int getWriterQueueSize()Returns the size of the writer queue (messages).- Returns:
- the size of the writer queue (messages).
-
setWriterQueueSize
public final void setWriterQueueSize(int writerQueueSize) Changes the value of the propertywriterQueueSize.- Parameters:
writerQueueSize- the new value of the property.
-
isTracing
public final boolean isTracing()Returnstrueif tracing inbound and outbound messages.- Returns:
trueif tracing inbound and outbound messages.
-
setTracing
public final void setTracing(boolean value) Enables or disables tracing of inbound and outbound messages.- Parameters:
value- iftruemessages will be traced.
-
getReaderBytes
public final long getReaderBytes()Returns the total number of bytes read by this channel.- Returns:
- the total number of bytes read by this channel.
-
getReaderMessages
public final int getReaderMessages()Returns the total number of messages read by this channel.- Returns:
- the total number of messages read by this channel.
-
getWriterBytes
public final long getWriterBytes()Returns the total number of bytes written by this channel.- Returns:
- the total number of bytes written by this channel.
-
getWriterMessages
public final int getWriterMessages()Returns the total number of messages written by this channel.- Returns:
- the total number of messages written by this channel.
-
connect
Connects this channel to remote address.- Parameters:
serverURI- the URI with protocol, host and port of server.tag- a tag associatted with this connection (can be null).- Throws:
NullPointerException- ifserverURIisnull.IllegalArgumentException- ifserverURIis invalid.Exception- if another error occurs.
-
handleInbound
Handles an inbound message received by this channel.- Parameters:
inbound- the inbound message to be handled.- Throws:
NullPointerException- ifinboundisnull.Exception- if another error occurs.
-
writeMessage
Writes the supplied outbound message to this channel.- Parameters:
outbound- the message that will be written to the channel.- Throws:
NullPointerException- ifoutboundisnull.Exception- if another error occurs.
-
writeMessage
Writes the supplied outbound message with optional write handler.- Parameters:
outbound- the message that will be written to the channel.handler- an asynchronous write completion handler (can be null).- Throws:
NullPointerException- ifoutboundisnull.Exception- if another error occurs.
-
isLoggable
Returnstrueif the given message level is being logged.- Parameters:
level- a message logging level.- Returns:
trueif the given message level is being logged.- Throws:
NullPointerException- iflevelisnull.
-
fine
-
info
-
warning
-
severe
-
severe
-
close
public void close()Close this channel, relinquishing any underlying resources.
-