You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/08 14:40:23 UTC

incubator-ignite git commit: #nodejs: add ignite.js

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-nodejs 5658d35b3 -> 7ef272797


#nodejs: add ignite.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/7ef27279
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7ef27279
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7ef27279

Branch: refs/heads/ignite-nodejs
Commit: 7ef2727977aa6b162efbe17d7c33ed3314dbc52f
Parents: 5658d35
Author: ivasilinets <iv...@gridgain.com>
Authored: Mon Jun 8 15:40:16 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Mon Jun 8 15:40:16 2015 +0300

----------------------------------------------------------------------
 modules/nodejs/src/main/js/apache-ignite.js |  3 +-
 modules/nodejs/src/main/js/cache.js         | 16 +++++----
 modules/nodejs/src/main/js/ignite.js        | 42 ++++++++++++++++++++++++
 modules/nodejs/src/main/js/ignition.js      |  7 ++--
 modules/nodejs/src/main/js/server.js        | 12 +++++++
 modules/nodejs/src/test/js/test-put-get.js  | 10 ++++--
 6 files changed, 77 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/modules/nodejs/src/main/js/apache-ignite.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/apache-ignite.js b/modules/nodejs/src/main/js/apache-ignite.js
index c20e3dd..e03334d 100644
--- a/modules/nodejs/src/main/js/apache-ignite.js
+++ b/modules/nodejs/src/main/js/apache-ignite.js
@@ -18,5 +18,6 @@
 module.exports = {
   Cache : require('./cache.js').Cache,
   Ignition : require('./ignition.js').Ignition,
-  Server : require('./server.js').Server
+  Server : require('./server.js').Server,
+  Ignite : require('./ignite.js').Ignite
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/modules/nodejs/src/main/js/cache.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/cache.js b/modules/nodejs/src/main/js/cache.js
index e3c5406..83a93c5 100644
--- a/modules/nodejs/src/main/js/cache.js
+++ b/modules/nodejs/src/main/js/cache.js
@@ -24,9 +24,11 @@
  * @param {string} cacheName Cache name
  */
 function Cache(server, cacheName) {
+  var Server = require("./server").Server;
+
   this._server = server;
   this._cacheName = cacheName;
-  this._cacheNameParam = _pair("cacheName", this._cacheName);
+  this._cacheNameParam = Server.pair("cacheName", this._cacheName);
 }
 
 /**
@@ -37,7 +39,9 @@ function Cache(server, cacheName) {
  * @param {Cache~onGet} callback Called on finish
  */
 Cache.prototype.get = function(key, callback) {
-  this._server.runCommand("get", [this._cacheNameParam, _pair("key", key)], callback);
+  var Server = require("./server").Server;
+
+  this._server.runCommand("get", [this._cacheNameParam, Server.pair("key", key)], callback);
 };
 
 /**
@@ -56,7 +60,9 @@ Cache.prototype.get = function(key, callback) {
  * @param {Cache~onPut} callback Called on finish
  */
 Cache.prototype.put = function(key, value, callback) {
-  this._server.runCommand("put", [this._cacheNameParam, _pair("key", key), _pair("val", value)],
+  var Server = require("./server").Server;
+
+  this._server.runCommand("put", [this._cacheNameParam, Server.pair("key", key), Server.pair("val", value)],
     callback);
 }
 
@@ -66,8 +72,4 @@ Cache.prototype.put = function(key, value, callback) {
  * @param {string} error Error
  */
 
-function _pair(key, value) {
-  return {key: key, value: value}
-}
-
 exports.Cache = Cache
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/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
new file mode 100644
index 0000000..a883267
--- /dev/null
+++ b/modules/nodejs/src/main/js/ignite.js
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * Create an instance of Ignite
+ *
+ * @constructor
+ * @this {Ignite}
+ * @param {Server} Server
+ */
+function Ignite(server) {
+  this._server = server;
+}
+
+/**
+ * Get an instance of cache
+ *
+ * @this {Ignite}
+ * @param {string} Cache name
+ * @returns {Cache} Cache
+ */
+Ignite.prototype.cache = function(cacheName) {
+  var Cache = require("./cache").Cache;
+
+  return new Cache(this._server, cacheName);
+}
+
+exports.Ignite = Ignite;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/modules/nodejs/src/main/js/ignition.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/ignition.js b/modules/nodejs/src/main/js/ignition.js
index 08398a1..8450fc7 100644
--- a/modules/nodejs/src/main/js/ignition.js
+++ b/modules/nodejs/src/main/js/ignition.js
@@ -28,7 +28,7 @@ function Ignition() {
  *
  * @callback Ignition~onStart
  * @param {string} error Error
- * @param {Server} server Connected server
+ * @param {Ignite} ignite Connected ignite
  */
 
 /**
@@ -39,7 +39,10 @@ function Ignition() {
  */
 Ignition.start = function(address, callback) {
   var Server = require("./server").Server;
+  var Ignite = require("./ignite").Ignite
+
   var numConn = address.length;
+
   for (var addr of address) {
     var params = addr.split(":");
     var server = new Server(params[0], params[1]);
@@ -51,7 +54,7 @@ Ignition.start = function(address, callback) {
 
     numConn--;
     if (!error) {
-      callback.call(null, null, server);
+      callback.call(null, null, new Ignite(server));
       callback = null;
       return;
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/modules/nodejs/src/main/js/server.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/server.js b/modules/nodejs/src/main/js/server.js
index 27256b8..a53985b 100644
--- a/modules/nodejs/src/main/js/server.js
+++ b/modules/nodejs/src/main/js/server.js
@@ -89,6 +89,7 @@ Server.prototype.runCommand = function(cmdName, params, callback) {
         }
       } catch (e) {
         console.log("fail on json parse: " + fullResponseString);
+
         callback.call(null, e, null);
       }
     });
@@ -112,4 +113,15 @@ Server.prototype.checkConnection = function(callback) {
   this.runCommand("version", [], callback);
 }
 
+/**
+ * Returns pair for runCommand
+ *
+ * @param {string} key Key
+ * @param {string} value Value
+ * @returns Pair of strings
+ */
+Server.pair = function(key, value) {
+  return {key: key, value: value}
+}
+
 exports.Server = Server;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7ef27279/modules/nodejs/src/test/js/test-put-get.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/test/js/test-put-get.js b/modules/nodejs/src/test/js/test-put-get.js
index 10205d5..3bf7b89 100644
--- a/modules/nodejs/src/test/js/test-put-get.js
+++ b/modules/nodejs/src/test/js/test-put-get.js
@@ -18,13 +18,17 @@
 var TestUtils = require("./test-utils").TestUtils;
 
 var Apache = require(TestUtils.scriptPath());
+var Ignition = Apache.Ignition;
 var Cache = Apache.Cache;
 var Server = Apache.Server;
 
 testPutGet = function() {
-    var server = new Server('127.0.0.1', 9095);
-    var cache = new Cache(server, "mycache");
-    cache.put("key", "6", onPut.bind(null, cache));
+  Ignition.start(['127.0.0.1:9095'], onStart);
+}
+
+function onStart(error, ignite) {
+  var cache = ignite.cache("mycache");
+  cache.put("key", "6", onPut.bind(null, cache));
 }
 
 function onPut(cache, error) {