-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a public factory for BiTransportObserver
#1135
Provide a public factory for BiTransportObserver
#1135
Conversation
Motivation: Users who need to report events to two `TransportObserver`s simultaneously on the server side or who need their own variant of `TransportObserverConnectionFactoryFilter` will find it useful. Modifications: - Move `BiTransportObserver` from `client-api` to `transport-api`; - Convert passes first and second observers into safe observers; - Add public `TransportObservers.biTransportObserver` factory; Result: Users can easily report events to two `TransportObserver`s.
* @return a {@link TransportObserver} that delegates all invocations to the {@code first} and {@code second} | ||
* {@link TransportObserver}s | ||
*/ | ||
public static TransportObserver biTransportObserver(final TransportObserver first, final TransportObserver second) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a public API, I would prefer a combine()
method with a var-arg and if we want, we can optimize for 2 vs many cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Added support for multiple
*/ | ||
public static TransportObserver biTransportObserver(final TransportObserver first, final TransportObserver second) { | ||
return new BiTransportObserver(first, second); | ||
public static TransportObserver combine(final TransportObserver first, final TransportObserver second, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just have combine(final TransportObserver... observers)
?
Also, may be modify the BiTransportObserver
to accept an array instead of two observers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least two observer are required to combine. Good to highlight that in the API instead of verifying at runtime.
Having an array inside BiTransportObserver
will require an array inside every observer level, producing boilerplate at every level to traverse the array. Let's start with simplified approach and we can reconsider if necessary.
public static TransportObserver combine(final TransportObserver... other) { | ||
switch (other.length) { | ||
case 0: | ||
throw new IllegalArgumentException("At least one TransportObserver is required to combine"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was trying to avoid by having first, second, others
arguments: http://jtechies.blogspot.com/2012/07/item-42-use-varargs-judiciously.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK and inline with what we do elsewhere:
public static TransportObserver combine(final TransportObserver... other) { | ||
switch (other.length) { | ||
case 0: | ||
throw new IllegalArgumentException("At least one TransportObserver is required to combine"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK and inline with what we do elsewhere:
Motivation: Users who need to report events to two `TransportObserver`s simultaneously on the server-side or who need their own variant of `TransportObserverConnectionFactoryFilter` will find it useful. Modifications: - Move `BiTransportObserver` from `client-api` to `transport-api`; - Convert passes first and second observers into safe observers; - Add public `TransportObservers.biTransportObserver` factory; Result: Users can easily report events to two `TransportObserver`s.
Motivation: Users who need to report events to two `TransportObserver`s simultaneously on the server-side or who need their own variant of `TransportObserverConnectionFactoryFilter` will find it useful. Modifications: - Move `BiTransportObserver` from `client-api` to `transport-api`; - Convert passes first and second observers into safe observers; - Add public `TransportObservers.biTransportObserver` factory; Result: Users can easily report events to two `TransportObserver`s.
Motivation:
Users who need to report events to two
TransportObserver
s simultaneouslyon the server-side or who need their own variant of
TransportObserverConnectionFactoryFilter
will find it useful.Modifications:
BiTransportObserver
fromclient-api
totransport-api
;TransportObservers.biTransportObserver
factory;Result:
Users can easily report events to two
TransportObserver
s.