Class CMFChannel

All Implemented Interfaces:
Cloneable, Configurable, ExceptionHandlerAware, BaseChannelMBean, ClientChannel, FactoryChannel, FilteredChannel, ISOChannel, ISOSource, ServerChannel, ISOMsgMetrics.Source, LogSource

public class CMFChannel extends BaseChannel
ISOChannel implementation for the jPOS-CMF framing. This channel uses a 3-byte big-endian length prefix (24-bit unsigned) and no additional message header.

Keep-alive handling

A zero-length frame is treated as a keep-alive. When a keep-alive is received and either replyKeepAlive is enabled or BaseChannel.isExpectKeepAlive() returns true, the channel echoes the keep-alive back to the peer.

Configuration

  • reply-keepalive (boolean, default true): Whether to echo a received keep-alive (zero-length frame) back to the peer.
  • max-keepalives-in-a-row (integer, default 0): Maximum number of consecutive keep-alives allowed while waiting for a non-zero length frame. A value of 0 disables the limit (unlimited), preserving legacy behavior.
Since:
3.0.1
See Also:
  • Constructor Details

  • Method Details

    • sendMessageLength

      protected void sendMessageLength(int len) throws IOException
      Sends the CMF message length prefix. The CMF framing uses a 3-byte big-endian length prefix (24-bit unsigned).
      Overrides:
      sendMessageLength in class BaseChannel
      Parameters:
      len - the packed message length in bytes.
      Throws:
      IOException - if an I/O error occurs writing to the socket output stream or if len is outside the valid range (0..0xFFFFFF).
    • getMessageLength

      protected int getMessageLength() throws IOException, ISOException
      Reads the CMF message length prefix. Reads a 3-byte big-endian length value. A zero-length frame is treated as a keep-alive. When a keep-alive is received and either replyKeepAlive is enabled or BaseChannel.isExpectKeepAlive() is true, the keep-alive is echoed back to the peer. The method continues reading until a non-zero length is obtained.

      If max-keepalives-in-a-row is configured to a value greater than 0, the method will fail after receiving more than that number of consecutive keep-alives without a subsequent non-zero length frame.

      Overrides:
      getMessageLength in class BaseChannel
      Returns:
      the packed message length in bytes (always > 0).
      Throws:
      IOException - if an I/O error occurs reading from the socket input stream, or if too many consecutive keep-alives are received (when limited).
      ISOException - if the channel detects an ISO-level framing/processing error.
    • getHeaderLength

      protected int getHeaderLength()
      Returns the channel header length. CMF framing does not include a separate message header beyond the 3-byte length prefix.
      Overrides:
      getHeaderLength in class BaseChannel
      Returns:
      0.
    • sendMessageHeader

      protected void sendMessageHeader(ISOMsg m, int len)
      Sends the message header (no-op). CMF framing does not define a message header; only the length prefix is used.
      Overrides:
      sendMessageHeader in class BaseChannel
      Parameters:
      m - the message being sent.
      len - the packed message length in bytes.
    • setConfiguration

      Applies configuration to this channel. In addition to the base BaseChannel configuration, this method reads:
      • reply-keepalive (boolean, default true).
      • max-keepalives-in-a-row (integer, default 0).
      Specified by:
      setConfiguration in interface Configurable
      Overrides:
      setConfiguration in class BaseChannel
      Parameters:
      cfg - the configuration source.
      Throws:
      ConfigurationException - if configuration cannot be applied.
    • getMaxPacketLength

      public int getMaxPacketLength()
      Returns the maximum packet length supported by this channel. CMF framing uses a 3-byte unsigned length prefix (24-bit). Therefore, the maximum representable non-zero payload length is 0xFFFFFF (16,777,215 bytes).
      Overrides:
      getMaxPacketLength in class BaseChannel
      Returns:
      the maximum packet length, in bytes.