peterxcli commented on code in PR #1481:
URL: https://github.com/apache/ratis/pull/1481#discussion_r3458226836
##########
ratis-netty/src/main/java/org/apache/ratis/netty/client/NettyClientStreamRpc.java:
##########
@@ -358,15 +364,40 @@ public void channelRead(ChannelHandlerContext ctx, Object
msg) {
LOG.error("{}: unexpected message {}", name, msg.getClass());
return;
}
- try (DataStreamReplyByteBuf reply = (DataStreamReplyByteBuf) msg) {
- process(reply);
+ final DataStreamReplyByteBuf reply = (DataStreamReplyByteBuf) msg;
+ final ReferenceCountedObject<DataStreamReply> ref =
ReferenceCountedObject.<DataStreamReply>newBuilder()
+ .setValue((DataStreamReplyByteBuf) msg)
+ .setReleaseMethod(r -> {
+ if (r != null) {
+ Preconditions.assertSame(reply, r, "reply");
+ reply.release();
+ }
+ }).build();
Review Comment:
Thanks, I plan to add as static RC builder function for `DataStreamReply`:
```java
public static ReferenceCountedObject<DataStreamReply>
asReferenceCounted(DataStreamReplyByteBuf reply) {
Objects.requireNonNull(reply, "reply == null");
return ReferenceCountedObject.<DataStreamReply>newBuilder()
.setValue(reply)
.setReleaseMethod(r -> {
if (r != null) {
Preconditions.assertSame(reply, r, "reply").release();
}
})
.build();
}
```
so prod and test can shared the same RC-DataStreamReply constructor code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]