|
| 1 | +/* |
| 2 | + * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +var Client = require('hazelcast-client').Client; |
| 18 | +var Config = require('hazelcast-client').Config; |
| 19 | + |
| 20 | +function createConfig() { |
| 21 | + var cfg = new Config.ClientConfig(); |
| 22 | + |
| 23 | + var nearCacheConfig = new Config.NearCacheConfig(); |
| 24 | + cfg.nearCacheConfigs['nearCachedMap'] = nearCacheConfig; |
| 25 | + cfg.properties['hazelcast.client.statistics.enabled'] = true; |
| 26 | + cfg.properties['hazelcast.client.statistics.period.seconds'] = 2; |
| 27 | + return cfg; |
| 28 | +} |
| 29 | + |
| 30 | +Client.newHazelcastClient(createConfig()).then(function (client) { |
| 31 | + var ncMap; |
| 32 | + return client.getMap('nearCachedMap').then(function (map) { |
| 33 | + ncMap = map; |
| 34 | + return ncMap.put('key1', 'value1'); |
| 35 | + }).then(function () { |
| 36 | + return ncMap.get('key1'); |
| 37 | + }).then(function () { |
| 38 | + return ncMap.get('key1'); |
| 39 | + }).then(function () { |
| 40 | + return ncMap.get('key1'); |
| 41 | + }).then(function () { |
| 42 | + // At this point, we have 1 near cache miss, 2 near cache hits as client near cache statistics. |
| 43 | + // Sleep more than statistics collection time and keep client running. Then, you can see the statistics |
| 44 | + // at the Management center. |
| 45 | + setTimeout(function () { |
| 46 | + client.shutdown(); |
| 47 | + }, 60000); |
| 48 | + }); |
| 49 | +}); |
0 commit comments