Skip to content

Commit

Permalink
add shutdown event for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Oct 28, 2019
1 parent cd85039 commit 3f632ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void Dispose()
{
RpcServer?.Dispose();
EnsureStoped(LocalNode);
Plugin.NotifyPluginsToShutdown();
// Dispose will call ActorSystem.Terminate()
ActorSystem.Dispose();
ActorSystem.WhenTerminated.Wait();
Expand Down
10 changes: 10 additions & 0 deletions neo/Plugins/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3f632ea

Please sign in to comment.