Пример #1
0
        /// <summary>
        /// The amount of time a Topic should stay in memory after its last subscriber is removed.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static TimeSpan TopicTtl(this TransportOptions options)
        {
            // If the deep-alive is disabled, don't take it into account when calculating the topic TTL.
            var keepAliveTimeout = options.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((options.DisconnectTimeout.Ticks + keepAliveTimeout.Ticks) * 2));
        }
Пример #2
0
 /// <summary>
 /// The amount of time the client should wait without seeing a keep alive before trying to reconnect.
 /// </summary>
 public static TimeSpan?KeepAliveTimeout(this TransportOptions options)
 {
     if (options.KeepAlive != null)
     {
         return(TimeSpan.FromTicks(options.KeepAlive.Value.Ticks * MissedTimeoutsBeforeClientReconnect));
     }
     else
     {
         return(null);
     }
 }
Пример #3
0
 /// <summary>
 /// The interval between successively checking connection states.
 /// </summary>
 public static TimeSpan HeartbeatInterval(this TransportOptions options)
 {
     if (options.KeepAlive != null)
     {
         return(TimeSpan.FromTicks(options.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(options.DisconnectTimeout.Ticks / HeartBeatsPerDisconnectTimeout));
     }
 }
        /// <summary>
        /// Initializes and instance of the <see cref="TransportHeartbeat"/> class.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IDependencyResolver"/>.</param>
        public TransportHeartbeat(IOptions<SignalROptions> optionsAccessor,
                                  IPerformanceCounterManager counters,
                                  ILoggerFactory loggerFactory)
        {
            _transportOptions = optionsAccessor.Value.Transports;
            _counters = counters;
            _logger = loggerFactory.CreateLogger<TransportHeartbeat>();

            // REVIEW: When to dispose the timer?
            _timer = new Timer(Beat,
                               null,
                               _transportOptions.HeartbeatInterval(),
                               _transportOptions.HeartbeatInterval());
        }
 public SignalROptions()
 {
     Hubs = new HubOptions();
     MessageBus = new MessageBusOptions();
     Transports = new TransportOptions();
 }