Skip to content

Rename Channel.bytesBeforeUnwritable() to writableBytes() #12530

Merged
normanmaurer merged 4 commits intomainfrom
writable_method
Jul 3, 2022
Merged

Rename Channel.bytesBeforeUnwritable() to writableBytes() #12530
normanmaurer merged 4 commits intomainfrom
writable_method

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

@normanmaurer normanmaurer commented Jun 29, 2022

… isWritable()

Motivation:

We should expose Channel.writableBytes() as a replacement for both, Channel.bytesBeforeUnwritable() and Channel.isWritable(). If the Channel is writable this method will return a positive number which can also give the user some idea how much data they can write without the risk of having the Channel become unwritable, if not writable it will return 0.

Modifications:

  • Rename Channel.bytesBeforeUnwritable() to writableBytes() and remove isWritable()
  • Adjust code

Result:

Less reduntant API and cleanup

@normanmaurer
Copy link
Copy Markdown
Member Author

This depends on #12517

@normanmaurer normanmaurer added this to the 5.0.0.Alpha3 milestone Jun 29, 2022
Copy link
Copy Markdown
Member

@chrisvest chrisvest left a comment

Choose a reason for hiding this comment

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

Spotted a copy-paste boo in the javadoc. Otherwise looks good.

Comment thread transport/src/main/java/io/netty5/channel/ChannelConfig.java Outdated
@normanmaurer normanmaurer force-pushed the writability branch 2 times, most recently from 475029b to bdc6910 Compare June 29, 2022 15:53
@olliecook
Copy link
Copy Markdown

nit: typo in summary (bytesBeforeUnwritabled)

@normanmaurer
Copy link
Copy Markdown
Member Author

nit: typo in summary (bytesBeforeUnwritabled)

Good catch!

Copy link
Copy Markdown
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Could Channel.isWritable() be left as a shortcut for writableBytes() > 0? What's the reasoning behind removing it?

@trustin trustin changed the title Rename Channel.bytesBeforeUnwritabled() to writableBytes() and remove… Rename Channel.bytesBeforeUnwritable() to writableBytes() and remove… Jun 30, 2022
@normanmaurer
Copy link
Copy Markdown
Member Author

@trustin it feels redundant... that said if you are strong about it we could also make it a default method :) WDYT ?

@normanmaurer normanmaurer force-pushed the writability branch 3 times, most recently from 2e23aaa to e3f118c Compare June 30, 2022 12:45
@normanmaurer normanmaurer force-pushed the writable_method branch 2 times, most recently from 534f6a0 to ec14bcb Compare June 30, 2022 13:04
@trustin
Copy link
Copy Markdown
Member

trustin commented Jun 30, 2022

@normanmaurer Yup, let's make it a default method. Thanks a lot 🙇

Copy link
Copy Markdown
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

Now that we added back isWritable(), we should revert most of the writableBytes() > 0 checks in this PR, because isWritable() has much lower cognitive load on the reader. I added them as suggestions, so you can easily revert them, although you'll have to optimize imports and make Checkstyle happy.

Comment thread transport/src/test/java/io/netty5/channel/PendingWriteQueueTest.java Outdated
Comment thread transport/src/test/java/io/netty5/channel/ReentrantChannelTest.java Outdated
Comment thread transport/src/test/java/io/netty5/channel/ReentrantChannelTest.java Outdated
Comment thread transport/src/test/java/io/netty5/channel/ReentrantChannelTest.java Outdated
Comment thread transport/src/test/java/io/netty5/channel/ReentrantChannelTest.java Outdated
@normanmaurer normanmaurer changed the title Rename Channel.bytesBeforeUnwritable() to writableBytes() and remove… Rename Channel.bytesBeforeUnwritable() to writableBytes() Jul 1, 2022
Base automatically changed from writability to main July 1, 2022 19:17
…ritable() default method

Motivation:

We should expose `Channel.writableBytes()` as a replacement for both, `Channel.bytesBeforeUnwritable()` and `Channel.isWritable()`. If the `Channel` is writable this method will return a positive number which can also give the user some idea how much data they can write without the risk of having the `Channel` become unwritable, if not writable it will return 0.

Modifications:

- Rename Channel.bytesBeforeUnwritabled() to writableBytes() and isWritable() default method
- Adjust code

Result:

Less reduntant API and cleanup

Co-authored-by: Chris Vest <christianvest_hansen@apple.com>
Co-authored-by: Trustin Lee <t@motd.kr>
@normanmaurer
Copy link
Copy Markdown
Member Author

Will merge this once green...

@chrisvest chrisvest self-requested a review July 3, 2022 01:11
@normanmaurer normanmaurer merged commit fa094c9 into main Jul 3, 2022
@normanmaurer normanmaurer deleted the writable_method branch July 3, 2022 09:18
violetagg added a commit to reactor/reactor-netty that referenced this pull request Jul 4, 2022
violetagg added a commit to reactor/reactor-netty that referenced this pull request Jul 4, 2022
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.

5 participants