Repository: incubator-ignite Updated Branches: refs/heads/ignite-45 16acd3fb1 -> d086ae050
# IGNITE-45 - 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/da36a72d Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/da36a72d Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/da36a72d Branch: refs/heads/ignite-45 Commit: da36a72df408de3bdd77dd877121ea0f569ebb38 Parents: 2b62e43 Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Sun Mar 22 13:56:25 2015 -0700 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Sun Mar 22 13:56:25 2015 -0700 ---------------------------------------------------------------------- .../ComputeClusterGroupsExample.java | 93 -------------------- .../cluster/ClusterGroupExample.java | 93 ++++++++++++++++++++ .../computegrid/cluster/package-info.java | 22 +++++ .../java8/cluster/ClusterGroupExample.java | 82 +++++++++++++++++ .../examples/java8/cluster/package-info.java | 22 +++++ .../ComputeClusterGroupsExample.java | 82 ----------------- .../examples/ClusterGroupExampleSelfTest.java | 39 ++++++++ .../ComputeClusterGroupsExampleSelfTest.java | 39 -------- .../testsuites/IgniteExamplesSelfTestSuite.java | 2 +- 9 files changed, 259 insertions(+), 215 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java/org/apache/ignite/examples/computegrid/ComputeClusterGroupsExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/ComputeClusterGroupsExample.java b/examples/src/main/java/org/apache/ignite/examples/computegrid/ComputeClusterGroupsExample.java deleted file mode 100644 index 40f8598..0000000 --- a/examples/src/main/java/org/apache/ignite/examples/computegrid/ComputeClusterGroupsExample.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.computegrid; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.examples.*; -import org.apache.ignite.lang.*; - -/** - * Demonstrates new functional APIs. - * <p> - * Remote nodes should always be started with special configuration file which - * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. - * <p> - * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node - * with {@code examples/config/example-ignite.xml} configuration. - */ -public class ComputeClusterGroupsExample { - /** - * Executes example. - * - * @param args Command line arguments, none required. - * @throws IgniteException If example execution failed. - */ - public static void main(String[] args) throws IgniteException { - try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { - if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) - return; - - System.out.println(); - System.out.println("Compute example started."); - - IgniteCluster cluster = ignite.cluster(); - - // Say hello to all nodes in the cluster, including local node. - sayHello(ignite, cluster); - - // Say hello to all remote nodes. - sayHello(ignite, cluster.forRemotes()); - - // Pick random node out of remote nodes. - ClusterGroup randomNode = cluster.forRemotes().forRandom(); - - // Say hello to a random node. - sayHello(ignite, randomNode); - - // Say hello to all nodes residing on the same host with random node. - sayHello(ignite, cluster.forHost(randomNode.node())); - - // Say hello to all nodes that have current CPU load less than 50%. - sayHello(ignite, cluster.forPredicate(new IgnitePredicate<ClusterNode>() { - @Override public boolean apply(ClusterNode n) { - return n.metrics().getCurrentCpuLoad() < 0.5; - } - })); - } - } - - /** - * Print 'Hello' message on remote nodes. - * - * @param ignite Ignite. - * @param grp Cluster group. - * @throws IgniteException If failed. - */ - private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException { - // Print out hello message on all cluster nodes. - ignite.compute(grp).broadcast( - new IgniteRunnable() { - @Override public void run() { - // Print ID of remote node on remote node. - System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id()); - } - } - ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/ClusterGroupExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/ClusterGroupExample.java b/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/ClusterGroupExample.java new file mode 100644 index 0000000..1982b17 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/ClusterGroupExample.java @@ -0,0 +1,93 @@ +/* + * 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.computegrid.cluster; + +import org.apache.ignite.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.examples.*; +import org.apache.ignite.lang.*; + +/** + * Demonstrates new functional APIs. + * <p> + * Remote nodes should always be started with special configuration file which + * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. + * <p> + * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node + * with {@code examples/config/example-ignite.xml} configuration. + */ +public class ClusterGroupExample { + /** + * Executes example. + * + * @param args Command line arguments, none required. + * @throws IgniteException If example execution failed. + */ + public static void main(String[] args) throws IgniteException { + try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { + if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) + return; + + System.out.println(); + System.out.println("Compute example started."); + + IgniteCluster cluster = ignite.cluster(); + + // Say hello to all nodes in the cluster, including local node. + sayHello(ignite, cluster); + + // Say hello to all remote nodes. + sayHello(ignite, cluster.forRemotes()); + + // Pick random node out of remote nodes. + ClusterGroup randomNode = cluster.forRemotes().forRandom(); + + // Say hello to a random node. + sayHello(ignite, randomNode); + + // Say hello to all nodes residing on the same host with random node. + sayHello(ignite, cluster.forHost(randomNode.node())); + + // Say hello to all nodes that have current CPU load less than 50%. + sayHello(ignite, cluster.forPredicate(new IgnitePredicate<ClusterNode>() { + @Override public boolean apply(ClusterNode n) { + return n.metrics().getCurrentCpuLoad() < 0.5; + } + })); + } + } + + /** + * Print 'Hello' message on remote nodes. + * + * @param ignite Ignite. + * @param grp Cluster group. + * @throws IgniteException If failed. + */ + private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException { + // Print out hello message on all cluster nodes. + ignite.compute(grp).broadcast( + new IgniteRunnable() { + @Override public void run() { + // Print ID of remote node on remote node. + System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id()); + } + } + ); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/package-info.java b/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/package-info.java new file mode 100644 index 0000000..b837f73 --- /dev/null +++ b/examples/src/main/java/org/apache/ignite/examples/computegrid/cluster/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Cluster group example. + */ +package org.apache.ignite.examples.computegrid.cluster; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java new file mode 100644 index 0000000..508caf2 --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/ClusterGroupExample.java @@ -0,0 +1,82 @@ +/* + * 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.java8.cluster; + +import org.apache.ignite.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.examples.*; + +/** + * Demonstrates new functional APIs. + * <p> + * Remote nodes should always be started with special configuration file which + * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. + * <p> + * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node + * with {@code examples/config/example-ignite.xml} configuration. + */ +public class ClusterGroupExample { + /** + * Executes example. + * + * @param args Command line arguments, none required. + * @throws IgniteException If example execution failed. + */ + public static void main(String[] args) throws IgniteException { + try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { + if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) + return; + + System.out.println(); + System.out.println("Compute example started."); + + IgniteCluster cluster = ignite.cluster(); + + // Say hello to all nodes in the cluster, including local node. + sayHello(ignite, cluster); + + // Say hello to all remote nodes. + sayHello(ignite, cluster.forRemotes()); + + // Pick random node out of remote nodes. + ClusterGroup randomNode = cluster.forRemotes().forRandom(); + + // Say hello to a random node. + sayHello(ignite, randomNode); + + // Say hello to all nodes residing on the same host with random node. + sayHello(ignite, cluster.forHost(randomNode.node())); + + // Say hello to all nodes that have current CPU load less than 50%. + sayHello(ignite, cluster.forPredicate(n -> n.metrics().getCurrentCpuLoad() < 0.5)); + } + } + + /** + * Print 'Hello' message on remote nodes. + * + * @param ignite Ignite. + * @param grp Cluster group. + * @throws IgniteException If failed. + */ + private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException { + // Print out hello message on all cluster nodes. + ignite.compute(grp).broadcast( + () -> System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id())); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java new file mode 100644 index 0000000..2cca35f --- /dev/null +++ b/examples/src/main/java8/org/apache/ignite/examples/java8/cluster/package-info.java @@ -0,0 +1,22 @@ +/* + * 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 description. --> + * Cluster group example. + */ +package org.apache.ignite.examples.java8.cluster; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClusterGroupsExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClusterGroupsExample.java b/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClusterGroupsExample.java deleted file mode 100644 index d28a579..0000000 --- a/examples/src/main/java8/org/apache/ignite/examples/java8/computegrid/ComputeClusterGroupsExample.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.java8.computegrid; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.examples.*; - -/** - * Demonstrates new functional APIs. - * <p> - * Remote nodes should always be started with special configuration file which - * enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}. - * <p> - * Alternatively you can run {@link ExampleNodeStartup} in another JVM which will start node - * with {@code examples/config/example-ignite.xml} configuration. - */ -public class ComputeClusterGroupsExample { - /** - * Executes example. - * - * @param args Command line arguments, none required. - * @throws IgniteException If example execution failed. - */ - public static void main(String[] args) throws IgniteException { - try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { - if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2)) - return; - - System.out.println(); - System.out.println("Compute example started."); - - IgniteCluster cluster = ignite.cluster(); - - // Say hello to all nodes in the cluster, including local node. - sayHello(ignite, cluster); - - // Say hello to all remote nodes. - sayHello(ignite, cluster.forRemotes()); - - // Pick random node out of remote nodes. - ClusterGroup randomNode = cluster.forRemotes().forRandom(); - - // Say hello to a random node. - sayHello(ignite, randomNode); - - // Say hello to all nodes residing on the same host with random node. - sayHello(ignite, cluster.forHost(randomNode.node())); - - // Say hello to all nodes that have current CPU load less than 50%. - sayHello(ignite, cluster.forPredicate(n -> n.metrics().getCurrentCpuLoad() < 0.5)); - } - } - - /** - * Print 'Hello' message on remote nodes. - * - * @param ignite Ignite. - * @param grp Cluster group. - * @throws IgniteException If failed. - */ - private static void sayHello(Ignite ignite, final ClusterGroup grp) throws IgniteException { - // Print out hello message on all cluster nodes. - ignite.compute(grp).broadcast( - () -> System.out.println(">>> Hello Node: " + grp.ignite().cluster().localNode().id())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/test/java/org/apache/ignite/examples/ClusterGroupExampleSelfTest.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/examples/ClusterGroupExampleSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/ClusterGroupExampleSelfTest.java new file mode 100644 index 0000000..81af84a --- /dev/null +++ b/examples/src/test/java/org/apache/ignite/examples/ClusterGroupExampleSelfTest.java @@ -0,0 +1,39 @@ +/* + * 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; + +import org.apache.ignite.examples.computegrid.cluster.*; +import org.apache.ignite.testframework.junits.common.*; + +/** + * + */ +public class ClusterGroupExampleSelfTest extends GridAbstractExamplesTest { + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + // Start up a node. + startGrid("ignite-cluster-groups-example", DFLT_CFG); + } + + /** + * @throws Exception If failed. + */ + public void testComputeClusterGroupsExample() throws Exception { + ClusterGroupExample.main(EMPTY_ARGS); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/test/java/org/apache/ignite/examples/ComputeClusterGroupsExampleSelfTest.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/examples/ComputeClusterGroupsExampleSelfTest.java b/examples/src/test/java/org/apache/ignite/examples/ComputeClusterGroupsExampleSelfTest.java deleted file mode 100644 index 6bde3f5..0000000 --- a/examples/src/test/java/org/apache/ignite/examples/ComputeClusterGroupsExampleSelfTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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; - -import org.apache.ignite.examples.computegrid.*; -import org.apache.ignite.testframework.junits.common.*; - -/** - * - */ -public class ComputeClusterGroupsExampleSelfTest extends GridAbstractExamplesTest { - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - // Start up a node. - startGrid("ignite-cluster-groups-example", DFLT_CFG); - } - - /** - * @throws Exception If failed. - */ - public void testComputeClusterGroupsExample() throws Exception { - ComputeClusterGroupsExample.main(EMPTY_ARGS); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/da36a72d/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java index 11af442..58a104e 100644 --- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java +++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java @@ -54,7 +54,7 @@ public class IgniteExamplesSelfTestSuite extends TestSuite { suite.addTest(new TestSuite(IgfsExamplesSelfTest.class)); suite.addTest(new TestSuite(CheckpointExamplesSelfTest.class)); suite.addTest(new TestSuite(HibernateL2CacheExampleSelfTest.class)); - suite.addTest(new TestSuite(ComputeClusterGroupsExampleSelfTest.class)); + suite.addTest(new TestSuite(ClusterGroupExampleSelfTest.class)); // Multi-node. suite.addTest(new TestSuite(CacheExamplesMultiNodeSelfTest.class));