public void Enqueue(BaseWoopsaSubscriptionServiceSubscription subscription, IWoopsaNotification notification,
                            out bool itemDiscarded)
        {
            PairSubscriptionNotification pair = new PairSubscriptionNotification(subscription, notification);

            lock (_notifications)
            {
                if (subscription.MonitorInterval == WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly)
                {
                    // remove any existing notification from this subscription, as we want to keep only the last
                    LinkedListNode <PairSubscriptionNotification> node = _notifications.First;
                    while (node != null)
                    {
                        var next = node.Next;
                        if (node.Value.Key == subscription)
                        {
                            _notifications.Remove(node);
                        }
                        node = next;
                    }
                }
                itemDiscarded = _notifications.Count >= MaxQueueSize;
                if (itemDiscarded)
                {
                    while (_notifications.Count >= MaxQueueSize)
                    {
                        _notifications.RemoveFirst();
                    }
                }
                _notifications.AddLast(pair);
            }
        }
 public IWoopsaNotification[] PeekNotifications(int maxCount)
 {
     lock (_notifications)
     {
         int count = Math.Min(_notifications.Count, maxCount);
         IWoopsaNotification[] result = new IWoopsaNotification[count];
         LinkedListNode <PairSubscriptionNotification> node = _notifications.First;
         int i = 0;
         while (node != null)
         {
             result[i] = node.Value.Value;
             i++;
             node = node.Next;
             if (i >= count)
             {
                 break;
             }
         }
         return(result);
     }
 }
Beispiel #3
0
 public void Add(IWoopsaNotification notification)
 {
     _notifications.Add(notification);
 }
 public static string Serialize(this IWoopsaNotification notification)
 {
     return(String.Format(NotificationFormat, notification.Value.Serialize(), notification.SubscriptionId, notification.Id));
 }
 public IWoopsaNotification[] PeekNotifications(int maxCount)
 {
     lock (_notifications)
     {
         int count = Math.Min(_notifications.Count, maxCount);
         IWoopsaNotification[] result = new IWoopsaNotification[count];
         LinkedListNode<PairSubscriptionNotification> node = _notifications.First;
         int i = 0;
         while (node != null)
         {
             result[i] = node.Value.Value;
             i++;
             node = node.Next;
             if (i >= count)
                 break;
         }
         return result;
     }
 }
 public void Enqueue(BaseWoopsaSubscriptionServiceSubscription subscription, IWoopsaNotification notification,
     out bool itemDiscarded)
 {
     PairSubscriptionNotification pair = new PairSubscriptionNotification(subscription, notification);
     lock (_notifications)
     {
         if (subscription.MonitorInterval == WoopsaSubscriptionServiceConst.MonitorIntervalLastPublishedValueOnly)
         {
             // remove any existing notification from this subscription, as we want to keep only the last
             LinkedListNode<PairSubscriptionNotification> node = _notifications.First;
             while (node != null)
             {
                 var next = node.Next;
                 if (node.Value.Key == subscription)
                     _notifications.Remove(node);
                 node = next;
             }
         }
         itemDiscarded = _notifications.Count >= MaxQueueSize;
         if (itemDiscarded)
             while (_notifications.Count >= MaxQueueSize)
                 _notifications.RemoveFirst();
         _notifications.AddLast(pair);
     }
 }
 public void Add(IWoopsaNotification notification)
 {
     _notifications.Add(notification);
 }