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 8D19A17202 for ; Tue, 22 Sep 2015 07:19:13 +0000 (UTC) Received: (qmail 14674 invoked by uid 500); 22 Sep 2015 07:19:04 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 14589 invoked by uid 500); 22 Sep 2015 07:19:04 -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 14552 invoked by uid 99); 22 Sep 2015 07:19:04 -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; Tue, 22 Sep 2015 07:19:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B56EFE060F; Tue, 22 Sep 2015 07:19:03 +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: Tue, 22 Sep 2015 07:19:04 -0000 Message-Id: <9484ea2ebcaf4da1b66edac25fcbd501@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [02/37] ignite git commit: IGNITE-1513: WIP on .Net. http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/StoreExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/StoreExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/StoreExample.cs new file mode 100644 index 0000000..6c2b40d --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/StoreExample.cs @@ -0,0 +1,114 @@ +/* + * 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. + /// + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start example (F5 or Ctrl+F5). + /// + /// This example can be run with standalone Apache Ignite .Net node: + /// 1) Run %IGNITE_HOME%/platforms/dotnet/Apache.Ignite/bin/${Platform]/${Configuration}/Apache.Ignite.exe: + /// Apache.Ignite.exe -IgniteHome="%IGNITE_HOME%" -springConfigUrl=platforms\dotnet\examples\config\example-cache-store.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// 2) Start example. + /// + class StoreExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\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/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/TransactionExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/TransactionExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Datagrid/TransactionExample.cs new file mode 100644 index 0000000..6be3523 --- /dev/null +++ b/modules/platform/dotnet/Examples2/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. + /// + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start example (F5 or Ctrl+F5). + /// + /// This example can be run with standalone Apache Ignite .Net node: + /// 1) Run %IGNITE_HOME%/platforms/dotnet/Apache.Ignite/bin/${Platform]/${Configuration}/Apache.Ignite.exe: + /// Apache.Ignite.exe -IgniteHome="%IGNITE_HOME%" -springConfigUrl=platforms\dotnet\examples\config\example-cache.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// 2) Start example. + /// + class TransactionExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\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/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Events/EventsExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Events/EventsExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Events/EventsExample.cs new file mode 100644 index 0000000..83802cc --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Events/EventsExample.cs @@ -0,0 +1,118 @@ +/* + * 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. + /// + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start example (F5 or Ctrl+F5). + /// + /// This example can be run with standalone Apache Ignite .Net node: + /// 1) Run %IGNITE_HOME%/platforms/dotnet/Apache.Ignite/bin/${Platform]/${Configuration}/Apache.Ignite.exe: + /// Apache.Ignite.exe -IgniteHome="%IGNITE_HOME%" -springConfigUrl=platforms\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// 2) Start example. + /// + public class EventsExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\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/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Messaging/MessagingExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Messaging/MessagingExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Messaging/MessagingExample.cs new file mode 100644 index 0000000..a24c47c --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Messaging/MessagingExample.cs @@ -0,0 +1,112 @@ +/* + * 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. Should be run with standalone Apache Ignite .Net node. + /// + /// 1) Run %IGNITE_HOME%/platforms/dotnet/Apache.Ignite/bin/${Platform]/${Configuration}/Apache.Ignite.exe: + /// Apache.Ignite.exe -IgniteHome="%IGNITE_HOME%" -springConfigUrl=platforms\dotnet\examples\config\example-compute.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// 2) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 3) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 4) Start example (F5 or Ctrl+F5). + /// + public class MessagingExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\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(); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Misc/LifecycleExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Misc/LifecycleExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Misc/LifecycleExample.cs new file mode 100644 index 0000000..2d319e8 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Misc/LifecycleExample.cs @@ -0,0 +1,109 @@ +/* + * 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.Lifecycle; +using Apache.Ignite.Core.Resource; + +namespace Apache.Ignite.Examples.Misc +{ + /// + /// This example shows how to provide your own implementation + /// to be able to hook into Apache lifecycle. Example bean will output occurred lifecycle + /// events to the console. + /// + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start example (F5 or Ctrl+F5). + /// + public class LifecycleExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + Console.WriteLine(); + Console.WriteLine(">>> Lifecycle example started."); + + // Create new configuration. + var lifecycleExampleBean = new LifecycleExampleBean(); + + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\dotnet\examples\config\example-compute.xml", + JvmOptions = new List { "-Xms512m", "-Xmx1024m" }, + LifecycleBeans = new List { lifecycleExampleBean } + }; + + // Provide lifecycle bean to configuration. + using (Ignition.Start(cfg)) + { + // Make sure that lifecycle bean was notified about Ignite startup. + Console.WriteLine(); + Console.WriteLine(">>> Started (should be true): " + lifecycleExampleBean.Started); + } + + // Make sure that lifecycle bean was notified about Ignite stop. + Console.WriteLine(); + Console.WriteLine(">>> Started (should be false): " + lifecycleExampleBean.Started); + + Console.WriteLine(); + Console.WriteLine(">>> Example finished, press any key to exit ..."); + Console.ReadKey(); + } + + /// + /// Sample lifecycle bean implementation. + /// + private class LifecycleExampleBean : ILifecycleBean + { + /** Auto-injected Ignite instance. */ + [InstanceResource] +#pragma warning disable 649 + private IIgnite _ignite; +#pragma warning restore 649 + + /** */ + public void OnLifecycleEvent(LifecycleEventType evt) + { + Console.WriteLine(); + Console.WriteLine(">>> Ignite lifecycle event occurred: " + evt); + Console.WriteLine(">>> Ignite name: " + (_ignite != null ? _ignite.Name : "not available")); + + if (evt == LifecycleEventType.AfterNodeStart) + Started = true; + else if (evt == LifecycleEventType.AfterNodeStop) + Started = false; + } + + /// + /// Started flag. + /// + public bool Started + { + get; + private set; + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Properties/AssemblyInfo.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..555a35f --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +/* + * 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.Reflection; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Apache Ignite Examples")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Apache Software Foundation")] +[assembly: AssemblyProduct("Apache Ignite")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +[assembly: ComVisible(false)] + +[assembly: Guid("41a0cb95-3435-4c78-b867-900b28e2c9ee")] + +[assembly: AssemblyVersion("1.5.0")] +[assembly: AssemblyFileVersion("1.5.0")] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/IMapService.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/IMapService.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/IMapService.cs new file mode 100644 index 0000000..7253a0b --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/IMapService.cs @@ -0,0 +1,56 @@ +/* + * 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 Apache.Ignite.ExamplesDll.Services; + +namespace Apache.Ignite.Examples.Services +{ + /// + /// Interface for service proxy interaction. + /// Actual service class () does not have to implement this interface. + /// Target method/property will be searched by signature (name, arguments). + /// + public interface IMapService + { + /// + /// Puts an entry to the map. + /// + /// The key. + /// The value. + void Put(TK key, TV value); + + /// + /// Gets an entry from the map. + /// + /// The key. + /// Entry value. + TV Get(TK key); + + /// + /// Clears the map. + /// + void Clear(); + + /// + /// Gets the size of the map. + /// + /// + /// The size. + /// + int Size { get; } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/ServicesExample.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/ServicesExample.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/ServicesExample.cs new file mode 100644 index 0000000..6d0ddd0 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.Examples/Services/ServicesExample.cs @@ -0,0 +1,77 @@ +/* + * 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.Services; + +namespace Apache.Ignite.Examples.Services +{ + /// + /// Example demonstrating Ignite services. + /// + /// 1) Build the project Apache.Ignite.ExamplesDll (select it -> right-click -> Build). + /// Apache.Ignite.ExamplesDll.dll must appear in %IGNITE_HOME%/platforms/dotnet/Examples/Apache.Ignite.ExamplesDll/bin/${Platform]/${Configuration} folder. + /// 2) Set this class as startup object (Apache.Ignite.Examples project -> right-click -> Properties -> + /// Application -> Startup object); + /// 3) Start example (F5 or Ctrl+F5). + /// + /// This example can be run with standalone Apache Ignite .Net node: + /// 1) Run %IGNITE_HOME%/platforms/dotnet/Apache.Ignite/bin/${Platform]/${Configuration}/Apache.Ignite.exe: + /// Apache.Ignite.exe -IgniteHome="%IGNITE_HOME%" -springConfigUrl=platforms\dotnet\examples\config\example-cache.xml -assembly=[path_to_Apache.Ignite.ExamplesDll.dll] + /// 2) Start example. + /// + public class ServicesExample + { + /// + /// Runs the example. + /// + [STAThread] + public static void Main() + { + var cfg = new IgniteConfiguration + { + SpringConfigUrl = @"platforms\dotnet\examples\config\example-compute.xml", + JvmOptions = new List {"-Xms512m", "-Xmx1024m"} + }; + + using (var ignite = Ignition.Start(cfg)) + { + Console.WriteLine(">>> Services example started."); + Console.WriteLine(); + + // Deploy a service + var svc = new MapService(); + Console.WriteLine(">>> Deploying service to all nodes..."); + ignite.GetServices().DeployNodeSingleton("service", svc); + + // Get a sticky service proxy so that we will always be contacting the same remote node. + var prx = ignite.GetServices().GetServiceProxy>("service", true); + + for (var i = 0; i < 10; i++) + prx.Put(i, i.ToString()); + + var mapSize = prx.Size; + + Console.WriteLine(">>> Map service size: " + mapSize); + + ignite.GetServices().CancelAll(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj new file mode 100644 index 0000000..cb2ff6f --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj @@ -0,0 +1,75 @@ + + + + + Debug + AnyCPU + {DFB08363-202E-412D-8812-349EF10A8702} + Library + Properties + Apache.Ignite.ExamplesDll + Apache.Ignite.ExamplesDll + v4.0 + 512 + + + x64 + bin\x64\Debug\ + + + x64 + bin\x64\Release\ + + + true + bin\x86\Debug\ + x86 + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + x86 + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {4CD2F726-7E2B-46C4-A5BA-057BB82EECB6} + Apache.Ignite.Core + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csprojrel ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csprojrel b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csprojrel new file mode 100644 index 0000000..fa6b71c --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csprojrel @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {DFB08363-202E-412D-8812-349EF10A8702} + Library + Properties + Apache.Ignite.ExamplesDll + Apache.Ignite.ExamplesDll + v4.0 + 512 + + + x64 + bin\x64\Debug\ + + + x64 + bin\x64\Release\ + + + true + bin\x86\Debug\ + x86 + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + x86 + MinimumRecommendedRules.ruleset + + + + ..\..\Apache.Ignite\bin\$(Platform)\$(Configuration)\Apache.Ignite.Core.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryJob.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryJob.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryJob.cs new file mode 100644 index 0000000..e4713d4 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryJob.cs @@ -0,0 +1,65 @@ +/* + * 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.Compute; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.ExamplesDll.Compute +{ + /// + /// Average salary job. + /// + [Serializable] + public class AverageSalaryJob : ComputeJobAdapter> + { + /// Employees. + private readonly ICollection _employees = new List(); + + /// + /// Adds employee. + /// + /// Employee. + public void Add(Employee employee) + { + _employees.Add(employee); + } + + /// + /// Execute the job. + /// + /// Job result: tuple with total salary in the first item and employees count in the second. + override public Tuple Execute() + { + long sum = 0; + int count = 0; + + Console.WriteLine(); + Console.WriteLine(">>> Executing salary job for " + _employees.Count + " employee(s) ..."); + Console.WriteLine(); + + foreach (Employee emp in _employees) + { + sum += emp.Salary; + count++; + } + + return new Tuple(sum, count); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryTask.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryTask.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryTask.cs new file mode 100644 index 0000000..f8acb01 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/AverageSalaryTask.cs @@ -0,0 +1,84 @@ +/* + * 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.Compute; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.ExamplesDll.Compute +{ + /// + /// Average salary task. + /// + public class AverageSalaryTask : ComputeTaskSplitAdapter, Tuple, long> + { + /// + /// Split the task distributing employees between several jobs. + /// + /// Number of available grid nodes. + /// Task execution argument. + protected override ICollection>> Split(int gridSize, ICollection arg) + { + ICollection employees = arg; + + var jobs = new List>>(gridSize); + + int count = 0; + + foreach (Employee employee in employees) + { + int idx = count++ % gridSize; + + AverageSalaryJob job; + + if (idx >= jobs.Count) + { + job = new AverageSalaryJob(); + + jobs.Add(job); + } + else + job = (AverageSalaryJob) jobs[idx]; + + job.Add(employee); + } + + return jobs; + } + + /// + /// Calculate average salary after all jobs are finished. + /// + /// Job results. + /// Average salary. + public override long Reduce(IList>> results) + { + long sum = 0; + int count = 0; + + foreach (var t in results.Select(result => result.Data())) + { + sum += t.Item1; + count += t.Item2; + } + + return sum / count; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountClosure.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountClosure.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountClosure.cs new file mode 100644 index 0000000..2823221 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountClosure.cs @@ -0,0 +1,43 @@ +/* + * 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 Apache.Ignite.Core.Compute; + +namespace Apache.Ignite.ExamplesDll.Compute +{ + /// + /// Closure counting characters in a string. + /// + [Serializable] + public class CharacterCountClosure : IComputeFunc + { + /// + /// Calculate character count of the given word. + /// + /// Word. + /// Character count. + public int Invoke(string arg) + { + int len = arg.Length; + + Console.WriteLine("Character count in word \"" + arg + "\": " + len); + + return len; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountReducer.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountReducer.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountReducer.cs new file mode 100644 index 0000000..6825046 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Compute/CharacterCountReducer.cs @@ -0,0 +1,51 @@ +/* + * 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 Apache.Ignite.Core.Compute; + +namespace Apache.Ignite.ExamplesDll.Compute +{ + /// + /// Character count reducer which collects individual string lengths and aggregate them. + /// + public class CharacterCountReducer : IComputeReducer + { + /// Total length. + private int _length; + + /// + /// Collect character counts of distinct words. + /// + /// Character count of a distinct word. + /// True to continue collecting results until all closures are finished. + public bool Collect(int res) + { + _length += res; + + return true; + } + + /// + /// Reduce all collected results. + /// + /// Total character count. + public int Reduce() + { + return _length; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/ContinuousQueryFilter.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/ContinuousQueryFilter.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/ContinuousQueryFilter.cs new file mode 100644 index 0000000..8c05f42 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/ContinuousQueryFilter.cs @@ -0,0 +1,50 @@ +/* + * 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 Apache.Ignite.Core.Cache.Event; + +namespace Apache.Ignite.ExamplesDll.Datagrid +{ + /// + /// Filter for continuous query example. + /// + [Serializable] + public class ContinuousQueryFilter : ICacheEntryEventFilter + { + /// Threshold. + private readonly int _threshold; + + /// + /// Constructor. + /// + /// Threshold. + public ContinuousQueryFilter(int threshold) + { + _threshold = threshold; + } + + /// + /// Evaluates cache entry event. + /// + /// Event. + public bool Evaluate(ICacheEntryEvent evt) + { + return evt.Key >= _threshold; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStore.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStore.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStore.cs new file mode 100644 index 0000000..742b048 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStore.cs @@ -0,0 +1,121 @@ +/* + * 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.Concurrent; +using System.Collections.Generic; +using Apache.Ignite.Core.Cache; +using Apache.Ignite.Core.Cache.Store; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.ExamplesDll.Datagrid +{ + /// + /// Example cache store implementation. + /// + public class EmployeeStore : CacheStoreAdapter + { + /// + /// Dictionary representing the store. + /// + private readonly ConcurrentDictionary _db = new ConcurrentDictionary( + new List> + { + new KeyValuePair(1, new Employee( + "Allison Mathis", + 25300, + new Address("2702 Freedom Lane, San Francisco, CA", 94109), + new List {"Development"} + )), + + new KeyValuePair(2, new Employee( + "Breana Robbin", + 6500, + new Address("3960 Sundown Lane, Austin, TX", 78130), + new List {"Sales"} + )) + }); + + /// + /// Loads all values from underlying persistent storage. + /// This method gets called as a result of call. + /// + /// Action that loads a cache entry. + /// Optional arguments. + public override void LoadCache(Action act, params object[] args) + { + // Iterate over whole underlying store and call act on each entry to load it into the cache. + foreach (var entry in _db) + act(entry.Key, entry.Value); + } + + /// + /// Loads multiple objects from the cache store. + /// This method gets called as a result of call. + /// + /// Keys to load. + /// + /// A map of key, values to be stored in the cache. + /// + public override IDictionary LoadAll(ICollection keys) + { + var result = new Dictionary(); + + foreach (var key in keys) + result[key] = Load(key); + + return result; + } + + /// + /// Loads an object from the cache store. + /// This method gets called as a result of call. + /// + /// Key to load. + /// Loaded value + public override object Load(object key) + { + object val; + + _db.TryGetValue(key, out val); + + return val; + } + + /// + /// Write key-value pair to store. + /// + /// Key to write. + /// Value to write. + public override void Write(object key, object val) + { + _db[key] = val; + } + + /// + /// Delete cache entry form store. + /// + /// Key to delete. + public override void Delete(object key) + { + object val; + + _db.TryRemove(key, out val); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStorePredicate.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStorePredicate.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStorePredicate.cs new file mode 100644 index 0000000..a585e5e --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Datagrid/EmployeeStorePredicate.cs @@ -0,0 +1,40 @@ +/* + * 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 Apache.Ignite.Core.Cache; +using Apache.Ignite.ExamplesDll.Portable; + +namespace Apache.Ignite.ExamplesDll.Datagrid +{ + /// + /// Example cache entry predicate. + /// + [Serializable] + public class EmployeeStorePredicate : ICacheEntryFilter + { + /// + /// Returns a value indicating whether provided cache entry satisfies this predicate. + /// + /// Cache entry. + /// Value indicating whether provided cache entry satisfies this predicate. + public bool Invoke(ICacheEntry entry) + { + return entry.Key == 1; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/LocalListener.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/LocalListener.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/LocalListener.cs new file mode 100644 index 0000000..8a28355 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/LocalListener.cs @@ -0,0 +1,55 @@ +/* + * 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.Threading; +using Apache.Ignite.Core.Events; + +namespace Apache.Ignite.ExamplesDll.Events +{ + /// + /// Local event listener. + /// + public class LocalListener : IEventFilter + { + /** Сount of received events. */ + private int _eventsReceived; + + /// + /// Gets the count of received events. + /// + public int EventsReceived + { + get { return _eventsReceived; } + } + + /// + /// Determines whether specified event passes this filter. + /// + /// Node identifier. + /// Event. + /// Value indicating whether specified event passes this filter. + public bool Invoke(Guid nodeId, IEvent evt) + { + Interlocked.Increment(ref _eventsReceived); + + Console.WriteLine("Local listener received an event [evt={0}]", evt.Name); + + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/RemoteFilter.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/RemoteFilter.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/RemoteFilter.cs new file mode 100644 index 0000000..db3204a --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Events/RemoteFilter.cs @@ -0,0 +1,42 @@ +/* + * 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 Apache.Ignite.Core.Events; + +namespace Apache.Ignite.ExamplesDll.Events +{ + /// + /// Remote event filter. + /// + [Serializable] + public class RemoteFilter : IEventFilter + { + /// + /// Determines whether specified event passes this filter. + /// + /// Node identifier. + /// Event. + /// Value indicating whether specified event passes this filter. + public bool Invoke(Guid nodeId, IEvent evt) + { + Console.WriteLine("Remote filter received event [evt={0}]", evt.Name); + + return evt is JobEvent; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/LocalListener.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/LocalListener.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/LocalListener.cs new file mode 100644 index 0000000..7659bb4 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/LocalListener.cs @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Threading; +using Apache.Ignite.Core.Messaging; + +namespace Apache.Ignite.ExamplesDll.Messaging +{ + /// + /// Local message listener which signals countdown event on each received message. + /// + public class LocalListener : IMessageFilter + { + /** Countdown event. */ + private readonly CountdownEvent _countdown; + + /// + /// Initializes a new instance of the class. + /// + /// The countdown event. + public LocalListener(CountdownEvent countdown) + { + if (countdown == null) + throw new ArgumentNullException("countdown"); + + _countdown = countdown; + } + + /// + /// Receives a message and returns a value + /// indicating whether provided message and node id satisfy this predicate. + /// Returning false will unsubscribe this listener from future notifications. + /// + /// Node identifier. + /// Message. + /// Value indicating whether provided message and node id satisfy this predicate. + public bool Invoke(Guid nodeId, int message) + { + _countdown.Signal(); + + return !_countdown.IsSet; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteOrderedListener.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteOrderedListener.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteOrderedListener.cs new file mode 100644 index 0000000..8ae5ac1 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteOrderedListener.cs @@ -0,0 +1,54 @@ +/* + * 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 Apache.Ignite.Core; +using Apache.Ignite.Core.Messaging; +using Apache.Ignite.Core.Resource; + +namespace Apache.Ignite.ExamplesDll.Messaging +{ + /// + /// Listener for Ordered topic. + /// + [Serializable] + public class RemoteOrderedListener : IMessageFilter + { + /** Injected Ignite instance. */ + [InstanceResource] +#pragma warning disable 649 + private readonly IIgnite _ignite; +#pragma warning restore 649 + + /// + /// Receives a message and returns a value + /// indicating whether provided message and node id satisfy this predicate. + /// Returning false will unsubscribe this listener from future notifications. + /// + /// Node identifier. + /// Message. + /// Value indicating whether provided message and node id satisfy this predicate. + public bool Invoke(Guid nodeId, int message) + { + Console.WriteLine("Received ordered message [msg={0}, fromNodeId={1}]", message, nodeId); + + _ignite.GetCluster().ForNodeIds(nodeId).GetMessaging().Send(message, Topic.Ordered); + + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteUnorderedListener.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteUnorderedListener.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteUnorderedListener.cs new file mode 100644 index 0000000..166dbd6 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/RemoteUnorderedListener.cs @@ -0,0 +1,54 @@ +/* + * 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 Apache.Ignite.Core; +using Apache.Ignite.Core.Messaging; +using Apache.Ignite.Core.Resource; + +namespace Apache.Ignite.ExamplesDll.Messaging +{ + /// + /// Listener for Unordered topic. + /// + [Serializable] + public class RemoteUnorderedListener : IMessageFilter + { + /** Injected Ignite instance. */ + [InstanceResource] +#pragma warning disable 649 + private readonly IIgnite _ignite; +#pragma warning restore 649 + + /// + /// Receives a message and returns a value + /// indicating whether provided message and node id satisfy this predicate. + /// Returning false will unsubscribe this listener from future notifications. + /// + /// Node identifier. + /// Message. + /// Value indicating whether provided message and node id satisfy this predicate. + public bool Invoke(Guid nodeId, int message) + { + Console.WriteLine("Received unordered message [msg={0}, fromNodeId={1}]", message, nodeId); + + _ignite.GetCluster().ForNodeIds(nodeId).GetMessaging().Send(message, Topic.Unordered); + + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/Topic.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/Topic.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/Topic.cs new file mode 100644 index 0000000..bda0bfe --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Messaging/Topic.cs @@ -0,0 +1,28 @@ +/* + * 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. + */ + +namespace Apache.Ignite.ExamplesDll.Messaging +{ + /// + /// Message topics. + /// + public static class Topic + { + public const int Ordered = 1; + public const int Unordered = 2; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Account.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Account.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Account.cs new file mode 100644 index 0000000..8e247e3 --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Account.cs @@ -0,0 +1,60 @@ +/* + * 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; + +namespace Apache.Ignite.ExamplesDll.Portable +{ + /// + /// Account object. Used in transaction example. + /// + [Serializable] + public class Account + { + /// + /// Constructor. + /// + /// Account ID. + /// Account balance. + public Account(int id, decimal balance) + { + Id = id; + Balance = balance; + } + + /// + /// Account ID. + /// + public int Id { get; set; } + + /// + /// Account balance. + /// + public decimal Balance { get; set; } + + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + override public String ToString() + { + return string.Format("{0} [id={1}, balance={2}]", typeof(Account).Name, Id, Balance); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Address.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Address.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Address.cs new file mode 100644 index 0000000..ca069cb --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Address.cs @@ -0,0 +1,81 @@ +/* + * 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 Apache.Ignite.Core.Portable; + +namespace Apache.Ignite.ExamplesDll.Portable +{ + /// + /// Address. + /// + [Serializable] + public class Address : IPortableMarshalAware + { + /// + /// Constructor. + /// + /// Street. + /// ZIP code. + public Address(string street, int zip) + { + Street = street; + Zip = zip; + } + + /// + /// Street. + /// + public string Street { get; set; } + + /// + /// ZIP code. + /// + public int Zip { get; set; } + + /// + /// Writes this object to the given writer. + /// + /// Writer. + public void WritePortable(IPortableWriter writer) + { + writer.WriteString("street", Street); + writer.WriteInt("zip", Zip); + } + + /// + /// Reads this object from the given reader. + /// + /// Reader. + public void ReadPortable(IPortableReader reader) + { + Street = reader.ReadString("street"); + Zip = reader.ReadInt("zip"); + } + + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + override public string ToString() + { + return string.Format("{0} [street={1}, zip={2}]", typeof(Address).Name, Street, Zip); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/525d66df/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Employee.cs ---------------------------------------------------------------------- diff --git a/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Employee.cs b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Employee.cs new file mode 100644 index 0000000..7f4388d --- /dev/null +++ b/modules/platform/dotnet/Examples2/Apache.Ignite.ExamplesDll/Portable/Employee.cs @@ -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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Apache.Ignite.ExamplesDll.Portable +{ + /// + /// Employee. + /// + [Serializable] + public class Employee + { + /// + /// Constructor. + /// + /// Name. + /// Salary. + /// Address. + /// Departments. + public Employee(string name, long salary, Address address, ICollection departments) + { + Name = name; + Salary = salary; + Address = address; + Departments = departments; + } + + /// + /// Name. + /// + public string Name { get; set; } + + /// + /// Salary. + /// + public long Salary { get; set; } + + /// + /// Address. + /// + public Address Address { get; set; } + + /// + /// Departments. + /// + public ICollection Departments { get; set; } + + /// + /// Returns a string that represents the current object. + /// + /// + /// A string that represents the current object. + /// + override public string ToString() + { + return string.Format("{0} [name={1}, salary={2}, address={3}, departments={4}]", typeof(Employee).Name, + Name, Salary, Address, CollectionToString(Departments)); + } + + /// + /// Get string representation of collection. + /// + /// + private static string CollectionToString(ICollection col) + { + if (col == null) + return "null"; + + var elements = col.Any() + ? col.Select(x => x.ToString()).Aggregate((x, y) => x + ", " + y) + : string.Empty; + + return string.Format("[{0}]", elements); + } + } +}