ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsetrak...@apache.org
Subject [1/2] incubator-ignite git commit: # ignite-45 - service example fixes..
Date Sun, 22 Mar 2015 08:13:54 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-45 cc5bd026e -> b34d7ae4e


# ignite-45 - service example fixes..


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/c2bfd696
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/c2bfd696
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/c2bfd696

Branch: refs/heads/ignite-45
Commit: c2bfd69626523b0d35bae08b4aa39dbec46a8724
Parents: 0eb53a9
Author: Dmitiry Setrakyan <dsetrakyan@gridgain.com>
Authored: Sun Mar 22 01:12:29 2015 -0700
Committer: Dmitiry Setrakyan <dsetrakyan@gridgain.com>
Committed: Sun Mar 22 01:12:29 2015 -0700

----------------------------------------------------------------------
 .../examples/servicegrid/ServicesExample.java   | 17 ++++--------
 .../servicegrid/SimpleMapServiceImpl.java       | 29 ++++++++------------
 2 files changed, 18 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c2bfd696/examples/src/main/java/org/apache/ignite/examples/servicegrid/ServicesExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/servicegrid/ServicesExample.java
b/examples/src/main/java/org/apache/ignite/examples/servicegrid/ServicesExample.java
index c8786cf..1a10211 100644
--- a/examples/src/main/java/org/apache/ignite/examples/servicegrid/ServicesExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/servicegrid/ServicesExample.java
@@ -18,7 +18,6 @@
 package org.apache.ignite.examples.servicegrid;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cluster.*;
 import org.apache.ignite.examples.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.resources.*;
@@ -45,19 +44,15 @@ public class ServicesExample {
      * @throws Exception If example execution failed.
      */
     public static void main(String[] args) throws Exception {
-        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
-            ClusterGroup rmts = ignite.cluster().forRemotes();
-
-            if (rmts.nodes().isEmpty()) {
-                System.err.println(">>>");
-                System.err.println(">>> Must start at least one remote node using
" +
-                    ExampleNodeStartup.class.getSimpleName() + '.');
-                System.err.println(">>>");
+        // Mark this node as client node.
+        Ignition.setClientMode(true);
 
+        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
+            if (!ExamplesUtils.hasServerNodes(ignite))
                 return;
-            }
 
-            IgniteServices svcs = ignite.services(rmts);
+            // Deploy services only on server nodes.
+            IgniteServices svcs = ignite.services(ignite.cluster().forServers());
 
             try {
                 // Deploy cluster singleton.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/c2bfd696/examples/src/main/java/org/apache/ignite/examples/servicegrid/SimpleMapServiceImpl.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/servicegrid/SimpleMapServiceImpl.java
b/examples/src/main/java/org/apache/ignite/examples/servicegrid/SimpleMapServiceImpl.java
index 5be2352..72bf7ef 100644
--- a/examples/src/main/java/org/apache/ignite/examples/servicegrid/SimpleMapServiceImpl.java
+++ b/examples/src/main/java/org/apache/ignite/examples/servicegrid/SimpleMapServiceImpl.java
@@ -18,63 +18,58 @@
 package org.apache.ignite.examples.servicegrid;
 
 import org.apache.ignite.*;
-import org.apache.ignite.cache.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.resources.*;
 import org.apache.ignite.services.*;
 
 /**
- * Simple service which loops infinitely and prints out a counter.
+ * Simple service which utilizes Ignite cache as a mechanism to provide
+ * distributed {@link SimpleMapService} functionality.
  */
 public class SimpleMapServiceImpl<K, V> implements Service, SimpleMapService<K,
V> {
     /** Serial version UID. */
     private static final long serialVersionUID = 0L;
 
-    /** Cache name. */
-    private static final String CACHE_NAME = SimpleMapServiceImpl.class.getSimpleName();
-
     /** Ignite instance. */
     @IgniteInstanceResource
     private Ignite ignite;
 
     /** Underlying cache map. */
-    private IgniteCache<K, V> map;
+    private IgniteCache<K, V> cache;
 
     /** {@inheritDoc} */
     @Override public void put(K key, V val) {
-        map.put(key, val);
+        cache.put(key, val);
     }
 
     /** {@inheritDoc} */
     @Override public V get(K key) {
-        return map.get(key);
+        return cache.get(key);
     }
 
     /** {@inheritDoc} */
     @Override public void clear() {
-        map.clear();
+        cache.clear();
     }
 
     /** {@inheritDoc} */
     @Override public int size() {
-        return map.size();
+        return cache.size();
     }
 
     /** {@inheritDoc} */
     @Override public void cancel(ServiceContext ctx) {
-        ignite.destroyCache(CACHE_NAME);
+        ignite.destroyCache(ctx.name());
 
         System.out.println("Service was cancelled: " + ctx.name());
     }
 
     /** {@inheritDoc} */
     @Override public void init(ServiceContext ctx) throws Exception {
-        CacheConfiguration<K, V> cfg = new CacheConfiguration<>();
-
-        cfg.setCacheMode(CacheMode.PARTITIONED);
-        cfg.setName(CACHE_NAME);
-
-        map = ignite.getOrCreateCache(cfg);
+        // Create a new cache for every service deployment.
+        // Note that we use service name as cache name, which allows
+        // for each service deployment to use its own isolated cache.
+        cache = ignite.getOrCreateCache(new CacheConfiguration<>(ctx.name()));
 
         System.out.println("Service was initialized: " + ctx.name());
     }


Mime
View raw message