chia7712 commented on a change in pull request #9563: URL: https://github.com/apache/kafka/pull/9563#discussion_r517824324
########## File path: clients/src/main/java/org/apache/kafka/common/network/SendBuilder.java ########## @@ -0,0 +1,119 @@ +/* + * 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.kafka.common.network; + +import org.apache.kafka.common.protocol.ObjectSerializationCache; +import org.apache.kafka.common.protocol.Writable; +import org.apache.kafka.common.requests.RequestHeader; +import org.apache.kafka.common.utils.ByteUtils; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * This class provides a way to build {@link Send} objects for network + * transmission from generated {@link org.apache.kafka.common.protocol.ApiMessage} + * types. Its main advantage over direct {@link ByteBuffer} allocation based on + * {@link org.apache.kafka.common.protocol.ApiMessage#size(ObjectSerializationCache, short)} + * is that it avoids copying "bytes" fields. The downside is that it is up to the caller + * to allocate a buffer which accounts only for the additional request overhead. + * + * See {@link org.apache.kafka.common.requests.EnvelopeRequest#toSend(String, RequestHeader)} + * for example usage. + */ +public class SendBuilder implements Writable { + private final List<ByteBuffer> buffers = new ArrayList<>(); + private final ByteBuffer buffer; + + public SendBuilder(ByteBuffer buffer) { Review comment: The ```buffer``` is used/owned by ```SendBuilder`` only. It seems to me this constructor should accept ```capacity(int type)``` rather than ```ByteBuffer```. (SendBuilder should create ```ByteBuffer``` in construction) ########## File path: clients/src/main/java/org/apache/kafka/common/network/SendBuilder.java ########## @@ -0,0 +1,119 @@ +/* + * 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.kafka.common.network; + +import org.apache.kafka.common.protocol.ObjectSerializationCache; +import org.apache.kafka.common.protocol.Writable; +import org.apache.kafka.common.requests.RequestHeader; +import org.apache.kafka.common.utils.ByteUtils; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * This class provides a way to build {@link Send} objects for network + * transmission from generated {@link org.apache.kafka.common.protocol.ApiMessage} + * types. Its main advantage over direct {@link ByteBuffer} allocation based on + * {@link org.apache.kafka.common.protocol.ApiMessage#size(ObjectSerializationCache, short)} + * is that it avoids copying "bytes" fields. The downside is that it is up to the caller + * to allocate a buffer which accounts only for the additional request overhead. + * + * See {@link org.apache.kafka.common.requests.EnvelopeRequest#toSend(String, RequestHeader)} + * for example usage. + */ +public class SendBuilder implements Writable { + private final List<ByteBuffer> buffers = new ArrayList<>(); + private final ByteBuffer buffer; + + public SendBuilder(ByteBuffer buffer) { Review comment: The ```buffer``` is used/owned by ```SendBuilder``` only. It seems to me this constructor should accept ```capacity(int type)``` rather than ```ByteBuffer```. (SendBuilder should create ```ByteBuffer``` in construction) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org