-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IClusterConnectionStatusObserver support (#9145)
* Add in-process test cluster to simplify testing of services which are hosted entirely in-process * Add IClusterConnectionStatusObserver support --------- Co-authored-by: Reuben Bond <[email protected]>
- Loading branch information
1 parent
fdc1c5e
commit 546b739
Showing
15 changed files
with
1,604 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Orleans; | ||
|
||
/// <summary> | ||
/// Interface that receives notifications about the status of the cluster connection. | ||
/// </summary> | ||
public interface IClusterConnectionStatusObserver | ||
{ | ||
/// <summary> | ||
/// Notifies this observer that the number of connected gateways has changed. | ||
/// </summary> | ||
/// <param name="currentNumberOfGateways"> | ||
/// The current number of gateways. | ||
/// </param> | ||
/// <param name="previousNumberOfGateways"> | ||
/// The previous number of gateways. | ||
/// </param> | ||
/// <param name="connectionRecovered">Indicates whether a loss of connectivity has been resolved.</param> | ||
void NotifyGatewayCountChanged(int currentNumberOfGateways, int previousNumberOfGateways, bool connectionRecovered); | ||
|
||
/// <summary> | ||
/// Notifies this observer that the connection to the cluster has been lost. | ||
/// </summary> | ||
void NotifyClusterConnectionLost(); | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Orleans.Core/Runtime/ClusterConnectionStatusObserverAdaptor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Orleans.Runtime; | ||
|
||
internal sealed class ClusterConnectionStatusObserverAdaptor( | ||
IEnumerable<GatewayCountChangedHandler> gatewayCountChangedHandlers, | ||
IEnumerable<ConnectionToClusterLostHandler> connectionLostHandlers, | ||
ILogger<ClusterClient> logger) : IClusterConnectionStatusObserver | ||
{ | ||
private readonly ImmutableArray<GatewayCountChangedHandler> _gatewayCountChangedHandlers = gatewayCountChangedHandlers.ToImmutableArray(); | ||
private readonly ImmutableArray<ConnectionToClusterLostHandler> _connectionLostHandler = connectionLostHandlers.ToImmutableArray(); | ||
|
||
public void NotifyClusterConnectionLost() | ||
{ | ||
foreach (var handler in _connectionLostHandler) | ||
{ | ||
try | ||
{ | ||
handler(null, EventArgs.Empty); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError((int)ErrorCode.ClientError, ex, "Error sending cluster connection lost notification."); | ||
} | ||
} | ||
} | ||
|
||
public void NotifyGatewayCountChanged(int currentNumberOfGateways, int previousNumberOfGateways, bool connectionRecovered) | ||
{ | ||
var args = new GatewayCountChangedEventArgs(currentNumberOfGateways, previousNumberOfGateways); | ||
foreach (var handler in _gatewayCountChangedHandlers) | ||
{ | ||
try | ||
{ | ||
handler(null, args); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError((int)ErrorCode.ClientError, ex, "Error sending gateway count changed notification."); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.