Skip to content
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

Merged
merged 3 commits into from
Aug 25, 2020

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

Users who need to report events to two TransportObservers 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 TransportObservers.

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) {
Copy link
Collaborator

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.

Copy link
Member Author

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,
Copy link
Collaborator

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.

Copy link
Member Author

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");
Copy link
Member Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public static TransportObserver combine(final TransportObserver... other) {
switch (other.length) {
case 0:
throw new IllegalArgumentException("At least one TransportObserver is required to combine");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@idelpivnitskiy idelpivnitskiy merged commit 11f911d into apple:transport-observability Aug 25, 2020
@idelpivnitskiy idelpivnitskiy deleted the bi-to branch August 25, 2020 21:52
idelpivnitskiy added a commit that referenced this pull request Aug 26, 2020
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.
idelpivnitskiy added a commit that referenced this pull request Aug 26, 2020
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants