How to use the hazelcast-client.Client.newHazelcastClient function in hazelcast-client

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 / 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 / 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 / lifecycle_listener.js View on Github external
* 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();
});
github hazelcast / hazelcast-nodejs-client / code_samples / queue.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 (hazelcastClient) {
    var client = hazelcastClient;
    var queue;
    hazelcastClient.getQueue('people').then(function (q) {
        queue = q;
        return queue.put('Item1');
    }).then(function () {
        return queue.put('Item2');
    }).then(function () {
        return queue.peek();
    }).then(function (item) {
        console.log('Peeked item: ' + item + '. Item is not removed from queue.');
        return queue.poll();
    }).then(function (item) {
        console.log('Retrieved item: ' + item + '. Item is removed from queue.');
        return queue.poll();
    }).then(function (item) {
github hazelcast / hazelcast-nodejs-client / code_samples / list.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 (hazelcastClient) {
    var client = hazelcastClient;
    var list;
    hazelcastClient.getList('people').then(function (l) {
        list = l;
        return list.add('John');
    }).then(function (value) {
        console.log('Added John.');
        return list.add('Jane', 1);
    }).then(function () {
        console.log('Added Jane to index 1.');
        return list.add('Thomas');
    }).then(function () {
        console.log('Added Thomas.');
        return list.remove('Jane');
    }).then(function (value) {
        console.log('Removed Jane.');
github hazelcast / hazelcast-nodejs-client / code_samples / pn_counter.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 (hazelcastClient) {
    var client = hazelcastClient;
    var pnCounter;
    hazelcastClient.getPNCounter('counter').then(function (counter) {
        pnCounter = counter;
        return pnCounter.addAndGet(5);
    }).then(function (val) {
        console.log('Added 5 to `counter`. Current value is ' + val);
        return pnCounter.decrementAndGet();
    }).then(function (val) {
        console.log('Decremented `counter`. Current value is ' + val);
        return client.shutdown();
    });
});
github hazelcast / hazelcast-nodejs-client / code_samples / logging.js View on Github external
info: function (objectName, message, furtherInfo) {
        this.log(LogLevel.INFO, objectName, message, furtherInfo);
    },

    debug: function (objectName, message, furtherInfo) {
        this.log(LogLevel.DEBUG, objectName, message, furtherInfo);
    },

    trace: function (objectName, message, furtherInfo) {
        this.log(LogLevel.TRACE, objectName, message, furtherInfo);
    }
};
cfg.customLogger = winstonAdapter;

HazelcastClient.newHazelcastClient(cfg).then(function (client) {
    client.shutdown();
});