Beispiel #1
0
        public Connection(IMessageBus newMessageBus,
                          IJsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IEnumerable<string> signals,
                          IEnumerable<string> groups,
                          ITraceManager traceManager,
                          IAckHandler ackHandler,
                          IPerformanceCounterWriter performanceCounterWriter)
        {
            _bus = newMessageBus;
            _serializer = jsonSerializer;
            _baseSignal = baseSignal;
            _connectionId = connectionId;
            _signals = new HashSet<string>(signals);
            _groups = new SafeSet<string>(groups);
            _traceSource = new Lazy<TraceSource>(() => traceManager["SignalR.Connection"]);
            _ackHandler = ackHandler;

            var counters = performanceCounterWriter;
            _msgsRecTotalCounter = counters.GetCounter(PerformanceCounters.ConnectionMessagesReceivedTotal);
            _msgsRecPerSecCounter = counters.GetCounter(PerformanceCounters.ConnectionMessagesReceivedPerSec);
            _msgsSentTotalCounter = counters.GetCounter(PerformanceCounters.ConnectionMessagesSentTotal);
            _msgsSentPerSecCounter = counters.GetCounter(PerformanceCounters.ConnectionMessagesSentPerSec);
        }
Beispiel #2
0
        public Connection(IMessageBus newMessageBus,
                          IJsonSerializer jsonSerializer,
                          string baseSignal,
                          string connectionId,
                          IEnumerable <string> signals,
                          IEnumerable <string> groups,
                          ITraceManager traceManager,
                          IAckHandler ackHandler,
                          IPerformanceCounterWriter performanceCounterWriter)
        {
            _bus          = newMessageBus;
            _serializer   = jsonSerializer;
            _baseSignal   = baseSignal;
            _connectionId = connectionId;
            _signals      = new HashSet <string>(signals);
            _groups       = new SafeSet <string>(groups);
            _traceSource  = new Lazy <TraceSource>(() => traceManager["SignalR.Connection"]);
            _ackHandler   = ackHandler;

            var counters = performanceCounterWriter;

            _msgsRecTotalCounter   = counters.GetCounter(PerformanceCounters.ConnectionMessagesReceivedTotal);
            _msgsRecPerSecCounter  = counters.GetCounter(PerformanceCounters.ConnectionMessagesReceivedPerSec);
            _msgsSentTotalCounter  = counters.GetCounter(PerformanceCounters.ConnectionMessagesSentTotal);
            _msgsSentPerSecCounter = counters.GetCounter(PerformanceCounters.ConnectionMessagesSentPerSec);
        }
        public ScaleoutSubscription(string identity,
                                    IEnumerable<string> eventKeys,
                                    string cursor,
                                    ConcurrentDictionary<string, Linktionary<ulong, ScaleoutMapping>> streamMappings,
                                    Func<MessageResult, Task<bool>> callback,
                                    int maxMessages,
                                    IPerformanceCounterWriter counters)
            : base(identity, eventKeys, callback, maxMessages, counters)
        {
            _streamMappings = streamMappings;

            IEnumerable<Cursor> cursors = null;

            if (cursor == null)
            {
                cursors = from key in _streamMappings.Keys
                          select new Cursor
                          {
                              Key = key,
                              Id = GetCursorId(key)
                          };
            }
            else
            {
                cursors = Cursor.GetCursors(cursor);
            }

            _cursors = new List<Cursor>(cursors);
        }
Beispiel #4
0
        public ScaleoutSubscription(string identity,
                                    IEnumerable <string> eventKeys,
                                    string cursor,
                                    ConcurrentDictionary <string, Linktionary <ulong, ScaleoutMapping> > streamMappings,
                                    Func <MessageResult, Task <bool> > callback,
                                    int maxMessages,
                                    IPerformanceCounterWriter counters)
            : base(identity, eventKeys, callback, maxMessages, counters)
        {
            _streams = streamMappings;

            IEnumerable <Cursor> cursors = null;

            if (cursor == null)
            {
                cursors = from key in _streams.Keys
                          select new Cursor
                {
                    Key = key,
                    Id  = GetCursorId(key)
                };
            }
            else
            {
                cursors = Cursor.GetCursors(cursor);
            }

            _cursors = new List <Cursor>(cursors);
        }
 public LongPollingTransport(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterWriter performanceCounterWriter)
     : base(context, jsonSerializer, heartBeat, performanceCounterWriter)
 {
     _jsonSerializer = jsonSerializer;
     var counters = performanceCounterWriter;
     _connConnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsConnected);
     _connReconnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsReconnected);
 }
 public WebSocketTransport(HostContext context, 
                           IJsonSerializer serializer, 
                           ITransportHeartBeat heartBeat,
                           IPerformanceCounterWriter performanceCounterWriter)
     : base(context, serializer, heartBeat, performanceCounterWriter)
 {
     _context = context;
 }
 public WebSocketTransport(HostContext context,
                           IJsonSerializer serializer,
                           ITransportHeartBeat heartBeat,
                           IPerformanceCounterWriter performanceCounterWriter)
     : base(context, serializer, heartBeat, performanceCounterWriter)
 {
     _context = context;
 }
        public MessageBroker(ConcurrentDictionary<string, Topic> topics, IPerformanceCounterWriter performanceCounterWriter)
        {
            _topics = topics;

            _timer = new Timer(_ => OnTimer(), state: null, dueTime: CheckWorkInterval, period: CheckWorkInterval);

            var counters = performanceCounterWriter;
            _allocatedWorkersCounter = counters.GetCounter(PerformanceCounters.MessageBusAllocatedWorkers);
            _busyWorkersCounter = counters.GetCounter(PerformanceCounters.MessageBusBusyWorkers);
        }
