public void Send (CompletableApnsNotification notification) { lock (notificationBatchQueueLock) { notifications.Enqueue (notification); if (notifications.Count >= Configuration.InternalBatchSize) { // Make the timer fire immediately and send a batch off timerBatchWait.Change (0, Timeout.Infinite); return; } // Restart the timer to wait for more notifications to be batched // This timer will keep getting 'restarted' before firing as long as notifications // are queued before the timer's due time // if the timer is actually called, it means no more notifications were queued, // so we should flush out the queue instead of waiting for more to be batched as they // might not ever come and we don't want to leave anything stranded in the queue timerBatchWait.Change (Configuration.InternalBatchingWaitPeriod, Timeout.InfiniteTimeSpan); } }
public void Send(CompletableApnsNotification notification) { lock (notificationBatchQueueLock) { notifications.Enqueue(notification); if (notifications.Count >= Configuration.InternalBatchSize) { // Make the timer fire immediately and send a batch off timerBatchWait.Change(0, Timeout.Infinite); return; } // Restart the timer to wait for more notifications to be batched // This timer will keep getting 'restarted' before firing as long as notifications // are queued before the timer's due time // if the timer is actually called, it means no more notifications were queued, // so we should flush out the queue instead of waiting for more to be batched as they // might not ever come and we don't want to leave anything stranded in the queue timerBatchWait.Change(Configuration.InternalBatchingWaitPeriod, Timeout.InfiniteTimeSpan); } }
private byte[] createBatch(BlockingCollection <CompletableApnsNotification> toSend) { if (toSend == null || toSend.Count <= 0) { return(null); } var batchData = new List <byte>(); // Add all the frame data foreach (var n in toSend) { CompletableApnsNotification temp = n; try { if (n != null && n.Notification != null) { batchData.AddRange(n.Notification.ToBytes()); } } catch (NotificationException ex) { toSend.TryTake(out temp); temp.CompleteFailed(new ApnsNotificationException(GetApnsNotificationErrorStatusCode(ex), n.Notification, ex)); } finally { if (batchData == null) { batchData = new List <byte>(); } } } return(batchData.ToArray()); }
public SentNotification(CompletableApnsNotification notification) { this.Notification = notification; this.SentAt = DateTime.UtcNow; this.Identifier = notification.Notification.Identifier; }
public SentNotification (CompletableApnsNotification notification) { this.Notification = notification; this.SentAt = DateTime.UtcNow; this.Identifier = notification.Notification.Identifier; }