Interface ChannelFilter


public interface ChannelFilter
Inspects or modifies inbound and outbound Messages of 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 ChannelFilter is specified in the configuration file of the server, and can be assigned to a Connector or a Listener. Each time a device channel is created, a new instance of the ChannelFilter is initialized and then bound to the channel. From that point on, every inbound or outbound Message is passed to the ChannelFilter for inspection and possible modification. Finally, when the channel is closed, the ChannelFilter instance is terminated and released.

  • Method Details

    • initialize

      void initialize(FilterContext context) throws Exception
      Called to initialize the ChannelFilter.

      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 filter.
      Throws:
      NullPointerException - if context is null.
      Exception - if another error occurs.
    • afterInboundReceived

      boolean afterInboundReceived(FilterContext context, Message inbound) throws Exception
      Called after an inbound message is received.

      If this method modifies the inbound message, the modified version will be dispatched to its destination.

      If this method returns true, the inbound message will dispatched, otherwise it will be discarded.

      If this message throws and exception, the exception will be logged, and then processing will continue as if the method had returned true. In other words, the exception will be ignored.

      Parameters:
      context - the context of the filter.
      inbound - the inbound message.
      Returns:
      true if the inbound message should be dispatched.
      Throws:
      NullPointerException - if an argument is null.
      Exception - if another error occurs.
    • beforeOutboundSent

      boolean beforeOutboundSent(FilterContext context, Message outbound) throws Exception
      Called before an outbound message is sent.

      If this method modifies the outbound message, the modified version will be written (sent) to the channel.

      If this method returns true, the outbound message will be sent, otherwise it will be discarded.

      If this message throws and exception, the exception will be logged, and then processing will continue as if the method had returned true. In other words, the exception will be ignored.

      Parameters:
      context - the context of the filter.
      outbound - the outbound message.
      Returns:
      true if the outbound message should be sent.
      Throws:
      NullPointerException - if an argument is null.
      Exception - if another error occurs.
    • terminate

      void terminate(FilterContext context) throws Exception
      Called to terminate the ChannelFilter.

      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 filter.
      Throws:
      NullPointerException - if context is null.
      Exception - if another error occurs.