Performance improvement by using strict equality, fixed heartbeat issue in connection stage
This commit is contained in:
@ -37,38 +37,38 @@ ConnectToPersistentSubscriptionOperation.prototype._createSubscriptionPackage =
|
||||
};
|
||||
|
||||
ConnectToPersistentSubscriptionOperation.prototype._inspectPackage = function(pkg) {
|
||||
if (pkg.command == TcpCommand.PersistentSubscriptionConfirmation)
|
||||
if (pkg.command === TcpCommand.PersistentSubscriptionConfirmation)
|
||||
{
|
||||
var dto = ClientMessage.PersistentSubscriptionConfirmation.decode(pkg.data.toBuffer());
|
||||
this._confirmSubscription(dto.last_commit_position, dto.last_event_number);
|
||||
this._subscriptionId = dto.subscription_id;
|
||||
return new InspectionResult(InspectionDecision.Subscribed, "SubscriptionConfirmation");
|
||||
}
|
||||
if (pkg.command == TcpCommand.PersistentSubscriptionStreamEventAppeared)
|
||||
if (pkg.command === TcpCommand.PersistentSubscriptionStreamEventAppeared)
|
||||
{
|
||||
var dto = ClientMessage.PersistentSubscriptionStreamEventAppeared.decode(pkg.data.toBuffer());
|
||||
this._onEventAppeared(new results.ResolvedEvent(dto.event));
|
||||
return new InspectionResult(InspectionDecision.DoNothing, "StreamEventAppeared");
|
||||
}
|
||||
if (pkg.command == TcpCommand.SubscriptionDropped)
|
||||
if (pkg.command === TcpCommand.SubscriptionDropped)
|
||||
{
|
||||
var dto = ClientMessage.SubscriptionDropped.decode(pkg.data.toBuffer());
|
||||
if (dto.reason == ClientMessage.SubscriptionDropped.SubscriptionDropReason.AccessDenied)
|
||||
if (dto.reason === ClientMessage.SubscriptionDropped.SubscriptionDropReason.AccessDenied)
|
||||
{
|
||||
this.dropSubscription(SubscriptionDropReason.AccessDenied, new Error("You do not have access to the stream."));
|
||||
return new InspectionResult(InspectionDecision.EndOperation, "SubscriptionDropped");
|
||||
}
|
||||
if (dto.reason == ClientMessage.SubscriptionDropped.SubscriptionDropReason.NotFound)
|
||||
if (dto.reason === ClientMessage.SubscriptionDropped.SubscriptionDropReason.NotFound)
|
||||
{
|
||||
this.dropSubscription(SubscriptionDropReason.NotFound, new Error("Subscription not found"));
|
||||
return new InspectionResult(InspectionDecision.EndOperation, "SubscriptionDropped");
|
||||
}
|
||||
if (dto.reason == ClientMessage.SubscriptionDropped.SubscriptionDropReason.PersistentSubscriptionDeleted)
|
||||
if (dto.reason === ClientMessage.SubscriptionDropped.SubscriptionDropReason.PersistentSubscriptionDeleted)
|
||||
{
|
||||
this.dropSubscription(SubscriptionDropReason.PersistentSubscriptionDeleted, new Error("Persistent subscription deleted."));
|
||||
return new InspectionResult(InspectionDecision.EndOperation, "SubscriptionDropped");
|
||||
}
|
||||
if (dto.reason == ClientMessage.SubscriptionDropped.SubscriptionDropReason.SubscriberMaxCountReached)
|
||||
if (dto.reason === ClientMessage.SubscriptionDropped.SubscriptionDropReason.SubscriberMaxCountReached)
|
||||
{
|
||||
this.dropSubscription(SubscriptionDropReason.MaxSubscribersReached, new Error("Maximum subscribers reached."));
|
||||
return new InspectionResult(InspectionDecision.EndOperation, "SubscriptionDropped");
|
||||
@ -111,10 +111,10 @@ ConnectToPersistentSubscriptionOperation.prototype.notifyEventsFailed = function
|
||||
action);
|
||||
|
||||
var pkg = new TcpPackage(TcpCommand.PersistentSubscriptionNakEvents,
|
||||
this._userCredentials != null ? TcpFlags.Authenticated : TcpFlags.None,
|
||||
this._userCredentials !== null ? TcpFlags.Authenticated : TcpFlags.None,
|
||||
this._correlationId,
|
||||
this._userCredentials != null ? this._userCredentials.username : null,
|
||||
this._userCredentials != null ? this._userCredentials.password : null,
|
||||
this._userCredentials !== null ? this._userCredentials.username : null,
|
||||
this._userCredentials !== null ? this._userCredentials.password : null,
|
||||
createBufferSegment(dto.toBuffer()));
|
||||
this._enqueueSend(pkg);
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ CreatePersistentSubscriptionOperation.prototype._createRequestDto = function() {
|
||||
return new ClientMessage.CreatePersistentSubscription(this._groupName, this._stream, this._resolveLinkTos,
|
||||
this._startFromBeginning, this._messageTimeoutMilliseconds, this._recordStatistics, this._liveBufferSize,
|
||||
this._readBatchSize, this._bufferSize, this._maxRetryCount,
|
||||
this._namedConsumerStrategy == SystemConsumerStrategies.RoundRobin, this._checkPointAfter,
|
||||
this._namedConsumerStrategy === SystemConsumerStrategies.RoundRobin, this._checkPointAfter,
|
||||
this._maxCheckPointCount, this._minCheckPointCount, this._maxSubscriberCount, this._namedConsumerStrategy);
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ OperationBase.prototype._succeed = function() {
|
||||
if (!this._completed) {
|
||||
this._completed = true;
|
||||
|
||||
if (this._response != null)
|
||||
if (this._response)
|
||||
this._cb(null, this._transformResponse(this._response));
|
||||
else
|
||||
this._cb(new Error("No result."))
|
||||
@ -118,7 +118,7 @@ OperationBase.prototype._inspectNotHandled = function(pkg)
|
||||
|
||||
case ClientMessage.NotHandled.NotHandledReason.NotMaster:
|
||||
var masterInfo = ClientMessage.NotHandled.MasterInfo.decode(message.additional_info);
|
||||
return new new InspectionResult(InspectionDecision.Reconnect, "NotHandled - NotMaster",
|
||||
return new InspectionResult(InspectionDecision.Reconnect, "NotHandled - NotMaster",
|
||||
{host: masterInfo.external_tcp_address, port: masterInfo.external_tcp_port},
|
||||
{host: masterInfo.external_secure_tcp_address, port: masterInfo.external_secure_tcp_port});
|
||||
|
||||
@ -130,7 +130,7 @@ OperationBase.prototype._inspectNotHandled = function(pkg)
|
||||
|
||||
OperationBase.prototype._inspectUnexpectedCommand = function(pkg, expectedCommand)
|
||||
{
|
||||
if (pkg.command == expectedCommand)
|
||||
if (pkg.command === expectedCommand)
|
||||
throw new Error("Command shouldn't be " + TcpCommand.getName(pkg.command));
|
||||
|
||||
this.log.error("Unexpected TcpCommand received.\n"
|
||||
|
@ -46,7 +46,7 @@ SubscriptionOperation.prototype._enqueueSend = function(pkg) {
|
||||
SubscriptionOperation.prototype.subscribe = function(correlationId, connection) {
|
||||
if (connection === null) throw new TypeError("connection is null.");
|
||||
|
||||
if (this._subscription != null || this._unsubscribed != 0)
|
||||
if (this._subscription !== null || this._unsubscribed)
|
||||
return false;
|
||||
|
||||
this._correlationId = correlationId;
|
||||
@ -128,7 +128,7 @@ SubscriptionOperation.prototype.inspectPackage = function(pkg) {
|
||||
|
||||
case TcpCommand.NotHandled:
|
||||
{
|
||||
if (this._subscription != null)
|
||||
if (this._subscription !== null)
|
||||
throw new Error("NotHandled command appeared while we already subscribed.");
|
||||
|
||||
var message = ClientMessage.NotHandled.decode(pkg.data.toBuffer());
|
||||
|
@ -39,7 +39,7 @@ UpdatePersistentSubscriptionOperation.prototype._createRequestDto = function() {
|
||||
return new ClientMessage.UpdatePersistentSubscription(this._groupName, this._stream, this._resolveLinkTos,
|
||||
this._startFromBeginning, this._messageTimeoutMilliseconds, this._recordStatistics, this._liveBufferSize,
|
||||
this._readBatchSize, this._bufferSize, this._maxRetryCount,
|
||||
this._namedConsumerStrategy == SystemConsumerStrategies.RoundRobin, this._checkPointAfter,
|
||||
this._namedConsumerStrategy === SystemConsumerStrategies.RoundRobin, this._checkPointAfter,
|
||||
this._maxCheckPointCount, this._minCheckPointCount, this._maxSubscriberCount, this._namedConsumerStrategy);
|
||||
};
|
||||
|
||||
|
@ -22,21 +22,21 @@ util.inherits(VolatileSubscriptionOperation, SubscriptionOperation);
|
||||
VolatileSubscriptionOperation.prototype._createSubscriptionPackage = function() {
|
||||
var dto = new ClientMessage.SubscribeToStream(this._streamId, this._resolveLinkTos);
|
||||
return new TcpPackage(TcpCommand.SubscribeToStream,
|
||||
this._userCredentials != null ? TcpFlags.Authenticated : TcpFlags.None,
|
||||
this._userCredentials !== null ? TcpFlags.Authenticated : TcpFlags.None,
|
||||
this._correlationId,
|
||||
this._userCredentials != null ? this._userCredentials.username : null,
|
||||
this._userCredentials != null ? this._userCredentials.password : null,
|
||||
this._userCredentials !== null ? this._userCredentials.username : null,
|
||||
this._userCredentials !== null ? this._userCredentials.password : null,
|
||||
new BufferSegment(dto.toBuffer()));
|
||||
};
|
||||
|
||||
VolatileSubscriptionOperation.prototype._inspectPackage = function(pkg) {
|
||||
try {
|
||||
if (pkg.command == TcpCommand.SubscriptionConfirmation) {
|
||||
if (pkg.command === TcpCommand.SubscriptionConfirmation) {
|
||||
var dto = ClientMessage.SubscriptionConfirmation.decode(pkg.data.toBuffer());
|
||||
this._confirmSubscription(dto.last_commit_position, dto.last_event_number);
|
||||
return new InspectionResult(InspectionDecision.Subscribed, "SubscriptionConfirmation");
|
||||
}
|
||||
if (pkg.command == TcpCommand.StreamEventAppeared) {
|
||||
if (pkg.command === TcpCommand.StreamEventAppeared) {
|
||||
var dto = ClientMessage.StreamEventAppeared.decode(pkg.data.toBuffer());
|
||||
this._onEventAppeared(new results.ResolvedEvent(dto.event));
|
||||
return new InspectionResult(InspectionDecision.DoNothing, "StreamEventAppeared");
|
||||
|
Reference in New Issue
Block a user