Skip to content
Snippets Groups Projects
Commit 4ea8ce19 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

add GrpcEnvironment.ShuttingDown event

parent a39d9fa0
No related branches found
No related tags found
No related merge requests found
...@@ -43,13 +43,15 @@ namespace Grpc.Core ...@@ -43,13 +43,15 @@ namespace Grpc.Core
static readonly HashSet<Channel> registeredChannels = new HashSet<Channel>(); static readonly HashSet<Channel> registeredChannels = new HashSet<Channel>();
static readonly HashSet<Server> registeredServers = new HashSet<Server>(); static readonly HashSet<Server> registeredServers = new HashSet<Server>();
static EventHandler shuttingDown;
static ILogger logger = new NullLogger(); static ILogger logger = new NullLogger();
readonly GrpcThreadPool threadPool; readonly GrpcThreadPool threadPool;
readonly DebugStats debugStats = new DebugStats(); readonly DebugStats debugStats = new DebugStats();
readonly AtomicCounter cqPickerCounter = new AtomicCounter(); readonly AtomicCounter cqPickerCounter = new AtomicCounter();
bool isClosed; bool isShutdown;
/// <summary> /// <summary>
/// Returns a reference-counted instance of initialized gRPC environment. /// Returns a reference-counted instance of initialized gRPC environment.
...@@ -237,6 +239,21 @@ namespace Grpc.Core ...@@ -237,6 +239,21 @@ namespace Grpc.Core
} }
} }
/// <summary>
/// Occurs when <c>GrpcEnvironment</c> is about the start the shutdown logic.
/// </summary>
public static event EventHandler ShuttingDown
{
add
{
shuttingDown += value;
}
remove
{
shuttingDown -= value;
}
}
/// <summary> /// <summary>
/// Creates gRPC environment. /// Creates gRPC environment.
/// </summary> /// </summary>
...@@ -311,13 +328,16 @@ namespace Grpc.Core ...@@ -311,13 +328,16 @@ namespace Grpc.Core
/// </summary> /// </summary>
private async Task ShutdownAsync() private async Task ShutdownAsync()
{ {
if (isClosed) if (isShutdown)
{ {
throw new InvalidOperationException("Close has already been called"); throw new InvalidOperationException("ShutdownAsync has already been called");
} }
await Task.Run(() => shuttingDown.Invoke(this, null));
await threadPool.StopAsync().ConfigureAwait(false); await threadPool.StopAsync().ConfigureAwait(false);
GrpcNativeShutdown(); GrpcNativeShutdown();
isClosed = true; isShutdown = true;
debugStats.CheckOK(); debugStats.CheckOK();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment