How to use the hazelcast-client.Client 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 / 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 / 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 / list.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;

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');
github hazelcast / hazelcast-nodejs-client / code_samples / lifecycle_listener.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 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 / jaas_sample / admin_client.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.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;
github hazelcast / hazelcast-nodejs-client / code_samples / map_entry_listener.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 listener = {
    added: function (entryEvent) {
        console.log('added key: ' + entryEvent.key + ', new value: ' + entryEvent.value
            + ', old value: ' + entryEvent.oldValue);
    },
    removed: function (entryEvent) {
        console.log('removed key: ' + entryEvent.key + ', new value: ' + entryEvent.value
            + ', old value: ' + entryEvent.oldValue);
    }
};

var pushNotification = function (map, key, value) {
    return map.put(key, value);
};

var removeNotification = function (map, key) {
github hazelcast / hazelcast-nodejs-client / code_samples / logging.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 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',
github hazelcast / hazelcast-nodejs-client / code_samples / org-website / CustomSerializerSample.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 CustomSerializable(value) {
    this.value = value;
}

CustomSerializable.prototype.hzGetCustomId = function () {
    return 10;
};

function CustomSerializer() {
    //Constructor function
}

CustomSerializer.prototype.getId = function () {
    return 10;