Exemplo n.º 1
0
        public bool TryDequeueTick(ref TickBinary tickBinary)
        {
            EventItem eventItem;
            var       result = false;

            if (filter.Receive(out eventItem))
            {
                var eventType = (EventType)eventItem.EventType;
                switch (eventType)
                {
                case EventType.Tick:
                    var box = (TickBinaryBox)eventItem.EventDetail;
                    tickBinary = box.TickBinary;
                    box.Free();
                    if (debug)
                    {
                        log.Debug("Freed box id in verify " + box.Id + ", count " + tickPool.AllocatedCount);
                    }
                    result = true;
                    filter.Pop();
                    break;

                default:
                    filter.Pop();
                    throw new QueueException(eventType);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        protected virtual Yield Invoke()
        {
            EventItem eventItem;

            if (filter.Receive(out eventItem))
            {
                switch ((EventType)eventItem.EventType)
                {
                case EventType.Shutdown:
                    Dispose();
                    filter.Pop();
                    break;

                default:
                    throw new ApplicationException("Unexpected event: " + eventItem);
                }
            }
            var result = Yield.NoWork.Repeat;

            try {
                if (writeQueue.Count == 0)
                {
                    return(result);
                }
                while (writeQueue.Count > 0)
                {
                    if (!writeQueue.TryPeek(ref tick))
                    {
                        break;
                    }
                    tickIO.Inject(tick);
                    if (tickFile.TryWriteTick(tickIO))
                    {
                        writeQueue.TryDequeue(ref tick);
                    }
                    result = Yield.DidWork.Repeat;
                }
                return(result);
            } catch (QueueException ex) {
                if (ex.EntryType == EventType.Terminate)
                {
                    log.Notice("Last tick written: " + tickIO);
                    if (debug)
                    {
                        log.Debug("Exiting, queue terminated.");
                    }
                    Finalize();
                    return(Yield.Terminate);
                }
                else
                {
                    Exception exception = new ApplicationException("Queue returned unexpected: " + ex.EntryType);
                    writeQueue.SetException(exception);
                    writeQueue.Dispose();
                    Dispose();
                    throw ex;
                }
            } catch (Exception ex) {
                writeQueue.SetException(ex);
                writeQueue.Dispose();
                Dispose();
                throw;
            }
        }