-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dbc6d1
commit dc9c668
Showing
7 changed files
with
127 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace Microsoft.Azure.SignalR | ||
{ | ||
public class GracefulShutdownOptions | ||
{ | ||
/// <summary> | ||
/// Specifies the timeout of a graceful shutdown process (in seconds). | ||
/// Default value is 30 seconds. | ||
/// </summary> | ||
public TimeSpan Timeout { get; set; } = Constants.Periods.DefaultShutdownTimeout; | ||
private Dictionary<string, List<object>> _dict = new Dictionary<string, List<object>>(); | ||
|
||
/// <summary> | ||
/// Specifies if the client-connection assigned to this server can be migrated to another server. | ||
/// Default value is 0. | ||
/// 1: Migrate client-connection if the server was shutdown gracefully. | ||
/// </summary> | ||
public GracefulShutdownMode Mode { get; set; } = GracefulShutdownMode.Off; | ||
|
||
/// <summary> | ||
/// Specifies the timeout of a graceful shutdown process (in seconds). | ||
/// Default value is 30 seconds. | ||
/// </summary> | ||
public TimeSpan Timeout { get; set; } = Constants.Periods.DefaultShutdownTimeout; | ||
|
||
private List<object> GetMethods<THub>() { | ||
var name = typeof(THub).Name; | ||
if (!_dict.ContainsKey(typeof(THub).Name)) | ||
{ | ||
_dict.Add(name, new List<object>()); | ||
} | ||
return _dict[name]; | ||
} | ||
|
||
public void Add<THub>(Func<IHubContext<THub>, Task> func) where THub : Hub | ||
{ | ||
GetMethods<THub>().Add(func); | ||
} | ||
|
||
public void Add<THub>(Action<IHubContext<THub>> action) where THub : Hub | ||
{ | ||
GetMethods<THub>().Add(action); | ||
} | ||
|
||
public void Add<THub>(Func<Task> func) | ||
{ | ||
GetMethods<THub>().Add(func); | ||
} | ||
|
||
public void Add<THub>(Action action) | ||
{ | ||
GetMethods<THub>().Add(action); | ||
} | ||
|
||
internal async Task OnShutdown<THub>(IHubContext<THub> context) where THub : Hub | ||
{ | ||
var name = typeof(THub).Name; | ||
if (_dict.TryGetValue(name, out var methods)) | ||
{ | ||
foreach (var method in methods) | ||
{ | ||
if (method is Action<IHubContext<THub>> action) | ||
{ | ||
action(context); | ||
} | ||
else if (method is Action action2) | ||
{ | ||
action2(); | ||
} | ||
else if (method is Func<IHubContext<THub>, Task> func) | ||
{ | ||
await func(context); | ||
} | ||
else if (method is Func<Task> func2) | ||
{ | ||
await func2(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/Microsoft.Azure.SignalR/ServerConnections/ServiceConnectionManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters