From 3f632ea20011c5363ae4afce9feaa6201b069d63 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Mon, 28 Oct 2019 12:45:28 +0100 Subject: [PATCH 1/4] add shutdown event for plugins --- neo/NeoSystem.cs | 1 + neo/Plugins/Plugin.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index 867d4e4201..b18f1119e4 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -44,6 +44,7 @@ public void Dispose() { RpcServer?.Dispose(); EnsureStoped(LocalNode); + Plugin.NotifyPluginsToShutdown(); // Dispose will call ActorSystem.Terminate() ActorSystem.Dispose(); ActorSystem.WhenTerminated.Wait(); diff --git a/neo/Plugins/Plugin.cs b/neo/Plugins/Plugin.cs index aa04b0778d..35fe02a518 100644 --- a/neo/Plugins/Plugin.cs +++ b/neo/Plugins/Plugin.cs @@ -62,6 +62,10 @@ protected virtual void OnPluginsLoaded() { } + protected virtual void OnShutdown() + { + } + private static void ConfigWatcher_Changed(object sender, FileSystemEventArgs e) { foreach (var plugin in Plugins) @@ -112,6 +116,12 @@ internal static void NotifyPluginsLoadedAfterSystemConstructed() plugin.OnPluginsLoaded(); } + internal static void NotifyPluginsToShutdown() + { + foreach (var plugin in Plugins) + plugin.OnShutdown(); + } + protected void Log(string message, LogLevel level = LogLevel.Info) { Log($"{nameof(Plugin)}:{Name}", level, message); From ce807bab60996d65b391f5c3e1d7ee2ce20603c5 Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Tue, 29 Oct 2019 08:06:08 +0100 Subject: [PATCH 2/4] use IDisposable --- neo/NeoSystem.cs | 5 ++++- neo/Plugins/Plugin.cs | 16 +++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index b18f1119e4..4cd15a24bc 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -44,7 +44,10 @@ public void Dispose() { RpcServer?.Dispose(); EnsureStoped(LocalNode); - Plugin.NotifyPluginsToShutdown(); + foreach (var p in Plugin.Plugins) + { + p.Dispose(); + } // Dispose will call ActorSystem.Terminate() ActorSystem.Dispose(); ActorSystem.WhenTerminated.Wait(); diff --git a/neo/Plugins/Plugin.cs b/neo/Plugins/Plugin.cs index 35fe02a518..14345d9de1 100644 --- a/neo/Plugins/Plugin.cs +++ b/neo/Plugins/Plugin.cs @@ -8,7 +8,7 @@ namespace Neo.Plugins { - public abstract class Plugin + public abstract class Plugin : IDisposable { public static readonly List Plugins = new List(); private static readonly List Loggers = new List(); @@ -62,10 +62,6 @@ protected virtual void OnPluginsLoaded() { } - protected virtual void OnShutdown() - { - } - private static void ConfigWatcher_Changed(object sender, FileSystemEventArgs e) { foreach (var plugin in Plugins) @@ -116,12 +112,6 @@ internal static void NotifyPluginsLoadedAfterSystemConstructed() plugin.OnPluginsLoaded(); } - internal static void NotifyPluginsToShutdown() - { - foreach (var plugin in Plugins) - plugin.OnShutdown(); - } - protected void Log(string message, LogLevel level = LogLevel.Info) { Log($"{nameof(Plugin)}:{Name}", level, message); @@ -179,5 +169,9 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven return null; } } + + public virtual void Dispose() + { + } } } From fbd7ba074ed11ea57d52dc549732174bd70f6e0c Mon Sep 17 00:00:00 2001 From: Erik van den Brink Date: Tue, 29 Oct 2019 08:54:15 +0100 Subject: [PATCH 3/4] dispose plugins first --- neo/NeoSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index 4cd15a24bc..b172f56999 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -42,12 +42,12 @@ public NeoSystem(Store store) public void Dispose() { - RpcServer?.Dispose(); - EnsureStoped(LocalNode); foreach (var p in Plugin.Plugins) { p.Dispose(); } + RpcServer?.Dispose(); + EnsureStoped(LocalNode); // Dispose will call ActorSystem.Terminate() ActorSystem.Dispose(); ActorSystem.WhenTerminated.Wait(); From 59c94cab69c8f5ee126850f8d9a3563588b93c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Tue, 29 Oct 2019 09:45:47 -0300 Subject: [PATCH 4/4] Removing brackets --- neo/NeoSystem.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index b172f56999..9265f47645 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -43,9 +43,7 @@ public NeoSystem(Store store) public void Dispose() { foreach (var p in Plugin.Plugins) - { p.Dispose(); - } RpcServer?.Dispose(); EnsureStoped(LocalNode); // Dispose will call ActorSystem.Terminate()