Beispiel #9
0
        public MessageBroker(ConcurrentDictionary <string, Topic> topics, IPerformanceCounterWriter performanceCounterWriter)
        {
            _topics = topics;

            _timer = new Timer(_ => OnTimer(), state: null, dueTime: CheckWorkInterval, period: CheckWorkInterval);

            var counters = performanceCounterWriter;

            _allocatedWorkersCounter = counters.GetCounter(PerformanceCounters.MessageBusAllocatedWorkers);
            _busyWorkersCounter      = counters.GetCounter(PerformanceCounters.MessageBusBusyWorkers);
        }
        public DefaultSubscription(string identity,
                                   IEnumerable <string> eventKeys,
                                   IDictionary <string, Topic> topics,
                                   string cursor,
                                   Func <MessageResult, Task <bool> > callback,
                                   int maxMessages,
                                   IPerformanceCounterWriter counters) :
            base(identity, eventKeys, callback, maxMessages, counters)
        {
            IEnumerable <Cursor> cursors = null;

            if (cursor == null)
            {
                cursors = from key in eventKeys
                          select new Cursor
                {
                    Key = key,
                    Id  = GetMessageId(topics, key)
                };
            }
            else
            {
                cursors = Cursor.GetCursors(cursor);
            }

            _cursors      = new List <Cursor>(cursors);
            _cursorTopics = new List <Topic>();

            if (!String.IsNullOrEmpty(cursor))
            {
                // Update all of the cursors so we're within the range
                for (int i = _cursors.Count - 1; i >= 0; i--)
                {
                    Cursor c = _cursors[i];
                    Topic  topic;
                    if (!eventKeys.Contains(c.Key))
                    {
                        _cursors.Remove(c);
                    }
                    else if (topics.TryGetValue(_cursors[i].Key, out topic) && _cursors[i].Id > topic.Store.GetMessageCount())
                    {
                        UpdateCursor(c.Key, 0);
                    }
                }
            }

            // Add dummy entries so they can be filled in
            for (int i = 0; i < _cursors.Count; i++)
            {
                _cursorTopics.Add(null);
            }
        }
Beispiel #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="traceManager"></param>
        public MessageBus(ITraceManager traceManager, IPerformanceCounterWriter performanceCounterWriter)
        {
            _trace = traceManager;

            _counters = performanceCounterWriter;
            _msgsTotalCounter = _counters.GetCounter(PerformanceCounters.MessageBusMessagesPublishedTotal);
            _msgsPerSecCounter = _counters.GetCounter(PerformanceCounters.MessageBusMessagesPublishedPerSec);

            _engine = new Engine(_topics, _counters)
            {
                Trace = Trace
            };
        }
Beispiel #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="traceManager"></param>
        public MessageBus(ITraceManager traceManager, IPerformanceCounterWriter performanceCounterWriter)
        {
            _trace = traceManager;

            _counters          = performanceCounterWriter;
            _msgsTotalCounter  = _counters.GetCounter(PerformanceCounters.MessageBusMessagesPublishedTotal);
            _msgsPerSecCounter = _counters.GetCounter(PerformanceCounters.MessageBusMessagesPublishedPerSec);

            _broker = new MessageBroker(_topics, _counters)
            {
                Trace = Trace
            };
        }
