Netflix/RxJava — pull request #1146 by akarnokd (2014-05-05 14:08:54+00:00)
Title: Scheduler fixes505

This PR contains some changes to the NewThreadScheduler and EventLoopScheduler, which makes them work more correctly and gives some flexibility to them.

Note that this conflicts with PR #1143.

Notable changes:
- Changed ```NewThreadScheduler``` to use a ```ScheduledExecutorService``` as I don't see any particular reason why not.
- Added proper logic for tracking and unsubscribing scheduled actions.
- Renamed inner classes to better express their purpose (got lost in all of those inner EventLoopScheduler workers).
- Added the ability to specify the number of cores and the worker selection policy to ```EventLoopScheduler```. Two policies are available: round robin and least-recent (default). A new ```Schedulers.fixed()``` method is added which lets the caller specify the pool size. Since the EventLoopScheduler is package private, I wasn't sure how to expose the worker selection policy. In addition, EventLoopScheduler implements Subscription so the Scheduler returned by ```fixed()``` can be terminated. I made sure the ```computation()``` scheduler can't be terminated this way.
- Fixed ```EventLoopScheduler``` to track the submitted actions properly.
- Note that the potential Subscription leak due to ```innerSubscription.remove()``` happening before ```innerSubscription.add()``` in ```EventLoopWorker``` is not handled. It can't happen with ```NewThreadScheduler``` though, although it would benefit from a ```CompositeSubscription.delete()``` method which doesn't unsubscribe the removed item and thus not interrupting the executor unnecessarily.