Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5686010081 for ; Thu, 17 Sep 2015 14:26:29 +0000 (UTC) Received: (qmail 104 invoked by uid 500); 17 Sep 2015 14:26:29 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 99931 invoked by uid 500); 17 Sep 2015 14:26:29 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 99914 invoked by uid 99); 17 Sep 2015 14:26:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Sep 2015 14:26:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A063EE054B; Thu, 17 Sep 2015 14:26:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 17 Sep 2015 14:26:30 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/3] ignite git commit: IGNITE-1496: Added .Net examples. IGNITE-1496: Added .Net examples. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1a5e5ff3 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1a5e5ff3 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1a5e5ff3 Branch: refs/heads/ignite-1282 Commit: 1a5e5ff32bc544ae6b1a32dfe07ef6204dc2053b Parents: c5fd4a5 Author: Pavel Tupitsyn Authored: Thu Sep 17 17:27:05 2015 +0300 Committer: vozerov-gridgain Committed: Thu Sep 17 17:27:05 2015 +0300 ---------------------------------------------------------------------- .../platform/src/main/dotnet/Apache.Ignite.sln | 20 ++ .../dotnet/Examples/Apache.Ignite.Examples.sln | 72 ++++++ .../Apache.Ignite.Examples.csproj | 80 +++++++ .../Examples/Apache.Ignite.Examples/App.config | 24 ++ .../Compute/ClosureExample.cs | 89 ++++++++ .../Compute/TaskExample.cs | 145 ++++++++++++ .../Datagrid/ContinuousQueryExample.cs | 105 +++++++++ .../Datagrid/CrossPlatformExample.cs | 208 +++++++++++++++++ .../Datagrid/DataStreamerExample.cs | 101 +++++++++ .../Datagrid/PutGetExample.cs | 219 ++++++++++++++++++ .../Datagrid/QueryExample.cs | 226 +++++++++++++++++++ .../Datagrid/StoreExample.cs | 116 ++++++++++ .../Datagrid/TransactionExample.cs | 104 +++++++++ .../Events/EventsExample.cs | 122 ++++++++++ .../Messaging/MessagingExample.cs | 119 ++++++++++ .../Misc/LifecycleExample.cs | 111 +++++++++ .../Properties/AssemblyInfo.cs | 35 +++ .../Services/IMapService.cs | 56 +++++ .../Services/ServicesExample.cs | 79 +++++++ .../Apache.Ignite.ExamplesDll.csproj | 75 ++++++ .../Compute/AverageSalaryJob.cs | 65 ++++++ .../Compute/AverageSalaryTask.cs | 84 +++++++ .../Compute/CharacterCountClosure.cs | 43 ++++ .../Compute/CharacterCountReducer.cs | 51 +++++ .../Datagrid/ContinuousQueryFilter.cs | 50 ++++ .../Datagrid/EmployeeStore.cs | 121 ++++++++++ .../Datagrid/EmployeeStorePredicate.cs | 40 ++++ .../Events/LocalListener.cs | 55 +++++ .../Events/RemoteFilter.cs | 42 ++++ .../Messaging/LocalListener.cs | 59 +++++ .../Messaging/RemoteOrderedListener.cs | 54 +++++ .../Messaging/RemoteUnorderedListener.cs | 54 +++++ .../Messaging/Topic.cs | 28 +++ .../Portable/Account.cs | 60 +++++ .../Portable/Address.cs | 81 +++++++ .../Portable/Employee.cs | 93 ++++++++ .../Portable/EmployeeKey.cs | 86 +++++++ .../Portable/Organization.cs | 84 +++++++ .../Portable/OrganizationType.cs | 43 ++++ .../Properties/AssemblyInfo.cs | 35 +++ .../Services/MapService.cs | 119 ++++++++++ .../Examples/Config/example-cache-query.xml | 111 +++++++++ .../Examples/Config/example-cache-store.xml | 60 +++++ .../dotnet/Examples/Config/example-cache.xml | 83 +++++++ .../dotnet/Examples/Config/example-compute.xml | 70 ++++++ .../Apache.Ignite.Core.Tests.csproj | 17 ++ .../Examples/Example.cs | 137 +++++++++++ .../Examples/ExamplesTest.cs | 137 +++++++++++ .../Examples/PathUtil.cs | 52 +++++ .../Examples/ProjectFilesTest.cs | 45 ++++ 50 files changed, 4165 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Apache.Ignite.sln ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.sln b/modules/platform/src/main/dotnet/Apache.Ignite.sln index e9886ed..e46d30f 100644 --- a/modules/platform/src/main/dotnet/Apache.Ignite.sln +++ b/modules/platform/src/main/dotnet/Apache.Ignite.sln @@ -13,6 +13,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.Core.Tests.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite", "Apache.Ignite\Apache.Ignite.csproj", "{27F7F3C6-BDDE-43A9-B565-856F8395A04B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.Examples", "Examples\Apache.Ignite.Examples\Apache.Ignite.Examples.csproj", "{069FA680-3C4D-43A9-B84F-E67513B87827}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.ExamplesDll", "Examples\Apache.Ignite.ExamplesDll\Apache.Ignite.ExamplesDll.csproj", "{DFB08363-202E-412D-8812-349EF10A8702}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -61,6 +65,22 @@ Global {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x64.Build.0 = Release|x64 {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x86.ActiveCfg = Release|x86 {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x86.Build.0 = Release|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x64.ActiveCfg = Debug|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x64.Build.0 = Debug|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x86.ActiveCfg = Debug|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x86.Build.0 = Debug|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x64.ActiveCfg = Release|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x64.Build.0 = Release|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x86.ActiveCfg = Release|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x86.Build.0 = Release|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x64.ActiveCfg = Debug|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x64.Build.0 = Debug|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x86.ActiveCfg = Debug|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x86.Build.0 = Debug|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x64.ActiveCfg = Release|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x64.Build.0 = Release|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x86.ActiveCfg = Release|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples.sln ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples.sln b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples.sln new file mode 100644 index 0000000..c1337f3 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples.sln @@ -0,0 +1,72 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.Core", "..\Apache.Ignite.Core\Apache.Ignite.Core.csproj", "{4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "..\..\cpp\common\project\vs\common.vcxproj", "{4F7E4917-4612-4B96-9838-025711ADE391}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.Examples", "Apache.Ignite.Examples\Apache.Ignite.Examples.csproj", "{069FA680-3C4D-43A9-B84F-E67513B87827}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite.ExamplesDll", "Apache.Ignite.ExamplesDll\Apache.Ignite.ExamplesDll.csproj", "{DFB08363-202E-412D-8812-349EF10A8702}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{F1491682-C798-4C23-8239-16C5BC2C5A02}" + ProjectSection(SolutionItems) = preProject + Config\example-cache-query.xml = Config\example-cache-query.xml + Config\example-cache-store.xml = Config\example-cache-store.xml + Config\example-cache.xml = Config\example-cache.xml + Config\example-compute.xml = Config\example-compute.xml + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Apache.Ignite", "..\Apache.Ignite\Apache.Ignite.csproj", "{27F7F3C6-BDDE-43A9-B565-856F8395A04B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Debug|x64.ActiveCfg = Debug|x64 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Debug|x64.Build.0 = Debug|x64 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Debug|x86.ActiveCfg = Debug|x86 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Debug|x86.Build.0 = Debug|x86 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Release|x64.ActiveCfg = Release|x64 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Release|x64.Build.0 = Release|x64 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Release|x86.ActiveCfg = Release|x86 + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6}.Release|x86.Build.0 = Release|x86 + {4F7E4917-4612-4B96-9838-025711ADE391}.Debug|x64.ActiveCfg = Debug|x64 + {4F7E4917-4612-4B96-9838-025711ADE391}.Debug|x64.Build.0 = Debug|x64 + {4F7E4917-4612-4B96-9838-025711ADE391}.Debug|x86.ActiveCfg = Debug|Win32 + {4F7E4917-4612-4B96-9838-025711ADE391}.Debug|x86.Build.0 = Debug|Win32 + {4F7E4917-4612-4B96-9838-025711ADE391}.Release|x64.ActiveCfg = Release|x64 + {4F7E4917-4612-4B96-9838-025711ADE391}.Release|x64.Build.0 = Release|x64 + {4F7E4917-4612-4B96-9838-025711ADE391}.Release|x86.ActiveCfg = Release|Win32 + {4F7E4917-4612-4B96-9838-025711ADE391}.Release|x86.Build.0 = Release|Win32 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x64.ActiveCfg = Debug|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x64.Build.0 = Debug|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x86.ActiveCfg = Debug|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Debug|x86.Build.0 = Debug|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x64.ActiveCfg = Release|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x64.Build.0 = Release|x64 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x86.ActiveCfg = Release|x86 + {069FA680-3C4D-43A9-B84F-E67513B87827}.Release|x86.Build.0 = Release|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x64.ActiveCfg = Debug|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Debug|x86.ActiveCfg = Debug|x86 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x64.ActiveCfg = Release|x64 + {DFB08363-202E-412D-8812-349EF10A8702}.Release|x86.ActiveCfg = Release|x86 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Debug|x64.ActiveCfg = Debug|x64 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Debug|x64.Build.0 = Debug|x64 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Debug|x86.ActiveCfg = Debug|x86 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Debug|x86.Build.0 = Debug|x86 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x64.ActiveCfg = Release|x64 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x64.Build.0 = Release|x64 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x86.ActiveCfg = Release|x86 + {27F7F3C6-BDDE-43A9-B565-856F8395A04B}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj new file mode 100644 index 0000000..8ee90d9 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Apache.Ignite.Examples.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {069FA680-3C4D-43A9-B84F-E67513B87827} + Exe + Properties + Apache.Ignite.Examples + Apache.Ignite.Examples + v4.0 + 512 + + + x64 + bin\x64\Debug\ + + + x64 + bin\x64\Release\ + + + Apache.Ignite.Examples.Compute.TaskExample + + + true + bin\x86\Debug\ + x86 + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + x86 + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + + + + + + + + + + + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6} + Apache.Ignite.Core + + + {dfb08363-202e-412d-8812-349ef10a8702} + Apache.Ignite.ExamplesDll + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/App.config ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/App.config b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/App.config new file mode 100644 index 0000000..8e69aeb --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/App.config @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/ClosureExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/ClosureExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/ClosureExample.cs new file mode 100644 index 0000000..cdc39ac --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/ClosureExample.cs @@ -0,0 +1,89 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using Apache.Ignite.Core; +using Apache.Ignite.ExamplesDll.Compute; + +namespace Apache.Ignite.Examples.Compute +{ + /// + /// Example demonstrating closure execution. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you havent't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> + /// Properties -> Build -> Output path); + /// 3) Go to .Net binaries folder [IGNITE_HOME]\platforms\dotnet and run Apache.Ignite.exe as follows: + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + /// As a result you will see console jobs output on one or several nodes. + /// + public class ClosureExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-compute.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Closure execution example started."); + + // Split the string by spaces to count letters in each word in parallel. + ICollection words = "Count characters using closure".Split().ToList(); + + Console.WriteLine(); + Console.WriteLine(">>> Calculating character count with manual reducing:"); + + var res = ignite.GetCompute().Apply(new CharacterCountClosure(), words); + + int totalLen = res.Sum(); + + Console.WriteLine(">>> Total character count: " + totalLen); + Console.WriteLine(); + Console.WriteLine(">>> Calculating character count with reducer:"); + + totalLen = ignite.GetCompute().Apply(new CharacterCountClosure(), words, new CharacterCountReducer()); + + Console.WriteLine(">>> Total character count: " + totalLen); + Console.WriteLine(); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/TaskExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/TaskExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/TaskExample.cs new file mode 100644 index 0000000..9124a35 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Compute/TaskExample.cs @@ -0,0 +1,145 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.ExamplesDll.Compute; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Compute +{ + /// + /// Example demonstrating task execution. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you haven't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> + /// Properties -> Build -> Output path); + /// 3) Go to .Net binaries folder [IGNITE_HOME]\platforms\dotnet and run Apache.Ignite.exe as follows: + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + /// As a result you will see console jobs output on one or several nodes. + /// + public class TaskExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-compute.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Task execution example started."); + + // Generate employees to calculate average salary for. + ICollection employees = Employees(); + + Console.WriteLine(); + Console.WriteLine(">>> Calculating average salary for employees:"); + + foreach (Employee employee in employees) + Console.WriteLine(">>> " + employee); + + // Execute task and get average salary. + var avgSalary = ignite.GetCompute().Execute(new AverageSalaryTask(), employees); + + Console.WriteLine(); + Console.WriteLine(">>> Average salary for all employees: " + avgSalary); + Console.WriteLine(); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Generates collection of employees for example. + /// + /// Collection of employees. + private static ICollection Employees() + { + return new [] + { + new Employee( + "James Wilson", + 12500, + new Address("1096 Eddy Street, San Francisco, CA", 94109), + new List {"Human Resources", "Customer Service"} + ), + new Employee( + "Daniel Adams", + 11000, + new Address("184 Fidler Drive, San Antonio, TX", 78205), + new List {"Development", "QA"} + ), + new Employee( + "Cristian Moss", + 12500, + new Address("667 Jerry Dove Drive, Florence, SC", 29501), + new List {"Logistics"} + ), + new Employee( + "Allison Mathis", + 25300, + new Address("2702 Freedom Lane, Hornitos, CA", 95325), + new List {"Development"} + ), + new Employee( + "Breana Robbin", + 6500, + new Address("3960 Sundown Lane, Austin, TX", 78758), + new List {"Sales"} + ), + new Employee( + "Philip Horsley", + 19800, + new Address("2803 Elsie Drive, Sioux Falls, SD", 57104), + new List {"Sales"} + ), + new Employee( + "Brian Peters", + 10600, + new Address("1407 Pearlman Avenue, Boston, MA", 02110), + new List {"Development", "QA"} + ), + new Employee( + "Jack Yang", + 12900, + new Address("4425 Parrish Avenue Smithsons Valley, TX", 78130), + new List {"Sales"} + ) + }; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/ContinuousQueryExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/ContinuousQueryExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/ContinuousQueryExample.cs new file mode 100644 index 0000000..c22577c --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/ContinuousQueryExample.cs @@ -0,0 +1,105 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Threading; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Cache.Event; +using Apache.Ignite.Core.Cache.Query.Continuous; +using Apache.Ignite.ExamplesDll.Datagrid; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// This example demonstrates continuous query API. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you havent't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> Properties -> Build -> Output path); + /// 3) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + public class ContinuousQueryExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache.xml", + JvmOptions = new List {"-Xms512m", "-Xmx1024m"} + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cache continuous query example started."); + + var cache = ignite.GetOrCreateCache("cache_continuous_query"); + + // Clean up caches on all nodes before run. + cache.Clear(); + + const int keyCnt = 20; + + for (int i = 0; i < keyCnt; i++) + cache.Put(i, i.ToString()); + + var qry = new ContinuousQuery(new Listener(), new ContinuousQueryFilter(15)); + + + // Create new continuous query. + using (cache.QueryContinuous(qry)) + { + // Add a few more keys and watch more query notifications. + for (var i = keyCnt; i < keyCnt + 5; i++) + cache.Put(i, i.ToString()); + + // Wait for a while while callback is notified about remaining puts. + Thread.Sleep(2000); + } + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Callback for continuous query example. + /// + private class Listener : ICacheEntryEventListener + { + public void OnEvent(IEnumerable> events) + { + foreach (var e in events) + Console.WriteLine("Queried entry [key=" + e.Key + ", val=" + e.Value + ']'); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/CrossPlatformExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/CrossPlatformExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/CrossPlatformExample.cs new file mode 100644 index 0000000..6d50144 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/CrossPlatformExample.cs @@ -0,0 +1,208 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Portable; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// This example demonstrates use of portable objects between different platforms. + /// + /// This example must be run with standalone Java node. To achieve this start a node from IGNITE_HOME + /// using "ignite.bat" with proper configuration: + /// 'bin\ignite.bat examples\config\example-server.xml'. + /// + /// Once remote node is started, launch this example as follows: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// To see how objects can be transferred between platforms, start cross-platform Java example + /// without restarting remote node. + /// + public class CrossPlatformExample + { + /// Key for Java object. + private const int KeyJava = 100; + + /// Key for .Net object. + private const int KeyDotnet = 200; + + /// Key for C++ object. + private const int KeyCpp = 300; + + /// Cache Name. + private const string CacheName = "cacheCrossPlatform"; + + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cross-platform example started."); + + if (ignite.GetCluster().ForRemotes().GetNodes().Count == 0) + { + Console.WriteLine(); + Console.WriteLine(">>> This example requires remote nodes to be started."); + Console.WriteLine(">>> Please start at least 1 remote node."); + Console.WriteLine(">>> Refer to example's documentation for details on configuration."); + Console.WriteLine(); + } + else + { + var cache = ignite.GetOrCreateCache(CacheName); + + // Create new Organization object to store in cache. + Organization org = new Organization( + "Apache", + new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404), + OrganizationType.Private, + DateTime.Now + ); + + // Put created data entry to cache. + cache.Put(KeyDotnet, org); + + // Retrieve value stored by Java client. + GetFromJava(ignite); + + // Retrieve value stored by C++ client. + GetFromCpp(ignite); + + // Gets portable value from cache in portable format, without de-serializing it. + GetDotNetPortableInstance(ignite); + + // Gets portable value form cache as a strongly-typed fully de-serialized instance. + GetDotNetTypedInstance(ignite); + + Console.WriteLine(); + } + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Gets entry put by Java client. In order for entry to be in cache, Java client example + /// must be run before this example. + /// + /// Ignite instance. + private static void GetFromJava(IIgnite ignite) + { + var cache = ignite.GetOrCreateCache(CacheName) + .WithKeepPortable().WithAsync(); + + cache.Get(KeyJava); + + var orgPortable = cache.GetFuture().ToTask().Result; + + if (orgPortable == null) + { + Console.WriteLine(">>> Java client hasn't put entry to cache. Run Java example before this example " + + "to see the output."); + } + else + { + Console.WriteLine(">>> Entry from Java client:"); + Console.WriteLine(">>> Portable: " + orgPortable); + Console.WriteLine(">>> Deserialized: " + orgPortable.Deserialize()); + } + } + + /// + /// Gets entry put by C++ client. In order for entry to be in cache, C++ client example + /// must be run before this example. + /// + /// Ignite instance. + private static void GetFromCpp(IIgnite ignite) + { + var cache = ignite.GetOrCreateCache(CacheName) + .WithKeepPortable().WithAsync(); + + cache.Get(KeyCpp); + + var orgPortable = cache.GetFuture().Get(); + + Console.WriteLine(); + + if (orgPortable == null) + { + Console.WriteLine(">>> CPP client hasn't put entry to cache. Run CPP example before this example " + + "to see the output."); + } + else + { + Console.WriteLine(">>> Entry from CPP client:"); + Console.WriteLine(">>> Portable: " + orgPortable); + Console.WriteLine(">>> Deserialized: " + orgPortable.Deserialize()); + } + } + + /// + /// Gets portable value from cache in portable format, without de-serializing it. + /// + /// Ignite instance. + private static void GetDotNetPortableInstance(IIgnite ignite) + { + // Apply "KeepPortable" flag on data projection. + var cache = ignite.GetOrCreateCache(CacheName) + .WithKeepPortable(); + + var org = cache.Get(KeyDotnet); + + string name = org.GetField("name"); + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization name from portable field: " + name); + } + + /// + /// Gets portable value form cache as a strongly-typed fully de-serialized instance. + /// + /// Ignite instance. + private static void GetDotNetTypedInstance(IIgnite ignite) + { + var cache = ignite.GetOrCreateCache(CacheName); + + // Get recently created employee as a strongly-typed fully de-serialized instance. + Organization emp = cache.Get(KeyDotnet); + + string name = emp.Name; + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization name from deserialized Organization instance: " + name); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/DataStreamerExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/DataStreamerExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/DataStreamerExample.cs new file mode 100644 index 0000000..0974761 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/DataStreamerExample.cs @@ -0,0 +1,101 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Datastream; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// Demonstrates how cache can be populated with data utilizing . + /// Data streamer is a lot more efficient to use than standard cache put operation + /// as it properly buffers cache requests together and properly manages load on remote nodes. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache.xml + /// + public class DataStreamerExample + { + /// Number of entries to load. + private const int EntryCount = 500000; + + /// Cache name. + private const string CacheName = "cache_data_streamer"; + + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache.xml", + JvmOptions = new List {"-Xms512m", "-Xmx1024m"} + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cache data streamer example started."); + + // Clean up caches on all nodes before run. + ignite.GetOrCreateCache(CacheName).Clear(); + + Stopwatch timer = new Stopwatch(); + + timer.Start(); + + using (var ldr = ignite.GetDataStreamer(CacheName)) + { + ldr.PerNodeBufferSize = 1024; + + for (int i = 0; i < EntryCount; i++) + { + ldr.AddData(i, new Account(i, i)); + + // Print out progress while loading cache. + if (i > 0 && i % 10000 == 0) + Console.WriteLine("Loaded " + i + " accounts."); + } + } + + timer.Stop(); + + long dur = timer.ElapsedMilliseconds; + + Console.WriteLine(">>> Loaded " + EntryCount + " accounts in " + dur + "ms."); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/PutGetExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/PutGetExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/PutGetExample.cs new file mode 100644 index 0000000..ca2dfd1 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/PutGetExample.cs @@ -0,0 +1,219 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Portable; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// This example demonstrates several put-get operations on Ignite cache + /// with portable values. Note that portable object can be retrieved in + /// fully-deserialized form or in portable object format using special + /// cache projection. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache.xml + /// + public class PutGetExample + { + /// Cache name. + private const string CacheName = "cache_put_get"; + + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cache put-get example started."); + + // Clean up caches on all nodes before run. + ignite.GetOrCreateCache(CacheName).Clear(); + + PutGet(ignite); + PutGetPortable(ignite); + PutAllGetAll(ignite); + PutAllGetAllPortable(ignite); + + Console.WriteLine(); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Execute individual Put and Get. + /// + /// Ignite instance. + private static void PutGet(IIgnite ignite) + { + var cache = ignite.GetCache(CacheName); + + // Create new Organization to store in cache. + Organization org = new Organization( + "Microsoft", + new Address("1096 Eddy Street, San Francisco, CA", 94109), + OrganizationType.Private, + DateTime.Now + ); + + // Put created data entry to cache. + cache.Put(1, org); + + // Get recently created employee as a strongly-typed fully de-serialized instance. + Organization orgFromCache = cache.Get(1); + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization instance from cache: " + orgFromCache); + } + + /// + /// Execute individual Put and Get, getting value in portable format, without de-serializing it. + /// + /// Ignite instance. + private static void PutGetPortable(IIgnite ignite) + { + var cache = ignite.GetCache(CacheName); + + // Create new Organization to store in cache. + Organization org = new Organization( + "Microsoft", + new Address("1096 Eddy Street, San Francisco, CA", 94109), + OrganizationType.Private, + DateTime.Now + ); + + // Put created data entry to cache. + cache.Put(1, org); + + // Create projection that will get values as portable objects. + var portableCache = cache.WithKeepPortable(); + + // Get recently created organization as a portable object. + var portableOrg = portableCache.Get(1); + + // Get organization's name from portable object (note that object doesn't need to be fully deserialized). + string name = portableOrg.GetField("name"); + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization name from portable object: " + name); + } + + /// + /// Execute bulk Put and Get operations. + /// + /// Ignite instance. + private static void PutAllGetAll(IIgnite ignite) + { + var cache = ignite.GetCache(CacheName); + + // Create new Organizations to store in cache. + Organization org1 = new Organization( + "Microsoft", + new Address("1096 Eddy Street, San Francisco, CA", 94109), + OrganizationType.Private, + DateTime.Now + ); + + Organization org2 = new Organization( + "Red Cross", + new Address("184 Fidler Drive, San Antonio, TX", 78205), + OrganizationType.NonProfit, + DateTime.Now + ); + + var map = new Dictionary { { 1, org1 }, { 2, org2 } }; + + // Put created data entries to cache. + cache.PutAll(map); + + // Get recently created organizations as a strongly-typed fully de-serialized instances. + IDictionary mapFromCache = cache.GetAll(new List { 1, 2 }); + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization instances from cache:"); + + foreach (Organization org in mapFromCache.Values) + Console.WriteLine(">>> " + org); + } + + /// + /// Execute bulk Put and Get operations getting values in portable format, without de-serializing it. + /// + /// Ignite instance. + private static void PutAllGetAllPortable(IIgnite ignite) + { + var cache = ignite.GetCache(CacheName); + + // Create new Organizations to store in cache. + Organization org1 = new Organization( + "Microsoft", + new Address("1096 Eddy Street, San Francisco, CA", 94109), + OrganizationType.Private, + DateTime.Now + ); + + Organization org2 = new Organization( + "Red Cross", + new Address("184 Fidler Drive, San Antonio, TX", 78205), + OrganizationType.NonProfit, + DateTime.Now + ); + + var map = new Dictionary { { 1, org1 }, { 2, org2 } }; + + // Put created data entries to cache. + cache.PutAll(map); + + // Create projection that will get values as portable objects. + var portableCache = cache.WithKeepPortable(); + + // Get recently created organizations as portable objects. + IDictionary portableMap = + portableCache.GetAll(new List { 1, 2 }); + + Console.WriteLine(); + Console.WriteLine(">>> Retrieved organization names from portable objects:"); + + foreach (IPortableObject poratbleOrg in portableMap.Values) + Console.WriteLine(">>> " + poratbleOrg.GetField("name")); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs new file mode 100644 index 0000000..b25c401 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs @@ -0,0 +1,226 @@ +/* + * 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. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Cache; +using Apache.Ignite.Core.Cache.Query; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// This example populates cache with sample data and runs several SQL and + /// full text queries over this data. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache-query.xml + /// + public class QueryExample + { + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache-query.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cache query example started."); + + var cache = ignite.GetCache(null); + + // Clean up caches on all nodes before run. + cache.Clear(); + + // Populate cache with sample data entries. + PopulateCache(cache); + + // Create cache that will work with specific types. + var employeeCache = ignite.GetCache(null); + + // Run SQL query example. + SqlQueryExample(employeeCache); + + // Run SQL query with join example. + SqlJoinQueryExample(employeeCache); + + // Run SQL fields query example. + SqlFieldsQueryExample(employeeCache); + + // Run full text query example. + FullTextQueryExample(employeeCache); + + Console.WriteLine(); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Queries employees that have provided ZIP code in address. + /// + /// Cache. + private static void SqlQueryExample(ICache cache) + { + const int zip = 94109; + + var qry = cache.Query(new SqlQuery(typeof(Employee), "zip = ?", zip)); + + Console.WriteLine(); + Console.WriteLine(">>> Employees with zipcode " + zip + ":"); + + foreach (var entry in qry) + Console.WriteLine(">>> " + entry.Value); + } + + /// + /// Queries employees that work for organization with provided name. + /// + /// Cache. + private static void SqlJoinQueryExample(ICache cache) + { + const string orgName = "Apache"; + + var qry = cache.Query(new SqlQuery("Employee", + "from Employee, Organization " + + "where Employee.organizationId = Organization._key and Organization.name = ?", orgName)); + + Console.WriteLine(); + Console.WriteLine(">>> Employees working for " + orgName + ":"); + + foreach (var entry in qry) + Console.WriteLine(">>> " + entry.Value); + } + + /// + /// Queries names and salaries for all employees. + /// + /// Cache. + private static void SqlFieldsQueryExample(ICache cache) + { + var qry = cache.QueryFields(new SqlFieldsQuery("select name, salary from Employee")); + + Console.WriteLine(); + Console.WriteLine(">>> Employee names and their salaries:"); + + foreach (IList row in qry) + Console.WriteLine(">>> [Name=" + row[0] + ", salary=" + row[1] + ']'); + } + + /// + /// Queries employees that live in Texas using full-text query API. + /// + /// Cache. + private static void FullTextQueryExample(ICache cache) + { + var qry = cache.Query(new TextQuery("Employee", "TX")); + + Console.WriteLine(); + Console.WriteLine(">>> Employees living in Texas:"); + + foreach (var entry in qry) + Console.WriteLine(">>> " + entry.Value); + } + + /// + /// Populate cache with data for this example. + /// + /// Cache. + private static void PopulateCache(ICache cache) + { + cache.Put(1, new Organization( + "Apache", + new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404), + OrganizationType.Private, + DateTime.Now + )); + + cache.Put(2, new Organization( + "Microsoft", + new Address("1096 Eddy Street, San Francisco, CA", 94109), + OrganizationType.Private, + DateTime.Now + )); + + cache.Put(new EmployeeKey(1, 1), new Employee( + "James Wilson", + 12500, + new Address("1096 Eddy Street, San Francisco, CA", 94109), + new List { "Human Resources", "Customer Service" } + )); + + cache.Put(new EmployeeKey(2, 1), new Employee( + "Daniel Adams", + 11000, + new Address("184 Fidler Drive, San Antonio, TX", 78130), + new List { "Development", "QA" } + )); + + cache.Put(new EmployeeKey(3, 1), new Employee( + "Cristian Moss", + 12500, + new Address("667 Jerry Dove Drive, Florence, SC", 29501), + new List { "Logistics" } + )); + + cache.Put(new EmployeeKey(4, 2), new Employee( + "Allison Mathis", + 25300, + new Address("2702 Freedom Lane, San Francisco, CA", 94109), + new List { "Development" } + )); + + cache.Put(new EmployeeKey(5, 2), new Employee( + "Breana Robbin", + 6500, + new Address("3960 Sundown Lane, Austin, TX", 78130), + new List { "Sales" } + )); + + cache.Put(new EmployeeKey(6, 2), new Employee( + "Philip Horsley", + 19800, + new Address("2803 Elsie Drive, Sioux Falls, SD", 57104), + new List { "Sales" } + )); + + cache.Put(new EmployeeKey(7, 2), new Employee( + "Brian Peters", + 10600, + new Address("1407 Pearlman Avenue, Boston, MA", 12110), + new List { "Development", "QA" } + )); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/StoreExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/StoreExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/StoreExample.cs new file mode 100644 index 0000000..020fc11 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/StoreExample.cs @@ -0,0 +1,116 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.ExamplesDll.Datagrid; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// Example demonstrating cache store. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you havent't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> Properties -> Build -> Output path); + /// 3) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache-store.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + class StoreExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache-store.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Cache store example started."); + + var cache = ignite.GetCache(null); + + // Clean up caches on all nodes before run. + cache.Clear(); + + Console.WriteLine(); + Console.WriteLine(">>> Cleared values from cache."); + Console.WriteLine(">>> Current cache size: " + cache.GetSize()); + + // Load entries from store which pass provided filter. + cache.LoadCache(new EmployeeStorePredicate()); + + Console.WriteLine(); + Console.WriteLine(">>> Loaded entry from store through ICache.LoadCache()."); + Console.WriteLine(">>> Current cache size: " + cache.GetSize()); + + // Load entry from store calling ICache.Get() method. + Employee emp = cache.Get(2); + + Console.WriteLine(); + Console.WriteLine(">>> Loaded entry from store through ICache.Get(): " + emp); + Console.WriteLine(">>> Current cache size: " + cache.GetSize()); + + // Put an entry to the cache + cache.Put(3, new Employee( + "James Wilson", + 12500, + new Address("1096 Eddy Street, San Francisco, CA", 94109), + new List { "Human Resources", "Customer Service" } + )); + + Console.WriteLine(); + Console.WriteLine(">>> Put entry to cache. "); + Console.WriteLine(">>> Current cache size: " + cache.GetSize()); + + // Clear values again. + cache.Clear(); + + Console.WriteLine(); + Console.WriteLine(">>> Cleared values from cache again."); + Console.WriteLine(">>> Current cache size: " + cache.GetSize()); + + // Read values from cache after clear. + Console.WriteLine(); + Console.WriteLine(">>> Read values after clear:"); + + for (int i = 1; i <= 3; i++) + Console.WriteLine(">>> Key=" + i + ", value=" + cache.Get(i)); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/TransactionExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/TransactionExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/TransactionExample.cs new file mode 100644 index 0000000..ffa0fc1 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Datagrid/TransactionExample.cs @@ -0,0 +1,104 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Transactions; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Datagrid +{ + /// + /// This example demonstrates how to use transactions on Apache cache. + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-cache.xml + /// + class TransactionExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-cache.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(); + Console.WriteLine(">>> Transaction example started."); + + var cache = ignite.GetCache("tx"); + + // Clean up caches on all nodes before run. + cache.Clear(); + + // Initialize. + cache.Put(1, new Account(1, 100)); + cache.Put(2, new Account(2, 200)); + + Console.WriteLine(); + Console.WriteLine(">>> Accounts before transfer: "); + Console.WriteLine(">>> " + cache.Get(1)); + Console.WriteLine(">>> " + cache.Get(2)); + Console.WriteLine(); + + // Transfer money between accounts in a single transaction. + using (var tx = cache.Ignite.GetTransactions().TxStart(TransactionConcurrency.Pessimistic, + TransactionIsolation.RepeatableRead)) + { + Account acc1 = cache.Get(1); + Account acc2 = cache.Get(2); + + acc1.Balance += 100; + acc2.Balance -= 100; + + cache.Put(1, acc1); + cache.Put(2, acc2); + + tx.Commit(); + } + + Console.WriteLine(">>> Transfer finished."); + + Console.WriteLine(); + Console.WriteLine(">>> Accounts after transfer: "); + Console.WriteLine(">>> " + cache.Get(1)); + Console.WriteLine(">>> " + cache.Get(2)); + Console.WriteLine(); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Events/EventsExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Events/EventsExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Events/EventsExample.cs new file mode 100644 index 0000000..7c2f6a3 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Events/EventsExample.cs @@ -0,0 +1,122 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using Apache.Ignite.Core; +using Apache.Ignite.Core.Events; +using Apache.Ignite.ExamplesDll.Compute; +using Apache.Ignite.ExamplesDll.Events; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.Examples.Events +{ + /// + /// Example demonstrating Ignite events. + /// + /// This example can be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you havent't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> Properties -> Build -> Output path); + /// 3) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// As a result you will see console events output on all nodes. + /// + public class EventsExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-compute.xml", + JvmOptions = new List {"-Xms512m", "-Xmx1024m"} + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(">>> Events example started."); + Console.WriteLine(); + + // Local listen example + Console.WriteLine(">>> Listening for a local event..."); + + var listener = new LocalListener(); + ignite.GetEvents().LocalListen(listener, EventType.EvtsTaskExecution); + + ExecuteTask(ignite); + + ignite.GetEvents().StopLocalListen(listener); + + Console.WriteLine(">>> Received events count: " + listener.EventsReceived); + Console.WriteLine(); + + // Remote listen example (start standalone nodes for better demonstration) + Console.WriteLine(">>> Listening for remote events..."); + + var localListener = new LocalListener(); + var remoteFilter = new RemoteFilter(); + + var listenId = ignite.GetEvents().RemoteListen(localListener: localListener, + remoteFilter: remoteFilter, types: EventType.EvtsJobExecution); + + ExecuteTask(ignite); + + ignite.GetEvents().StopRemoteListen(listenId); + + Console.WriteLine(">>> Received events count: " + localListener.EventsReceived); + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Executes a task to generate events. + /// + /// Ignite instance. + private static void ExecuteTask(IIgnite ignite) + { + var employees = Enumerable.Range(1, 10).SelectMany(x => new[] + { + new Employee("Allison Mathis", + 25300, + new Address("2702 Freedom Lane, San Francisco, CA", 94109), + new[] {"Development"}), + + new Employee("Breana Robbin", + 6500, + new Address("3960 Sundown Lane, Austin, TX", 78130), + new[] {"Sales"}) + }).ToArray(); + + ignite.GetCompute().Execute(new AverageSalaryTask(), employees); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/1a5e5ff3/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Messaging/MessagingExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Messaging/MessagingExample.cs b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Messaging/MessagingExample.cs new file mode 100644 index 0000000..8d0a169 --- /dev/null +++ b/modules/platform/src/main/dotnet/Examples/Apache.Ignite.Examples/Messaging/MessagingExample.cs @@ -0,0 +1,119 @@ +/* + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Threading; +using Apache.Ignite.Core; +using Apache.Ignite.ExamplesDll.Messaging; + +namespace Apache.Ignite.Examples.Messaging +{ + /// + /// Example demonstrating Ignite messaging. + /// + /// This example should be run in conjunction with standalone Apache Ignite .Net node. + /// To start standalone node please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll if you havent't done it yet (select it -> right-click -> Build); + /// 2) Locate created Apache.Ignite.ExamplesDll.dll file (Apache.Ignite.ExamplesDll project -> right-click -> Properties -> Build -> Output path); + /// 3) Locate Apache.Ignite.exe file (Apache.Ignite project -> right-click -> Properties -> Build -> Output path) + /// Apache.Ignite.exe -IgniteHome=[path_to_IGNITE_HOME] -springConfigUrl=modules\platform\src\main\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// + /// To run the example please do the following: + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build); + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start application (F5 or Ctrl+F5). + /// + /// As a result you will see console messages output on all nodes. + /// + public class MessagingExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"modules\platform\src\main\dotnet\examples\config\example-compute.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" } + }; + + using (var ignite = Ignition.Start(cfg)) + { + var remotes = ignite.GetCluster().ForRemotes(); + + if (remotes.GetNodes().Count == 0) + { + Console.WriteLine(">>> This example requires remote nodes to be started."); + Console.WriteLine(">>> Please start at least 1 remote node."); + Console.WriteLine(">>> Refer to example's documentation for details on configuration."); + } + else + { + Console.WriteLine(">>> Messaging example started."); + Console.WriteLine(); + + // Set up local listeners + var localMessaging = ignite.GetCluster().ForLocal().GetMessaging(); + + var msgCount = remotes.GetNodes().Count * 10; + + var orderedCounter = new CountdownEvent(msgCount); + var unorderedCounter = new CountdownEvent(msgCount); + + localMessaging.LocalListen(new LocalListener(unorderedCounter), Topic.Unordered); + localMessaging.LocalListen(new LocalListener(orderedCounter), Topic.Ordered); + + // Set up remote listeners + var remoteMessaging = remotes.GetMessaging(); + + remoteMessaging.RemoteListen(new RemoteUnorderedListener(), Topic.Unordered); + remoteMessaging.RemoteListen(new RemoteOrderedListener(), Topic.Ordered); + + // Send unordered + Console.WriteLine(">>> Sending unordered messages..."); + + for (var i = 0; i < 10; i++) + remoteMessaging.Send(i, Topic.Unordered); + + Console.WriteLine(">>> Finished sending unordered messages."); + + // Send ordered + Console.WriteLine(">>> Sending ordered messages..."); + + for (var i = 0; i < 10; i++) + remoteMessaging.SendOrdered(i, Topic.Ordered); + + Console.WriteLine(">>> Finished sending ordered messages."); + + Console.WriteLine(">>> Check output on all nodes for message printouts."); + Console.WriteLine(">>> Waiting for messages acknowledgements from all remote nodes..."); + + unorderedCounter.Wait(); + orderedCounter.Wait(); + } + } + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + } +}