Package anbxj
Class Channel_Client
java.lang.Object
anbxj.Channel_Abstraction
anbxj.Channel_Client
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:
-
Field Summary
Fields inherited from class anbxj.Channel_Abstraction
cp -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new client channel with the given properties. -
Method Summary
Modifier and TypeMethodDescriptionvoidClose()Closes the client socket and the associated streams.static SocketCreates a client socket connected to the destination described by the given channel properties, using the same retry strategy asOpen().voidOpen()Opens the client channel and establishes a connection to the remote server.static voidsetBaseDelayMs(long baseDelayMs) Set the initial (base) delay between retries in milliseconds.static voidsetJitterFactor(double jitterFactor) Set the jitter factor (0.0 = no jitter, 1.0 = -/+100%).static voidsetMaxDelayMs(long maxDelayMs) Set the maximum delay between retries in milliseconds.static voidsetMaxRetries(int maxRetries) Set the maximum number of connection attempts.static voidsetTimeoutMs(int timeoutMs) Set the connection timeout in milliseconds.Methods inherited from class anbxj.Channel_Abstraction
checkPort, getChannelRole, getChannelSettings, OpenStreams, Receive, Receive, safeReadObject, Send, setStep
-
Constructor Details
-
Channel_Client
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:
Closein classChannel_Abstraction
-
Open
public void Open()Opens the client channel and establishes a connection to the remote server.- Overrides:
Openin classChannel_Abstraction
-
connectSocket
Creates a client socket connected to the destination described by the given channel properties, using the same retry strategy asOpen(). The socket is connected (and SSL-handshaked when required) but no ObjectStreams are attached - it is intended to be handed toChannel_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
-