Class CMFChannel
java.lang.Object
java.util.Observable
org.jpos.iso.BaseChannel
org.jpos.iso.channel.CMFChannel
- All Implemented Interfaces:
Cloneable, Configurable, ExceptionHandlerAware, BaseChannelMBean, ClientChannel, FactoryChannel, FilteredChannel, ISOChannel, ISOSource, ServerChannel, ISOMsgMetrics.Source, LogSource
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 eitherreplyKeepAlive is enabled or BaseChannel.isExpectKeepAlive() returns true, the channel
echoes the keep-alive back to the peer.
Configuration
reply-keepalive(boolean, defaulttrue): Whether to echo a received keep-alive (zero-length frame) back to the peer.max-keepalives-in-a-row(integer, default0): Maximum number of consecutive keep-alives allowed while waiting for a non-zero length frame. A value of0disables the limit (unlimited), preserving legacy behavior.
- Since:
- 3.0.1
- See Also:
-
Field Summary
Fields inherited from class BaseChannel
cnt, header, incomingFilters, logger, originalRealm, outgoingFilters, overrideHeader, packager, realm, serverIn, serverInLock, serverOut, serverOutLock, serverSocket, socketFactory, usableFields inherited from interface ISOChannel
CONNECT, RX, SIZEOF_CNT, TX -
Constructor Summary
ConstructorsConstructorDescriptionCreates an unconfiguredCMFChannel.CMFChannel(String host, int port, ISOPackager p) Constructs a clientCMFChannel.Constructs a serverCMFChannel.CMFChannel(ISOPackager p, ServerSocket serverSocket) Constructs a serverCMFChannelassociated with an existingServerSocket. -
Method Summary
Modifier and TypeMethodDescriptionprotected intReturns the channel header length.intReturns the maximum packet length supported by this channel.protected intReads the CMF message length prefix.protected voidsendMessageHeader(ISOMsg m, int len) Sends the message header (no-op).protected voidsendMessageLength(int len) Sends the CMF message length prefix.voidApplies configuration to this channel.Methods inherited from class BaseChannel
accept, addFilter, addFilter, addIncomingFilter, addOutgoingFilter, applyIncomingFilters, applyIncomingFilters, applyOutgoingFilters, applyTimeout, clone, closeSocket, connect, connect, createISOMsg, createMsg, disconnect, getBytes, getChannel, getConfiguration, getCounters, getDynamicHeader, getDynamicPackager, getDynamicPackager, getDynamicPackager, getExceptionHandlers, getHeader, getHeaderLength, getHeaderLength, getHost, getIncomingFilters, getISOMsgMetrics, getLogger, getMessage, getMessageTrailer, getMessageTrailler, getName, getOriginalRealm, getOutgoingFilters, getPackager, getPort, getRealm, getServerSocket, getSocket, getSocketFactory, getSoLingerSeconds, getTimeout, incrementMsgInCounter, incrementMsgOutCounter, isConnected, isExpectKeepAlive, isOverrideHeader, isRejected, isSoLingerOn, newSocket, newSocket, pack, postConnectHook, readHeader, receive, reconnect, removeFilter, removeFilter, removeIncomingFilter, removeOutgoingFilter, resetCounters, send, send, sendKeepAlive, sendMessage, sendMessageTrailer, sendMessageTrailler, sendMessageTrailler, setHeader, setHeader, setHost, setHost, setIncomingFilters, setISOMsgMetrics, setLocalAddress, setLogger, setMaxPacketLength, setName, setOutgoingFilters, setOverrideHeader, setPackager, setPort, setServerSocket, setSocketFactory, setSoLinger, setTimeout, setUsable, shouldIgnore, streamReceive, unpackMethods inherited from class Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChangedMethods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ExceptionHandlerAware
addHandler, addHandler, handle, removeHandler, removeHandler, removeHandlers
-
Constructor Details
-
CMFChannel
public CMFChannel()Creates an unconfiguredCMFChannel. The caller is expected to set the packager/connection parameters through the usualBaseChannelconfiguration and/or setters before use. -
CMFChannel
Constructs a clientCMFChannel.- Parameters:
host- server TCP address or hostname.port- server TCP port number.p- theISOPackagerused to pack/unpackISOMsgs.- See Also:
-
CMFChannel
Constructs a serverCMFChannel. This constructor creates aServerSocketinternally (as perBaseChannel) and waits for inbound connections whenis invoked.invalid reference
#accept()- Parameters:
p- theISOPackagerused to pack/unpackISOMsgs.- Throws:
IOException- if the underlying server socket cannot be created.- See Also:
-
CMFChannel
Constructs a serverCMFChannelassociated with an existingServerSocket.- Parameters:
p- theISOPackagerused to pack/unpackISOMsgs.serverSocket- the server socket used to accept a connection.- Throws:
IOException- if an I/O error occurs while initializing the channel.- See Also:
-
-
Method Details
-
sendMessageLength
Sends the CMF message length prefix. The CMF framing uses a 3-byte big-endian length prefix (24-bit unsigned).- Overrides:
sendMessageLengthin classBaseChannel- Parameters:
len- the packed message length in bytes.- Throws:
IOException- if an I/O error occurs writing to the socket output stream or iflenis outside the valid range (0..0xFFFFFF).
-
getMessageLength
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 eitherreplyKeepAliveis enabled orBaseChannel.isExpectKeepAlive()istrue, 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-rowis configured to a value greater than0, the method will fail after receiving more than that number of consecutive keep-alives without a subsequent non-zero length frame.- Overrides:
getMessageLengthin classBaseChannel- 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
Returns the channel header length. CMF framing does not include a separate message header beyond the 3-byte length prefix.- Overrides:
getHeaderLengthin classBaseChannel- Returns:
0.
-
sendMessageHeader
Sends the message header (no-op). CMF framing does not define a message header; only the length prefix is used.- Overrides:
sendMessageHeaderin classBaseChannel- Parameters:
m- the message being sent.len- the packed message length in bytes.
-
setConfiguration
Applies configuration to this channel. In addition to the baseBaseChannelconfiguration, this method reads:reply-keepalive(boolean, defaulttrue).max-keepalives-in-a-row(integer, default0).
- Specified by:
setConfigurationin interfaceConfigurable- Overrides:
setConfigurationin classBaseChannel- Parameters:
cfg- the configuration source.- Throws:
ConfigurationException- if configuration cannot be applied.
-
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 is0xFFFFFF(16,777,215 bytes).- Overrides:
getMaxPacketLengthin classBaseChannel- Returns:
- the maximum packet length, in bytes.
-