ivandasch commented on a change in pull request #9863:
URL: https://github.com/apache/ignite/pull/9863#discussion_r822370669
##########
File path:
modules/core/src/main/java/org/apache/ignite/configuration/ClientConfiguration.java
##########
@@ -678,4 +684,68 @@ public ClientConfiguration
setAsyncContinuationExecutor(Executor asyncContinuati
return this;
}
+
+ /**
+ * Gets a value indicating whether heartbeats are enabled.
+ * <p />
+ * When thin client connection is idle (no operations are performed),
heartbeat messages are sent periodically
+ * to keep the connection alive and detect potential half-open state.
+ * <p />
+ * See also {@link ClientConfiguration#heartbeatInterval}.
+ *
+ * @return Whether heartbeats are enabled.
+ */
+ public boolean isHeartbeatEnabled() {
+ return heartbeatEnabled;
+ }
+
+ /**
+ * Sets a value indicating whether heartbeats are enabled.
+ * <p />
+ * When thin client connection is idle (no operations are performed),
heartbeat messages are sent periodically
+ * to keep the connection alive and detect potential half-open state.
+ * <p />
+ * See also {@link ClientConfiguration#heartbeatInterval}.
+ *
+ * @param heartbeatEnabled Whether to enable heartbeats.
+ * @return {@code this} for chaining.
+ */
+ public ClientConfiguration setHeartbeatEnabled(boolean heartbeatEnabled) {
+ this.heartbeatEnabled = heartbeatEnabled;
+
+ return this;
+ }
+
+ /**
+ * Gets the heartbeat message interval, in milliseconds. Default is
<code>30_000</code>.
+ * <p />
+ * When server-side <see cref="ClientConnectorConfiguration.IdleTimeout"/>
is not zero, effective heartbeat
+ * interval is set to <code>min(heartbeatInterval, idleTimeout / 3)</code>.
+ * <p />
+ * When thin client connection is idle (no operations are performed),
heartbeat messages are sent periodically
+ * to keep the connection alive and detect potential half-open state. *
+ *
+ * @return Heartbeat interval.
+ */
+ public long getHeartbeatInterval() {
+ return heartbeatInterval;
+ }
+
+ /**
+ * Sets the heartbeat message interval, in milliseconds. Default is
<code>30_000</code>.
+ * <p />
+ * When server-side <see cref="ClientConnectorConfiguration.IdleTimeout"/>
is not zero, effective heartbeat
Review comment:
It seems to be not valid javadoc...
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
##########
@@ -705,9 +724,65 @@ private ClientException handleIOError(String chInfo,
@Nullable IOException ex) {
return new ClientConnectionException("Ignite cluster is unavailable ["
+ chInfo + ']', ex);
}
+ /**
+ * Initializes heartbeats.
+ *
+ * @param configuredInterval Configured heartbeat interval, in
milliseconds.
+ * @return Heartbeat timer.
+ */
+ private Timer initHeartbeat(long configuredInterval) {
+ long heartbeatInterval = getHeartbeatInterval(configuredInterval);
+
+ Timer timer = new Timer("tcp-client-channel-heartbeats-" + hashCode());
+
+ timer.schedule(new HeartbeatTask(heartbeatInterval),
heartbeatInterval, heartbeatInterval);
+
+ return timer;
+ }
+
+ /**
+ * Gets the heartbeat interval based on the configured value and
served-side idle timeout.
+ *
+ * @param configuredInterval Configured interval.
+ * @return Resolved interval.
+ */
+ private long getHeartbeatInterval(long configuredInterval) {
+ long serverIdleTimeoutMs = service(ClientOperation.GET_IDLE_TIMEOUT,
null, in -> in.in().readLong());
+
+ if (serverIdleTimeoutMs <= 0)
+ return configuredInterval;
+
+ long recommendedHeartbeatInterval = serverIdleTimeoutMs / 3;
Review comment:
What if `recommendedHeartbeatInterval` equals to 0?
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/client/thin/TcpClientChannel.java
##########
@@ -705,9 +724,65 @@ private ClientException handleIOError(String chInfo,
@Nullable IOException ex) {
return new ClientConnectionException("Ignite cluster is unavailable ["
+ chInfo + ']', ex);
}
+ /**
+ * Initializes heartbeats.
+ *
+ * @param configuredInterval Configured heartbeat interval, in
milliseconds.
+ * @return Heartbeat timer.
+ */
+ private Timer initHeartbeat(long configuredInterval) {
+ long heartbeatInterval = getHeartbeatInterval(configuredInterval);
+
+ Timer timer = new Timer("tcp-client-channel-heartbeats-" + hashCode());
+
+ timer.schedule(new HeartbeatTask(heartbeatInterval),
heartbeatInterval, heartbeatInterval);
+
+ return timer;
+ }
+
+ /**
+ * Gets the heartbeat interval based on the configured value and
served-side idle timeout.
+ *
+ * @param configuredInterval Configured interval.
+ * @return Resolved interval.
+ */
+ private long getHeartbeatInterval(long configuredInterval) {
+ long serverIdleTimeoutMs = service(ClientOperation.GET_IDLE_TIMEOUT,
null, in -> in.in().readLong());
+
+ if (serverIdleTimeoutMs <= 0)
+ return configuredInterval;
+
+ long recommendedHeartbeatInterval = serverIdleTimeoutMs / 3;
Review comment:
Let's introduce adequate minimum for this value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]