imported signalr 1.1.3 into NzbDrone.

This commit is contained in:
kayone
2013-11-21 21:26:57 -08:00
parent 891443e05d
commit 0e623e7ce4
236 changed files with 20490 additions and 35 deletions
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
using System;
namespace Microsoft.AspNet.SignalR.Configuration
{
internal static class ConfigurationExtensions
{
public const int MissedTimeoutsBeforeClientReconnect = 2;
public const int HeartBeatsPerKeepAlive = 2;
public const int HeartBeatsPerDisconnectTimeout = 6;
/// <summary>
/// The amount of time the client should wait without seeing a keep alive before trying to reconnect.
/// </summary>
public static TimeSpan? KeepAliveTimeout(this IConfigurationManager config)
{
if (config.KeepAlive != null)
{
return TimeSpan.FromTicks(config.KeepAlive.Value.Ticks * MissedTimeoutsBeforeClientReconnect);
}
else
{
return null;
}
}
/// <summary>
/// The interval between successively checking connection states.
/// </summary>
public static TimeSpan HeartbeatInterval(this IConfigurationManager config)
{
if (config.KeepAlive != null)
{
return TimeSpan.FromTicks(config.KeepAlive.Value.Ticks / HeartBeatsPerKeepAlive);
}
else
{
// If KeepAlives are disabled, have the heartbeat run at the same rate it would if the KeepAlive was
// kept at the default value.
return TimeSpan.FromTicks(config.DisconnectTimeout.Ticks / HeartBeatsPerDisconnectTimeout);
}
}
/// <summary>
/// The amount of time a Topic should stay in memory after its last subscriber is removed.
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public static TimeSpan TopicTtl(this IConfigurationManager config)
{
// If the deep-alive is disabled, don't take it into account when calculating the topic TTL.
var keepAliveTimeout = config.KeepAliveTimeout() ?? TimeSpan.Zero;
// Keep topics alive for twice as long as we let connections to reconnect. (The DisconnectTimeout)
// Also add twice the keep-alive timeout since clients might take a while to notice they are disconnected.
// This should be a very conservative estimate for how long we must wait before considering a topic dead.
return TimeSpan.FromTicks((config.DisconnectTimeout.Ticks + keepAliveTimeout.Ticks) * 2);
}
}
}
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
using System;
namespace Microsoft.AspNet.SignalR.Configuration
{
public class DefaultConfigurationManager : IConfigurationManager
{
// The below effectively sets the minimum heartbeat to once per second.
// if _minimumKeepAlive != 2 seconds, update the ArguementOutOfRanceExceptionMessage below
private static readonly TimeSpan _minimumKeepAlive = TimeSpan.FromSeconds(2);
// if _minimumKeepAlivesPerDisconnectTimeout != 3, update the ArguementOutOfRanceExceptionMessage below
private const int _minimumKeepAlivesPerDisconnectTimeout = 3;
// if _minimumDisconnectTimeout != 6 seconds, update the ArguementOutOfRanceExceptionMessage below
private static readonly TimeSpan _minimumDisconnectTimeout = TimeSpan.FromTicks(_minimumKeepAlive.Ticks * _minimumKeepAlivesPerDisconnectTimeout);
private bool _keepAliveConfigured;
private TimeSpan? _keepAlive;
private TimeSpan _disconnectTimeout;
public DefaultConfigurationManager()
{
ConnectionTimeout = TimeSpan.FromSeconds(110);
DisconnectTimeout = TimeSpan.FromSeconds(30);
DefaultMessageBufferSize = 1000;
}
// TODO: Should we guard against negative TimeSpans here like everywhere else?
public TimeSpan ConnectionTimeout
{
get;
set;
}
public TimeSpan DisconnectTimeout
{
get
{
return _disconnectTimeout;
}
set
{
if (value < _minimumDisconnectTimeout)
{
throw new ArgumentOutOfRangeException("value", Resources.Error_DisconnectTimeoutMustBeAtLeastSixSeconds);
}
if (_keepAliveConfigured)
{
throw new InvalidOperationException(Resources.Error_DisconnectTimeoutCannotBeConfiguredAfterKeepAlive);
}
_disconnectTimeout = value;
_keepAlive = TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout);
}
}
public TimeSpan? KeepAlive
{
get
{
return _keepAlive;
}
set
{
if (value < _minimumKeepAlive)
{
throw new ArgumentOutOfRangeException("value", Resources.Error_KeepAliveMustBeGreaterThanTwoSeconds);
}
if (value > TimeSpan.FromTicks(_disconnectTimeout.Ticks / _minimumKeepAlivesPerDisconnectTimeout))
{
throw new ArgumentOutOfRangeException("value", Resources.Error_KeepAliveMustBeNoMoreThanAThirdOfTheDisconnectTimeout);
}
_keepAlive = value;
_keepAliveConfigured = true;
}
}
public int DefaultMessageBufferSize
{
get;
set;
}
}
}
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
using System;
namespace Microsoft.AspNet.SignalR.Configuration
{
/// <summary>
/// Provides access to server configuration.
/// </summary>
public interface IConfigurationManager
{
/// <summary>
/// Gets or sets a <see cref="TimeSpan"/> representing the amount of time to leave a connection open before timing out.
/// </summary>
TimeSpan ConnectionTimeout { get; set; }
/// <summary>
/// Gets or sets a <see cref="TimeSpan"/> representing the amount of time to wait after a connection goes away before raising the disconnect event.
/// </summary>
TimeSpan DisconnectTimeout { get; set; }
/// <summary>
/// Gets or sets a <see cref="TimeSpan"/> representing the amount of time between send keep alive messages.
/// If enabled, this value must be at least two seconds. Set to null to disable.
/// </summary>
TimeSpan? KeepAlive { get; set; }
/// <summary>
/// Gets of sets the number of messages to buffer for a specific signal.
/// </summary>
int DefaultMessageBufferSize { get; set; }
}
}