Dr. Dobb's Journal - February 2008 - (Page 56) d02hoff_p4ma 12/7/07 1:44 PM Page 56 Core Technology CONTINUOUS LINQ The problem with this implementation is that tickData is completely stale. Immediately after you run the query, tickData will never grow or shrink dynamically on its own. It would be nice if the contents of tickData could continuously update every time new market data is added to the original source of the query, MarketData.Ticks. This is what the Continuous LINQ extension does. Continuous LINQ works by attaching listeners, or adapters, to the source collection when the Where, OrderBy, and GroupBy language extensions are invoked. At some point in the future, it might support other extensions as well, but these were the most important. The adapter’s job is to listen to changes to the source collection, including all items in the source collection, and decide if that change needs to be propagated to the destination collection. For example, using the preceding market-data query, if MarketData.Ticks was derived from ContinuousCollection , then adapters would be created that listen to the source data. If a new item is added to the source collection that has a symbol name of “AAPL,” then the item is automatically added to the results. These adapters also maintain sort order and can be nested and chained at will. Figure 1 illustrates the flow of data through adapters from a typical CLINQ query. You can extend any IEnumerable derivative class and provide your own domain-specific implementations for the where, orderby, and groupby LINQ query operators. Listing One illustrates the where and orderby extensions to a class called ContinuousCollection . This class is really nothing more than a thread-safe derivative of ObservableCollection that ensures that all change publications take place on the main GUI dispatcher thread to let all WPF GUIs and CLINQ adapters see the changes. In the constructor of the adapters, the adapter attaches event handlers for the collection-changed events and the propertychanged events for each item in the collection. Then, in response to these changes, the adapter determines if the changed item needs to be propagated to the destination collection or if it needs to be removed from the destination collection (for example, a modified item no longer satisfies the query predicate and needs to be removed). The removal will cascade down the chain so it makes no difference how many where, groupby, or orderby adapters the change needs to pass through. The great thing about CLINQ and other language extensions enabled through LINQ is that all of the complexity is hidden from developers. You don’t need to look at Listing One to use the advanced functionality—simply write a LINQ query against a ContinuousCollection instead of a standard list and it “just works.” There are lots of different samples that can be written to illustrate CLINQ in action, but one of the more applicable samples I’ve found is an Order Book. An order book application monitors the market data for a select subset of symbols. Without CLINQ, I would have to set up manual monitoring threads that listen for changes to the underlying market data and then manually propagate those changes to the model, which is then bound to the GUI. This creates a lot of moving parts, makes debugging difficult, and can be very error56 Dr. Dobb’s Journal l www.ddj.com l February 2008 prone. With CLINQ, I can simply set up some queries in the controller code and everything is dynamically updated as needed. For example, in the demo order book application, to open a new book and create a variable that contains just the subset of market data belonging to a particular symbol, you can use a simple CLINQ query (a LINQ query against a ContinuousCollection). Listing Two shows the controller method SubscribeToSymbol, which creates a new window and sets the AskTicks and BidTicks properties of that window to CLINQ queries. Filter View Adapter Continuous Collection var askTicks= from tick in MarketData.Ticks where tick.symbol==”AAPL” && tick.Side==TickSide.Ask orderby tick.Price descending select tick; Market Data Sort View Adapter AAPL Ticks Sorted by Price Figure 1: Data flow through CLINQ adapters. Figure 2: Sample Order Book Demo using CLINQ. Figure 3: Having a little fun with CLINQ. http://www.ddj.com
Table of Contents Feed for the Digital Edition of Dr. Dobb's Journal - February 2008 Dr. Dobb's Journal - February 2008 Contents Hmmmm Alia Vox Developer Diaries Developer’s Notebook South American Software Development Conversations Inside Visual Studio 2008 BibPort: Creating Bibliographic References Continuous LINQ The ZK Framework Static Testing C++ Code The Agile Edge Effective Concurrency Swaine’s Flames Dr. Dobb's Journal - February 2008 Dr. Dobb's Journal - February 2008 - Dr. Dobb's Journal - February 2008 (Page Cover1) Dr. Dobb's Journal - February 2008 - Dr. Dobb's Journal - February 2008 (Page Cover2) Dr. Dobb's Journal - February 2008 - Dr. Dobb's Journal - February 2008 (Page 1) Dr. Dobb's Journal - February 2008 - Dr. Dobb's Journal - February 2008 (Page 2) Dr. Dobb's Journal - February 2008 - Dr. Dobb's Journal - February 2008 (Page 3) Dr. Dobb's Journal - February 2008 - Contents (Page 4) Dr. Dobb's Journal - February 2008 - Contents (Page 5) Dr. Dobb's Journal - February 2008 - Hmmmm (Page 6) Dr. Dobb's Journal - February 2008 - Hmmmm (Page 7) Dr. Dobb's Journal - February 2008 - Hmmmm (Page 8) Dr. Dobb's Journal - February 2008 - Hmmmm (Page 9) Dr. Dobb's Journal - February 2008 - Alia Vox (Page 10) Dr. Dobb's Journal - February 2008 - Alia Vox (Page 11) Dr. Dobb's Journal - February 2008 - Developer Diaries (Page 12) Dr. Dobb's Journal - February 2008 - Developer Diaries (Page 13) Dr. Dobb's Journal - February 2008 - Developer’s Notebook (Page 14) Dr. Dobb's Journal - February 2008 - Developer’s Notebook (Page 15) Dr. Dobb's Journal - February 2008 - South American Software Development (Page 16) Dr. Dobb's Journal - February 2008 - South American Software Development (Page 17) Dr. Dobb's Journal - February 2008 - South American Software Development (Page 18) Dr. Dobb's Journal - February 2008 - South American Software Development (Page 19) Dr. Dobb's Journal - February 2008 - Conversations (Page 20) Dr. Dobb's Journal - February 2008 - Conversations (Page 21) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 22) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 23) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 24) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 25) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 26) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 27) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 28) Dr. Dobb's Journal - February 2008 - Inside Visual Studio 2008 (Page 29) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 30) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 31) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 32) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 33) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 34) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 35) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 36) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 37) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 38) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 39) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 40) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 41) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 42) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 43) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 44) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 45) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 46) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 47) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 48) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 49) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 50) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 51) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 52) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 53) Dr. Dobb's Journal - February 2008 - BibPort: Creating Bibliographic References (Page 54) Dr. Dobb's Journal - February 2008 - Continuous LINQ (Page 55) Dr. Dobb's Journal - February 2008 - Continuous LINQ (Page 56) Dr. Dobb's Journal - February 2008 - Continuous LINQ (Page 57) Dr. Dobb's Journal - February 2008 - Continuous LINQ (Page 58) Dr. Dobb's Journal - February 2008 - Continuous LINQ (Page 59) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 60) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 61) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 62) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 63) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 64) Dr. Dobb's Journal - February 2008 - The ZK Framework (Page 65) Dr. Dobb's Journal - February 2008 - Static Testing C++ Code (Page 66) Dr. Dobb's Journal - February 2008 - Static Testing C++ Code (Page 67) Dr. Dobb's Journal - February 2008 - Static Testing C++ Code (Page 68) Dr. Dobb's Journal - February 2008 - Static Testing C++ Code (Page 69) Dr. Dobb's Journal - February 2008 - Static Testing C++ Code (Page 70) Dr. Dobb's Journal - February 2008 - The Agile Edge (Page 71) Dr. Dobb's Journal - February 2008 - The Agile Edge (Page 72) Dr. Dobb's Journal - February 2008 - The Agile Edge (Page 73) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 74) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 75) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 76) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 77) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 78) Dr. Dobb's Journal - February 2008 - Effective Concurrency (Page 79) Dr. Dobb's Journal - February 2008 - Swaine’s Flames (Page 80) Dr. Dobb's Journal - February 2008 - Swaine’s Flames (Page Cover3) Dr. Dobb's Journal - February 2008 - Swaine’s Flames (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.