How to use hazelcast-client - 10 common examples

To help you get started, we’ve selected a few hazelcast-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hazelcast / hazelcast-nodejs-client / code_samples / org-website / RingBufferSample.js View on Github external
* Copyright (c) 2008-2019, 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.
 */

var Client = require('hazelcast-client').Client;
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient().then(function (hz) {
    var rb;
    // Get a Ringbuffer called "rb"
    hz.getRingbuffer('rb').then(function (buffer) {
        rb = buffer;
        return rb.add(100);
    }).then(function () {
        return rb.add(200);
    }).then(function (value) {
        // we start from the oldest item.
        // if you want to start from the next item, call rb.tailSequence()+1
        return rb.headSequence();
    }).then(function (sequence) {
        return rb.readOne(sequence).then(function (value) {
            console.log(value);
github hazelcast / hazelcast-nodejs-client / code_samples / membership_listener.js View on Github external
* 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 Client = require('hazelcast-client').Client;

Client.newHazelcastClient().then(function (client) {

    // when a member is added and removed or its attribute is changed, member events are invoked.
    var membershipListener = {
        memberAdded: function (membershipEvent) {
            console.log('Member Added:', membershipEvent.member.address);
        },
        memberRemoved: function (membershipEvent) {
            console.log('Member Removed:', membershipEvent.member.address);
        },
        memberAttributeChanged: function (memberAttributeEvent) {
            console.log('Member Attribute Changed:', memberAttributeEvent.member.address);
        }
    }

    client.clusterService.addMembershipListener(membershipListener);
});
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / ListSample.js View on Github external
* 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 Client = require('hazelcast-client').Client;
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient().then(function (hz) {
    var list;
    // Get the Distributed List from Cluster.
    hz.getList('my-distributed-list').then(function (l) {
        list = l;
        // Add elements to the list
        return list.add('item1');
    }).then(function () {
        return list.add('item2');
    }).then(function () {
        //Remove the first element
        return list.removeAt(0);
    }).then(function (value) {
        console.log(value);
        // There is only one element left
        return list.size();
    }).then(function (len) {
github hazelcast / hazelcast-nodejs-client / code_samples / jaas_sample / admin_client.js View on Github external
* 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.ClientConfig;

var UsernamePasswordCredentials = require('./user_pass_cred').UsernamePasswordCredentials;
var UsernamePasswordCredentialsFactory = require('./user_pass_cred_factory').UsernamePasswordCredentialsFactory;

var adminClientConfig = new Config();

adminClientConfig.serializationConfig.portableFactories[1] = new UsernamePasswordCredentialsFactory();
adminClientConfig.customCredentials = new UsernamePasswordCredentials('admin', 'password1', '127.0.0.1');

Client.newHazelcastClient(adminClientConfig).then(function (adminClient) {
    console.log('Admin client connected');
    var adminMap;
    return adminClient.getMap('importantAdminMap').then(function (map) {
        console.log('Admin can create a map');
        adminMap = map;
        return adminMap.get('someKey');
    }).then(function (value) {
        console.log('Admin can read from map: ' + value);
        return adminMap.put('anotherKey', 'anotherValue'); // Should resolve
    }).then(function () {
        console.log('Admin can put to map');
        return adminMap.get('anotherKey');
    }).then(function (value) {
        console.log('Value for the "anotherKey" is ' + value);
        return adminClient.shutdown();
    });
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / MultiMapSample.js View on Github external
* Copyright (c) 2008-2019, 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.
 */

var Client = require('hazelcast-client').Client;
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient().then(function (hz) {
    var multiMap;
    // Get the Distributed MultiMap from Cluster.
    hz.getMultiMap('my-distributed-multimap').then(function (mmp) {
        multiMap = mmp;
        // Put values in the map against the same key
        return multiMap.put('my-key', 'value1');
    }).then(function () {
        return multiMap.put('my-key', 'value2');
    }).then(function () {
        return multiMap.put('my-key', 'value3');
    }).then(function () {
        // Print out all the values for associated with key called "my-key"
        return multiMap.get('my-key')
    }).then(function (values) {
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / QueueSample.js View on Github external
* Copyright (c) 2008-2019, 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.
 */

var Client = require('hazelcast-client').Client;
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient().then(function (hz) {
    var queue;
    // Get a Blocking Queue called "my-distributed-queue"
    hz.getQueue('my-distributed-queue').then(function (q) {
        queue = q;
        // Offer a String into the Distributed Queue
        return queue.offer('item');
    }).then(function () {
        // Poll the Distributed Queue and return the String
        return queue.poll();
    }).then(function () {
        // Timed blocking Operations
        return queue.offer('anotheritem', 500);
    }).then(function () {
        return queue.poll(5000);
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / EntryProcessorSample.js View on Github external
* Copyright (c) 2008-2019, 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.
 */

var Client = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;

function IdentifiedEntryProcessor(value) {
    // Constructor function
}

IdentifiedEntryProcessor.prototype.readData = function (inp) {
};

IdentifiedEntryProcessor.prototype.writeData = function (outp) {
};

IdentifiedEntryProcessor.prototype.getFactoryId = function () {
    return 1;
};
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / IdentifiedDataSerializableSample.js View on Github external
function SampleDataSerializableFactory() {
    // Constructor function
}

SampleDataSerializableFactory.prototype.create = function (type) {
    if (type === 100) {
        return new Employee();
    }
    return null;
};

var cfg = new Config.ClientConfig();
cfg.serializationConfig.dataSerializableFactories[1000] = new SampleDataSerializableFactory();
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient(cfg).then(function (hz) {
    // Employee can be used here
    hz.shutdown();
});
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / MapSample.js View on Github external
* 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 Client = require('hazelcast-client').Client;
// Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
Client.newHazelcastClient().then(function (hz) {
    var map;
    // Get the Distributed Map from Cluster.
    hz.getMap('my-distributed-map').then(function (mp) {
        map = mp;
        // Standard Put and Get.
        return map.put('key', 'value');
    }).then(function () {
        return map.get('key');
    }).then(function (val) {
        // Concurrent Map methods, optimistic updating
        return map.putIfAbsent('somekey', 'somevalue');
    }).then(function () {
        return map.replace('key', 'value', 'newvalue');
    }).then(function (value) {
        // Shutdown this Hazelcast client
        hz.shutdown();
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / EntryProcessorSample.js View on Github external
*
 * 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 Client = require('hazelcast-client').Client;
var Config = require('hazelcast-client').Config;

function IdentifiedEntryProcessor(value) {
    // Constructor function
}

IdentifiedEntryProcessor.prototype.readData = function (inp) {
};

IdentifiedEntryProcessor.prototype.writeData = function (outp) {
};

IdentifiedEntryProcessor.prototype.getFactoryId = function () {
    return 1;
};

IdentifiedEntryProcessor.prototype.getClassId = function () {