Ejemplo n.º 1
0
        private void Run()
        {
            IList snapshots = new ArrayList();

            do
            {
                lock (_snapshotQueue)
                {
                    if (_snapshotQueue.Count == 0)
                    {
                        Monitor.Wait(_snapshotQueue);
                    }

                    snapshots.Clear();
                    while (_snapshotQueue.Count > 0)
                    {
                        ExternalFeedProducer myProducer = (ExternalFeedProducer)_snapshotQueue[0];
                        snapshots.Add(myProducer);
                        _snapshotQueue.RemoveAt(0);
                    }
                }

                foreach (ExternalFeedProducer myProducer in snapshots)
                {
                    _listener.OnEvent(myProducer.GetItemName(), myProducer.GetCurrentValues(true), true);
                }
            } while (true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Forces sending an event with a full snapshot for a stock.
        /// </summary>
        public void SendCurrentValues(string itemName)
        {
            ExternalFeedProducer myProducer = (ExternalFeedProducer)_stockGenerators[itemName];

            if (myProducer == null)
            {
                return;
            }

            lock (_snapshotQueue)
            {
                _snapshotQueue.Add(myProducer);
                Monitor.Pulse(_snapshotQueue);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts generating update events for the stocks. Sumulates attaching
        /// and reading from an external broadcast feed.
        /// </summary>
        public void Start()
        {
            if (_snapshotSender != null)
            {
                return;
            }

            for (int i = 0; i < 30; i++)
            {
                string itemName = "item" + (i + 1);
                ExternalFeedProducer myProducer = new ExternalFeedProducer(itemName,
                                                                           _openprices[i], _refprices[i], _minprices[i], _maxprices[i],
                                                                           _updateTimeMeans[i], _updateTimeStdDevs[i], _stockNames[i]);

                _stockGenerators[itemName] = myProducer;
                myProducer.SetFeedListener(_listener);
                myProducer.Start();
            }

            _snapshotSender = new Thread(new ThreadStart(Run));
            _snapshotSender.Start();
        }