ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [04/16] ignite git commit: IGNITE-4825 Inject resources from platform plugins
Date Fri, 17 Mar 2017 14:50:01 GMT
IGNITE-4825 Inject resources from platform plugins


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

Branch: refs/heads/ignite-4565-ddl
Commit: 4820c458fde5d641c114b2fda94061abe452a2d0
Parents: 8e5e3cb
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Wed Mar 15 17:41:41 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Wed Mar 15 17:41:41 2017 +0300

----------------------------------------------------------------------
 .../Plugin/PluginTest.cs                        | 24 ++++++++++++++++++++
 .../Impl/Plugin/PluginContext.cs                |  9 ++++++++
 .../Apache.Ignite.Core/Plugin/IPluginContext.cs |  8 +++++++
 3 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4820c458/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Plugin/PluginTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Plugin/PluginTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Plugin/PluginTest.cs
index 8256bba..7e766a0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Plugin/PluginTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Plugin/PluginTest.cs
@@ -25,6 +25,7 @@ namespace Apache.Ignite.Core.Tests.Plugin
     using Apache.Ignite.Core.Common;
     using Apache.Ignite.Core.Interop;
     using Apache.Ignite.Core.Plugin;
+    using Apache.Ignite.Core.Resource;
     using NUnit.Framework;
 
     /// <summary>
@@ -67,6 +68,7 @@ namespace Apache.Ignite.Core.Tests.Plugin
                 Assert.IsNotNull(ctx.Ignite);
                 Assert.AreEqual(cfg, ctx.IgniteConfiguration);
                 Assert.AreEqual("barbaz", ctx.PluginConfiguration.PluginProperty);
+                CheckResourceInjection(ctx);
 
                 var plugin2 = ignite.GetPlugin<TestIgnitePlugin>(TestIgnitePluginProvider.PluginName);
                 Assert.AreEqual(plugin, plugin2);
@@ -82,6 +84,21 @@ namespace Apache.Ignite.Core.Tests.Plugin
         }
 
         /// <summary>
+        /// Checks the resource injection.
+        /// </summary>
+        private static void CheckResourceInjection(IPluginContext<TestIgnitePluginConfiguration>
ctx)
+        {
+            var obj = new Injectee();
+
+            Assert.IsNull(obj.Ignite);
+
+            ctx.InjectResources(obj);
+
+            Assert.IsNotNull(obj.Ignite);
+            Assert.AreEqual(ctx.Ignite.Name, obj.Ignite.Name);
+        }
+
+        /// <summary>
         /// Checks the plugin target operations.
         /// </summary>
         private static void CheckPluginTarget(IPlatformTarget target, string expectedName,
@@ -314,5 +331,12 @@ namespace Apache.Ignite.Core.Tests.Plugin
                 PluginLog.Add(Name + ".Start");
             }
         }
+
+        private class Injectee
+        {
+            [InstanceResource]
+            // ReSharper disable once UnusedAutoPropertyAccessor.Local
+            public IIgnite Ignite { get; set; }
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4820c458/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Plugin/PluginContext.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Plugin/PluginContext.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Plugin/PluginContext.cs
index fd7033c..cc20cb3 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Plugin/PluginContext.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Plugin/PluginContext.cs
@@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Impl.Plugin
 {
     using Apache.Ignite.Core.Common;
     using Apache.Ignite.Core.Impl.Common;
+    using Apache.Ignite.Core.Impl.Resource;
     using Apache.Ignite.Core.Impl.Unmanaged;
     using Apache.Ignite.Core.Interop;
     using Apache.Ignite.Core.Plugin;
@@ -87,5 +88,13 @@ namespace Apache.Ignite.Core.Impl.Plugin
 
             _pluginProcessor.RegisterCallback(callbackId, callback);
         }
+
+        /** <inheritdoc /> */
+        public void InjectResources(object target)
+        {
+            IgniteArgumentCheck.NotNull(target, "target");
+
+            ResourceProcessor.Inject(target, _pluginProcessor.Ignite);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/4820c458/modules/platforms/dotnet/Apache.Ignite.Core/Plugin/IPluginContext.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Plugin/IPluginContext.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Plugin/IPluginContext.cs
index 03d130b..9349611 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Plugin/IPluginContext.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Plugin/IPluginContext.cs
@@ -19,6 +19,7 @@ namespace Apache.Ignite.Core.Plugin
 {
     using Apache.Ignite.Core.Common;
     using Apache.Ignite.Core.Interop;
+    using Apache.Ignite.Core.Resource;
 
     /// <summary>
     /// Plugin execution context.
@@ -64,5 +65,12 @@ namespace Apache.Ignite.Core.Plugin
         /// <param name="callbackId">Callback id.</param>
         /// <param name="callback">Callback delegate.</param>
         void RegisterCallback(long callbackId, PluginCallback callback);
+
+        /// <summary>
+        /// Injects resources into specified target:
+        /// populates members marked with <see cref="InstanceResourceAttribute"/>.
+        /// </summary>
+        /// <param name="target">Target object.</param>
+        void InjectResources(object target);
     }
 }
\ No newline at end of file


Mime
View raw message