public Consumer(ICoalescingBuffer<long, MarketSnapshot> buffer, int numberOfInstruments, MarketSnapshot poisonPill, StopWatch stopWatch) { _buffer = buffer; _numberOfInstruments = numberOfInstruments; _poisonPill = poisonPill; _stopWatch = stopWatch; LatestSnapshots = new MarketSnapshot[numberOfInstruments]; }
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; }
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); }
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); }
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"); } }
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); } }
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; }
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 + ":"); } }
private static int IndexOf(MarketSnapshot snapshot) { return (int)snapshot.GetInstrumentId(); }
private void AddNonCollapsibleValue(MarketSnapshot snapshot) { Assert.True(Buffer.Offer(snapshot)); }
private void AddCollapsibleValue(MarketSnapshot snapshot) { Assert.True(Buffer.Offer(snapshot.GetInstrumentId(), snapshot)); }
private static int IndexOf(MarketSnapshot snapshot) { return((int)snapshot.GetInstrumentId()); }
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()); } }