Netflix/RxJava — pull request #605 by akarnokd (2013-12-11 21:44:09+00:00)
Title: Subjects reimplemented.

Reimplemented all 4 kinds of subjects with the following properties:

- The ```onNext```, ```onError``` and ```onCompleted``` are fully thread safe against subscription and unsubscription.
- A terminated subject won't accept any new events; ```AsyncSubject```, ```PublishSubject``` and ```BehaviorSubject``` will re-emit just the very first exception when an observer subscribes to them.
- Emitting events to subscribed observers is done while holding the state lock.
- In Rx.NET when an event is received, the list of observers is retrieved while holding the lock, then outside the lock, the list is traversed and the events are propagated to the observers. Note however, if an observer unsubscribes right after the unlock and before the event propagation, it will still appear in the list and will receive the event. IMO, this is an undesired behavior.
- The drawback of my solution is that it might be possible to deadlock the subjects, i.e., when an observer deliberately passes the source subject to another thread (which sends an event to the subject) and waits for its completion.
- Added the ```Notification.acceptSafe``` which will capture the exception of the ```onNext``` and propagate it through the ```onError```. Its return value indicates if the observer can still be used after (i.e., no terminal event was delivered).
- Added the reusable state classes to ```AbstractSubject```, although none of the subjects use this class any more.
- There is an ```UnsubscribeTester``` class, which seems to be out-of-place. Can this be moved into the test directory?