Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ServiceEndpoint related codes #2094

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Microsoft.Azure.SignalR.Common/Endpoints/EndpointType.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Azure.SignalR;

namespace Microsoft.Azure.SignalR
public enum EndpointType
{
public enum EndpointType
{
Primary,
Secondary
}
Primary,

Secondary
}
106 changes: 53 additions & 53 deletions src/Microsoft.Azure.SignalR.Common/Endpoints/HubServiceEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,60 @@
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Azure.SignalR
namespace Microsoft.Azure.SignalR;

internal class HubServiceEndpoint : ServiceEndpoint
{
internal class HubServiceEndpoint : ServiceEndpoint
private static long s_currentIndex;

private readonly ServiceEndpoint _endpoint;

private readonly long _uniqueIndex;

private TaskCompletionSource<bool> _scaleTcs;

public string Hub { get; }

public override string Name => _endpoint.Name;

public IServiceEndpointProvider Provider { get; }

public IServiceConnectionContainer ConnectionContainer { get; set; }

/// <summary>
/// Task waiting for HubServiceEndpoint turn ready when live add/remove endpoint
/// </summary>
public Task ScaleTask => _scaleTcs?.Task ?? Task.CompletedTask;

public long UniqueIndex => _uniqueIndex;

// Value here is not accurate.
internal override bool PendingReload => throw new NotSupportedException();

public HubServiceEndpoint(string hub,
IServiceEndpointProvider provider,
ServiceEndpoint endpoint) : base(endpoint)
{
Hub = hub;
Provider = provider;
_endpoint = endpoint;
_scaleTcs = endpoint.PendingReload ? new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously) : null;
_uniqueIndex = Interlocked.Increment(ref s_currentIndex);
}

public void CompleteScale()
{
_scaleTcs?.TrySetResult(true);
}

// When remove an existing HubServiceEndpoint.
public void ResetScale()
{
_scaleTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
}

public override string ToString()
{
private readonly ServiceEndpoint _endpoint;
private readonly long _uniqueIndex;
private static long s_currentIndex;
private TaskCompletionSource<bool> _scaleTcs;

public HubServiceEndpoint(
string hub,
IServiceEndpointProvider provider,
ServiceEndpoint endpoint
) : base(endpoint)
{
Hub = hub;
Provider = provider;
_endpoint = endpoint;
_scaleTcs = endpoint.PendingReload ? new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously) : null;
_uniqueIndex = Interlocked.Increment(ref s_currentIndex);
}

public string Hub { get; }

public override string Name => _endpoint.Name;

public IServiceEndpointProvider Provider { get; }

public IServiceConnectionContainer ConnectionContainer { get; set; }

/// <summary>
/// Task waiting for HubServiceEndpoint turn ready when live add/remove endpoint
/// </summary>
public Task ScaleTask => _scaleTcs?.Task ?? Task.CompletedTask;

public void CompleteScale()
{
_scaleTcs?.TrySetResult(true);
}

// When remove an existing HubServiceEndpoint.
public void ResetScale()
{
_scaleTcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
}

public long UniqueIndex => _uniqueIndex;

public override string ToString()
{
return base.ToString() + $"(hub={Hub})";
}

// Value here is not accurate.
internal override bool PendingReload => throw new NotSupportedException();
return base.ToString() + $"(hub={Hub})";
}
}
41 changes: 20 additions & 21 deletions src/Microsoft.Azure.SignalR.Common/Endpoints/ServerStickyMode.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.Azure.SignalR
namespace Microsoft.Azure.SignalR;

/// <summary>
/// Specifies the mode for server sticky, when client is always routed to the server which it first /negotiate with, we call it "server sticky mode".
/// </summary>
public enum ServerStickyMode
{
/// <summary>
/// Specifies the mode for server sticky, when client is always routed to the server which it first /negotiate with, we call it "server sticky mode".
/// We the server sticky mode is disabled, it picks the server connection by some algorithm
/// In general, local server connection first
/// least client connections routed server connection first
/// </summary>
public enum ServerStickyMode
{
/// <summary>
/// We the server sticky mode is disabled, it picks the server connection by some algorithm
/// In general, local server connection first
/// least client connections routed server connection first
/// </summary>
Disabled = 0,
Disabled = 0,

///// <summary>
///// We will try to find the server it /neogitate with from local, if that server is connected to this runtime instance, we choose that server
///// Otherwise, we fallback to local existed server
///// </summary>
Preferred = 1,
///// <summary>
///// We will try to find the server it /neogitate with from local, if that server is connected to this runtime instance, we choose that server
///// Otherwise, we fallback to local existed server
///// </summary>
Preferred = 1,

/// <summary>
/// We will try to find the server it /negotiate with from both local and global route table, it the server is not connected, throw,
/// If it is globally routed, this request will be always globally routed
/// </summary>
Required = 2,
}
/// <summary>
/// We will try to find the server it /negotiate with from both local and global route table, it the server is not connected, throw,
/// If it is globally routed, this request will be always globally routed
/// </summary>
Required = 2,
}
Loading
Loading