public void EnqueueNotification(INotification notification, bool urgent) { lock (_syncObj) { if (urgent) { _urgentQueue.Insert(0, notification); } else { _normalQueue.Insert(0, notification); } int numUrgentMessages = _urgentQueue.Count; int numNormalMessages = _normalQueue.Count; int numPendingNotifications = numUrgentMessages + numNormalMessages; if (numPendingNotifications > PENDING_NOTIFICATIONS_WARNING_THRESHOLD) { ServiceRegistration.Get <ILogger>().Warn("NotificationService: {0} pending notifications", numPendingNotifications); while (_urgentQueue.Count > MAX_NUM_PENDING_NOTIFICATIONS_THRESHOLD) { INotification prunedNotification = _urgentQueue[_urgentQueue.Count - 1]; ServiceRegistration.Get <ILogger>().Warn("NotificationService: Removing unhandled urgent notification '{0}'", prunedNotification); _urgentQueue.RemoveAt(_urgentQueue.Count - 1); } while (_normalQueue.Count > MAX_NUM_PENDING_NOTIFICATIONS_THRESHOLD) { INotification prunedNotification = _normalQueue[_normalQueue.Count - 1]; ServiceRegistration.Get <ILogger>().Warn("NotificationService: Removing unhandled normal notification '{0}'", prunedNotification); _normalQueue.RemoveAt(_normalQueue.Count - 1); } } } NotificationServiceMessaging.SendMessage(NotificationServiceMessaging.MessageType.NotificationEnqueued, notification); }
public void RemoveNotification(INotification notification) { bool removed; lock (_syncObj) removed = _normalQueue.Remove(notification) || _urgentQueue.Remove(notification); if (removed) { NotificationServiceMessaging.SendMessage(NotificationServiceMessaging.MessageType.NotificationRemoved, notification); } }
public INotification DequeueNotification() { INotification notification; lock (_syncObj) { if (_urgentQueue.Count > 0) { notification = _urgentQueue[_urgentQueue.Count - 1]; _urgentQueue.RemoveAt(_urgentQueue.Count - 1); } else if (_normalQueue.Count > 0) { notification = _normalQueue[_normalQueue.Count - 1]; _normalQueue.RemoveAt(_normalQueue.Count - 1); } else { return(null); } } NotificationServiceMessaging.SendMessage(NotificationServiceMessaging.MessageType.NotificationRemoved, notification); return(notification); }