This class is the main coordinator. It schedules work to be done for a particular subscription.
Inheritance: IDisposable
Example #1
0
        public MessageBus(IStringMinifier stringMinifier,
                          ILoggerFactory loggerFactory,
                          IPerformanceCounterManager performanceCounterManager,
                          IOptions<MessageBusOptions> optionsAccessor)
        {
            if (stringMinifier == null)
            {
                throw new ArgumentNullException("stringMinifier");
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            if (performanceCounterManager == null)
            {
                throw new ArgumentNullException("performanceCounterManager");
            }

            if (optionsAccessor == null)
            {
                throw new ArgumentNullException("optionsAccessor");
            }

            var options = optionsAccessor.Options;

            if (options.MessageBufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(Resources.Error_BufferSizeOutOfRange);
            }

            _stringMinifier = stringMinifier;
            _loggerFactory = loggerFactory;
            Counters = performanceCounterManager;
            _logger = _loggerFactory.CreateLogger<MessageBus>();
            _maxTopicsWithNoSubscriptions = options.MaxTopicsWithNoSubscriptions;

            _gcTimer = new Timer(_ => GarbageCollectTopics(), state: null, dueTime: _gcInterval, period: _gcInterval);

            _broker = new MessageBroker(Counters)
            {
                Logger = _logger
            };

            // The default message store size
            _messageStoreSize = (uint)options.MessageBufferSize;

            _topicTtl = options.TopicTTL;
            _createTopic = CreateTopic;
            _addEvent = AddEvent;
            _removeEvent = RemoveEvent;
            _disposeSubscription = o => DisposeSubscription(o);

            Topics = new TopicLookup();
        }
Example #2
0
        public MessageBus(IStringMinifier stringMinifier,
                          ITraceManager traceManager,
                          IPerformanceCounterManager performanceCounterManager,
                          IConfigurationManager configurationManager,
                          int maxTopicsWithNoSubscriptions)
        {
            if (stringMinifier == null)
            {
                throw new ArgumentNullException("stringMinifier");
            }

            if (traceManager == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            if (performanceCounterManager == null)
            {
                throw new ArgumentNullException("performanceCounterManager");
            }

            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            if (configurationManager.DefaultMessageBufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(Resources.Error_BufferSizeOutOfRange);
            }

            _stringMinifier = stringMinifier;
            _traceManager = traceManager;
            Counters = performanceCounterManager;
            _trace = _traceManager["SignalR.MessageBus"];
            _maxTopicsWithNoSubscriptions = maxTopicsWithNoSubscriptions;

            _gcTimer = new Timer(_ => GarbageCollectTopics(), state: null, dueTime: _gcInterval, period: _gcInterval);

            _broker = new MessageBroker(Counters)
            {
                Trace = Trace
            };

            // The default message store size
            _messageStoreSize = (uint)configurationManager.DefaultMessageBufferSize;

            _topicTtl = configurationManager.TopicTtl();

            Topics = new TopicLookup();
        }
Example #3
0
        public MessageBus(IStringMinifier stringMinifier,
                          ITraceManager traceManager,
                          IPerformanceCounterManager performanceCounterManager,
                          IConfigurationManager configurationManager,
                          int maxTopicsWithNoSubscriptions)
        {
            if (stringMinifier == null)
            {
                throw new ArgumentNullException("stringMinifier");
            }

            if (traceManager == null)
            {
                throw new ArgumentNullException("traceManager");
            }

            if (performanceCounterManager == null)
            {
                throw new ArgumentNullException("performanceCounterManager");
            }

            if (configurationManager == null)
            {
                throw new ArgumentNullException("configurationManager");
            }

            if (configurationManager.DefaultMessageBufferSize < 0)
            {
                throw new ArgumentOutOfRangeException(Resources.Error_BufferSizeOutOfRange);
            }

            _stringMinifier = stringMinifier;
            _traceManager = traceManager;
            Counters = performanceCounterManager;
            _trace = _traceManager["SignalR.MessageBus"];
            _maxTopicsWithNoSubscriptions = maxTopicsWithNoSubscriptions;

            _gcTimer = new Timer(_ => GarbageCollectTopics(), state: null, dueTime: _gcInterval, period: _gcInterval);

            _broker = new MessageBroker(Counters)
            {
                Trace = Trace
            };

            // The default message store size
            _messageStoreSize = (uint)configurationManager.DefaultMessageBufferSize;

            // Calculate keepAlive duration in context of ticks. This is necessary because keepAlive indicates how
            // many heartbeat intervals to wait before sending a keep alive.
            var keepAlive = configurationManager.KeepAlive * configurationManager.HeartbeatInterval.Ticks;

            // Keep topics alive for twice as long as we let connections to reconnect.
            // Also add twice the keepalive interval since clients might take a while to notice they are disconnected.
            // This should be a good enough estimate for how long until we should consider a topic dead.
            _topicTtl = TimeSpan.FromTicks((configurationManager.DisconnectTimeout.Ticks + keepAlive) * 2);

            Topics = new ConcurrentDictionary<string, Topic>();
        }
 public WorkContext(ISubscription subscription, MessageBroker broker)
 {
     Subscription = subscription;
     Broker = broker;
 }
Example #5
0
 public WorkContext(ISubscription subscription, MessageBroker broker)
 {
     Subscription = subscription;
     Broker       = broker;
 }