UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

72 lines 3.45 kB
"use strict"; /* * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); var LoggingService_1 = require("../../logging/LoggingService"); var TopicMessage_1 = require("./TopicMessage"); var ReliableTopicListenerRunner = /** @class */ (function () { function ReliableTopicListenerRunner(listenerId, listener, ringbuffer, batchSize, serializationService, proxy) { this.sequenceNumber = 0; this.cancelled = false; this.loggingService = LoggingService_1.LoggingService.getLoggingService(); this.listenerId = listenerId; this.listener = listener; this.ringbuffer = ringbuffer; this.batchSize = batchSize; this.serializationService = serializationService; this.proxy = proxy; } ReliableTopicListenerRunner.prototype.next = function () { var _this = this; if (this.cancelled) { return; } this.ringbuffer.readMany(this.sequenceNumber, 1, this.batchSize).then(function (result) { if (!_this.cancelled) { result.forEach(function (raw) { var msg = new TopicMessage_1.TopicMessage(); msg.messageObject = _this.serializationService.toObject(raw.payload); msg.publisher = raw.publisherAddress; msg.publishingTime = raw.publishTime; setImmediate(_this.listener, msg); _this.sequenceNumber++; }); setImmediate(_this.next.bind(_this)); } }).catch(function (e) { if (e.className === 'com.hazelcast.ringbuffer.StaleSequenceException') { _this.ringbuffer.headSequence().then(function (seq) { var newSequence = seq.toNumber(); var message = 'Topic "' + _this.proxy.getName() + '" ran into a stale sequence. ' + ' Jumping from old sequence ' + _this.sequenceNumber + ' to new sequence ' + newSequence; _this.loggingService.warn('ReliableTopicListenerRunner', message); _this.sequenceNumber = newSequence; setImmediate(_this.next.bind(_this)); }); return; } var message = 'Listener of topic "' + _this.proxy.getName() + '" caught an exception, terminating listener. ' + e; _this.loggingService.warn('ReliableTopicListenerRunner', message); _this.proxy.removeMessageListener(_this.listenerId); }); }; ReliableTopicListenerRunner.prototype.cancel = function () { this.cancelled = true; }; return ReliableTopicListenerRunner; }()); exports.ReliableTopicListenerRunner = ReliableTopicListenerRunner; //# sourceMappingURL=ReliableTopicListenerRunner.js.map