http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java ---------------------------------------------------------------------- diff --cc examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java index 0000000,0000000..83411ec new file mode 100644 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteQueueExample.java @@@ -1,0 -1,0 +1,206 @@@ ++/* ++ * 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. ++ */ ++ ++package org.apache.ignite.examples.datagrid.datastructures; ++ ++import org.apache.ignite.*; ++import org.apache.ignite.configuration.*; ++import org.apache.ignite.examples.datagrid.*; ++import org.apache.ignite.lang.*; ++ ++import java.util.*; ++ ++/** ++ * Ignite cache distributed queue example. This example demonstrates {@code FIFO} unbounded ++ * cache queue. ++ * <p> ++ * Remote nodes should always be started with special configuration file which ++ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}. ++ * <p> ++ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will ++ * start node with {@code examples/config/example-cache.xml} configuration. ++ */ ++public class IgniteQueueExample { ++ /** Cache name. */ ++ private static final String CACHE_NAME = "partitioned_tx"; ++ ++ /** Number of retries */ ++ private static final int RETRIES = 20; ++ ++ /** Queue instance. */ ++ private static IgniteQueue<String> queue; ++ ++ /** ++ * Executes example. ++ * ++ * @param args Command line arguments, none required. ++ * @throws Exception If example execution failed. ++ */ ++ public static void main(String[] args) throws Exception { ++ try (Ignite ignite = Ignition.start("examples/config/example-cache.xml")) { ++ System.out.println(); ++ System.out.println(">>> Cache queue example started."); ++ ++ // Make queue name. ++ String queueName = UUID.randomUUID().toString(); ++ ++ queue = initializeQueue(ignite, queueName); ++ ++ readFromQueue(ignite); ++ ++ writeToQueue(ignite); ++ ++ clearAndRemoveQueue(); ++ } ++ ++ System.out.println("Cache queue example finished."); ++ } ++ ++ /** ++ * Initialize queue. ++ * ++ * @param ignite Ignite. ++ * @param queueName Name of queue. ++ * @return Queue. ++ * @throws IgniteException If execution failed. ++ */ ++ private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName) throws IgniteException { ++ IgniteCollectionConfiguration colCfg = new IgniteCollectionConfiguration(); ++ ++ colCfg.setCacheName(CACHE_NAME); ++ ++ // Initialize new FIFO queue. ++ IgniteQueue<String> queue = ignite.queue(queueName, colCfg, 0, true); ++ ++ // Initialize queue items. ++ // We will be use blocking operation and queue size must be appropriated. ++ for (int i = 0; i < ignite.cluster().nodes().size() * RETRIES * 2; i++) ++ queue.put(Integer.toString(i)); ++ ++ System.out.println("Queue size after initializing: " + queue.size()); ++ ++ return queue; ++ } ++ ++ /** ++ * Read items from head and tail of queue. ++ * ++ * @param ignite Ignite. ++ * @throws IgniteException If failed. ++ */ ++ private static void readFromQueue(Ignite ignite) throws IgniteException { ++ final String queueName = queue.name(); ++ ++ // Read queue items on each node. ++ ignite.compute().run(new QueueClosure(queueName, false)); ++ ++ System.out.println("Queue size after reading [expected=0, actual=" + queue.size() + ']'); ++ } ++ ++ /** ++ * Write items into queue. ++ * ++ * @param ignite Ignite. ++ * @throws IgniteException If failed. ++ */ ++ private static void writeToQueue(Ignite ignite) throws IgniteException { ++ final String queueName = queue.name(); ++ ++ // Write queue items on each node. ++ ignite.compute().run(new QueueClosure(queueName, true)); ++ ++ System.out.println("Queue size after writing [expected=" + ignite.cluster().nodes().size() * RETRIES + ++ ", actual=" + queue.size() + ']'); ++ ++ System.out.println("Iterate over queue."); ++ ++ // Iterate over queue. ++ for (String item : queue) ++ System.out.println("Queue item: " + item); ++ } ++ ++ /** ++ * Clear and remove queue. ++ * ++ * @throws IgniteException If execution failed. ++ */ ++ private static void clearAndRemoveQueue() throws IgniteException { ++ System.out.println("Queue size before clearing: " + queue.size()); ++ ++ // Clear queue. ++ queue.clear(); ++ ++ System.out.println("Queue size after clearing: " + queue.size()); ++ ++ // Remove queue. ++ queue.close(); ++ ++ // Try to work with removed queue. ++ try { ++ queue.poll(); ++ } ++ catch (IgniteException expected) { ++ System.out.println("Expected exception - " + expected.getMessage()); ++ } ++ } ++ ++ /** ++ * Closure to populate or poll the queue. ++ */ ++ private static class QueueClosure implements IgniteRunnable { ++ /** Queue name. */ ++ private final String queueName; ++ ++ /** Flag indicating whether to put or poll. */ ++ private final boolean put; ++ ++ /** ++ * @param queueName Queue name. ++ * @param put Flag indicating whether to put or poll. ++ */ ++ QueueClosure(String queueName, boolean put) { ++ this.queueName = queueName; ++ this.put = put; ++ } ++ ++ /** {@inheritDoc} */ ++ @Override public void run() { ++ IgniteQueue<String> queue = Ignition.ignite().queue(queueName, null, 0, false); ++ ++ if (put) { ++ UUID locId = Ignition.ignite().cluster().localNode().id(); ++ ++ for (int i = 0; i < RETRIES; i++) { ++ String item = locId + "_" + Integer.toString(i); ++ ++ queue.put(item); ++ ++ System.out.println("Queue item has been added: " + item); ++ } ++ } ++ else { ++ // Take items from queue head. ++ for (int i = 0; i < RETRIES; i++) ++ System.out.println("Queue item has been read from queue head: " + queue.take()); ++ ++ // Take items from queue head once again. ++ for (int i = 0; i < RETRIES; i++) ++ System.out.println("Queue item has been read from queue head: " + queue.poll()); ++ } ++ } ++ } ++}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java ---------------------------------------------------------------------- diff --cc examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java index 0000000,0000000..56e4f8b new file mode 100644 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/datagrid/datastructures/IgniteSetExample.java @@@ -1,0 -1,0 +1,186 @@@ ++/* ++ * 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. ++ */ ++ ++package org.apache.ignite.examples.datagrid.datastructures; ++ ++import org.apache.ignite.*; ++import org.apache.ignite.configuration.*; ++import org.apache.ignite.examples.datagrid.*; ++import org.apache.ignite.lang.*; ++ ++import java.util.*; ++ ++/** ++ * Ignite cache distributed set example. ++ * <p> ++ * Remote nodes should always be started with special configuration file which ++ * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-cache.xml'}. ++ * <p> ++ * Alternatively you can run {@link CacheNodeStartup} in another JVM which will ++ * start node with {@code examples/config/example-cache.xml} configuration. ++ */ ++public class IgniteSetExample { ++ /** Cache name. */ ++ private static final String CACHE_NAME = "partitioned_tx"; ++ ++ /** Set instance. */ ++ private static IgniteSet<String> set; ++ ++ /** ++ * Executes example. ++ * ++ * @param args Command line arguments, none required. ++ * @throws Exception If example execution failed. ++ */ ++ public static void main(String[] args) throws Exception { ++ try (Ignite ignite = Ignition.start("examples/config/example-cache.xml")) { ++ System.out.println(); ++ System.out.println(">>> Ignite set example started."); ++ ++ // Make set name. ++ String setName = UUID.randomUUID().toString(); ++ ++ set = initializeSet(ignite, setName); ++ ++ writeToSet(ignite); ++ ++ clearAndRemoveSet(); ++ } ++ ++ System.out.println("Ignite set example finished."); ++ } ++ ++ /** ++ * Initialize set. ++ * ++ * @param ignite Ignite. ++ * @param setName Name of set. ++ * @return Set. ++ * @throws IgniteException If execution failed. ++ */ ++ private static IgniteSet<String> initializeSet(Ignite ignite, String setName) throws IgniteException { ++ IgniteCollectionConfiguration setCfg = new IgniteCollectionConfiguration(); ++ ++ setCfg.setCacheName(CACHE_NAME); ++ ++ // Initialize new set. ++ IgniteSet<String> set = ignite.set(setName, setCfg, true); ++ ++ // Initialize set items. ++ for (int i = 0; i < 10; i++) ++ set.add(Integer.toString(i)); ++ ++ System.out.println("Set size after initializing: " + set.size()); ++ ++ return set; ++ } ++ ++ /** ++ * Write items into set. ++ * ++ * @param ignite Ignite. ++ * @throws IgniteException If failed. ++ */ ++ private static void writeToSet(Ignite ignite) throws IgniteException { ++ final String setName = set.name(); ++ ++ // Write set items on each node. ++ ignite.compute().broadcast(new SetClosure(setName)); ++ ++ System.out.println("Set size after writing [expected=" + (10 + ignite.cluster().nodes().size() * 5) + ++ ", actual=" + set.size() + ']'); ++ ++ System.out.println("Iterate over set."); ++ ++ // Iterate over set. ++ for (String item : set) ++ System.out.println("Set item: " + item); ++ ++ // Set API usage examples. ++ if (!set.contains("0")) ++ throw new RuntimeException("Set should contain '0' among its elements."); ++ ++ if (set.add("0")) ++ throw new RuntimeException("Set should not allow duplicates."); ++ ++ if (!set.remove("0")) ++ throw new RuntimeException("Set should correctly remove elements."); ++ ++ if (set.contains("0")) ++ throw new RuntimeException("Set should not contain '0' among its elements."); ++ ++ if (!set.add("0")) ++ throw new RuntimeException("Set should correctly add new elements."); ++ } ++ ++ /** ++ * Clear and remove set. ++ * ++ * @throws IgniteException If execution failed. ++ */ ++ private static void clearAndRemoveSet() throws IgniteException { ++ System.out.println("Set size before clearing: " + set.size()); ++ ++ // Clear set. ++ set.clear(); ++ ++ System.out.println("Set size after clearing: " + set.size()); ++ ++ // Remove set. ++ set.close(); ++ ++ System.out.println("Set was removed: " + set.removed()); ++ ++ // Try to work with removed set. ++ try { ++ set.contains("1"); ++ } ++ catch (IgniteException expected) { ++ System.out.println("Expected exception - " + expected.getMessage()); ++ } ++ } ++ ++ /** ++ * Closure to populate the set. ++ */ ++ private static class SetClosure implements IgniteRunnable { ++ /** Set name. */ ++ private final String setName; ++ ++ /** ++ * @param setName Set name. ++ */ ++ SetClosure(String setName) { ++ this.setName = setName; ++ } ++ ++ /** {@inheritDoc} */ ++ @Override public void run() { ++ IgniteSet<String> set = Ignition.ignite().set(setName, null, false); ++ ++ UUID locId = Ignition.ignite().cluster().localNode().id(); ++ ++ for (int i = 0; i < 5; i++) { ++ String item = locId + "_" + Integer.toString(i); ++ ++ set.add(item); ++ ++ System.out.println("Set item has been added: " + item); ++ } ++ } ++ } ++} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/examples/src/main/java/org/apache/ignite/examples/misc/client/memcache/MemcacheRestExample.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/modules/core/src/main/java/org/apache/ignite/Ignite.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java ---------------------------------------------------------------------- diff --cc modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java index b930cbb,83c96ae..19b959d --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java @@@ -221,61 -221,8 +221,63 @@@ public class IgniteMock implements Igni } /** {@inheritDoc} */ + @Override public void close() {} + + @Nullable @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteAtomicReference<T> atomicReference(String name, + @Nullable T initVal, + boolean create) + { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name, + @Nullable T initVal, + @Nullable S initStamp, + boolean create) + { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteCountDownLatch countDownLatch(String name, + int cnt, + boolean autoDel, + boolean create) + { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteQueue<T> queue(String name, + IgniteCollectionConfiguration cfg, + int cap, + boolean create) + { + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteSet<T> set(String name, + IgniteCollectionConfiguration cfg, + boolean create) + { + return null; + } + + /** {@inheritDoc} */ + @Override public void close() throws IgniteCheckedException {} + /** {@inheritDoc} */ @Override public <K> CacheAffinity<K> affinity(String cacheName) { return null; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala ---------------------------------------------------------------------- diff --cc modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala index e9d95c0,6a71f54..1fbcb26 --- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala @@@ -39,11 -38,11 +39,11 @@@ class ScalarAffinityRoutingSpec extend c += (1 -> 1) c += (2 -> 2) - val cnt = c.dataStructures().atomicLong("affinityRun", 0, true) + val cnt = Ignition.ignite.atomicLong("affinityRun", 0, true) - grid$.affinityRun$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null) - grid$.affinityRun$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null) - grid$.affinityRun$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null) + ignite$.affinityRun$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null) + ignite$.affinityRun$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null) + ignite$.affinityRun$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null) assert(cnt.get === 3) } @@@ -55,11 -54,11 +55,11 @@@ c += (1 -> 1) c += (2 -> 2) - val cnt = c.dataStructures().atomicLong("affinityRunAsync", 0, true) + val cnt = Ignition.ignite.atomicLong("affinityRunAsync", 0, true) - grid$.affinityRunAsync$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null).get - grid$.affinityRunAsync$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null).get - grid$.affinityRunAsync$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null).get + ignite$.affinityRunAsync$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null).get + ignite$.affinityRunAsync$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null).get + ignite$.affinityRunAsync$(CACHE_NAME, 2, () => { cnt.incrementAndGet() }, null).get assert(cnt.get === 3) } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/ce325948/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java ---------------------------------------------------------------------- diff --cc modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java index 4e20379,89350ab..57129ca --- a/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java +++ b/modules/spring/src/main/java/org/apache/ignite/IgniteSpringBean.java @@@ -320,80 -320,11 +320,85 @@@ public class IgniteSpringBean implement } /** {@inheritDoc} */ + @Override public void close() throws IgniteException { + g.close(); + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteAtomicSequence atomicSequence(String name, long initVal, boolean create) { + assert g != null; + + return g.atomicSequence(name, initVal, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) { + assert g != null; + + return g.atomicLong(name, initVal, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteAtomicReference<T> atomicReference(String name, + @Nullable T initVal, + boolean create) + { + assert g != null; + + return g.atomicReference(name, initVal, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public <T, S> IgniteAtomicStamped<T, S> atomicStamped(String name, + @Nullable T initVal, + @Nullable S initStamp, + boolean create) + { + assert g != null; + + return g.atomicStamped(name, initVal, initStamp, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public IgniteCountDownLatch countDownLatch(String name, + int cnt, + boolean autoDel, + boolean create) + { + assert g != null; + + return g.countDownLatch(name, cnt, autoDel, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteQueue<T> queue(String name, + IgniteCollectionConfiguration cfg, + int cap, + boolean create) + { + assert g != null; + + return g.queue(name, cfg, cap, create); + } + + /** {@inheritDoc} */ + @Nullable @Override public <T> IgniteSet<T> set(String name, + IgniteCollectionConfiguration cfg, + boolean create) + { + assert g != null; + + return g.set(name, cfg, create); + } + + /** {@inheritDoc} */ + @Override public void close() throws IgniteCheckedException { + assert g != null; + + g.close(); + } + + /** {@inheritDoc} */ @Override public <K> CacheAffinity<K> affinity(String cacheName) { return g.affinity(cacheName); }