#35 implement heartbeatInfo event on connection

This commit is contained in:
Nicolas Dextraze
2017-05-15 12:55:14 -07:00
parent 917b89cf3d
commit 121e248dd8
5 changed files with 42 additions and 5 deletions

View File

@ -460,7 +460,26 @@ EventStoreConnectionLogicHandler.prototype._handleTcpPackage = function(connecti
this._packageNumber += 1;
if (pkg.command === TcpCommand.HeartbeatResponseCommand)
{
if (pkg.correlationId === this._heartbeatInfo.correlationId)
{
var now = Date.now();
var heartbeatEvent = {
connectionId: this._connection.connectionId,
remoteEndPoint: this._connection.remoteEndPoint,
requestSentAt: this._heartbeatInfo.timeStamp,
requestPkgNumber: this._heartbeatInfo.lastPackageNumber,
responseReceivedAt: now,
responsePkgNumber: this._packageNumber
};
try {
this.emit('heartbeatInfo', heartbeatEvent);
} catch(e) {
this._logDebug("IGNORED: emit heartbeat event failed.\n%s", e.stack);
}
}
return;
}
if (pkg.command === TcpCommand.HeartbeatRequestCommand)
{
this._connection.enqueueSend(new TcpPackage(
@ -640,12 +659,13 @@ EventStoreConnectionLogicHandler.prototype._manageHeartbeats = function() {
if (this._heartbeatInfo.isIntervalStage)
{
var correlationId = uuid.v4();
// TcpMessage.Heartbeat analog
this._connection.enqueueSend(new TcpPackage(
TcpCommand.HeartbeatRequestCommand,
TcpFlags.None,
uuid.v4()));
this._heartbeatInfo = {lastPackageNumber: this._heartbeatInfo.lastPackageNumber, isIntervalStage: false, timeStamp: Date.now()};
correlationId));
this._heartbeatInfo = {correlationId: correlationId, lastPackageNumber: this._heartbeatInfo.lastPackageNumber, isIntervalStage: false, timeStamp: Date.now()};
}
else
{

View File

@ -59,6 +59,9 @@ function EventStoreNodeConnection(settings, clusterSettings, endpointDiscoverer,
this._handler.on('error', function(e) {
self.emit('error', e);
});
this._handler.on('heartbeatInfo', function(e) {
self.emit('heartbeatInfo', e);
});
}
util.inherits(EventStoreNodeConnection, EventEmitter);