Beispiel #1
0
            public void WaitForFirstMessage()
            {
                pollingCollectionObserver = PollingCollectionObserver.Observe(() =>
                {
                    try
                    {
                        if (Interlocked.Exchange(ref sending, 1) == 1)
                        {
                            return;
                        }

                        if (pendingMessages.TryDequeue(out OutgoingMessage message))
                        {
                            do
                            {
                                message.SendMessage(cancellationToken);
                            } while (pendingMessages.TryDequeue(out message));
                        }

                        sending = 0;
                        communicationProtocol.LogVerbose("Sending cycle completed. Wait for next message.");
                    }
                    catch (Exception)
                    {
                        //do nothing as this is executed without owning task
                    }
                }, pendingMessages);
            }
Beispiel #2
0
 public void WaitForFirstMessage()
 {
     readingThread = new Thread(StartReading)
     {
         Priority     = ThreadPriority.AboveNormal,
         IsBackground = true
     };
     readingThread.Start();
     pollingCollectionObserver = PollingCollectionObserver.Observe(Flush, messages);
 }
Beispiel #3
0
            public void WaitForFirstMessage()
            {
                pollingCollectionObserver = PollingCollectionObserver.Observe(() =>
                {
                    try
                    {
                        if (Interlocked.Exchange(ref sending, 1) == 1)
                        {
                            return;
                        }

                        while (pendingConfirmations.TryDequeue(out Confirmation confirmation))
                        {
                            confirmation.Send();
                        }

                        if (resendMessages.TryDequeue(out OutgoingMessage resend))
                        {
                            do
                            {
                                SendMessage(resend);
                            } while (resendMessages.TryDequeue(out resend));
                        }
                        else if (unconfirmedMessages.IsEmpty && pendingMessages.TryDequeue(out OutgoingMessage message))
                        {
                            SendMessage(message);
                        }

                        sending = 0;
                        log.LogVerbose("Sending cycle completed. Wait for next message.");
                    }
                    catch (Exception)
                    {
                        //do nothing as this is executed without owning task
                    }
                }, pendingConfirmations, pendingMessages, resendMessages);

                void SendMessage(OutgoingMessage message)
                {
                    unconfirmedMessages.TryAdd(message.Id, message);
                    message.SendMessage(cancellationToken);
                }
            }