You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by iv...@apache.org on 2015/07/14 13:46:01 UTC
[3/3] incubator-ignite git commit: #ignite-961: rewrite examples.
#ignite-961: rewrite examples.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/341f3031
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/341f3031
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/341f3031
Branch: refs/heads/ignite-961-promise
Commit: 341f30310c38627bd8de338b2e52ce35049a85f9
Parents: fee4ed9
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jul 14 14:45:53 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jul 14 14:45:53 2015 +0300
----------------------------------------------------------------------
examples/src/main/js/cache-api-example.js | 58 ++++------
.../main/js/cache-not-promise-api-example.js | 81 --------------
.../src/main/js/cache-promise-api-example.js | 75 -------------
.../src/main/js/cache-promise-query-example.js | 108 -------------------
examples/src/main/js/cache-query-example.js | 65 +++++------
.../main/js/cache-sql-fields-query-example.js | 80 ++++++++++++--
examples/src/main/js/compute-run-example.js | 38 ++++---
examples/src/main/js/map-reduce-example.js | 23 ++--
8 files changed, 156 insertions(+), 372 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/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 f708160..1d4ddda 100644
--- a/examples/src/main/js/cache-api-example.js
+++ b/examples/src/main/js/cache-api-example.js
@@ -31,69 +31,57 @@ function main() {
var cacheName = "ApiExampleCache";
/** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
+ Ignition.start(['127.0.0.1:8000..9000'], null).then(function(ignite) {
console.log(">>> Cache API example started.");
// Create cache on server with cacheName.
- ignite.getOrCreateCache(cacheName, function(err, cache) {
+ ignite.getOrCreateCache(cacheName).then(function(cache){
atomicMapOperations(ignite, cache);
});
- }
+ }).catch(function(err) {
+ if (err !== null)
+ console.log("Start remote node with config examples/config/example-ignite.xml.");
+ });
/**
* 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) {
+ function atomicMapOperations (ignite, cache) {
console.log(">>> Cache atomic map operation examples.");
- cache.removeAllFromCache(function(err) {
+ cache.removeAllFromCache().then(function(){
// Put and return previous value.
- cache.getAndPut(1, "1", onGetAndPut)
- });
-
- function onGetAndPut(err, entry) {
+ return cache.getAndPut(1, "1");
+ }).then(function(entry){
console.log(">>> Get and put finished [result=" + entry + "]");
// Put and do not return previous value.
// Performs better when previous value is not needed.
- cache.put(2, "2", onPut);
- }
-
- onPut = function(err) {
+ return cache.put(2, "2")
+ }).then(function(){
console.log(">>> Put finished.");
// Put-if-absent.
- cache.putIfAbsent(4, "44", onPutIfAbsent);
- }
-
- onPutIfAbsent = function(err, res) {
+ return cache.putIfAbsent(4, "44");
+ }).then(function(res){
console.log(">>> Put if absent finished [result=" + res + "]");
// Replace.
- cache.replaceValue(4, "55", "44", onReplaceValue);
- }
-
- onReplaceValue = function(err, res) {
+ return cache.replaceValue(4, "55", "44");
+ }).then(function(res) {
console.log(">>> Replace value finished [result=" + res + "]");
// Replace not correct value.
- cache.replaceValue(4, "555", "44", onEnd);
- }
-
- onEnd = function(err) {
+ return cache.replaceValue(4, "555", "44");
+ }).then(function(res) {
console.log(">>> Replace finished.");
- // Destroying cache.
- ignite.destroyCache(cacheName, function(err) {
- console.log(">>> End of Cache API example.");
- });
- }
+ //Destroying cache.
+ return ignite.destroyCache(cacheName);
+ }).then(function(){
+ console.log(">>> End of Cache API example.");
+ })
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/cache-not-promise-api-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-not-promise-api-example.js b/examples/src/main/js/cache-not-promise-api-example.js
deleted file mode 100644
index 519e4d7..0000000
--- a/examples/src/main/js/cache-not-promise-api-example.js
+++ /dev/null
@@ -1,81 +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;
-
-/**
- * This example demonstrates some of the cache rich API capabilities.
- * <p>
- * Start Ignite node with {@code examples/config/example-ignite.xml} configuration before running example.
- * <p>
- * Alternatively you can run ExampleJsNodeStartup which will
- * start node with {@code examples/config/example-ignite.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:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
- console.log(">>> Cache API example started.");
-
- // Create cache on server with cacheName.
- ignite.getOrCreateCache(cacheName, function(err, promiseCache) {
- atomicMapOperations(ignite, promiseCache);
- });
- }
-
- /**
- * 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.");
-
- cache.put(1, "1", onPut1);
-
- function onPut1(err,res) {
- cache.get(1, onGet1);
- }
-
- function onGet1(err, res) {
- if (res === "1") {
- return cache.put(1, "2", onEnd);
- }
- else {
- return cache.put(1, "3", onEnd);
- }
- }
-
- function onEnd() {
- console.log(">>> Replace finished.");
-
- // Destroying cache.
- ignite.destroyCache(cacheName, function(err) {
- console.log(">>> End of Cache API example.");
- });
- };
- }
-}
-
-main();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/cache-promise-api-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-promise-api-example.js b/examples/src/main/js/cache-promise-api-example.js
deleted file mode 100644
index b73b5c1..0000000
--- a/examples/src/main/js/cache-promise-api-example.js
+++ /dev/null
@@ -1,75 +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;
-
-/**
- * This example demonstrates some of the cache rich API capabilities.
- * <p>
- * Start Ignite node with {@code examples/config/example-ignite.xml} configuration before running example.
- * <p>
- * Alternatively you can run ExampleJsNodeStartup which will
- * start node with {@code examples/config/example-ignite.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:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
- console.log(">>> Cache API example started.");
-
- // Create cache on server with cacheName.
- ignite.getOrCreatePromiseCache(cacheName, function(err, promiseCache) {
- atomicMapOperations(ignite, promiseCache);
- });
- }
-
- /**
- * 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.");
-
- cache.put(1, "1").then(function(res) {
- return cache.get(1);
- }).then(function(res) {
- if (res === "1") {
- return cache.put(1, "2");
- }
- else {
- return cache.put(1, "3");
- }
- }).then(function() {
- console.log(">>> Replace finished.");
-
- // Destroying cache.
- ignite.destroyCache(cacheName, function(err) {
- console.log(">>> End of Cache API example.");
- });
- });
- }
-}
-
-main();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/cache-promise-query-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-promise-query-example.js b/examples/src/main/js/cache-promise-query-example.js
deleted file mode 100644
index c31b8fb..0000000
--- a/examples/src/main/js/cache-promise-query-example.js
+++ /dev/null
@@ -1,108 +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 SqlQuery = apacheIgnite.SqlQuery;
-var SqlFieldsQuery = apacheIgnite.SqlFieldsQuery;
-var CacheEntry = apacheIgnite.CacheEntry;
-
-
-/**
- * Cache queries example. This example demonstrates SQL queries over cache.
- * <p>
- * Start Ignite node with {@code examples/config/example-ignite.xml} configuration before running example.
- * <p>
- * Alternatively you can run ExampleJsNodeStartup which will
- * start node with {@code examples/config/example-ignite.xml} configuration.
- */
-main = function() {
- /** Cache name. */
- var cacheName = "CacheQueryExample";
-
- /** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
- console.log(">>> Cache query example started.");
-
- var entries = initializeEntries();
-
- ignite.getOrCreatePromiseCache(cacheName, function(err, cache) {
- cacheQuery(ignite, cache, entries);
- });
- }
-
- function cacheQuery(ignite, cache, entries) {
- cache.putAll(entries, onCachePut);
-
- function onCachePut(err) {
- console.log(">>> Create cache for people.")
-
- //SQL clause which selects salaries based on range.
- var qry = new SqlQuery("salary > ? and salary <= ?");
- qry.setReturnType("Object");
-
- // Set page size for query.
- qry.setPageSize(2);
-
- //Set salary range.
- qry.setArguments([0, 2000]);
-
- var fullRes = [];
-
- ignite.cache(cacheName).query(qry).then(onQuery);
-
- function onQuery(cursor) {
- fullRes.concat(cursor.page());
-
- if (cursor.isFinished()) {
- console.log("Result=" + fullRes);
-
- return;
- }
-
- var nextPromise = cursor.next();
-
- nextPromise.then(onQuery);
- }
- }
- }
-
- // Initialize cache for people.
- function initializeEntries() {
- var key1 = "1";
- var value1 = {"firstName" : "John", "lastName" : "Doe", "salary" : 2000};
- var key2 = "2";
- var value2 = {"firstName" : "Jane", "lastName" : "Doe", "salary" : 1000};
- var key3 = "3";
- var value3 = {"firstName" : "John", "lastName" : "Smith", "salary" : 1000};
- var key4 = "4";
- var value4 = {"firstName" : "Jane", "lastName" : "Smith", "salary" : 2000};
- var key5 = "5";
- var value5 = {"firstName" : "Ann", "lastName" : "Smith", "salary" : 3000};
-
- return [new CacheEntry(key1, value1), new CacheEntry(key2, value2),
- new CacheEntry(key3, value3), new CacheEntry(key4, value4)];
- }
-}
-
-main();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/cache-query-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-query-example.js b/examples/src/main/js/cache-query-example.js
index 1c6b980..a83b577 100644
--- a/examples/src/main/js/cache-query-example.js
+++ b/examples/src/main/js/cache-query-example.js
@@ -36,26 +36,25 @@ main = function() {
var cacheName = "CacheQueryExample";
/** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
+ Ignition.start(['127.0.0.1:8000..9000'], null).then(function(ignite) {
console.log(">>> Cache query example started.");
- var entries = initializeEntries();
-
- ignite.getOrCreateCache(cacheName, function(err, cache) {
- cacheQuery(ignite, cache, entries);
+ // Create cache on server with cacheName.
+ ignite.getOrCreateCache(cacheName).then(function(cache){
+ cacheQuery(ignite, cache);
});
- }
+ }).catch(function(err) {
+ if (err !== null)
+ console.log("Start remote node with config examples/config/example-ignite.xml.");
+ });
- function cacheQuery(ignite, cache, entries) {
- cache.putAll(entries, onCachePut);
+ // Run query example.
+ function cacheQuery(ignite, cache) {
+ var entries = initializeEntries();
- function onCachePut(err) {
- console.log(">>> Create cache for people.")
+ // Initialize cache.
+ cache.putAll(entries).then(function(){
+ console.log(">>> Create cache for people.");
//SQL clause which selects salaries based on range.
var qry = new SqlQuery("salary > ? and salary <= ?");
@@ -69,27 +68,31 @@ main = function() {
var fullRes = [];
- //This function is called when we get part of query result.
- qry.on("page", function(res) {
+ function onQuery(cursor) {
console.log(">>> Get result on page: " + JSON.stringify(res));
- fullRes = fullRes.concat(res);
- });
+ //Concat query page results.
+ fullRes.concat(cursor.page());
+
+ // IsFinished return true if it is the last page.
+ if (cursor.isFinished()) {
+ console.log(">>> People with salaries between 0 and 2000 (queried with SQL query): " +
+ JSON.stringify(fullRes));
- //This function is called when query is finished.
- qry.on("end", function(err) {
- console.log(">>> People with salaries between 0 and 2000 (queried with SQL query): " +
- JSON.stringify(fullRes));
+ return ignite.destroyCache(cacheName);
+ }
- // Destroying cache.
- ignite.destroyCache(cacheName, function(err) {
- console.log(">>> End of query example.");
- });
- });
+ //Get Promise for next page.
+ var nextPromise = cursor.next();
- //Run query.
- ignite.cache(cacheName).query(qry);
- }
+ nextPromise.then(onQuery);
+ }
+
+ // Run query.
+ ignite.cache(cacheName).query(qry).then(onQuery);
+ }).then(function(){
+ console.log(">>> End of sql query example.");
+ });
}
// Initialize cache for people.
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/cache-sql-fields-query-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/cache-sql-fields-query-example.js b/examples/src/main/js/cache-sql-fields-query-example.js
index 58eb26b..fed91e4 100644
--- a/examples/src/main/js/cache-sql-fields-query-example.js
+++ b/examples/src/main/js/cache-sql-fields-query-example.js
@@ -22,6 +22,7 @@ var SqlQuery = apacheIgnite.SqlQuery;
var SqlFieldsQuery = apacheIgnite.SqlFieldsQuery;
var CacheEntry = apacheIgnite.CacheEntry;
+
/**
* Cache queries example. This example demonstrates SQL queries over cache.
* <p>
@@ -32,24 +33,87 @@ var CacheEntry = apacheIgnite.CacheEntry;
*/
main = function() {
/** Cache name. */
- var cacheName = "CacheSqlFieldsQueryExample";
+ var cacheName = "CacheQueryExample";
/** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
+ Ignition.start(['127.0.0.1:8000..9000'], null).then(function(ignite) {
+ console.log(">>> Cache sql fields query example started.");
- function onConnect(err, ignite) {
+ // Create cache on server with cacheName.
+ ignite.getOrCreateCache(cacheName).then(function(cache){
+ cacheSqlFieldsQuery(ignite, cache);
+ });
+ }).catch(function(err) {
if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
- console.log(">>> Cache sql fields query example started.");
+ console.log("Start remote node with config examples/config/example-ignite.xml.");
+ });
+ // Run query example.
+ function cacheSqlFieldsQuery(ignite, cache) {
var entries = initializeEntries();
- ignite.getOrCreateCache(cacheName, function(err, cache) {
- cacheSqlFieldsQuery(ignite, cache, entries);
+ // Initialize cache.
+ cache.putAll(entries).then(function(){
+ console.log(">>> Create cache for people.");
+
+ //Sql query to get names of all employees.
+ var qry = new SqlFieldsQuery("select concat(firstName, ' ', lastName) from Person");
+
+ // Set page size for query.
+ qry.setPageSize(2);
+
+ //Set salary range.
+ qry.setArguments([0, 2000]);
+
+ var fullRes = [];
+
+ function onQuery(cursor) {
+ console.log(">>> Get result on page: " + JSON.stringify(res));
+
+ //Concat query page results.
+ fullRes.concat(cursor.page());
+
+ // IsFinished return true if it is the last page.
+ if (cursor.isFinished()) {
+ console.log(">>> Names of all employees: " + JSON.stringify(fullRes));
+
+ return ignite.destroyCache(cacheName);
+ }
+
+ //Get Promise for next page.
+ var nextPromise = cursor.next();
+
+ nextPromise.then(onQuery);
+ }
+
+ // Run query.
+ ignite.cache(cacheName).query(qry).then(onQuery);
+ }).then(function(){
+ console.log(">>> End of sql fields query example.");
});
}
+ // Initialize cache for people.
+ function initializeEntries() {
+ var key1 = "1";
+ var value1 = {"firstName" : "John", "lastName" : "Doe", "salary" : 2000};
+ var key2 = "2";
+ var value2 = {"firstName" : "Jane", "lastName" : "Doe", "salary" : 1000};
+ var key3 = "3";
+ var value3 = {"firstName" : "John", "lastName" : "Smith", "salary" : 1000};
+ var key4 = "4";
+ var value4 = {"firstName" : "Jane", "lastName" : "Smith", "salary" : 2000};
+ var key5 = "5";
+ var value5 = {"firstName" : "Ann", "lastName" : "Smith", "salary" : 3000};
+
+ return [new CacheEntry(key1, value1), new CacheEntry(key2, value2),
+ new CacheEntry(key3, value3), new CacheEntry(key4, value4)];
+ }
+}
+
+main();
+
+
function cacheSqlFieldsQuery(ignite, cache, entries) {
cache.putAll(entries, onCachePut.bind(null, ignite));
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/compute-run-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/compute-run-example.js b/examples/src/main/js/compute-run-example.js
index 189c63f..9d2a9ad 100644
--- a/examples/src/main/js/compute-run-example.js
+++ b/examples/src/main/js/compute-run-example.js
@@ -31,25 +31,24 @@ function main() {
var cacheName = "RunCacheScriptCache";
/** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
+ Ignition.start(['127.0.0.1:8000..9000'], null).then(function(ignite) {
console.log(">>> Run cache script example started.");
- ignite.getOrCreateCache(cacheName, function(err, cache) { runCacheScript(ignite, cache); });
- }
+ // Create cache on server with cacheName.
+ ignite.getOrCreateCache(cacheName).then(function(cache){
+ runCacheScript(ignite, cache);
+ });
+ }).catch(function(err) {
+ if (err !== null)
+ console.log("Start remote node with config examples/config/example-ignite.xml.");
+ });
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) {
+ cache.put(key, person).then(function(){
var job = function (args) {
print(">>> Hello node: " + ignite.name());
@@ -65,16 +64,15 @@ function main() {
return val.salary;
}
- var onRun = function(err, salary) {
- console.log(">>> " + key + "'s salary is " + salary);
-
- // Destroying cache.
- ignite.destroyCache(cacheName, function(err) { console.log(">>> End of run cache script example."); });
- }
-
/** Run remote job on server ignite node with arguments [cacheName, key]. */
- ignite.compute().run(job, [cacheName, key], onRun);
- }
+ return ignite.compute().run(job, [cacheName, key]);
+ }).then(function(salary){
+ console.log(">>> " + key + "'s salary is " + salary);
+
+ return ignite.destroyCache(cacheName);
+ }).then(function() {
+ console.log(">>> End of run cache script example.");
+ });
}
}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/341f3031/examples/src/main/js/map-reduce-example.js
----------------------------------------------------------------------
diff --git a/examples/src/main/js/map-reduce-example.js b/examples/src/main/js/map-reduce-example.js
index db2da87..93913fe 100644
--- a/examples/src/main/js/map-reduce-example.js
+++ b/examples/src/main/js/map-reduce-example.js
@@ -32,12 +32,7 @@ var Ignition = apacheIgnite.Ignition;
*/
function main() {
/** Connect to node that started with {@code examples/config/js/example-js-cache.xml} configuration. */
- Ignition.start(['127.0.0.1:8000..9000'], null, onConnect);
-
- function onConnect(err, ignite) {
- if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
+ Ignition.start(['127.0.0.1:8000..9000'], null).then(function(ignite) {
console.log(">>> Compute map reduce example started.");
/**
@@ -72,14 +67,14 @@ function main() {
return sum;
}
- // Called when map reduced finished.
- var onMapReduce = function(err, cnt) {
- console.log(">>> Total number of characters in the phrase is '" + cnt + "'.");
- console.log(">>> End of compute map reduce example.");
- }
-
- ignite.compute().mapReduce(map, reduce, "Hello Ignite Enabled World!", onMapReduce);
- }
+ return ignite.compute().mapReduce(map, reduce, "Hello Ignite World!");
+ }).then(function(cnt){
+ console.log(">>> Total number of characters in the phrase is '" + cnt + "'.");
+ console.log(">>> End of compute map reduce example.");
+ }).catch(function(err) {
+ if (err !== null)
+ console.log("Start remote node with config examples/config/example-ignite.xml. ");
+ });
}
main();
\ No newline at end of file