UNPKG

hazelcast-client

Version:

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

44 lines 1.71 kB
"use strict"; var GetPartitionsCodec = require("./codec/GetPartitionsCodec"); var PartitionService = (function () { function PartitionService(client) { this.client = client; } PartitionService.prototype.initialize = function () { var _this = this; return this.refresh().then(function () { return _this; }); }; PartitionService.prototype.refresh = function () { var _this = this; var ownerConnection = this.client.getClusterService().getOwnerConnection(); var clientMessage = GetPartitionsCodec.encodeRequest(); return this.client.getInvocationService() .invokeOnConnection(ownerConnection, clientMessage) .then(function (clientMessage) { _this.partitionMap = GetPartitionsCodec.decodeResponse(clientMessage); _this.partitionCount = Object.keys(_this.partitionMap).length; }); }; ; PartitionService.prototype.getAddressForPartition = function (partitionId) { return this.partitionMap[partitionId]; }; PartitionService.prototype.getPartitionId = function (key) { var partitionHash; if (typeof key === 'object' && 'getPartitionHash' in key) { partitionHash = key.getPartitionHash(); } else { partitionHash = this.client.getSerializationService().toData(key).getPartitionHash(); } return Math.abs(partitionHash) % this.partitionCount; }; PartitionService.prototype.getPartitionCount = function () { return this.partitionCount; }; return PartitionService; }()); module.exports = PartitionService; //# sourceMappingURL=PartitionService.js.map