1 / 56

eneta.ee/foorum

www.eneta.ee/foorum. Sissejuhatus Rx raamistikku. Juri Mulenko Sr. Software Engineer Symantec www.devclub.eu www.devclub.ee. Kava. Kaasaegsed rakendused “ push ” ja “pull” mudel Mis on Rx Observable Collections idee Millest Rx koosneb

tale
Download Presentation

eneta.ee/foorum

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. www.eneta.ee/foorum

  2. Sissejuhatus Rx raamistikku JuriMulenko Sr. Software Engineer Symantec www.devclub.euwww.devclub.ee

  3. Kava • Kaasaegsed rakendused • “push” ja “pull” mudel • Mis on Rx • ObservableCollections idee • Millest Rx koosneb • Mõnede primitiivide ja operatsioonide seletus • Konstrueerimine ja kasutus • Demo

  4. Kaasaegsed rakendused

  5. Kaasaegsed rakendused • Veebi - põhised • Ajax • Integratsioon teiste teenustega • Pilvides

  6. Kaasaegsed rakendused • Desktop/rich • Ei blokeeri kasutajat • Mitu paralleelset tegevust • Veebiteenused

  7. Kaasaegsed rakendused • Enterprise • Desktop + veeb • Modulaarsus • Edasilükatud töö (deferredexecution) • ESB (Enterprise Service Bus)

  8. Kaasaegsed rakendused • Interaktiivsus • Asünkroonsus • Parallel-töötlus • Sündmus-orienteeritud

  9. Pull vs push Keskkond Rakendus • Pull Andmed Push

  10. Kasutaja vaatest on Push • Äratuskell • Chat/IM rakendused • RSS lugeja • Sotsiaalvõrgustike “Wall/Updates” • Web streaming • Outlook kalender - meeldetuletaja

  11. Tarkvaras on Push • Windows Message Loop • Driver interrupt • Http server push / Http streaming • MVC push (C annab andmed V-le) • Sündmus-orineeritud rakendused • fraud – detection • börsi reaalaja analüüs • Muu CEP (Complex Event Processing)

  12. .NET’is on Push • Sündmused ja sündmuste töötlejad Event / EventHandler • Callback void DoSomething(…, Action callBack) • Async pattern BeginXXX / EndXXX WebRequest.BeginGetResponse / EndGetResponse

  13. Mis on Rx ? (Reactive Extensions)

  14. “Rx is a library for composing asynchronous and event-based programs using observable collections.” DevLabs

  15. Rx idee • Sündmuste voog = andmete voog = andmetekollektsioon = sündmuste kollektsioon • Nt. hiir on lõpmatu koordinaatide kollektsioon

  16. Mis on Observable collection? (Ilusjalihtneidee)

  17. public interface IEnumerable<T> { IEnumerator<T> GetEnumerator(); } public interface IEnumerator<T> : IDisposable { T Current { get; } bool MoveNext(); void Reset(); }

  18. interface IEnumerator<T> { T Current { get; } // gets the current element // same as TGetCurrent(); } interface IX<T>  { voidSetCurrent(Tvalue); }

  19. interface IEnumerator<T>  { bool MoveNext(); } interface IX<T>  { void SetCurrent(T value); voidMoveNext(boolmoreItems); }

  20. interface IEnumerator<T>  { bool MoveNext(); } interface IX<T>  { void SetCurrent(T value); //void MoveNext(boolmoreItems); void Break(); }

  21. interface IEnumerator<T>  { bool MoveNext(); //or throws Excepton: //(bool | Exception) MoveNext(); } interface IX<T>  { void SetCurrent(T value); void Break(); void Throw(Exception ex); }

  22. interface IEnumerator<T> { T Current { get; } bool MoveNext(); void Reset(); } interface IX<T>  { void SetCurrent(T value); void Break(); void Throw(Exception ex); }

  23. interface IEnumerator<T> : IDisposable { T Current { get; } bool MoveNext(); } interface IObserver<T>  { void OnNext(T value); void OnCompleted(); void OnError(Exception ex); }

  24. interface IEnumerable<T> { IEnumerator<T>GetEnumerator(); } interface IX<T> { void Attach(IObserver<T> observer); }

  25. interface IEnumerable<T> { IEnumerator<T>GetEnumerator(); } interface IX<T> { void Attach(IObserver<T> observer); void Detach(IObserver<T> observer); }

  26. interface IEnumerable<T> { IEnumerator<T>:IDisposableGetEnumerator(); } interface IX<T> { IDisposableAttach(IObserver<T> observer); }

  27. interface IEnumerable<T> { IEnumerator<T> GetEnumerator(); } interface IObservable<T> { IDisposableSubscribe(IObserver<T> observer); }

  28. interface IObservable<T> { IDisposable Subscribe(IObserver<T> observer); } interface IObserver<T>  { void OnNext(T value); void OnCompleted(); void OnError(Exception ex); }

  29. Enumerables & Observables • Enumerable = pull • Observable = push • E ja O on duaalsed • LINQ!

  30. MillestRxkoosneb

  31. IObserver<T> IObservable<T> Metainfo + Generators Concurrency LINQ Async pattern Events Custom

  32. Rx versioonid • .NET 3.5 SP1 (k.a. Client Profile) • .NET 4.0 (k.a. Client Profile) • Silverlight 3 / 4 • XNA • Windows Phone 7 • JavaScript

  33. Tagasisidelehed

  34. Primitiivid

  35. Marble diagram aeg sündmus/andmed OnNext(T value) viga (exception)OnError(Exception error) lõppOnCompleted();

  36. IObservable<T> Never() Empty() Return(T value) Thow()

  37. Operatsoonid

  38. IO<T>Concat (IO<T> x, IO<T> y) x y z var z = x.Concat(y);

  39. IO<T> Merge (IO<T> x, IO<T> y) x y z var z = x.Merge(y);

  40. IO<Z> Zip(IO<X> x, IO<Y> y, Func<X, Y, Z> f) x y f f f z var z = x.Zip(y, func);

  41. IO<T> Catch (IO<T> x, IO<T> y) x y z var z = x.Catch(y);

  42. IO<T> Throttle (IO<T> x, TimeSpants) x < ts > ts z var z = x.Throttle(ts);

  43. Konstrueerimine

  44. Sündmusest var z = Observable.FromEvent<EventArgs>( textBox1, “TextChanged”); var z = Observable.FromEvent( h => textBox1.TextChanged += h, h => textBox1.TextChanged -= h);

  45. Async pattern = BeginXXX / EndXXX Stream s = …; varfunc = Observable .FromAsyncPattern<byte[], int, int>( stream.BeginWrite,  stream.EndWrite); //returns Func<byte[], int, int, IObservable<Unit>> var z = func(…);

  46. Delegaatidest Func<int, string> del = (i) => i.ToString(); var z1 = del.ToAsync()(5); // del.ToAsync() returns Func<int, IObservable<string>> var z2 = Observable .FromAsyncPattern<int, string>( del.BeginInvoke,  del.EndInvoke)(5); //samaBeginXXX / EndXXX

  47. Kasutus / Subscription

  48. interface IObservable<T> { IDisposable Subscribe(IObserver<T> observer); } interface IObserver<T>  { void OnNext(T value); void OnCompleted(); void OnError(Exception ex); }

  49. ImplementeeridesIObserver<T> var z = Observable.FromEvent<EventArgs>( textBox1, “TextChanged”); public class MyObserver: IObserver<T> { public void OnNext(T value) {…}; public void OnCompleted(value){…}; public void OnError(Exception ex){…}; } IDisposable subscription = z.Subscribe(new MyObserver());

  50. Anonüümsed meetodid var z = Observable.FromEvent<EventArgs>( textBox1, “TextChanged”); IDisposable subscription = z.Subscribe( //Action<EventArgs> OnNext (eventArgs) => { Console.Writeline(“OnNext”); }, //Action<Exception> OnError (error) => { Console.Writeline(error.Message); }, //Action OnCompleted () => { Console.Writeline(“OnCompleted”)} );

More Related