@@ -97,21 +97,34 @@ public abstract class BaseChannel extends Observable
9797 /** Send timeout in milliseconds. */
9898 private long sendTimeout = 15000L ;
9999 // private int serverPort = -1;
100+ /** Input stream for reading from the connected socket. */
100101 protected DataInputStream serverIn ;
102+ /** Output stream for writing to the connected socket. */
101103 protected DataOutputStream serverOut ;
102104 // The lock objects should be final, and never changed, but due to the clone() method, they must be set there.
105+ /** Lock guarding {@link #serverIn} and read operations. */
103106 protected Lock serverInLock = new ReentrantLock ();
107+ /** Lock guarding {@link #serverOut} and write operations. */
104108 protected Lock serverOutLock = new ReentrantLock ();
109+ /** The packager used to pack/unpack ISO messages. */
105110 protected ISOPackager packager ;
111+ /** The server socket used when this channel acts as a server. */
106112 protected ServerSocket serverSocket = null ;
113+ /** Filter chains applied to incoming and outgoing messages respectively. */
107114 protected List <ISOFilter > incomingFilters , outgoingFilters ;
115+ /** Optional factory for creating client sockets. */
108116 protected ISOClientSocketFactory socketFactory = null ;
109117
118+ /** Event counters (connect, sent, received, etc.). */
110119 protected int [] cnt ;
111120
121+ /** The logger for this channel. */
112122 protected Logger logger = null ;
123+ /** The current log realm. */
113124 protected String realm = null ;
125+ /** The original log realm before any modification. */
114126 protected String originalRealm = null ;
127+ /** Optional channel-level header prepended to outgoing messages. */
115128 protected byte [] header = null ;
116129 private static final int DEFAULT_TIMEOUT = 300000 ;
117130 private int nextHostPort = 0 ;
@@ -319,7 +332,10 @@ protected void connect (Socket socket) throws IOException {
319332 setChanged ();
320333 notifyObservers ();
321334 }
322- /** Hook called after a successful connect; subclasses may override. @throws IOException on I/O error */
335+ /**
336+ * Hook called after a successful connect; subclasses may override.
337+ * @throws IOException on I/O error
338+ */
323339 protected void postConnectHook () throws IOException {
324340 // do nothing
325341 }
@@ -425,7 +441,10 @@ public void setTimeout (int timeout) throws SocketException {
425441 this .timeout = timeout ;
426442 applyTimeout ();
427443 }
428- /** @return the current socket timeout in milliseconds */
444+ /**
445+ * Returns the current socket read timeout.
446+ * @return socket timeout in milliseconds
447+ */
429448 public int getTimeout () {
430449 return timeout ;
431450 }
@@ -452,9 +471,11 @@ public void setSoLinger(boolean on, int linger) {
452471 this .soLingerOn = on ;
453472 this .soLingerSeconds = linger ;
454473 }
474+ /** @return true if SO_LINGER is enabled */
455475 public boolean isSoLingerOn () {
456476 return soLingerOn ;
457477 }
478+ /** @return the SO_LINGER timeout in seconds */
458479 public int getSoLingerSeconds () {
459480 return soLingerSeconds ;
460481 }
@@ -637,7 +658,9 @@ protected void getMessageTrailer(ISOMsg m) throws IOException {
637658 getMessageTrailler ();
638659 }
639660
640- /** @param b buffer to read into
661+ /**
662+ * Reads exactly {@code len} bytes from the input stream into the buffer.
663+ * @param b buffer to read into
641664 * @param offset buffer offset
642665 * @param len number of bytes to read
643666 * @throws IOException on I/O failure
@@ -654,11 +677,25 @@ protected void getMessage (byte[] b, int offset, int len) throws IOException, IS
654677 protected int getMessageLength () throws IOException , ISOException {
655678 return -1 ;
656679 }
680+ /**
681+ * Returns the length of the channel-level header, or 0 if none.
682+ * @return header length in bytes
683+ */
657684 protected int getHeaderLength () {
658685 return header != null ? header .length : 0 ;
659686 }
687+ /**
688+ * Returns the header length for the given raw buffer; default is 0.
689+ * @param b raw buffer
690+ * @return header length
691+ */
660692 protected int getHeaderLength (byte [] b ) { return 0 ; }
661693
694+ /**
695+ * Returns the effective header length for the given message.
696+ * @param m the ISO message
697+ * @return header length in bytes
698+ */
662699 protected int getHeaderLength (ISOMsg m ) {
663700 return !overrideHeader && m .getHeader () != null ?
664701 m .getHeader ().length : getHeaderLength ();
@@ -815,14 +852,27 @@ public void sendKeepAlive () throws IOException {
815852 }
816853 }
817854
855+ /** @return true if this channel expects keep-alive messages from the remote end */
818856 public boolean isExpectKeepAlive () {
819857 return expectKeepAlive ;
820858 }
821859
860+ /**
861+ * Returns true if the given message frame should be treated as a rejection.
862+ * Subclasses (e.g. VAPChannel) may override.
863+ * @param b raw message bytes
864+ * @return true if rejected
865+ */
822866 protected boolean isRejected (byte [] b ) {
823867 // VAP Header support - see VAPChannel
824868 return false ;
825869 }
870+ /**
871+ * Returns true if the given message frame should be silently ignored.
872+ * Subclasses (e.g. VAPChannel) may override.
873+ * @param b raw message bytes
874+ * @return true if the frame should be ignored
875+ */
826876 protected boolean shouldIgnore (byte [] b ) {
827877 // VAP Header support - see VAPChannel
828878 return false ;
@@ -834,6 +884,10 @@ protected boolean shouldIgnore (byte[] b) {
834884 protected ISOMsg createMsg () {
835885 return createISOMsg ();
836886 }
887+ /**
888+ * Creates a new ISOMsg using the configured packager.
889+ * @return new ISOMsg instance
890+ */
837891 protected ISOMsg createISOMsg () {
838892 return packager .createISOMsg ();
839893 }
@@ -1017,11 +1071,17 @@ public void setLogger (Logger logger, String realm) {
10171071 public String getRealm () {
10181072 return realm ;
10191073 }
1020- /** @return the Logger associated with this channel */
1074+ /**
1075+ * Returns the Logger associated with this channel.
1076+ * @return the channel Logger
1077+ */
10211078 public Logger getLogger () {
10221079 return logger ;
10231080 }
1024- /** @return the original realm name, or the class name if none was set */
1081+ /**
1082+ * Returns the original realm name, or the class name if none was set.
1083+ * @return original realm
1084+ */
10251085 public String getOriginalRealm () {
10261086 return originalRealm == null ?
10271087 this .getClass ().getName () : originalRealm ;
@@ -1117,7 +1177,9 @@ public void removeIncomingFilter (ISOFilter filter) {
11171177 public void removeOutgoingFilter (ISOFilter filter ) {
11181178 removeFilter (filter , ISOMsg .OUTGOING );
11191179 }
1120- /** @param m message to filter
1180+ /**
1181+ * Applies the outgoing filter chain to the given message.
1182+ * @param m message to filter
11211183 * @param evt log event
11221184 * @return filtered message
11231185 * @throws VetoException if a filter vetoes the message
@@ -1129,7 +1191,9 @@ protected ISOMsg applyOutgoingFilters (ISOMsg m, LogEvent evt)
11291191 m = f .filter (this , m , evt );
11301192 return m ;
11311193 }
1132- /** @param m message to filter
1194+ /**
1195+ * Applies the incoming filter chain to the given message.
1196+ * @param m message to filter
11331197 * @param evt log event
11341198 * @return filtered message
11351199 * @throws VetoException if a filter vetoes the message
@@ -1139,7 +1203,9 @@ protected ISOMsg applyIncomingFilters (ISOMsg m, LogEvent evt)
11391203 {
11401204 return applyIncomingFilters (m , null , null , evt );
11411205 }
1142- /** @param m message to filter
1206+ /**
1207+ * Applies the incoming filter chain, optionally providing raw header and image bytes.
1208+ * @param m message to filter
11431209 * @param header raw header bytes (may be null)
11441210 * @param image raw message image (may be null)
11451211 * @param evt log event
@@ -1157,14 +1223,18 @@ protected ISOMsg applyIncomingFilters (ISOMsg m, byte[] header, byte[] image, Lo
11571223 }
11581224 return m ;
11591225 }
1160- /** @param m message to unpack into
1226+ /**
1227+ * Unpacks the byte array into the given message using the configured packager.
1228+ * @param m message to unpack into
11611229 * @param b packed bytes
11621230 * @throws ISOException on unpacking error
11631231 */
11641232 protected void unpack (ISOMsg m , byte [] b ) throws ISOException {
11651233 m .unpack (b );
11661234 }
1167- /** @param m message to pack
1235+ /**
1236+ * Packs the given message into a byte array using the configured packager.
1237+ * @param m message to pack
11681238 * @return packed bytes
11691239 * @throws ISOException on packing error
11701240 */
@@ -1227,43 +1297,73 @@ public void setConfiguration (Configuration cfg)
12271297 throw new ConfigurationException (e );
12281298 }
12291299 }
1230- /** @return this channel's current configuration */
1300+ /**
1301+ * Returns this channel's current configuration.
1302+ * @return the channel configuration
1303+ */
12311304 public Configuration getConfiguration () {
12321305 return cfg ;
12331306 }
1234- /** @return the incoming filter chain */
1307+ /**
1308+ * Returns the incoming filter chain.
1309+ * @return incoming filters
1310+ */
12351311 public Collection <ISOFilter > getIncomingFilters () {
12361312 return incomingFilters ;
12371313 }
1238- /** @return the outgoing filter chain */
1314+ /**
1315+ * Returns the outgoing filter chain.
1316+ * @return outgoing filters
1317+ */
12391318 public Collection <ISOFilter > getOutgoingFilters () {
12401319 return outgoingFilters ;
12411320 }
1242- /** @param filters replacement incoming filter set */
1321+ /**
1322+ * Replaces the incoming filter chain.
1323+ * @param filters the new incoming filter set
1324+ */
12431325 public void setIncomingFilters (Collection filters ) {
12441326 incomingFilters = new ArrayList (filters );
12451327 }
1246- /** @param filters replacement outgoing filter set */
1328+ /**
1329+ * Replaces the outgoing filter chain.
1330+ * @param filters the new outgoing filter set
1331+ */
12471332 public void setOutgoingFilters (Collection filters ) {
12481333 outgoingFilters = new ArrayList (filters );
12491334 }
1250- /** @param header channel-level header bytes to prepend to outgoing messages */
1335+ /**
1336+ * Sets the channel-level header prepended to outgoing messages.
1337+ * @param header header bytes
1338+ */
12511339 public void setHeader (byte [] header ) {
12521340 this .header = header ;
12531341 }
1254- /** @param header channel-level header string (encoded as platform bytes) */
1342+ /**
1343+ * Sets the channel-level header from a string (encoded as platform bytes).
1344+ * @param header header string
1345+ */
12551346 public void setHeader (String header ) {
12561347 setHeader (header .getBytes ());
12571348 }
1258- /** @return the channel-level header bytes, or null if none */
1349+ /**
1350+ * Returns the channel-level header bytes.
1351+ * @return header bytes, or null if none is configured
1352+ */
12591353 public byte [] getHeader () {
12601354 return header ;
12611355 }
1262- /** @param overrideHeader if true, the channel header takes precedence over the message header */
1356+ /**
1357+ * Controls whether the channel-level header overrides the message header.
1358+ * @param overrideHeader true to override
1359+ */
12631360 public void setOverrideHeader (boolean overrideHeader ) {
12641361 this .overrideHeader = overrideHeader ;
12651362 }
1266- /** @return true if this channel's header overrides the message's own header */
1363+ /**
1364+ * Returns true if the channel-level header overrides the message's own header.
1365+ * @return true if overriding
1366+ */
12671367 public boolean isOverrideHeader () {
12681368 return overrideHeader ;
12691369 }
@@ -1294,19 +1394,29 @@ public ISOClientSocketFactory getSocketFactory() {
12941394 * @see ISOClientSocketFactory
12951395 * @since 1.3.3
12961396 */
1297- /** @param socketFactory the socket factory to use for outbound connections */
1397+ /**
1398+ * Sets the socket factory used for outbound connections.
1399+ * @param socketFactory the socket factory
1400+ */
12981401 public void setSocketFactory (ISOClientSocketFactory socketFactory ) {
12991402 this .socketFactory = socketFactory ;
13001403 }
1301- /** @return maximum packet length this channel will accept */
1404+ /**
1405+ * Returns the maximum packet length this channel will accept.
1406+ * @return max packet length
1407+ */
13021408 public int getMaxPacketLength () {
13031409 return maxPacketLength ;
13041410 }
1305- /** @param maxPacketLength the maximum packet length to accept */
1411+ /**
1412+ * Sets the maximum packet length this channel will accept.
1413+ * @param maxPacketLength max packet length
1414+ */
13061415 public void setMaxPacketLength (int maxPacketLength ) {
13071416 this .maxPacketLength = maxPacketLength ;
13081417 }
1309- /** Closes the underlying socket; idempotent.
1418+ /**
1419+ * Closes the underlying socket; idempotent.
13101420 * @throws IOException on close failure
13111421 */
13121422 protected void closeSocket () throws IOException {
@@ -1362,7 +1472,8 @@ private UUID getSocketUUID() {
13621472 uuid ;
13631473 }
13641474
1365- /** Records an incoming message in metrics if configured.
1475+ /**
1476+ * Records an incoming message in metrics if configured.
13661477 * @param m the received message
13671478 * @throws ISOException on metrics error
13681479 */
@@ -1371,7 +1482,8 @@ protected void incrementMsgInCounter(ISOMsg m) throws ISOException {
13711482 isoMsgMetrics .recordMessage (m , MeterInfo .ISOMSG_IN );
13721483 }
13731484 }
1374- /** Records an outgoing message in metrics if configured.
1485+ /**
1486+ * Records an outgoing message in metrics if configured.
13751487 * @param m the sent message
13761488 * @throws ISOException on metrics error
13771489 */
0 commit comments