Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6EA26174AD for ; Fri, 10 Jul 2015 08:57:40 +0000 (UTC) Received: (qmail 30970 invoked by uid 500); 10 Jul 2015 08:57:40 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 30899 invoked by uid 500); 10 Jul 2015 08:57:40 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 30883 invoked by uid 99); 10 Jul 2015 08:57:40 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jul 2015 08:57:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id C118DD379A for ; Fri, 10 Jul 2015 08:57:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.21 X-Spam-Level: * X-Spam-Status: No, score=1.21 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.571, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 8hu4MnbRq8GB for ; Fri, 10 Jul 2015 08:57:33 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 457F9215D2 for ; Fri, 10 Jul 2015 08:57:25 +0000 (UTC) Received: (qmail 29874 invoked by uid 99); 10 Jul 2015 08:57:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Jul 2015 08:57:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DAEFFE3C3B; Fri, 10 Jul 2015 08:57:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ivasilinets@apache.org To: commits@ignite.incubator.apache.org Date: Fri, 10 Jul 2015 08:57:59 -0000 Message-Id: <79c62530bf5649e8959a4dde07acc565@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [37/50] [abbrv] incubator-ignite git commit: #ignite-964: change cache-api-example.js #ignite-964: change cache-api-example.js Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/242c21bb Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/242c21bb Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/242c21bb Branch: refs/heads/ignite-964 Commit: 242c21bb10ee0578055adeda1014a536e73ef88f Parents: 7763a37 Author: ivasilinets Authored: Thu Jul 9 17:08:06 2015 +0300 Committer: ivasilinets Committed: Thu Jul 9 17:08:06 2015 +0300 ---------------------------------------------------------------------- examples/config/js/example-js-cache.xml | 3 + .../examples/js/ExampleJsNodeStartup.java | 4 +- examples/src/main/js/cache-api-example.js | 103 ++++++++++++------- modules/nodejs/src/main/js/ignite.js | 4 +- 4 files changed, 74 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242c21bb/examples/config/js/example-js-cache.xml ---------------------------------------------------------------------- diff --git a/examples/config/js/example-js-cache.xml b/examples/config/js/example-js-cache.xml index 2599e38..e8ffc8a 100644 --- a/examples/config/js/example-js-cache.xml +++ b/examples/config/js/example-js-cache.xml @@ -31,6 +31,9 @@ + + + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242c21bb/examples/src/main/java/org/apache/ignite/examples/js/ExampleJsNodeStartup.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/js/ExampleJsNodeStartup.java b/examples/src/main/java/org/apache/ignite/examples/js/ExampleJsNodeStartup.java index 6fa2e6c..0de6047 100644 --- a/examples/src/main/java/org/apache/ignite/examples/js/ExampleJsNodeStartup.java +++ b/examples/src/main/java/org/apache/ignite/examples/js/ExampleJsNodeStartup.java @@ -21,11 +21,11 @@ import org.apache.ignite.*; import org.apache.ignite.spi.discovery.tcp.internal.*; /** - * Starts up an empty node with example compute configuration. + * Starts up an empty node with example node js configuration. */ public class ExampleJsNodeStartup { /** - * Start up an empty node with example compute configuration. + * Start up an empty node with example node js configuration. * * @param args Command line arguments, none required. * @throws IgniteException If failed. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242c21bb/examples/src/main/js/cache-api-example.js ---------------------------------------------------------------------- diff --git a/examples/src/main/js/cache-api-example.js b/examples/src/main/js/cache-api-example.js index 13368d5..d17276a 100644 --- a/examples/src/main/js/cache-api-example.js +++ b/examples/src/main/js/cache-api-example.js @@ -18,50 +18,81 @@ var apacheIgnite = require("apache-ignite"); var Ignition = apacheIgnite.Ignition; -Ignition.start(['127.0.0.1:9095'], null, onConnect); +/** + * This example demonstrates some of the cache rich API capabilities. + *

+ * Remote nodes should always be started with special configuration file which + * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/js/example-js-cache.xml'}. + *

