java.lang.Object
cl.netswitch.lib.aio.ChannelBase
- Direct Known Subclasses:
ClientChannel
,ServerChannel
Asynchronous bidirectional communication channel with NetSwitch server.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close this channel, relinquishing any underlying resources.final void
Connects this channel to remote address.final void
Logs a fine message with supplied format and arguments.final int
Returns the size of the writer queue (messages).final InetSocketAddress
Returns the local address ornull
if not connected.final Logger
Returns the logger of this channel.final String
Returns the logger header of this channel.final int
Returns the free size of the reader buffer (bytes).final int
Returns the maximum size of the reader buffer (bytes).final int
Returns the minimum size of the reader buffer (bytes).final int
Returns the warning size of the reader buffer (bytes).final long
Returns the total number of bytes read by this channel.final int
Returns the total number of messages read by this channel.final InetSocketAddress
Returns the remote address ornull
if not connected.final boolean
Returnstrue
if the SO_KEEPALIVE socket option is enabled.final int
Returns the maximum time for an SSL handshake (milliseconds).final String
getTag()
Returns the connection tag ornull
if not connected.final boolean
Returnstrue
if the TCP_NODELAY socket option is enabled.final String
Returns the trust store file ornull
if none defined.final long
Returns the total number of bytes written by this channel.final int
Returns the total number of messages written by this channel.final int
Returns the size of the writer queue (messages).protected abstract void
handleInbound
(Message inbound) Handles an inbound message received by this channel.final void
Generate an information entry with message and args.final boolean
isClosed()
Returnstrue
if this channel is closed.final boolean
Returnstrue
if this channel is connected.final boolean
isLoggable
(Level level) Returnstrue
if the given message level is being logged.final boolean
isSecure()
Returnstrue
if this channel is secure.final boolean
Returnstrue
if tracing inbound and outbound messages.final void
setCompressionThreshold
(int compressionThreshold) Changes the value of the propertycompressionThreshold
.protected final void
Changes the logger of this channel.protected final void
setLoggerHeader
(String header) Changes the logger header of this channel.final void
setReaderBufferFreeSize
(int readerBufferFreeSize) Changes the free size of the reader buffer (bytes).final void
setReaderBufferMaxSize
(int readerBufferMaxSize) Changes the maximum size of the reader buffer (bytes).final void
setReaderBufferMinSize
(int readerBufferMinSize) Changes the minimum size of the reader buffer (bytes).final void
setReaderBufferWarnSize
(int readerBufferWarnSize) Changes the warning size of the reader buffer (bytes).final void
setSoKeepAlive
(boolean value) Enables or disables the SO_KEEPALIVE socket option.final void
setSslHandshakeTimeout
(int sslHandshakeTimeout) Changes the maximum time for an SSL handshake (milliseconds).final void
setTcpNoDelay
(boolean value) Enables or disables the TCP_NODELAY socket option.final void
setTracing
(boolean value) Enables or disables tracing of inbound and outbound messages.final void
setTrustStoreFile
(String trustStore) Changes the trust store file of this channel.final void
setWriterQueueSize
(int writerQueueSize) Changes the value of the propertywriterQueueSize
.final void
Generate a severe error entry with message and args.final void
Generate a severe error entry with message, args and throwable.final void
Generate a warning entry with message and args.final void
writeMessage
(Message outbound) Writes the supplied outbound message to this channel.final void
writeMessage
(Message outbound, WriteHandler handler) Writes the supplied outbound message with optional write handler.
-
Constructor Details
-
ChannelBase
protected ChannelBase()Constructs a newChannelBase
instance.
-
-
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()Returnstrue
if this channel is closed.- Returns:
true
if this channel is closed.
-
isConnected
public final boolean isConnected()Returnstrue
if this channel is connected.- Returns:
true
if this channel is connected.
-
isSecure
public final boolean isSecure()Returnstrue
if this channel is secure.- Returns:
true
if this channel is secure.
-
getTag
Returns the connection tag ornull
if not connected.- Returns:
- the connection tag or
null
if not connected.
-
getLocalAddress
Returns the local address ornull
if not connected.- Returns:
- the local address or
null
if not connected.
-
getRemoteAddress
Returns the remote address ornull
if not connected.- Returns:
- the remote address or
null
if not connected.
-
getSoKeepAlive
public final boolean getSoKeepAlive()Returnstrue
if the SO_KEEPALIVE socket option is enabled.- Returns:
true
if 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()Returnstrue
if the TCP_NODELAY socket option is enabled.- Returns:
true
if 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 ornull
if none defined.- Returns:
- the trust store file or
null
if 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()Returnstrue
if tracing inbound and outbound messages.- Returns:
true
if tracing inbound and outbound messages.
-
setTracing
public final void setTracing(boolean value) Enables or disables tracing of inbound and outbound messages.- Parameters:
value
- iftrue
messages 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
- ifserverURI
isnull
.IllegalArgumentException
- ifserverURI
is 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
- ifinbound
isnull
.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
- ifoutbound
isnull
.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
- ifoutbound
isnull
.Exception
- if another error occurs.
-
isLoggable
Returnstrue
if the given message level is being logged.- Parameters:
level
- a message logging level.- Returns:
true
if the given message level is being logged.- Throws:
NullPointerException
- iflevel
isnull
.
-
fine
Logs a fine message with supplied format and arguments.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
info
Generate an information entry with message and args.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
warning
Generate a warning entry with message and args.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
severe
Generate a severe error entry with message and args.- Parameters:
message
- the text of the message or format.args
- an array of optional format arguments.
-
severe
Generate a severe error entry with message, args and throwable.- Parameters:
thrown
- the associatted throwable instance.message
- the text of the message or format.args
- an array of optional format arguments.
-
close
public void close()Close this channel, relinquishing any underlying resources.
-