Repository: incubator-ignite Updated Branches: refs/heads/ignite-nodejs a3aa145c3 -> 551b713a3
#nodejs: npm codestyle. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/86ba5d9a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/86ba5d9a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/86ba5d9a Branch: refs/heads/ignite-nodejs Commit: 86ba5d9aa8e229380278d3c0f721f60cf1199f32 Parents: a3aa145 Author: ivasilinets <ivasilin...@gridgain.com> Authored: Mon Jun 8 14:01:38 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Mon Jun 8 14:01:38 2015 +0300 ---------------------------------------------------------------------- modules/nodejs/src/main/js/apache_ignite.js | 6 +- modules/nodejs/src/main/js/cache.js | 14 ++--- modules/nodejs/src/main/js/ignition.js | 38 ++++++------ modules/nodejs/src/main/js/package.json | 6 +- modules/nodejs/src/main/js/server.js | 79 ++++++++++++------------ 5 files changed, 73 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ba5d9a/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 03bc3a8..c20e3dd 100644 --- a/modules/nodejs/src/main/js/apache_ignite.js +++ b/modules/nodejs/src/main/js/apache_ignite.js @@ -16,7 +16,7 @@ */ module.exports = { - Cache : require('./cache.js').Cache, - Ignition : require('./ignition.js').Ignition, - Server : require('./server.js').Server + Cache : require('./cache.js').Cache, + Ignition : require('./ignition.js').Ignition, + Server : require('./server.js').Server } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ba5d9a/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 9ee6f9c..e3c5406 100644 --- a/modules/nodejs/src/main/js/cache.js +++ b/modules/nodejs/src/main/js/cache.js @@ -24,9 +24,9 @@ * @param {string} cacheName Cache name */ function Cache(server, cacheName) { - this._server = server; - this._cacheName = cacheName; - this._cacheNameParam = _pair("cacheName", this._cacheName); + this._server = server; + this._cacheName = cacheName; + this._cacheNameParam = _pair("cacheName", this._cacheName); } /** @@ -37,7 +37,7 @@ 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); + this._server.runCommand("get", [this._cacheNameParam, _pair("key", key)], callback); }; /** @@ -56,8 +56,8 @@ 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)], - callback); + this._server.runCommand("put", [this._cacheNameParam, _pair("key", key), _pair("val", value)], + callback); } /** @@ -67,7 +67,7 @@ Cache.prototype.put = function(key, value, callback) { */ function _pair(key, value) { - return {key: key, value: 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/86ba5d9a/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 1ac8faa..08398a1 100644 --- a/modules/nodejs/src/main/js/ignition.js +++ b/modules/nodejs/src/main/js/ignition.js @@ -38,30 +38,30 @@ function Ignition() { * @param {Ignition~onStart} callback Called on finish */ Ignition.start = function(address, callback) { - var Server = require("./server").Server; - var numConn = address.length; - for (var addr of address) { - var params = addr.split(":"); - var server = new Server(params[0], params[1]); - server.checkConnection(onConnect.bind(null, server)); - } + var Server = require("./server").Server; + var numConn = address.length; + for (var addr of address) { + var params = addr.split(":"); + var server = new Server(params[0], params[1]); + server.checkConnection(onConnect.bind(null, server)); + } - function onConnect(server, error) { - if (!callback) - return; + function onConnect(server, error) { + if (!callback) return; - numConn--; - if (!error) { - callback.call(null, null, server); - callback = null; - return; - } + numConn--; + if (!error) { + callback.call(null, null, server); + callback = null; + return; + } - console.log("onConnect:" + error); + console.log("onConnect:" + error); - if (!numConn) - callback.call(null, "Cannot connect to servers.", null); + if (!numConn) { + callback.call(null, "Cannot connect to servers.", null); } + } } exports.Ignition = Ignition; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ba5d9a/modules/nodejs/src/main/js/package.json ---------------------------------------------------------------------- diff --git a/modules/nodejs/src/main/js/package.json b/modules/nodejs/src/main/js/package.json index b88cc22..e4fab0a 100644 --- a/modules/nodejs/src/main/js/package.json +++ b/modules/nodejs/src/main/js/package.json @@ -1,11 +1,13 @@ { "name" : "apache-ignite", - "version" : "1.0.0", + "version" : "1.0.0-SNAPSHOT", "author" : "Semyon Boikov <sboi...@gridgain.com>", "contributors": [{ "name": "Irina Vasilinets", "email": "ivasilie...@gridgain.com" }], "main" : "apache_ignite.js", - "license" : "Apache License, Version 2.0." + "license" : "Apache-2.0", + "keywords" : "grid", + "homepage" : "https://ignite.incubator.apache.org/" } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/86ba5d9a/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 f570eef..27256b8 100644 --- a/modules/nodejs/src/main/js/server.js +++ b/modules/nodejs/src/main/js/server.js @@ -24,8 +24,8 @@ * @param {number} port Port */ function Server(host, port) { - this._host = host; - this._port = port; + this._host = host; + this._port = port; } /** @@ -34,9 +34,8 @@ function Server(host, port) { * @this {Server} * @returns {string} Host value */ -Server.prototype.host = function() -{ - return this._host; +Server.prototype.host = function() { + return this._host; } /** @@ -56,49 +55,51 @@ Server.prototype.host = function() * @param {Server~onRunCommand} Called on finish */ Server.prototype.runCommand = function(cmdName, params, callback) { - var paramsString = ""; + var paramsString = ""; - for (var p of params) - //TODO: escape value - paramsString += "&" + p.key + "=" + p.value; + for (var p of params) { + paramsString += "&" + p.key + "=" + p.value; + } - var requestQry = "cmd=" + cmdName + paramsString; + var requestQry = "cmd=" + cmdName + paramsString; - var http = require('http'); + var http = require('http'); - var options = { - host: this._host, - port: this._port, - path: "/ignite?" + requestQry - }; + var options = { + host: this._host, + port: this._port, + path: "/ignite?" + requestQry + }; - function streamCallback(response) { - var fullResponseString = ''; + function streamCallback(response) { + var fullResponseString = ''; - response.on('data', function (chunk) { - fullResponseString += chunk; - }); + response.on('data', function (chunk) { + fullResponseString += chunk; + }); - response.on('end', function () { - try { - var response = JSON.parse(fullResponseString); - if (response.successStatus) - callback.call(null, response.error, null) - else - callback.call(null, null, response.response); - } catch (e) { - console.log("fail on json parse: " + fullResponseString) - callback.call(null, e, null); - } - }); - } + response.on('end', function () { + try { + var response = JSON.parse(fullResponseString); - var request = http.request(options, streamCallback); + if (response.successStatus) { + callback.call(null, response.error, null) + } else { + callback.call(null, null, response.response); + } + } catch (e) { + console.log("fail on json parse: " + fullResponseString); + callback.call(null, e, null); + } + }); + } - request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); + var request = http.request(options, streamCallback); - request.on('error', callback); - request.end(); + request.setTimeout(5000, callback.bind(null, "Request timeout: >5 sec")); + + request.on('error', callback); + request.end(); } /** @@ -108,7 +109,7 @@ Server.prototype.runCommand = function(cmdName, params, callback) { * @param {Server~onRunCommand} callback Called on finish */ Server.prototype.checkConnection = function(callback) { - this.runCommand("version", [], callback); + this.runCommand("version", [], callback); } exports.Server = Server; \ No newline at end of file