ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ivasilin...@apache.org
Subject [28/28] incubator-ignite git commit: #ignite-964: change run-cache-script.js
Date Thu, 09 Jul 2015 14:59:56 GMT
#ignite-964: change run-cache-script.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/9413747c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/9413747c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/9413747c

Branch: refs/heads/ignite-964-1
Commit: 9413747ce03999b5e746c4387eae207f75268799
Parents: bfc899e
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Thu Jul 9 17:59:17 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Thu Jul 9 17:59:17 2015 +0300

----------------------------------------------------------------------
 examples/src/main/js/cache-put-get-example.js   | 10 +--
 .../main/js/compute-callable-cache-example.js   | 49 -------------
 examples/src/main/js/run-cache-script.js        | 76 ++++++++++++++++++++
 3 files changed, 81 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9413747c/examples/src/main/js/cache-put-get-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-put-get-example.js b/examples/src/main/js/cache-put-get-example.js
index 75da096..80c2080 100644
--- a/examples/src/main/js/cache-put-get-example.js
+++ b/examples/src/main/js/cache-put-get-example.js
@@ -55,7 +55,7 @@ function main() {
         }
 
         function onGet(err, res) {
-            console.log("Get val=" + res);
+            console.log("Get value=" + res);
 
             putAllGetAll(ignite, cache);
         }
@@ -79,23 +79,23 @@ function main() {
             batch.push(new CacheEntry(key, val));
         }
 
+        // Bulk-store entries in cache.
         cache.putAll(batch, onPutAll);
 
         function onPutAll(err) {
             console.log(">>> Stored values in cache.");
 
+            // Bulk-get values from cache.
             cache.getAll(keys, onGetAll);
         }
 
         function onGetAll(err, entries) {
             for (var e of entries) {
-                console.log("Got entry [key=" + e.key + ", val=" + e.value + ']');
+                console.log("Got entry [key=" + e.key + ", value=" + e.value + ']');
             }
 
             // Destroying cache.
-            ignite.destroyCache(cacheName, function(err) {
-                    console.log(">>> End of cache put-get example.");
-                });
+            ignite.destroyCache(cacheName, function(err) { console.log(">>> End
of cache put-get example."); });
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9413747c/examples/src/main/js/compute-callable-cache-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/compute-callable-cache-example.js b/examples/src/main/js/compute-callable-cache-example.js
deleted file mode 100644
index 1b92d7c..0000000
--- a/examples/src/main/js/compute-callable-cache-example.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 apacheIgnite = require("apache-ignite");
-var Ignition = apacheIgnite.Ignition;
-
-var cacheName = "ComputeCallableCacheExample";
-
-Ignition.start(['127.0.0.1:9095'], null, onConnect);
-
-function onConnect(err, ignite) {
-    console.log(">>> Compute callable example started.");
-
-    var f = function (args) {
-        print(">>> Hello node: " + ignite.name());
-
-        var cache = ignite.getOrCreateCache(args);
-
-        cache.put(ignite.name(), "Hello");
-
-        return ignite.name();
-    }
-
-    var onRunScript = function(err, igniteName) {
-        var cache = ignite.cache(cacheName);
-
-        cache.get(igniteName, function(err, res) {
-                console.log(res+ " " + igniteName);
-
-                console.log(">>> Check all nodes for output (this node is also part
of the cluster).");
-            });
-    }
-
-    ignite.compute().runScript(f, cacheName, onRunScript);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9413747c/examples/src/main/js/run-cache-script.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/run-cache-script.js b/examples/src/main/js/run-cache-script.js
new file mode 100644
index 0000000..1640cea
--- /dev/null
+++ b/examples/src/main/js/run-cache-script.js
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 apacheIgnite = require("apache-ignite");
+var Ignition = apacheIgnite.Ignition;
+
+/**
+  * This example demonstrates very basic operations on cache in functions for Compute.run.
+  * <p>
+  * 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'}.
+  * <p>
+  * 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 = "RunCacheScriptCache";
+
+    /** 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(">>> Run cache script example started.");
+
+        ignite.getOrCreateCache(cacheName, function(err, cache) { runCacheScript(ignite,
cache); });
+    }
+
+    function runCacheScript(ignite, cache) {
+        var key = "John";
+        var person = {"firstName": "John", "lastName": "Doe", "salary" : 2000};
+
+        // Store person in the cache
+        cache.put(key, person, onPut);
+
+        function onPut(err) {
+            var job = function (args) {
+                print(">>> Hello node: " + ignite.name());
+
+                var cacheName = args[0];
+                var key = args[1];
+
+                /** Get cache with name. */
+                var cache = ignite.cache(cacheName);
+
+                /** Get person with name John. */
+                var val = cache.get(key);
+
+                return val.salary;
+            }
+
+            var onRunScript = function(err, salary) {
+               console.log(">>> " + key + "'s salary is " + salary);
+            }
+
+            /** Run remote job on server ignite node with arguments [cacheName, key]. */
+            ignite.compute().runScript(job, [cacheName, key], onRunScript);
+        }
+    }
+}
+
+main();
\ No newline at end of file


Mime
View raw message