Subscriber cleanup#137
Conversation
#### Problem `Publishers` was using different implementations of `CancellableSubscriber` to provide different callbacks using inheritance. eg: by providing methods like `doOnNext`, `doOnCancel`, etc. This is problematic as it requires calls to `super.do*` by implementator. Also, it created unnecessary class hierarchy with little benefit. #### Modification Rolled up all implementations into a single class that takes various callbacks as different lambdas. This is easier to use and there are less chances of errors when the implementor forgot to call `super` methods. Thanks @yschimke for the comment in PR rsocket#127 which led me to change the approach.
|
I'm not sure my comment meant that changing to a deep Java 8 approach was the only solution, I suspect that more private methods and choosing which public doXXX to override was possible. But I'm interested at the same time to see how this plays out. LGTM |
|
@yschimke Indeed your comment didn't suggest this approach but made me realize the problem with the older approach. Here was the problem with the older approach: There were 3 classes |
Instead of sending an error, on detecting duplicate `onSubscribe` call, according to the spec, we should send a `cancel`
|
I had the same knee-jerk reaction than @yschimke but your comment motivate the current implementation. Otherwise, 👍 |
|
@stevegury updated the PR description |
* Add RESPONSE Next Flag As per discussion in rsocket/rsocket#126 in order to remove ambiguity and use of sentinel value of 0-bytes, and allow 0-byte payloads. * Update Protocol.md * Clarify Data or Metadata for Next. * Clarify the sample code
Problem
Publisherswas using different implementations ofCancellableSubscriberto provide different callbacks using inheritance. eg: by providing methods likedoOnNext,doOnCancel, etc.This is problematic as it requires calls to
super.do*by implementator. Also, it created unnecessary class hierarchy with little benefit.(Edit: Adding more context from the comments below)
There were 3 classes
CancellableSubscriber,SafeCancellableSubscriberandSafeCancellableSubscriberProxy, each of them would override some of the methods fromSubscriber. eg:doOnCancelwas something that was to be used bySafeCancellableSubscriberandCancellableSubscriberin a way thatSafeCancellableSubscriberhad to implementdoOnCanceland provide yet another methoddoOnCancel0which if implemented bySafeCancellableSubscriberProxywill have to provide yet another protected method.So, I figured not only the approach was error prone it was painful to code and maintain. Thus this approach where in specific callbacks can be overridden and controlled by the caller.
Modification
Rolled up all implementations into a single class that takes various callbacks as different lambdas.
This is easier to use and there are less chances of errors when the implementor forgot to call
supermethods.Thanks @yschimke for the comment in PR #127 which led me to change the approach.