Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-964-1 94ca8f29e -> 70fa58e07


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

Branch: refs/heads/ignite-964-1
Commit: 70fa58e070ebd5fea9e6bdb9a7a1d05f5b3dda15
Parents: 94ca8f2
Author: ivasilinets <ivasilin...@gridgain.com>
Authored: Mon Jul 6 20:17:03 2015 +0300
Committer: ivasilinets <ivasilin...@gridgain.com>
Committed: Mon Jul 6 20:17:03 2015 +0300

----------------------------------------------------------------------
 .../rest/handlers/scripting/NodeJSIgnite.java   |  8 +++
 .../main/js/examples/config/example-ignite.xml  |  2 +
 .../main/js/examples/src/cache-query-example.js | 59 ++++++++++++++++++++
 .../src/compute-callable-cache-example.js       | 57 +++++++++++++++++++
 4 files changed, 126 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70fa58e0/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/NodeJSIgnite.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/NodeJSIgnite.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/NodeJSIgnite.java
index 3a54f2f..3e1ef4e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/NodeJSIgnite.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/NodeJSIgnite.java
@@ -42,6 +42,14 @@ public class NodeJSIgnite {
     }
 
     /**
+     * @param cache Cache name.
+     * @return Node js cache.
+     */
+    public NodeJsCache getOrCreateCache(String cache) {
+        return new NodeJsCache(ignite.getOrCreateCache(cache));
+    }
+
+    /**
      * @return Local node.
      */
     public NodeJsClusterNode localNode() {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70fa58e0/modules/nodejs/src/main/js/examples/config/example-ignite.xml
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/config/example-ignite.xml 
b/modules/nodejs/src/main/js/examples/config/example-ignite.xml
index fd76bcf..d351631 100644
--- a/modules/nodejs/src/main/js/examples/config/example-ignite.xml
+++ b/modules/nodejs/src/main/js/examples/config/example-ignite.xml
@@ -29,6 +29,8 @@
         http://www.springframework.org/schema/util
         http://www.springframework.org/schema/util/spring-util.xsd";>
     <bean id="ignite.cfg" 
class="org.apache.ignite.configuration.IgniteConfiguration">
+        <property name="gridName" value="ServerNode" />
+
         <property name="connectorConfiguration">
             <bean 
class="org.apache.ignite.configuration.ConnectorConfiguration">
                 <property name="jettyPath" 
value="modules/nodejs/src/main/js/examples/config/rest-jetty.xml"/>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70fa58e0/modules/nodejs/src/main/js/examples/src/cache-query-example.js
----------------------------------------------------------------------
diff --git a/modules/nodejs/src/main/js/examples/src/cache-query-example.js 
b/modules/nodejs/src/main/js/examples/src/cache-query-example.js
new file mode 100644
index 0000000..b6eb37a
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/cache-query-example.js
@@ -0,0 +1,59 @@
+/*
+ * 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 Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+var SqlQuery = Ignite.SqlQuery;
+var SqlFieldsQuery = Ignite.SqlFieldsQuery;
+var Entry = Ignite.Entry;
+
+var cacheName = "CacheQueryExample";
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null, err);
+
+    console.log(">>> Cache query example started.");
+
+    var entries = [new Entry("key0", "val0"), new Entry("key1", "val1")];
+
+    ignite.getOrCreateCache(cacheName).putAll(entries, onCachePut.bind(null, 
ignite));
+}
+
+function onCachePut(ignite, err) {
+    assert(err == null, err);
+
+    var qry = new SqlQuery("Select * from String");
+    qry.setReturnType("String");
+
+     var fullRes = [];
+
+    qry.on("page", function(res) {
+        fullRes = fullRes.concat(res);
+    });
+
+    qry.on("end", function(err) {
+        assert(err == null, err);
+
+        console.log(fullRes);
+    });
+
+    ignite.cache(cacheName).query(qry);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/70fa58e0/modules/nodejs/src/main/js/examples/src/compute-callable-cache-example.js
----------------------------------------------------------------------
diff --git 
a/modules/nodejs/src/main/js/examples/src/compute-callable-cache-example.js 
b/modules/nodejs/src/main/js/examples/src/compute-callable-cache-example.js
new file mode 100644
index 0000000..a1e8c0f
--- /dev/null
+++ b/modules/nodejs/src/main/js/examples/src/compute-callable-cache-example.js
@@ -0,0 +1,57 @@
+/*
+ * 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 Ignite = require("../../");
+var assert = require("assert");
+
+var Ignition = Ignite.Ignition;
+
+var cacheName = "ComputeCallableCacheExample";
+
+Ignition.start(['127.0.0.1:9095'], null, onConnect);
+
+function onConnect(err, ignite) {
+    assert(err === null);
+
+    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) {
+        assert(err == null, err);
+
+        var cache = ignite.cache(cacheName);
+
+        cache.get(igniteName, function(err, res) {
+                assert(err == null, err);
+
+                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

Reply via email to