Exemplo n.º 1
0
        private void write(ConcurrentQueue <Message> queue, int count) //-1 ==all
        {
            const int ABORT_TIMEOUT_MS = 10000;

            var     processed = 0;
            Message msg;
            var     started = App.TimeSource.UTCNow;

            while ((count < 0 || processed < count) && queue.TryDequeue(out msg))
            {
                if (!Running && (App.TimeSource.UTCNow - started).TotalMilliseconds > ABORT_TIMEOUT_MS)
                {
                    log(MessageType.Error, "{0}.Write(msg) aborted on svc shutdown: timed-out after {1} ms.".Args(m_Sink.GetType().FullName, ABORT_TIMEOUT_MS), null);
                    break;
                }

                try
                {
                    statSend();
                    m_Sink.SendMsg(msg);
                }
                catch (Exception error)
                {
                    statSendError();
                    var et = error.ToMessageWithType();
                    log(MessageType.Error, "{0}.Write(msg) leaked {1}".Args(m_Sink.GetType().FullName, et), et);

                    writeFallback(msg);
                }

                processed++;
            }
        }
Exemplo n.º 2
0
 private void writeFallback(Message msg)
 {
     try
     {
         statFallback();
         m_FallbackSink.SendMsg(msg);
     }
     catch (Exception error)
     {
         statFallbackError();
         var et = error.ToMessageWithType();
         log(MessageType.Error, "{0}.Write(msg) leaked {1}".Args(m_FallbackSink.GetType().FullName, et), et);
     }
 }