The StreamInsight Object Model and Observables

In the last installment about the object model, let's the at the third development style, using .NET's IObservable/IObserver. IObservable/IObserver is a new interface in .NET 4.0, the "mirror image" (to use a less controversial term) of IEnumerable/IEnumerator. A really simplistic way of thinking about it is the Enumerable/Enumarator is allowing you to pull, IObservable/IObserver is watching someone push. So supporting IObservable/IObserver makes it possible to use StreamInsight with .NET classes.

What they've done in this case is write a generic StreamInsight adapter set over the interfaces. It's called ObservableXXXInputAdapter and ObservableXXXOutputAdapter, where XXX stands for the three StreamInsight event shapes (Point, Edge, and Interval). So there's six classes plus a Factories and Config class for each adapter. Similar in concept to some of the generic text providers they use in the samples, but shipped in a supported library.

To encapsulate the rest of the model there are some ExtensionMethods for the .NET classes that implement IObservables (and a hook for IEnumerables). The main ones are ToObservable and ToCepStream.  They work with other extension methods and helper classes to provide for a generic transformation of .NET classes that implement the right interfaces to StreamInsight objects from the familiar Object Model. These extension methods create the (same) StreamInsight object model along the way. Although there is one method currently that may allow you to inject/use your own Server instance, therefore, being able to navigate the whole Object Model.

So at the end of the day, you work with IObservables/IObservers (and maybe IEnumerables/IEnumerators). And the same object model. For a code-assisted review of the main components of the object model, you may now return the the Explicit Server sample. Or for a data-assisted review, a CE database that's been "used" to register CEP objects. 😉

4 thoughts on “The StreamInsight Object Model and Observables

  1. I made the same mistake, thinking that IObservable/IObserver in StreamInsight is the same one as in .Net 4.0, but it isn’t. StreamInsight couldn’t take a dependency on .Net 4.0, so they have a version of IObservable/IObserver, but in the Microsoft.ComplexEventProcessing.Adapters.Observable namespace, which is in the Microsoft.ComplexEventProcessing.Adapters.Observable assembly. Same members, but different implementation.

  2. Hi Don,

    My understanding (without specifically checking) is that the IObservable/IObserver in StreamInsight is the same *interface* as .NET 4.0. An interface by definition has no implementation, so I’m confused by your statement that the implementation is different. You’re right that StreamInsight has no dependency on .NET 4.0, though.

  3. They are in different dlls and namespaces, so you will not be able to switch to using the .Net 4.0 version without changing your code and recompiling. Not much to do, but they are different interfaces, just with the same signature.

  4. Right, the same signatures was what I was trying to point out. They’d need to be different in namespaces so that StreamInsight did not have a dependency in .NET 4.0.

Comments are closed.

Other articles

Imagine feeling confident enough to handle whatever your database throws at you.

With training and consulting from SQLskills, you’ll be able to solve big problems, elevate your team’s capacity, and take control of your data career.