Package anbxj

Class Channel_Client


public class Channel_Client extends Channel_Abstraction
Client-side communication channel.

This class establishes a connection to a remote server using either plain TCP or TLS/SSL (depending on the Channel_Properties). It implements a configurable linear backoff retry strategy with jitter to handle transient connection failures gracefully.

See Also:
  • Constructor Details

    • Channel_Client

      public Channel_Client(Channel_Properties cp)
      Creates a new client channel with the given properties.
      Parameters:
      cp - the channel properties (host, port, security type, etc.)
  • Method Details

    • Close

      public void Close()
      Closes the client socket and the associated streams.

      If an I/O error occurs during closing, the application exits with status 1.

      Overrides:
      Close in class Channel_Abstraction
    • Open

      public void Open()
      Opens the client channel and establishes a connection to the remote server.
      Overrides:
      Open in class Channel_Abstraction
    • connectSocket

      public static Socket connectSocket(Channel_Properties cp) throws IOException
      Creates a client socket connected to the destination described by the given channel properties, using the same retry strategy as Open(). The socket is connected (and SSL-handshaked when required) but no ObjectStreams are attached - it is intended to be handed to Channel_Protobuf.
      Parameters:
      cp - the channel properties (host, port, security type)
      Returns:
      a connected Socket (plain or SSLSocket)
      Throws:
      IOException - if all connection attempts fail
    • setTimeoutMs

      public static void setTimeoutMs(int timeoutMs)
      Set the connection timeout in milliseconds.
      Parameters:
      timeoutMs - timeout (must be > 500)
    • setMaxRetries

      public static void setMaxRetries(int maxRetries)
      Set the maximum number of connection attempts.
      Parameters:
      maxRetries - number of attempts (must be > 0)
    • setBaseDelayMs

      public static void setBaseDelayMs(long baseDelayMs)
      Set the initial (base) delay between retries in milliseconds. This is the delay used for the first retry; subsequent delays increase exponentially.
      Parameters:
      baseDelayMs - base delay (must be > 0)
    • setMaxDelayMs

      public static void setMaxDelayMs(long maxDelayMs)
      Set the maximum delay between retries in milliseconds.
      Parameters:
      maxDelayMs - maximum delay (must be > baseDelayMs)
    • setJitterFactor

      public static void setJitterFactor(double jitterFactor)
      Set the jitter factor (0.0 = no jitter, 1.0 = -/+100%). Recommended value: 0.1 to 0.3.
      Parameters:
      jitterFactor - factor between 0 and 1 inclusive
    • getSerializer

      public Channel_MessageSerializer getSerializer()