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 14:27:35 UTC
incubator-ignite git commit: #ignite-961: rewrite
cache-put-get-example.
Repository: incubator-ignite
Updated Branches:
refs/heads/ignite-961-promise f7595eaa4 -> 37f748c45
#ignite-961: rewrite cache-put-get-example.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/37f748c4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/37f748c4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/37f748c4
Branch: refs/heads/ignite-961-promise
Commit: 37f748c45b78d2d7673eb50ad09861dfa5959328
Parents: f7595ea
Author: ivasilinets <iv...@gridgain.com>
Authored: Tue Jul 14 15:27:31 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Tue Jul 14 15:27:31 2015 +0300
----------------------------------------------------------------------
examples/src/main/js/cache-put-get-example.js | 73 ++++++++++------------
1 file changed, 32 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/37f748c4/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 e12a54d..69972b8 100644
--- a/examples/src/main/js/cache-put-get-example.js
+++ b/examples/src/main/js/cache-put-get-example.js
@@ -32,48 +32,29 @@ function main() {
var cacheName = "PutGetExampleCache";
/** 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 put-get example started.");
- function onConnect(err, ignite) {
+ // Create cache on server with cacheName.
+ ignite.getOrCreateCache(cacheName).then(function(cache){
+ putGetExample(ignite, cache);
+ });
+ }).catch(function(err) {
if (err !== null)
- throw "Start remote node with config examples/config/example-ignite.xml.";
-
- ignite.getOrCreateCache(cacheName, function(err, cache) { putGetExample(ignite, cache); });
- }
+ console.log("Start remote node with config examples/config/example-ignite.xml.");
+ });
/** Execute individual puts and gets. */
- putGetExample = function(ignite, cache) {
- console.log(">>> Cache put-get example started.");
-
+ function putGetExample (ignite, cache) {
var key = 1;
- // Store key in cache.
- cache.put(key, "1", onPut);
-
- function onPut(err) {
- console.log(">>> Stored values in cache.");
-
- cache.get(key, onGet);
- }
-
- function onGet(err, res) {
- console.log("Get value=" + res);
-
- putAllGetAll(ignite, cache);
- }
- }
-
- /** Execute bulk {@code putAll(...)} and {@code getAll(...)} operations. */
- function putAllGetAll(ignite, cache) {
- console.log(">>> Starting putAll-getAll example.");
-
var keyCnt = 20;
// Create batch.
var batch = [];
var keys = [];
- for (var i = keyCnt; i < keyCnt + keyCnt; ++i) {
+ for (var i = 0; i < keyCnt; ++i) {
var key = i;
var val = "bulk-" + i;
@@ -81,24 +62,34 @@ function main() {
batch.push(new CacheEntry(key, val));
}
- // Bulk-store entries in cache.
- cache.putAll(batch, onPutAll);
-
- function onPutAll(err) {
+ // Store key in cache.
+ cache.put(key, "1").then(function(){
console.log(">>> Stored values in cache.");
- // Bulk-get values from cache.
- cache.getAll(keys, onGetAll);
- }
+ // Get value.
+ return cache.get(key);
+ }).then(function(entry){
+ console.log(">>> Get finished [result=" + entry + "]");
+
+ console.log(">>> Starting putAll-getAll example.");
- function onGetAll(err, entries) {
+ // Bulk-store entries in cache.
+ return cache.putAll(batch);
+ }).then(function(){
+ console.log(">>> Stored values in cache.");
+
+ // GetAll keys.
+ return cache.getAll(keys);
+ }).then(function(entries){
for (var e of entries) {
- console.log("Got entry [key=" + e.key + ", value=" + 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."); });
- }
+ return ignite.destroyCache(cacheName);
+ }).then(function(){
+ console.log(">>> End of cache put-get example.")
+ })
}
}