hazelcast-client
Version:
Hazelcast - open source In-Memory Data Grid - client for NodeJS
71 lines • 2.91 kB
JavaScript
;
/*
* 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 ClusterDataFactoryHelper_1 = require("../ClusterDataFactoryHelper");
var VectorClock = /** @class */ (function () {
function VectorClock() {
this.replicaTimestamps = new Map();
}
VectorClock.prototype.isAfter = function (other) {
var _this = this;
var atLeastOneBigger = false;
other.replicaTimestamps.forEach(function (otherTimestamp, replicaId) {
var thisTimetamp = _this.replicaTimestamps.get(replicaId);
if (thisTimetamp == null || otherTimestamp.greaterThan(thisTimetamp)) {
return false;
}
else if (otherTimestamp.lessThan(thisTimetamp)) {
atLeastOneBigger = true;
}
});
return atLeastOneBigger || this.replicaTimestamps.size > other.replicaTimestamps.size;
};
VectorClock.prototype.setReplicaTimestamp = function (replicaId, timestamp) {
this.replicaTimestamps.set(replicaId, timestamp);
};
VectorClock.prototype.entrySet = function () {
var entrySet = [];
this.replicaTimestamps.forEach(function (timestamp, replicaId) {
entrySet.push([replicaId, timestamp]);
});
return entrySet;
};
VectorClock.prototype.readData = function (input) {
var stateSize = input.readInt();
for (var i = 0; i < stateSize; i++) {
var replicaId = input.readUTF();
var timestamp = input.readLong();
this.replicaTimestamps.set(replicaId, timestamp);
}
};
VectorClock.prototype.writeData = function (output) {
output.writeInt(this.replicaTimestamps.size);
this.replicaTimestamps.forEach(function (timestamp, replicaId) {
output.writeUTF(replicaId);
output.writeLong(timestamp);
});
};
VectorClock.prototype.getFactoryId = function () {
return ClusterDataFactoryHelper_1.ClusterDataFactoryHelper.FACTORY_ID;
};
VectorClock.prototype.getClassId = function () {
return ClusterDataFactoryHelper_1.ClusterDataFactoryHelper.VECTOR_CLOCK;
};
return VectorClock;
}());
exports.VectorClock = VectorClock;
//# sourceMappingURL=VectorClock.js.map