UNPKG

hazelcast-client

Version:

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

128 lines 6.23 kB
"use strict"; var SerializationService_1 = require('./serialization/SerializationService'); var InvocationService_1 = require('./invocation/InvocationService'); var Config_1 = require('./Config'); var LoggingService_1 = require('./logging/LoggingService'); var LifecycleService_1 = require('./LifecycleService'); var ClientGetDistributedObjectsCodec_1 = require('./codec/ClientGetDistributedObjectsCodec'); var ClientConnectionManager = require('./invocation/ClientConnectionManager'); var ProxyManager = require('./proxy/ProxyManager'); var PartitionService = require('./PartitionService'); var ClusterService = require('./invocation/ClusterService'); var Heartbeat = require('./HeartbeatService'); var HazelcastClient = (function () { function HazelcastClient(config) { this.config = new Config_1.ClientConfig(); if (config) { this.config = config; } LoggingService_1.LoggingService.initialize(this.config.properties['hazelcast.logging']); this.loggingService = LoggingService_1.LoggingService.getLoggingService(); this.invocationService = new InvocationService_1.InvocationService(this); this.listenerService = new InvocationService_1.ListenerService(this); this.serializationService = new SerializationService_1.SerializationServiceV1(this.config.serializationConfig); this.proxyManager = new ProxyManager(this); this.partitionService = new PartitionService(this); this.connectionManager = new ClientConnectionManager(this); this.clusterService = new ClusterService(this); this.lifecycleService = new LifecycleService_1.LifecycleService(this); this.heartbeat = new Heartbeat(this); } HazelcastClient.newHazelcastClient = function (config) { var client = new HazelcastClient(config); return client.init(); }; HazelcastClient.prototype.init = function () { var _this = this; return this.clusterService.start().then(function () { return _this.partitionService.initialize(); }).then(function () { return _this.heartbeat.start(); }).then(function () { _this.lifecycleService.emitLifecycleEvent(LifecycleService_1.LifecycleEvent.started); _this.loggingService.info('HazelcastClient', 'Client started'); return _this; }).catch(function (e) { _this.loggingService.error('HazelcastClient', 'Client failed to start', e); throw e; }); }; HazelcastClient.prototype.getLocalEndpoint = function () { return this.clusterService.getClientInfo(); }; HazelcastClient.prototype.getDistributedObjects = function () { var clientMessage = ClientGetDistributedObjectsCodec_1.ClientGetDistributedObjectsCodec.encodeRequest(); var toObjectFunc = this.serializationService.toObject.bind(this); var proxyManager = this.proxyManager; return this.invocationService.invokeOnRandomTarget(clientMessage).then(function (resp) { var response = ClientGetDistributedObjectsCodec_1.ClientGetDistributedObjectsCodec.decodeResponse(resp, toObjectFunc).response; return response.map(function (objectInfo) { return proxyManager.getOrCreateProxy(objectInfo['value'], objectInfo['key'], false); }); }); }; HazelcastClient.prototype.getMap = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.MAP_SERVICE); }; HazelcastClient.prototype.getSet = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.SET_SERVICE); }; HazelcastClient.prototype.getLock = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.LOCK_SERVICE); }; HazelcastClient.prototype.getQueue = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.QUEUE_SERVICE); }; HazelcastClient.prototype.getList = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.LIST_SERVICE); }; HazelcastClient.prototype.getMultiMap = function (name) { return this.proxyManager.getOrCreateProxy(name, this.proxyManager.MULTIMAP_SERVICE); }; HazelcastClient.prototype.getConfig = function () { return this.config; }; HazelcastClient.prototype.getSerializationService = function () { return this.serializationService; }; HazelcastClient.prototype.getInvocationService = function () { return this.invocationService; }; HazelcastClient.prototype.getListenerService = function () { return this.listenerService; }; HazelcastClient.prototype.getConnectionManager = function () { return this.connectionManager; }; HazelcastClient.prototype.getPartitionService = function () { return this.partitionService; }; HazelcastClient.prototype.getProxyManager = function () { return this.proxyManager; }; HazelcastClient.prototype.getClusterService = function () { return this.clusterService; }; HazelcastClient.prototype.getHeartbeat = function () { return this.heartbeat; }; HazelcastClient.prototype.getLifecycleService = function () { return this.lifecycleService; }; HazelcastClient.prototype.addDistributedObjectListener = function (listenerFunc) { return this.proxyManager.addDistributedObjectListener(listenerFunc); }; HazelcastClient.prototype.removeDistributedObjectListener = function (listenerId) { return this.proxyManager.removeDistributedObjectListener(listenerId); }; HazelcastClient.prototype.shutdown = function () { this.lifecycleService.emitLifecycleEvent(LifecycleService_1.LifecycleEvent.shuttingDown); this.heartbeat.cancel(); this.connectionManager.shutdown(); this.lifecycleService.emitLifecycleEvent(LifecycleService_1.LifecycleEvent.shutdown); }; return HazelcastClient; }()); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = HazelcastClient; //# sourceMappingURL=HazelcastClient.js.map