+ * Alternatively you can run {@link ExampleJsNodeStartup} in another JVM which will + * start node with {@code examples/config/js/example-js-cache.xml} configuration. + */ +function main() { + /** Cache name. */ + var cacheName = "ApiExampleCache"; + + /** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */ + Ignition.start(['127.0.0.1:9095'], null, onConnect); + + function onConnect(err, ignite) { + console.log(">>> Cache API example started."); + + // Create cache on server with cacheName. + ignite.getOrCreateCache(cacheName, function(err, cache) { + atomicMapOperations(ignite, cache); + }); + } -function onConnect(err, ignite) { - console.log(">>> Cache API example started."); + /** + * Demonstrates cache operations similar to {@link ConcurrentMap} API. Note that + * cache API is a lot richer than the JDK {@link ConcurrentMap}. + */ + atomicMapOperations = function(ignite, cache) { + console.log(">>> Cache atomic map operation examples."); - ignite.getOrCreateCache("ApiExampleCache", function(err, cache) { - atomicMapOperations(cache); + cache.removeAllFromCache(function(err) { + // Put and return previous value. + cache.getAndPut(1, "1", onGetAndPut) }); -} -/** - * Demonstrates cache operations similar to {@link ConcurrentMap} API. Note that - * cache API is a lot richer than the JDK {@link ConcurrentMap}. - */ -atomicMapOperations = function(cache) { - console.log(">>> Cache atomic map operation examples."); + onGetAndPut = function(err, entry) { + console.log(">>> Get and put finished [result=" + entry + "]"); - cache.removeAllFromCache(function(err) { - cache.getAndPut(1, "1", onGetAndPut.bind(null, cache)) - }); -} + // Put and do not return previous value. + // Performs better when previous value is not needed. + cache.put(2, "2", onPut); + } -function onGetAndPut(cache, err, entry) { - cache.put(2, "2", onPut.bind(null, cache)); -} + onPut = function(err) { + console.log(">>> Put finished."); -function onPut(cache, err) { - cache.putIfAbsent(4, "44", onPutIfAbsent.bind(null, cache, true)); -} + // Put-if-absent. + cache.putIfAbsent(4, "44", onPutIfAbsent); + } -function onPutIfAbsent(cache, expRes, err, res) { - if (expRes) { - cache.putIfAbsent(4, "44", onPutIfAbsent.bind(null, cache, false)); - } - else { - cache.replaceValue(4, "55", "44", onReplaceValue.bind(null, cache, true)); + onPutIfAbsent = function(err, res) { + console.log(">>> Put if absent finished [result=" + res + "]"); + + // Replace. + cache.replaceValue(4, "55", "44", onReplaceValue); + } + + onReplaceValue = function(err, res) { + console.log(">>> Replace value finished [result=" + res + "]"); + + // Replace not correct value. + cache.replaceValue(4, "555", "44", onEnd); + } + + onEnd = function(err) { + console.log(">>> Replace finished."); + + // Destroying cache. + ignite.destroyCache(cacheName, function(err) { + console.log(">>> End of Cache API example."); + }); + } } } -function onReplaceValue(cache, expRes, err, res) { - if (expRes) { - cache.replaceValue(4, "555", "44", onReplaceValue.bind(null, cache, false)); - } - else { - console.log("End of the example.") - } -} \ No newline at end of file +main(); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/242c21bb/modules/nodejs/src/main/js/ignite.js ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/ignite.js b/modules/nodejs/src/main/js/ignite.js index 5dfb15b..a4a1dd9 100644 --- a/modules/nodejs/src/main/js/ignite.js +++ b/modules/nodejs/src/main/js/ignite.js @@ -59,7 +59,7 @@ Ignite.prototype.cache = function(cacheName) { * @param callback Callback with cache. */ Ignite.prototype.getOrCreateCache = function(cacheName, callback) { - var onCreateCallback = function(err) { + var onCreateCallback = function(callback, err, res) { if (err !== null) { callback.call(null, err, null); @@ -70,7 +70,7 @@ Ignite.prototype.getOrCreateCache = function(cacheName, callback) { } this._server.runCommand(new Command("getorcreatecache").addParam("cacheName", cacheName), - onCreateCallback.bind(this)); + onCreateCallback.bind(this, callback)); } /**