Class ChannelBase

java.lang.Object
cl.netswitch.lib.aio.ChannelBase
Direct Known Subclasses:
ClientChannel, ServerChannel

public abstract class ChannelBase extends Object
Asynchronous bidirectional communication channel with NetSwitch server.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructs a new ChannelBase instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close this channel, relinquishing any underlying resources.
    final void
    connect(URI serverURI, String tag)
    Connects this channel to remote address.
    final void
    fine(String message, Object... args)
    Logs a fine message with supplied format and arguments.
    final int
    Returns the size of the writer queue (messages).
    Returns the local address or null 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.
    Returns the remote address or null if not connected.
    final boolean
    Returns true if the SO_KEEPALIVE socket option is enabled.
    final int
    Returns the maximum time for an SSL handshake (milliseconds).
    final String
    Returns the connection tag or null if not connected.
    final boolean
    Returns true if the TCP_NODELAY socket option is enabled.
    final String
    Returns the trust store file or null 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
    Handles an inbound message received by this channel.
    final void
    info(String message, Object... args)
    Generate an information entry with message and args.
    final boolean
    Returns true if this channel is closed.
    final boolean
    Returns true if this channel is connected.
    final boolean
    Returns true if the given message level is being logged.
    final boolean
    Returns true if this channel is secure.
    final boolean
    Returns true if tracing inbound and outbound messages.
    final void
    setCompressionThreshold(int compressionThreshold)
    Changes the value of the property compressionThreshold.
    protected final void
    setLogger(Logger logger)
    Changes the logger of this channel.
    protected final void
    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
    Changes the trust store file of this channel.
    final void
    setWriterQueueSize(int writerQueueSize)
    Changes the value of the property writerQueueSize.
    final void
    severe(String message, Object... args)
    Generate a severe error entry with message and args.
    final void
    severe(Throwable thrown, String message, Object... args)
    Generate a severe error entry with message, args and throwable.
    final void
    warning(String message, Object... args)
    Generate a warning entry with message and args.
    final void
    Writes the supplied outbound message to this channel.
    final void
    writeMessage(Message outbound, WriteHandler handler)
    Writes the supplied outbound message with optional write handler.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChannelBase

      protected ChannelBase()
      Constructs a new ChannelBase instance.
  • Method Details

    • getLogger

      public final Logger getLogger()
      Returns the logger of this channel.
      Returns:
      the logger of this channel.
    • setLogger

      protected final void setLogger(Logger logger)
      Changes the logger of this channel.
      Parameters:
      logger - the new logger (can be null).
    • getLoggerHeader

      public final String getLoggerHeader()
      Returns the logger header of this channel.
      Returns:
      the logger header of this channel.
    • setLoggerHeader

      protected final void setLoggerHeader(String header)
      Changes the logger header of this channel.
      Parameters:
      header - the new logger header (can be null).
    • isClosed

      public final boolean isClosed()
      Returns true if this channel is closed.
      Returns:
      true if this channel is closed.
    • isConnected

      public final boolean isConnected()
      Returns true if this channel is connected.
      Returns:
      true if this channel is connected.
    • isSecure

      public final boolean isSecure()
      Returns true if this channel is secure.
      Returns:
      true if this channel is secure.
    • getTag

      public final String getTag()
      Returns the connection tag or null if not connected.
      Returns:
      the connection tag or null if not connected.
    • getLocalAddress

      public final InetSocketAddress getLocalAddress()
      Returns the local address or null if not connected.
      Returns:
      the local address or null if not connected.
    • getRemoteAddress

      public final InetSocketAddress getRemoteAddress()
      Returns the remote address or null if not connected.
      Returns:
      the remote address or null if not connected.
    • getSoKeepAlive

      public final boolean getSoKeepAlive()
      Returns true 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()
      Returns true 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

      public final String getTrustStoreFile()
      Returns the trust store file or null if none defined.
      Returns:
      the trust store file or null if none defined.
    • setTrustStoreFile

      public final void setTrustStoreFile(String trustStore)
      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 property compressionThreshold.
      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 property writerQueueSize.
      Parameters:
      writerQueueSize - the new value of the property.
    • isTracing

      public final boolean isTracing()
      Returns true 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 - if true 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

      public final void connect(URI serverURI, String tag) throws Exception
      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 - if serverURI is null.
      IllegalArgumentException - if serverURI is invalid.
      Exception - if another error occurs.
    • handleInbound

      protected abstract void handleInbound(Message inbound) throws Exception
      Handles an inbound message received by this channel.
      Parameters:
      inbound - the inbound message to be handled.
      Throws:
      NullPointerException - if inbound is null.
      Exception - if another error occurs.
    • writeMessage

      public final void writeMessage(Message outbound) throws Exception
      Writes the supplied outbound message to this channel.
      Parameters:
      outbound - the message that will be written to the channel.
      Throws:
      NullPointerException - if outbound is null.
      Exception - if another error occurs.
    • writeMessage

      public final void writeMessage(Message outbound, WriteHandler handler) throws Exception
      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 - if outbound is null.
      Exception - if another error occurs.
    • isLoggable

      public final boolean isLoggable(Level level)
      Returns true 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 - if level is null.
    • fine

      public final void fine(String message, Object... args)
      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

      public final void info(String message, Object... args)
      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

      public final void warning(String message, Object... args)
      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

      public final void severe(String message, Object... args)
      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

      public final void severe(Throwable thrown, String message, Object... args)
      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.