Interface ChannelCodec

All Superinterfaces:
ChannelDecoder, ChannelEncoder

public interface ChannelCodec extends ChannelEncoder, ChannelDecoder
Encodes and decodes messages sent through a communication channel.

An NetSwitch server has two types of devices: Connectors and Listeners. A Connector (or client) connects to a remote listener, and can have one (or more) bidirectional communication channels (or sockets). A Listener (or server) waits for connections from remote clients, and can have several bidirectional communication channels, one for each client.

A ChannelCodec is specified in the configuration file of the server, and can be assigned to a Connector or a Listener. Each time a device channel receives input bytes, it calls the ChannelCodec to decode the bytes and produce an inbound Message. Also, each time a channel writes a Message, it calls the ChannelCodec to encode the message into an outbound sequence of bytes.

  • Method Details

    • initialize

      void initialize(CodecContext context) throws Exception
      Called to initialize the ChannelCodec.

      This method is called only once at the beginning of the life cycle of a channel. This method can be used to perform one-time initializations.

      If this message throws and exception, the exception will be logged, and then processing will continue as if nothing had happened. In other worlds, the exception will be ignored.

      Parameters:
      context - the context of the codec.
      Throws:
      Exception - if an error occurs.
    • terminate

      void terminate(CodecContext context) throws Exception
      Called to terminate the ChannelCodec.

      This method is called only once at the end of the life cycle of a channel. This method can be used to release resources, and perform other cleanup activities.

      If this message throws and exception, the exception will be logged, and then processing will continue as if nothing had happened. In other worlds, the exception will be ignored.

      Parameters:
      context - the context of the codec.
      Throws:
      Exception - if an error occurs.