You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "nicoloboschi (via GitHub)" <gi...@apache.org> on 2023/04/14 13:05:16 UTC

[GitHub] [bookkeeper] nicoloboschi commented on a diff in pull request #3733: Use ChannelVoidPromise to avoid useless promise objects creation

nicoloboschi commented on code in PR #3733:
URL: https://github.com/apache/bookkeeper/pull/3733#discussion_r1166812256


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/util/NettyChannelUtil.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.bookkeeper.util;
+
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelOutboundInvoker;
+import io.netty.channel.VoidChannelPromise;
+
+/**
+ * Contains utility methods for working with Netty Channels.
+ */
+public final class NettyChannelUtil {
+
+    private NettyChannelUtil() {
+    }
+
+    /**
+     * Write and flush the message to the channel.
+     *
+     * The promise is an instance of {@link VoidChannelPromise} that properly propagates exceptions up to the pipeline.
+     * Netty has many ad-hoc optimization if the promise is an instance of {@link VoidChannelPromise}.
+     * Lastly, it reduces pollution of useless {@link io.netty.channel.ChannelPromise} objects created
+     * by the default write and flush method {@link ChannelOutboundInvoker#writeAndFlush(Object)}.
+     * See https://stackoverflow.com/q/54169262 and https://stackoverflow.com/a/9030420 for more details.
+     *
+     * @param ctx channel's context
+     * @param msg buffer to write in the channel
+     */
+    public static void writeAndFlushWithVoidPromise(ChannelOutboundInvoker ctx, Object msg) {

Review Comment:
   what's your concern? even if different, the right implementation method will be called based on the pass argument



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org