Browse Source

Code structure of ReplaySubject.

Bart De Smet 10 years ago
parent
commit
84e189084a
1 changed files with 83 additions and 38 deletions
  1. 83 38
      Rx.NET/Source/System.Reactive.Linq/Reactive/Subjects/ReplaySubject.cs

+ 83 - 38
Rx.NET/Source/System.Reactive.Linq/Reactive/Subjects/ReplaySubject.cs

@@ -13,31 +13,18 @@ namespace System.Reactive.Subjects
     /// <typeparam name="T">The type of the elements processed by the subject.</typeparam>
     public sealed class ReplaySubject<T> : ISubject<T>, IDisposable
     {
-        private readonly IReplaySubjectImplementation _implementation;
+        #region Fields
 
         /// <summary>
-        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size, window and scheduler.
+        /// Underlying optimized implementation of the replay subject.
         /// </summary>
-        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
-        /// <param name="window">Maximum time length of the replay buffer.</param>
-        /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
-        public ReplaySubject(int bufferSize, TimeSpan window, IScheduler scheduler)
-        {
-            _implementation = new ReplayByTime(bufferSize, window, scheduler);
-        }
+        private readonly IReplaySubjectImplementation _implementation;
 
-        /// <summary>
-        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size and window.
-        /// </summary>
-        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
-        /// <param name="window">Maximum time length of the replay buffer.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
-        public ReplaySubject(int bufferSize, TimeSpan window)
-        {
-            _implementation = new ReplayByTime(bufferSize, window);
-        }
+        #endregion
+
+        #region Constructors
+
+        #region All
 
         /// <summary>
         /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class.
@@ -57,19 +44,9 @@ namespace System.Reactive.Subjects
             _implementation = new ReplayByTime(scheduler);
         }
 
-        //TODO: Does this overload make any sense with the optimisations? Surely this now is just <c>new ReplaySubject<T>(bufferSize).SubscribeOn(scheduler)</c>?
-        //Potentially should be marked as obsolete
-        /// <summary>
-        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size and scheduler.
-        /// </summary>
-        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
-        /// <param name="scheduler">Scheduler the observers are invoked on.</param>
-        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
-        public ReplaySubject(int bufferSize, IScheduler scheduler)
-        {
-            _implementation = new ReplayByTime(bufferSize, scheduler);
-        }
+        #endregion
+
+        #region Count
 
         /// <summary>
         /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size.
@@ -92,6 +69,32 @@ namespace System.Reactive.Subjects
             }
         }
 
+        /// <summary>
+        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size and scheduler.
+        /// </summary>
+        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
+        /// <param name="scheduler">Scheduler the observers are invoked on.</param>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero.</exception>
+        public ReplaySubject(int bufferSize, IScheduler scheduler)
+        {
+            _implementation = new ReplayByTime(bufferSize, scheduler);
+        }
+
+        #endregion
+
+        #region Time
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified window.
+        /// </summary>
+        /// <param name="window">Maximum time length of the replay buffer.</param>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        public ReplaySubject(TimeSpan window)
+        {
+            _implementation = new ReplayByTime(window);
+        }
+
         /// <summary>
         /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified window and scheduler.
         /// </summary>
@@ -104,16 +107,40 @@ namespace System.Reactive.Subjects
             _implementation = new ReplayByTime(window, scheduler);
         }
 
+        #endregion
+
+        #region Count & Time
+
         /// <summary>
-        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified window.
+        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size and window.
         /// </summary>
+        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
         /// <param name="window">Maximum time length of the replay buffer.</param>
-        /// <exception cref="ArgumentOutOfRangeException"><paramref name="window"/> is less than TimeSpan.Zero.</exception>
-        public ReplaySubject(TimeSpan window)
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        public ReplaySubject(int bufferSize, TimeSpan window)
         {
-            _implementation = new ReplayByTime(window);
+            _implementation = new ReplayByTime(bufferSize, window);
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;" /> class with the specified buffer size, window and scheduler.
+        /// </summary>
+        /// <param name="bufferSize">Maximum element count of the replay buffer.</param>
+        /// <param name="window">Maximum time length of the replay buffer.</param>
+        /// <param name="scheduler">Scheduler the observers are invoked on.</param>
+        /// <exception cref="ArgumentOutOfRangeException"><paramref name="bufferSize"/> is less than zero. -or- <paramref name="window"/> is less than TimeSpan.Zero.</exception>
+        /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
+        public ReplaySubject(int bufferSize, TimeSpan window, IScheduler scheduler)
+        {
+            _implementation = new ReplayByTime(bufferSize, window, scheduler);
         }
 
+        #endregion
+
+        #endregion
+
+        #region Properties
+
         /// <summary>
         /// Indicates whether the subject has observers subscribed to it.
         /// </summary>
@@ -122,6 +149,12 @@ namespace System.Reactive.Subjects
             get { return _implementation.HasObservers; }
         }
 
+        #endregion
+
+        #region Methods
+
+        #region Observer implementation
+
         /// <summary>
         /// Notifies all subscribed and future observers about the arrival of the specified element in the sequence.
         /// </summary>
@@ -149,6 +182,10 @@ namespace System.Reactive.Subjects
             _implementation.OnCompleted();
         }
 
+        #endregion
+
+        #region IObservable implementation
+
         /// <summary>
         /// Subscribes an observer to the subject.
         /// </summary>
@@ -160,6 +197,10 @@ namespace System.Reactive.Subjects
             return _implementation.Subscribe(observer);
         }
 
+        #endregion
+
+        #region IDisposable implementation
+
         /// <summary>
         /// Releases all resources used by the current instance of the <see cref="System.Reactive.Subjects.ReplaySubject&lt;T&gt;"/> class and unsubscribe all observers.
         /// </summary>
@@ -168,6 +209,10 @@ namespace System.Reactive.Subjects
             _implementation.Dispose();
         }
 
+        #endregion
+
+        #endregion
+
         private interface IReplaySubjectImplementation : ISubject<T>, IDisposable
         {
             bool HasObservers { get; }