Beispiel #13
0
        public DefaultSubscription(string identity,
                                   IEnumerable<string> eventKeys,
                                   IDictionary<string, Topic> topics,
                                   string cursor,
                                   Func<MessageResult, Task<bool>> callback,
                                   int maxMessages,
                                   IPerformanceCounterWriter counters)
            : base(identity, eventKeys, callback, maxMessages, counters)
        {
            IEnumerable<Cursor> cursors = null;
            if (cursor == null)
            {
                cursors = from key in eventKeys
                          select new Cursor
                          {
                              Key = key,
                              Id = GetMessageId(topics, key)
                          };
            }
            else
            {
               cursors = Cursor.GetCursors(cursor);
            }

            _cursors = new List<Cursor>(cursors);
            _cursorTopics = new List<Topic>();

            if (!String.IsNullOrEmpty(cursor))
            {
                // Update all of the cursors so we're within the range
                for (int i = _cursors.Count - 1; i >= 0; i--)
                {
                    Cursor c = _cursors[i];
                    Topic topic;
                    if (!eventKeys.Contains(c.Key))
                    {
                        _cursors.Remove(c);
                    }
                    else if (topics.TryGetValue(_cursors[i].Key, out topic) && _cursors[i].Id > topic.Store.GetMessageCount())
                    {
                        UpdateCursor(c.Key, 0);
                    }
                }
            }

            // Add dummy entries so they can be filled in
            for (int i = 0; i < _cursors.Count; i++)
            {
                _cursorTopics.Add(null);
            }
        }
Beispiel #14
0
        public Subscription(string identity, IEnumerable<string> eventKeys, Func<MessageResult, Task<bool>> callback, int maxMessages, IPerformanceCounterWriter counters)
        {
            Identity = identity;
            _callback = callback;
            _maxMessages = maxMessages;
            EventKeys = eventKeys;
            MaxMessages = maxMessages;

            _subsTotalCounter = counters.GetCounter(PerformanceCounters.MessageBusSubscribersTotal);
            _subsCurrentCounter = counters.GetCounter(PerformanceCounters.MessageBusSubscribersCurrent);
            _subsPerSecCounter = counters.GetCounter(PerformanceCounters.MessageBusSubscribersPerSec);

            _subsTotalCounter.SafeIncrement();
            _subsCurrentCounter.SafeIncrement();
            _subsPerSecCounter.SafeIncrement();
        }
Beispiel #15
0
        public ForeverTransport(HostContext context,
                                IJsonSerializer jsonSerializer,
                                ITransportHeartBeat heartBeat,
                                IPerformanceCounterWriter performanceCounterWriter)
            : base(context, jsonSerializer, heartBeat, performanceCounterWriter)
        {
            _jsonSerializer = jsonSerializer;

            var counters = performanceCounterWriter;
            _connConnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsConnected);
            _connReconnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsReconnected);
            _allErrorsTotalCounter = counters.GetCounter(PerformanceCounters.ErrorsAllTotal);
            _allErrorsPerSecCounter = counters.GetCounter(PerformanceCounters.ErrorsAllPerSec);
            _transportErrorsTotalCounter = counters.GetCounter(PerformanceCounters.ErrorsTransportTotal);
            _transportErrorsPerSecCounter = counters.GetCounter(PerformanceCounters.ErrorsTransportPerSec);
        }
Beispiel #16
0
        public ForeverTransport(HostContext context,
                                IJsonSerializer jsonSerializer,
                                ITransportHeartBeat heartBeat,
                                IPerformanceCounterWriter performanceCounterWriter)
            : base(context, jsonSerializer, heartBeat, performanceCounterWriter)
        {
            _jsonSerializer = jsonSerializer;

            var counters = performanceCounterWriter;

            _connConnectedCounter         = counters.GetCounter(PerformanceCounters.ConnectionsConnected);
            _connReconnectedCounter       = counters.GetCounter(PerformanceCounters.ConnectionsReconnected);
            _allErrorsTotalCounter        = counters.GetCounter(PerformanceCounters.ErrorsAllTotal);
            _allErrorsPerSecCounter       = counters.GetCounter(PerformanceCounters.ErrorsAllPerSec);
            _transportErrorsTotalCounter  = counters.GetCounter(PerformanceCounters.ErrorsTransportTotal);
            _transportErrorsPerSecCounter = counters.GetCounter(PerformanceCounters.ErrorsTransportPerSec);
        }
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterWriter performanceCounterWriter)
        {
            _context = context;
            _jsonSerializer = jsonSerializer;
            _heartBeat = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _endTokenSource = new CancellationTokenSource();
            _disconnectedToken = new CancellationTokenSource();
            _hostShutdownToken = context.HostShutdownToken();
            Completed = new TaskCompletionSource<object>();

            var counters = performanceCounterWriter;
            _connDisconnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsDisconnected);

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _endTokenSource.Token, _disconnectedToken.Token, _hostShutdownToken);
        }
