コード例 #1
0
 public Consumer(ICoalescingBuffer<long, MarketSnapshot> buffer, int numberOfInstruments, MarketSnapshot poisonPill, StopWatch stopWatch)
 {
     _buffer = buffer;
     _numberOfInstruments = numberOfInstruments;
     _poisonPill = poisonPill;
     _stopWatch = stopWatch;
     LatestSnapshots = new MarketSnapshot[numberOfInstruments];
 }
コード例 #2
0
 public static MarketSnapshot CreateMarketSnapshot(long instrumentId, long bestBid, long bestAsk)
 {
     var snapshot = new MarketSnapshot();
     snapshot.SetInstrumentId(instrumentId);
     snapshot.SetBestBid(bestBid);
     snapshot.SetBestAsk(bestAsk);
     return snapshot;
 }
コード例 #3
0
 public Producer(ICoalescingBuffer<long, MarketSnapshot> buffer, int numberOfInstruments, long numberOfUpdates, MarketSnapshot poisonPill, StopWatch stopWatch)
 {
     _buffer = buffer;
     _numberOfInstruments = numberOfInstruments;
     _numberOfUpdates = numberOfUpdates;
     _poisonPill = poisonPill;
     _stopWatch = stopWatch;
     _snapshots = CreateSnapshots(numberOfInstruments);
 }
コード例 #4
0
        public static MarketSnapshot CreateMarketSnapshot(long instrumentId, long bestBid, long bestAsk)
        {
            var snapshot = new MarketSnapshot();

            snapshot.SetInstrumentId(instrumentId);
            snapshot.SetBestBid(bestBid);
            snapshot.SetBestAsk(bestAsk);
            return(snapshot);
        }
コード例 #5
0
            private void Put(long key, long bid, long ask)
            {
                var success = _snapshotBuffer.Offer(key, MarketSnapshot.CreateMarketSnapshot(key, bid, ask));

                if (!success)
                {
                    throw new Exception("adding of key " + key + " failed");
                }
            }
コード例 #6
0
        private void CheckCapacity(int capacity, ICoalescingBuffer <long, MarketSnapshot> buffer)
        {
            Assert.AreEqual(capacity, buffer.Capacity());

            for (int i = 0; i < capacity; i++)
            {
                bool success = buffer.Offer(MarketSnapshot.CreateMarketSnapshot(i, i, i));
                Assert.True(success);
            }
        }
コード例 #7
0
        private static MarketSnapshot[] CreateSnapshots(int numberOfInstruments)
        {
            var snapshots = new MarketSnapshot[numberOfInstruments];

            for (int i = 0; i < numberOfInstruments; i++)
            {
                int bid = numberOfInstruments * i;
                int ask = numberOfInstruments * numberOfInstruments * i;

                snapshots[i] = MarketSnapshot.CreateMarketSnapshot(i, bid, ask);
            }

            return snapshots;
        }
コード例 #8
0
        public void ShouldSeeLastPrices()
        {
            ICoalescingBuffer <long, MarketSnapshot> buffer = new CoalescingRingBuffer <long, MarketSnapshot>(1 << 20);

            var consumer       = new Consumer(buffer);
            var consumerThread = new Thread(consumer.Run);


            new Thread(() => new Producer(buffer).Run()).Start();
            consumerThread.Start();

            consumerThread.Join();

            for (int instrument = 0; instrument < NumberOfInstruments; instrument++)
            {
                MarketSnapshot snapshot = consumer.Snapshots[instrument];

                Assert.AreEqual(SecondBid, snapshot.GetBid(), "bid for instrument " + instrument + ":");
                Assert.AreEqual(SecondAsk, snapshot.GetAsk(), "ask for instrument " + instrument + ":");
            }
        }
コード例 #9
0
 private static int IndexOf(MarketSnapshot snapshot)
 {
     return (int)snapshot.GetInstrumentId();
 }
コード例 #10
0
 private void AddNonCollapsibleValue(MarketSnapshot snapshot)
 {
     Assert.True(Buffer.Offer(snapshot));
 }
コード例 #11
0
 private void AddCollapsibleValue(MarketSnapshot snapshot)
 {
     Assert.True(Buffer.Offer(snapshot.GetInstrumentId(), snapshot));
 }
コード例 #12
0
 private static int IndexOf(MarketSnapshot snapshot)
 {
     return((int)snapshot.GetInstrumentId());
 }
コード例 #13
0
 private void AddNonCollapsibleValue(MarketSnapshot snapshot)
 {
     Assert.True(Buffer.Offer(snapshot));
 }
コード例 #14
0
 private void AddCollapsibleValue(MarketSnapshot snapshot)
 {
     Assert.True(Buffer.Offer(snapshot.GetInstrumentId(), snapshot));
 }
コード例 #15
0
        private void Put(long id, MarketSnapshot snapshot)
        {
            bool success = _buffer.Offer(id, snapshot);

            if (!success)
            {
                throw new Exception("failed to add instrument id " + snapshot.GetInstrumentId());
            }
        }