Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
PortableFactory.prototype.create = function (classId) {
if (classId === 1) {
return new User();
}
return null;
};
function generateUsers(users) {
return users.put('Rod', new User('Rod', 19, true)).then(function () {
return users.put('Jane', new User('Jane', 20, true));
}).then(function () {
return users.put('Freddy', new User('Freddy', 23, true));
});
}
var cfg = new Config.ClientConfig();
cfg.serializationConfig.portableFactories[1] = new PortableFactory();
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient(cfg).then(function (hz) {
var users;
// Get a Distributed Map called "users"
hz.getMap('users').then(function (mp) {
users = mp;
// Add some users to the Distributed Map
return generateUsers(users)
}).then(function () {
// Create a Predicate
var criteriaQuery = Predicates.and(
Predicates.equal('active', true),
Predicates.between('age', 18, 21)
);
// Get result collections using the the Predicate
let initConfig = (nearCache) => {
let config = new Config.ClientConfig();
config.networkConfig.addresses = [{host: '127.0.0.1', port: '5701'}];
//region NearCache
if (nearCache) {
let orgsNearCacheConfig = new Config.NearCacheConfig();
orgsNearCacheConfig.invalidateOnChange = true;
orgsNearCacheConfig.name = 'my-distributed-map';
let ncConfigs = {};
ncConfigs[orgsNearCacheConfig.name] = orgsNearCacheConfig;
config.nearCacheConfigs = ncConfigs;
}
process.stdout.write("Config Start ==> \n");
// process.stdout.write((JSON.stringify(config, null, 2)));
process.stdout.write("Config End ==> \n");
* 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.
*/
var Client = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;
var EvictionPolicy = require('hazelcast-client').EvictionPolicy;
var nearCachedMapName = 'nearCachedMap';
var regularMapName = 'reqularMap';
var client;
var cfg = new Config.ClientConfig();
var nearCacheConfig = new Config.NearCacheConfig();
nearCacheConfig.name = nearCachedMapName;
nearCacheConfig.evictionPolicy = EvictionPolicy.LFU;
nearCacheConfig.invalidateOnChange = true;
cfg.nearCacheConfigs[nearCachedMapName] = nearCacheConfig;
function do50000Gets(client, mapName) {
var timerStart;
var timerEnd;
var map;
return client.getMap(mapName).then(function (mp) {
map = mp;
return map.put('item', 'anItem');
}).then(function () {
// warm up the cache
Customer.prototype.getClassId = function () {
return 1;
};
function PortableFactory() {
// Constructor function
}
PortableFactory.prototype.create = function (classId) {
if (classId === 1) {
return new Customer();
}
return null;
};
var cfg = new Config.ClientConfig();
cfg.serializationConfig.portableFactories[1] = new PortableFactory();
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient(cfg).then(function (hz) {
//Customer can be used here
hz.shutdown();
});
* 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.
*/
var HazelcastClient = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;
var cfg = new Config.ClientConfig();
cfg.listeners.addLifecycleListener(function (state) {
console.log('Lifecycle Event >>> ' + state);
});
HazelcastClient.newHazelcastClient(cfg).then(function (hazelcastClient) {
hazelcastClient.shutdown();
});
* 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.
*/
var Config = require('hazelcast-client').Config;
var HazelcastClient = require('hazelcast-client').Client;
var cfg = new Config.ClientConfig();
cfg.networkConfig.sslConfig.enabled = true;
HazelcastClient.newHazelcastClient(cfg).then(function (client) {
console.log('This client is authenticated using SSL.');
client.shutdown();
});
*
* 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.
*/
var winston = require('winston');
var Config = require('hazelcast-client').Config;
var HazelcastClient = require('hazelcast-client').Client;
var LogLevel = require('hazelcast-client').LogLevel;
var cfg = new Config.ClientConfig();
var winstonAdapter = {
logger: new (winston.Logger)({
transports: [
new (winston.transports.Console)()
]
}),
levels: [
'error',
'warn',
'info',
'debug',
'silly'
],
* 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.
*/
var Client = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;
var Predicates = require('hazelcast-client').Predicates;
var HazelcastJsonValue = require('hazelcast-client').HazelcastJsonValue;
var JsonStringDeserializationPolicy = require('hazelcast-client').JsonStringDeserializationPolicy;
var config = new Config.ClientConfig();
config.serializationConfig.jsonStringDeserializationPolicy = JsonStringDeserializationPolicy.NO_DESERIALIZATION;
Client.newHazelcastClient(config).then(function(hz) {
var map;
return hz.getMap('employees').then(function(mp) {
map = mp;
var employees = [
{ name: 'Alice', age: 35 },
{ name: 'Andy', age: 22},
{ name: 'Bob', age: 37 }
];
return map.putAll(employees.map(function (employee, index) {
return [index, new HazelcastJsonValue(JSON.stringify(employee))];
}));
}).then(function() {
function createConfig() {
var cfg = new Config.ClientConfig();
var nearCacheConfig = new Config.NearCacheConfig();
cfg.nearCacheConfigs['nearCachedMap'] = nearCacheConfig;
cfg.properties['hazelcast.client.statistics.enabled'] = true;
cfg.properties['hazelcast.client.statistics.period.seconds'] = 2;
return cfg;
}
*
* 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.
*/
/**
* JSON serialization is not capable if handling circular references.
* We will use Mousse serializer to serialize our self referring objects.
*/
var mousse = require('mousse');
var Client = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;
var cfg = new Config.ClientConfig();
cfg.serializationConfig.globalSerializer = {
mousseSerialize: mousse.serialize,
mousseDeserialize: mousse.deserialize,
getId: function () {
return 10;
},
write: function (out, obj) {
out.writeUTF(this.mousseSerialize(obj))
},
read: function (inp) {
var representation = inp.readUTF();
return this.mousseDeserialize(representation).then(function (obj) {
return obj;
});
}
};