IGNITE-3548 .NET: Rename ILifecycleBean to ILifecycleHandler This closes #1694
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d66f27c5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d66f27c5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d66f27c5 Branch: refs/heads/ignite-4986 Commit: d66f27c5ac6728e5294282636784bde134cb16b0 Parents: 44a8f93 Author: Pavel Tupitsyn <[email protected]> Authored: Fri Apr 14 14:58:35 2017 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Fri Apr 14 14:58:35 2017 +0300 ---------------------------------------------------------------------- .../IgniteConfigurationSerializerTest.cs | 12 ++-- .../Apache.Ignite.Core.Tests/LifecycleTest.cs | 8 +-- .../Log/CustomLoggerTest.cs | 4 +- .../Apache.Ignite.Core.Tests/TestUtils.cs | 2 +- .../Apache.Ignite.Core.csproj | 4 +- .../Apache.Ignite.Core/IgniteConfiguration.cs | 6 +- .../IgniteConfigurationSection.xsd | 6 +- .../dotnet/Apache.Ignite.Core/Ignition.cs | 32 +++++----- .../dotnet/Apache.Ignite.Core/Impl/Ignite.cs | 16 ++--- .../Impl/LifecycleBeanHolder.cs | 66 -------------------- .../Impl/LifecycleHandlerHolder.cs | 66 ++++++++++++++++++++ .../Impl/Unmanaged/UnmanagedCallbacks.cs | 2 +- .../Lifecycle/ILifecycleBean.cs | 64 ------------------- .../Lifecycle/ILifecycleHandler.cs | 64 +++++++++++++++++++ .../Lifecycle/LifecycleEventType.cs | 2 +- .../Apache.Ignite/Service/IgniteService.cs | 6 +- .../Misc/LifecycleExample.cs | 12 ++-- 17 files changed, 186 insertions(+), 186 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs index b22b78d..d649637 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs @@ -86,9 +86,9 @@ namespace Apache.Ignite.Core.Tests </discoverySpi> <communicationSpi type='TcpCommunicationSpi' ackSendThreshold='33' idleConnectionTimeout='0:1:2' /> <jvmOptions><string>-Xms1g</string><string>-Xmx4g</string></jvmOptions> - <lifecycleBeans> - <iLifecycleBean type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+LifecycleBean' foo='15' /> - </lifecycleBeans> + <lifecycleHandlers> + <iLifecycleHandler type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+LifecycleBean' foo='15' /> + </lifecycleHandlers> <cacheConfiguration> <cacheConfiguration cacheMode='Replicated' readThrough='true' writeThrough='true' enableStatistics='true'> <queryEntities> @@ -150,7 +150,7 @@ namespace Apache.Ignite.Core.Tests Assert.AreEqual(7, ((TcpDiscoveryMulticastIpFinder) ((TcpDiscoverySpi) cfg.DiscoverySpi).IpFinder).AddressRequestAttempts); Assert.AreEqual(new[] { "-Xms1g", "-Xmx4g" }, cfg.JvmOptions); - Assert.AreEqual(15, ((LifecycleBean) cfg.LifecycleBeans.Single()).Foo); + Assert.AreEqual(15, ((LifecycleBean) cfg.LifecycleHandlers.Single()).Foo); Assert.AreEqual("testBar", ((NameMapper) cfg.BinaryConfiguration.NameMapper).Bar); Assert.AreEqual( "Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+FooClass, Apache.Ignite.Core.Tests", @@ -719,7 +719,7 @@ namespace Apache.Ignite.Core.Tests JvmDllPath = @"c:\jvm", JvmInitialMemoryMb = 1024, JvmMaxMemoryMb = 2048, - LifecycleBeans = new[] {new LifecycleBean(), new LifecycleBean()}, + LifecycleHandlers = new[] {new LifecycleBean(), new LifecycleBean()}, MetricsExpireTime = TimeSpan.FromSeconds(15), MetricsHistorySize = 45, MetricsLogFrequency = TimeSpan.FromDays(2), @@ -813,7 +813,7 @@ namespace Apache.Ignite.Core.Tests /// <summary> /// Test bean. /// </summary> - public class LifecycleBean : ILifecycleBean + public class LifecycleBean : ILifecycleHandler { /// <summary> /// Gets or sets the foo. http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs index 256ce46..7c9c10d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/LifecycleTest.cs @@ -83,7 +83,7 @@ namespace Apache.Ignite.Core.Tests { // 1. Test start events. IIgnite grid = Start(CfgNoBeans); - Assert.AreEqual(2, grid.GetConfiguration().LifecycleBeans.Count); + Assert.AreEqual(2, grid.GetConfiguration().LifecycleHandlers.Count); Assert.AreEqual(2, BeforeStartEvts.Count); CheckEvent(BeforeStartEvts[0], null, null, 0, null); @@ -123,7 +123,7 @@ namespace Apache.Ignite.Core.Tests { // 1. Test .Net start events. IIgnite grid = Start(CfgBeans); - Assert.AreEqual(2, grid.GetConfiguration().LifecycleBeans.Count); + Assert.AreEqual(2, grid.GetConfiguration().LifecycleHandlers.Count); Assert.AreEqual(4, BeforeStartEvts.Count); CheckEvent(BeforeStartEvts[0], null, null, 0, null); @@ -199,7 +199,7 @@ namespace Apache.Ignite.Core.Tests cfg.JvmOptions = TestUtils.TestJavaOptions(); cfg.SpringConfigUrl = cfgPath; - cfg.LifecycleBeans = new List<ILifecycleBean> { new Bean(), new Bean() }; + cfg.LifecycleHandlers = new List<ILifecycleHandler> { new Bean(), new Bean() }; return Ignition.Start(cfg); } @@ -239,7 +239,7 @@ namespace Apache.Ignite.Core.Tests } } - public class Bean : AbstractBean, ILifecycleBean + public class Bean : AbstractBean, ILifecycleHandler { [InstanceResource] public IIgnite Grid2; http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs index 68d107a..f8f7f7a 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Log/CustomLoggerTest.cs @@ -112,7 +112,7 @@ namespace Apache.Ignite.Core.Tests.Log Assert.Throws<IgniteException>(() => Ignition.Start(new IgniteConfiguration(GetConfigWithLogger()) { - LifecycleBeans = new[] {new FailBean()} + LifecycleHandlers = new[] {new FailBean()} })); var err = TestLogger.Entries.First(x => x.Level == LogLevel.Error); @@ -426,7 +426,7 @@ namespace Apache.Ignite.Core.Tests.Log /// <summary> /// Failing lifecycle bean. /// </summary> - private class FailBean : ILifecycleBean + private class FailBean : ILifecycleHandler { public void OnLifecycleEvent(LifecycleEventType evt) { http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs index 02df61a..945d0df 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/TestUtils.cs @@ -286,7 +286,7 @@ namespace Apache.Ignite.Core.Tests if (WaitForCondition(() => handleRegistry.Count == expectedCount, timeout)) return; - var items = handleRegistry.GetItems().Where(x => !(x.Value is LifecycleBeanHolder)).ToList(); + var items = handleRegistry.GetItems().Where(x => !(x.Value is LifecycleHandlerHolder)).ToList(); if (items.Any()) Assert.Fail("HandleRegistry is not empty in grid '{0}' (expected {1}, actual {2}):\n '{3}'", http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj index e8e9329..3ee705d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Apache.Ignite.Core.csproj @@ -368,7 +368,7 @@ <Compile Include="Impl\Handle\HandleRegistry.cs" /> <Compile Include="Impl\Handle\IHandle.cs" /> <Compile Include="Impl\IInteropCallback.cs" /> - <Compile Include="Impl\LifecycleBeanHolder.cs" /> + <Compile Include="Impl\LifecycleHandlerHolder.cs" /> <Compile Include="Impl\Memory\InteropExternalMemory.cs" /> <Compile Include="Impl\Memory\InteropMemoryUtils.cs" /> <Compile Include="Impl\Memory\IPlatformMemory.cs" /> @@ -460,7 +460,7 @@ <Compile Include="Log\LogLevel.cs" /> <Compile Include="Messaging\Package-Info.cs" /> <Compile Include="Package-Info.cs" /> - <Compile Include="Lifecycle\ILifecycleBean.cs" /> + <Compile Include="Lifecycle\ILifecycleHandler.cs" /> <Compile Include="Lifecycle\LifecycleEventType.cs" /> <Compile Include="Messaging\IMessageListener.cs" /> <Compile Include="Messaging\IMessaging.cs" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs index c40fc6e..a22c568 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfiguration.cs @@ -513,7 +513,7 @@ namespace Apache.Ignite.Core JvmOptions = cfg.JvmOptions; Assemblies = cfg.Assemblies; SuppressWarnings = cfg.SuppressWarnings; - LifecycleBeans = cfg.LifecycleBeans; + LifecycleHandlers = cfg.LifecycleHandlers; Logger = cfg.Logger; JvmInitialMemoryMb = cfg.JvmInitialMemoryMb; JvmMaxMemoryMb = cfg.JvmMaxMemoryMb; @@ -611,10 +611,10 @@ namespace Apache.Ignite.Core public bool SuppressWarnings { get; set; } /// <summary> - /// Lifecycle beans. + /// Lifecycle handlers. /// </summary> [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public ICollection<ILifecycleBean> LifecycleBeans { get; set; } + public ICollection<ILifecycleHandler> LifecycleHandlers { get; set; } /// <summary> /// Initial amount of memory in megabytes given to JVM. Maps to -Xms Java option. http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd index b5a431d..9859b2d 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd +++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd @@ -734,13 +734,13 @@ </xs:sequence> </xs:complexType> </xs:element> - <xs:element name="lifecycleBeans" minOccurs="0"> + <xs:element name="lifecycleHandlers" minOccurs="0"> <xs:annotation> - <xs:documentation>Lifecycle beans.</xs:documentation> + <xs:documentation>Lifecycle event handlers.</xs:documentation> </xs:annotation> <xs:complexType> <xs:sequence> - <xs:element maxOccurs="unbounded" name="iLifecycleBean"> + <xs:element maxOccurs="unbounded" name="iLifecycleHandler"> <xs:complexType> <xs:attribute name="type" type="xs:string" use="required"> <xs:annotation> http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs index f3b8c98..6bc3b34 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Ignition.cs @@ -323,7 +323,7 @@ namespace Apache.Ignite.Core PrepareConfiguration(reader, outStream, log); - PrepareLifecycleBeans(reader, outStream, handleRegistry); + PrepareLifecycleHandlers(reader, outStream, handleRegistry); PrepareAffinityFunctions(reader, outStream); @@ -369,42 +369,42 @@ namespace Apache.Ignite.Core } /// <summary> - /// Prepare lifecycle beans. + /// Prepare lifecycle handlers. /// </summary> /// <param name="reader">Reader.</param> /// <param name="outStream">Output stream.</param> /// <param name="handleRegistry">Handle registry.</param> - private static void PrepareLifecycleBeans(IBinaryRawReader reader, IBinaryStream outStream, + private static void PrepareLifecycleHandlers(IBinaryRawReader reader, IBinaryStream outStream, HandleRegistry handleRegistry) { - IList<LifecycleBeanHolder> beans = new List<LifecycleBeanHolder> + IList<LifecycleHandlerHolder> beans = new List<LifecycleHandlerHolder> { - new LifecycleBeanHolder(new InternalLifecycleBean()) // add internal bean for events + new LifecycleHandlerHolder(new InternalLifecycleHandler()) // add internal bean for events }; // 1. Read beans defined in Java. int cnt = reader.ReadInt(); for (int i = 0; i < cnt; i++) - beans.Add(new LifecycleBeanHolder(CreateObject<ILifecycleBean>(reader))); + beans.Add(new LifecycleHandlerHolder(CreateObject<ILifecycleHandler>(reader))); // 2. Append beans defined in local configuration. - ICollection<ILifecycleBean> nativeBeans = _startup.Configuration.LifecycleBeans; + ICollection<ILifecycleHandler> nativeBeans = _startup.Configuration.LifecycleHandlers; if (nativeBeans != null) { - foreach (ILifecycleBean nativeBean in nativeBeans) - beans.Add(new LifecycleBeanHolder(nativeBean)); + foreach (ILifecycleHandler nativeBean in nativeBeans) + beans.Add(new LifecycleHandlerHolder(nativeBean)); } // 3. Write bean pointers to Java stream. outStream.WriteInt(beans.Count); - foreach (LifecycleBeanHolder bean in beans) + foreach (LifecycleHandlerHolder bean in beans) outStream.WriteLong(handleRegistry.AllocateCritical(bean)); // 4. Set beans to STARTUP object. - _startup.LifecycleBeans = beans; + _startup.LifecycleHandlers = beans; } /// <summary> @@ -456,7 +456,7 @@ namespace Apache.Ignite.Core throw new IgniteException("Ignite with the same name already started: " + name); _startup.Ignite = new Ignite(_startup.Configuration, _startup.Name, interopProc, _startup.Marshaller, - _startup.LifecycleBeans, _startup.Callbacks); + _startup.LifecycleHandlers, _startup.Callbacks); } catch (Exception e) { @@ -744,9 +744,9 @@ namespace Apache.Ignite.Core internal UnmanagedCallbacks Callbacks { get; private set; } /// <summary> - /// Lifecycle beans. + /// Lifecycle handlers. /// </summary> - internal IList<LifecycleBeanHolder> LifecycleBeans { get; set; } + internal IList<LifecycleHandlerHolder> LifecycleHandlers { get; set; } /// <summary> /// Node name. @@ -770,9 +770,9 @@ namespace Apache.Ignite.Core } /// <summary> - /// Internal bean for event notification. + /// Internal handler for event notification. /// </summary> - private class InternalLifecycleBean : ILifecycleBean + private class InternalLifecycleHandler : ILifecycleHandler { /** */ #pragma warning disable 649 // unused field http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs index c38cd95..35950b6 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Ignite.cs @@ -78,8 +78,8 @@ namespace Apache.Ignite.Core.Impl /** Cached proxy. */ private readonly IgniteProxy _proxy; - /** Lifecycle beans. */ - private readonly IList<LifecycleBeanHolder> _lifecycleBeans; + /** Lifecycle handlers. */ + private readonly IList<LifecycleHandlerHolder> _lifecycleHandlers; /** Local node. */ private IClusterNode _locNode; @@ -108,22 +108,22 @@ namespace Apache.Ignite.Core.Impl /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> - /// <param name="lifecycleBeans">Lifecycle beans.</param> + /// <param name="lifecycleHandlers">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IUnmanagedTarget proc, Marshaller marsh, - IList<LifecycleBeanHolder> lifecycleBeans, UnmanagedCallbacks cbs) + IList<LifecycleHandlerHolder> lifecycleHandlers, UnmanagedCallbacks cbs) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); - Debug.Assert(lifecycleBeans != null); + Debug.Assert(lifecycleHandlers != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; - _lifecycleBeans = lifecycleBeans; + _lifecycleHandlers = lifecycleHandlers; _cbs = cbs; marsh.Ignite = this; @@ -173,7 +173,7 @@ namespace Apache.Ignite.Core.Impl { PluginProcessor.OnIgniteStart(); - foreach (var lifecycleBean in _lifecycleBeans) + foreach (var lifecycleBean in _lifecycleHandlers) lifecycleBean.OnStart(this); } @@ -389,7 +389,7 @@ namespace Apache.Ignite.Core.Impl /// </summary> internal void AfterNodeStop() { - foreach (var bean in _lifecycleBeans) + foreach (var bean in _lifecycleHandlers) bean.OnLifecycleEvent(LifecycleEventType.AfterNodeStop); var handler = Stopped; http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs deleted file mode 100644 index 7544bf1..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleBeanHolder.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Apache.Ignite.Core.Impl -{ - using Apache.Ignite.Core.Impl.Resource; - using Apache.Ignite.Core.Lifecycle; - - /// <summary> - /// Lifecycle bean holder. - /// </summary> - internal class LifecycleBeanHolder - { - /** Target bean. */ - private readonly ILifecycleBean _target; - - /** Whether start event was invoked. */ - private volatile bool _startEvt; - - /// <summary> - /// Constructor. - /// </summary> - /// <param name="target">Target bean.</param> - public LifecycleBeanHolder(ILifecycleBean target) - { - _target = target; - } - - /** <inheritDoc /> */ - public void OnLifecycleEvent(LifecycleEventType evt) - { - if (evt == LifecycleEventType.AfterNodeStart) - // This event cannot be propagated right away because at this point we - // do not have Ignite instance yet. So just schedule it. - _startEvt = true; - else - _target.OnLifecycleEvent(evt); - } - - /// <summary> - /// Grid start callback. - /// </summary> - /// <param name="grid">Ignite instance.</param> - internal void OnStart(Ignite grid) - { - ResourceProcessor.Inject(_target, grid); - - if (_startEvt) - _target.OnLifecycleEvent(LifecycleEventType.AfterNodeStart); - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleHandlerHolder.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleHandlerHolder.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleHandlerHolder.cs new file mode 100644 index 0000000..c2edf81 --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/LifecycleHandlerHolder.cs @@ -0,0 +1,66 @@ +/* + * 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.Core.Impl +{ + using Apache.Ignite.Core.Impl.Resource; + using Apache.Ignite.Core.Lifecycle; + + /// <summary> + /// Lifecycle bean holder. + /// </summary> + internal class LifecycleHandlerHolder + { + /** Target bean. */ + private readonly ILifecycleHandler _target; + + /** Whether start event was invoked. */ + private volatile bool _startEvt; + + /// <summary> + /// Constructor. + /// </summary> + /// <param name="target">Target bean.</param> + public LifecycleHandlerHolder(ILifecycleHandler target) + { + _target = target; + } + + /** <inheritDoc /> */ + public void OnLifecycleEvent(LifecycleEventType evt) + { + if (evt == LifecycleEventType.AfterNodeStart) + // This event cannot be propagated right away because at this point we + // do not have Ignite instance yet. So just schedule it. + _startEvt = true; + else + _target.OnLifecycleEvent(evt); + } + + /// <summary> + /// Grid start callback. + /// </summary> + /// <param name="grid">Ignite instance.</param> + internal void OnStart(Ignite grid) + { + ResourceProcessor.Inject(_target, grid); + + if (_startEvt) + _target.OnLifecycleEvent(LifecycleEventType.AfterNodeStart); + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs index fe0f9e6..2400390 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedCallbacks.cs @@ -805,7 +805,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged private long LifecycleOnEvent(long ptr, long evt, long unused, void* arg) { - var bean = _handleRegistry.Get<LifecycleBeanHolder>(ptr); + var bean = _handleRegistry.Get<LifecycleHandlerHolder>(ptr); bean.OnLifecycleEvent((LifecycleEventType) evt); http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleBean.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleBean.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleBean.cs deleted file mode 100644 index 06cb523..0000000 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleBean.cs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Apache.Ignite.Core.Lifecycle -{ - using Apache.Ignite.Core.Resource; - - /// <summary> - /// A bean that reacts to Ignite lifecycle events defined in <see cref="LifecycleEventType"/>. - /// Use this bean whenever you need to plug some custom logic before or after - /// Ignite startup and stopping routines. - /// <para /> - /// There are four events you can react to: - /// <list type="bullet"> - /// <item> - /// <term>BeforeNodeStart</term> - /// <description>Invoked before Ignite startup routine is initiated. Note that Ignite - /// is not available during this event, therefore if you injected an Ignite instance - /// via <see cref="InstanceResourceAttribute"/> attribute, you cannot - /// use it yet.</description> - /// </item> - /// <item> - /// <term>AfterNodeStart</term> - /// <description>Invoked right after Ignite has started. At this point, if you injected - /// an Ignite instance via <see cref="InstanceResourceAttribute"/> attribute, - /// you can start using it.</description> - /// </item> - /// <item> - /// <term>BeforeNodeStop</term> - /// <description>Invoked right before Ignite stop routine is initiated. Ignite is still - /// available at this stage, so if you injected an Ignite instance via - /// <see cref="InstanceResourceAttribute"/> attribute, you can use it. - /// </description> - /// </item> - /// <item> - /// <term>AfterNodeStop</term> - /// <description>Invoked right after Ignite has stopped. Note that Ignite is not available - /// during this event.</description> - /// </item> - /// </list> - /// </summary> - public interface ILifecycleBean - { - /// <summary> - /// This method is called when lifecycle event occurs. - /// </summary> - /// <param name="evt">Lifecycle event.</param> - void OnLifecycleEvent(LifecycleEventType evt); - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleHandler.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleHandler.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleHandler.cs new file mode 100644 index 0000000..bc4d66a --- /dev/null +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/ILifecycleHandler.cs @@ -0,0 +1,64 @@ +/* + * 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.Core.Lifecycle +{ + using Apache.Ignite.Core.Resource; + + /// <summary> + /// Handles lifecycle events defined in <see cref="LifecycleEventType"/>. + /// Use this interface whenever you need to plug some custom logic before or after + /// Ignite startup and stopping routines. + /// <para /> + /// There are four events you can react to: + /// <list type="bullet"> + /// <item> + /// <term>BeforeNodeStart</term> + /// <description>Invoked before Ignite startup routine is initiated. Note that Ignite + /// is not available during this event, therefore if you injected an Ignite instance + /// via <see cref="InstanceResourceAttribute"/> attribute, you cannot + /// use it yet.</description> + /// </item> + /// <item> + /// <term>AfterNodeStart</term> + /// <description>Invoked right after Ignite has started. At this point, if you injected + /// an Ignite instance via <see cref="InstanceResourceAttribute"/> attribute, + /// you can start using it.</description> + /// </item> + /// <item> + /// <term>BeforeNodeStop</term> + /// <description>Invoked right before Ignite stop routine is initiated. Ignite is still + /// available at this stage, so if you injected an Ignite instance via + /// <see cref="InstanceResourceAttribute"/> attribute, you can use it. + /// </description> + /// </item> + /// <item> + /// <term>AfterNodeStop</term> + /// <description>Invoked right after Ignite has stopped. Note that Ignite is not available + /// during this event.</description> + /// </item> + /// </list> + /// </summary> + public interface ILifecycleHandler + { + /// <summary> + /// This method is called when lifecycle event occurs. + /// </summary> + /// <param name="evt">Lifecycle event.</param> + void OnLifecycleEvent(LifecycleEventType evt); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/LifecycleEventType.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/LifecycleEventType.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/LifecycleEventType.cs index beea555..fca8bff 100644 --- a/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/LifecycleEventType.cs +++ b/modules/platforms/dotnet/Apache.Ignite.Core/Lifecycle/LifecycleEventType.cs @@ -21,7 +21,7 @@ namespace Apache.Ignite.Core.Lifecycle /// Ignite lifecycle event types. These events are used to notify lifecycle beans /// about changes in Ignite lifecycle state. /// <para /> - /// For more information and detailed examples refer to <see cref="ILifecycleBean"/> + /// For more information and detailed examples refer to <see cref="ILifecycleHandler"/> /// documentation. /// </summary> public enum LifecycleEventType http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/Apache.Ignite/Service/IgniteService.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/Apache.Ignite/Service/IgniteService.cs b/modules/platforms/dotnet/Apache.Ignite/Service/IgniteService.cs index 4517f71..839727e 100644 --- a/modules/platforms/dotnet/Apache.Ignite/Service/IgniteService.cs +++ b/modules/platforms/dotnet/Apache.Ignite/Service/IgniteService.cs @@ -32,7 +32,7 @@ namespace Apache.Ignite.Service /// <summary> /// Ignite windows service. /// </summary> - internal class IgniteService : ServiceBase, ILifecycleBean + internal class IgniteService : ServiceBase, ILifecycleHandler { /** Service name. */ public const string SvcName = "Apache Ignite.NET"; @@ -66,11 +66,11 @@ namespace Apache.Ignite.Service _cfg = cfg; // Subscribe to lifecycle events - var beans = _cfg.LifecycleBeans ?? new List<ILifecycleBean>(); + var beans = _cfg.LifecycleHandlers ?? new List<ILifecycleHandler>(); beans.Add(this); - _cfg.LifecycleBeans = beans; + _cfg.LifecycleHandlers = beans; } /** <inheritDoc /> */ http://git-wip-us.apache.org/repos/asf/ignite/blob/d66f27c5/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Misc/LifecycleExample.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Misc/LifecycleExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Misc/LifecycleExample.cs index 4831b2c..c30d60a 100644 --- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Misc/LifecycleExample.cs +++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Misc/LifecycleExample.cs @@ -26,7 +26,7 @@ namespace Apache.Ignite.Examples.Misc using Apache.Ignite.Core.Resource; /// <summary> - /// This example shows how to provide your own <see cref="ILifecycleBean"/> implementation + /// This example shows how to provide your own <see cref="ILifecycleHandler"/> implementation /// to be able to hook into Apache lifecycle. Example bean will output occurred lifecycle /// events to the console. /// <para /> @@ -48,7 +48,7 @@ namespace Apache.Ignite.Examples.Misc Console.WriteLine(">>> Lifecycle example started."); // Create new configuration. - var lifecycleExampleBean = new LifecycleExampleBean(); + var lifecycleAwareExample = new LifecycleHandlerExample(); var cfg = new IgniteConfiguration { @@ -59,7 +59,7 @@ namespace Apache.Ignite.Examples.Misc Endpoints = new[] {"127.0.0.1:47500"} } }, - LifecycleBeans = new List<ILifecycleBean> {lifecycleExampleBean} + LifecycleHandlers = new[] {lifecycleAwareExample} }; // Provide lifecycle bean to configuration. @@ -67,12 +67,12 @@ namespace Apache.Ignite.Examples.Misc { // Make sure that lifecycle bean was notified about Ignite startup. Console.WriteLine(); - Console.WriteLine(">>> Started (should be true): " + lifecycleExampleBean.Started); + Console.WriteLine(">>> Started (should be true): " + lifecycleAwareExample.Started); } // Make sure that lifecycle bean was notified about Ignite stop. Console.WriteLine(); - Console.WriteLine(">>> Started (should be false): " + lifecycleExampleBean.Started); + Console.WriteLine(">>> Started (should be false): " + lifecycleAwareExample.Started); Console.WriteLine(); Console.WriteLine(">>> Example finished, press any key to exit ..."); @@ -82,7 +82,7 @@ namespace Apache.Ignite.Examples.Misc /// <summary> /// Sample lifecycle bean implementation. /// </summary> - private class LifecycleExampleBean : ILifecycleBean + private class LifecycleHandlerExample : ILifecycleHandler { /** Auto-injected Ignite instance. */ [InstanceResource]
