You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by mxf <91...@qq.com> on 2017/10/22 14:44:49 UTC
How does the HeartBeat work?
Hello,There's a question I'd like to ask about apache-sshd keealive.
The sshclient only send keepAlive every interal time,but not to check the reply of the keepAlive timeout.
> how does the client know that the server is available.
> Or does other param need to set to make the client heartbeat work?
what param of ssh client I set is :
I just set the HEARTBEAT_INTERVAL(20 senconds) and the IDLE_TIMEOUT(300senconds), the NIO_READ_TIMEOUT(315seconds).Does other param need to set to make the heartbeat available?
related code i understand is:
protected void startHeartBeat() {
ClientSession session = getClientSession();
long interval = session.getLongProperty(ClientFactoryManager.HEARTBEAT_INTERVAL, ClientFactoryManager.DEFAULT_HEARTBEAT_INTERVAL);
if (interval > 0L) {
FactoryManager manager = session.getFactoryManager();
ScheduledExecutorService service = manager.getScheduledExecutorService();
service.scheduleAtFixedRate(this::sendHeartBeat, interval, interval, TimeUnit.MILLISECONDS);
if (log.isDebugEnabled()) {
log.debug("startHeartbeat - started at interval={}", interval);
}
}
}
/**
* Sends a heartbeat message
* @return The {@link IoWriteFuture} that can be used to wait for the
* message write completion
*/
protected IoWriteFuture sendHeartBeat() {
ClientSession session = getClientSession();
String request = session.getStringProperty(ClientFactoryManager.HEARTBEAT_REQUEST, ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING);
try {
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, request.length() + Byte.SIZE);
buf.putString(request);
buf.putBoolean(false);
return session.writePacket(buf);
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug("Error (" + e.getClass().getSimpleName() + ") sending keepalive message=" + request + ": " + e.getMessage());
}
Throwable t = e;
return new AbstractIoWriteFuture(request, null) {
{
setValue(t);
}
};
}
}
Re: How does the HeartBeat work?
Posted by elijah baley <e_...@outlook.com>.
You don't even have to set these parameters - there are some defaults that are used anyway (unless you override them). The recommendation is to intervene only if the defaults are not compatible with your needs and/or to disable the features
________________________________
From: mxf <91...@qq.com>
Sent: Sunday, October 22, 2017 5:44 PM
To: dev
Subject: How does the HeartBeat work?
Hello,There's a question I'd like to ask about apache-sshd keealive.
The sshclient only send keepAlive every interal time,but not to check the reply of the keepAlive timeout.
> how does the client know that the server is available.
> Or does other param need to set to make the client heartbeat work?
what param of ssh client I set is :
I just set the HEARTBEAT_INTERVAL(20 senconds) and the IDLE_TIMEOUT(300senconds), the NIO_READ_TIMEOUT(315seconds).Does other param need to set to make the heartbeat available?
related code i understand is:
protected void startHeartBeat() {
ClientSession session = getClientSession();
long interval = session.getLongProperty(ClientFactoryManager.HEARTBEAT_INTERVAL, ClientFactoryManager.DEFAULT_HEARTBEAT_INTERVAL);
if (interval > 0L) {
FactoryManager manager = session.getFactoryManager();
ScheduledExecutorService service = manager.getScheduledExecutorService();
service.scheduleAtFixedRate(this::sendHeartBeat, interval, interval, TimeUnit.MILLISECONDS);
if (log.isDebugEnabled()) {
log.debug("startHeartbeat - started at interval={}", interval);
}
}
}
/**
* Sends a heartbeat message
* @return The {@link IoWriteFuture} that can be used to wait for the
* message write completion
*/
protected IoWriteFuture sendHeartBeat() {
ClientSession session = getClientSession();
String request = session.getStringProperty(ClientFactoryManager.HEARTBEAT_REQUEST, ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING);
try {
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, request.length() + Byte.SIZE);
buf.putString(request);
buf.putBoolean(false);
return session.writePacket(buf);
} catch (IOException e) {
if (log.isDebugEnabled()) {
log.debug("Error (" + e.getClass().getSimpleName() + ") sending keepalive message=" + request + ": " + e.getMessage());
}
Throwable t = e;
return new AbstractIoWriteFuture(request, null) {
{
setValue(t);
}
};
}
}