Beispiel #18
0
        public virtual void Initialize(IDependencyResolver resolver)
        {
            if (_initialized)
            {
                return;
            }

            _newMessageBus = resolver.Resolve <IMessageBus>();
            _connectionIdPrefixGenerator = resolver.Resolve <IConnectionIdPrefixGenerator>();
            _jsonSerializer       = resolver.Resolve <IJsonSerializer>();
            _transportManager     = resolver.Resolve <ITransportManager>();
            _trace                = resolver.Resolve <ITraceManager>();
            _serverMessageHandler = resolver.Resolve <IServerCommandHandler>();
            _counters             = resolver.Resolve <IPerformanceCounterWriter>();
            _ackHandler           = resolver.Resolve <IAckHandler>();

            _allErrorsTotalCounter  = _counters.GetCounter(PerformanceCounters.ErrorsAllTotal);
            _allErrorsPerSecCounter = _counters.GetCounter(PerformanceCounters.ErrorsAllPerSec);

            _initialized = true;
        }
Beispiel #19
0
        public Subscription(string identity, IEnumerable <string> eventKeys, Func <MessageResult, Task <bool> > callback, int maxMessages, IPerformanceCounterWriter counters)
        {
            Identity     = identity;
            _callback    = callback;
            _maxMessages = maxMessages;
            EventKeys    = new HashSet <string>(eventKeys);
            MaxMessages  = maxMessages;

            _subsTotalCounter   = counters.GetCounter(PerformanceCounters.MessageBusSubscribersTotal);
            _subsCurrentCounter = counters.GetCounter(PerformanceCounters.MessageBusSubscribersCurrent);
            _subsPerSecCounter  = counters.GetCounter(PerformanceCounters.MessageBusSubscribersPerSec);

            _subsTotalCounter.SafeIncrement();
            _subsCurrentCounter.SafeIncrement();
            _subsPerSecCounter.SafeIncrement();
        }
Beispiel #20
0
        public TransportDisconnectBase(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterWriter performanceCounterWriter)
        {
            _context            = context;
            _jsonSerializer     = jsonSerializer;
            _heartBeat          = heartBeat;
            _timeoutTokenSource = new CancellationTokenSource();
            _endTokenSource     = new CancellationTokenSource();
            _disconnectedToken  = new CancellationTokenSource();
            _hostShutdownToken  = context.HostShutdownToken();
            Completed           = new TaskCompletionSource <object>();

            var counters = performanceCounterWriter;

            _connDisconnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsDisconnected);

            // Create a token that represents the end of this connection's life
            _connectionEndToken = CancellationTokenSource.CreateLinkedTokenSource(_timeoutTokenSource.Token, _endTokenSource.Token, _disconnectedToken.Token, _hostShutdownToken);
        }
Beispiel #21
0
            public Engine(ConcurrentDictionary<string, Topic> topics, IPerformanceCounterWriter performanceCounterWriter)
            {
                _topics = topics;

                var counters = performanceCounterWriter;
                _allocatedWorkersCounter = counters.GetCounter(PerformanceCounters.MessageBusAllocatedWorkers);
                _busyWorkersCounter = counters.GetCounter(PerformanceCounters.MessageBusBusyWorkers);
            }
        public virtual void Initialize(IDependencyResolver resolver)
        {
            if (_initialized)
            {
                return;
            }

            _newMessageBus = resolver.Resolve<IMessageBus>();
            _connectionIdPrefixGenerator = resolver.Resolve<IConnectionIdPrefixGenerator>();
            _jsonSerializer = resolver.Resolve<IJsonSerializer>();
            _transportManager = resolver.Resolve<ITransportManager>();
            _trace = resolver.Resolve<ITraceManager>();
            _serverMessageHandler = resolver.Resolve<IServerCommandHandler>();
            _counters = resolver.Resolve<IPerformanceCounterWriter>();
            _ackHandler = resolver.Resolve<IAckHandler>();

            _allErrorsTotalCounter = _counters.GetCounter(PerformanceCounters.ErrorsAllTotal);
            _allErrorsPerSecCounter = _counters.GetCounter(PerformanceCounters.ErrorsAllPerSec);

            _initialized = true;
        }
Beispiel #23
0
        public LongPollingTransport(HostContext context, IJsonSerializer jsonSerializer, ITransportHeartBeat heartBeat, IPerformanceCounterWriter performanceCounterWriter)
            : base(context, jsonSerializer, heartBeat, performanceCounterWriter)
        {
            _jsonSerializer = jsonSerializer;
            var counters = performanceCounterWriter;

            _connConnectedCounter   = counters.GetCounter(PerformanceCounters.ConnectionsConnected);
            _connReconnectedCounter = counters.GetCounter(PerformanceCounters.ConnectionsReconnected);
        }