BewareMyPower commented on a change in pull request #12403:
URL: https://github.com/apache/pulsar/pull/12403#discussion_r775118067



##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ChunkMessageIdImpl.java
##########
@@ -0,0 +1,90 @@
+/**
+ * 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.pulsar.client.impl;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.Objects;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.common.api.proto.MessageIdData;
+
+public class ChunkMessageIdImpl extends MessageIdImpl implements MessageId {
+    private final MessageIdImpl firstChunkMsgId;
+
+    public ChunkMessageIdImpl(MessageIdImpl firstChunkMsgId, MessageIdImpl 
lastChunkMsgId) {
+        super(lastChunkMsgId.getLedgerId(), lastChunkMsgId.getEntryId(), 
lastChunkMsgId.getPartitionIndex());
+        this.firstChunkMsgId = firstChunkMsgId;
+    }
+
+    public MessageIdImpl getFirstChunkMessageId() {
+        return firstChunkMsgId;
+    }
+
+    public MessageIdImpl getLastChunkMessageId() {
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder()
+                // First chunk message id part
+                .append(firstChunkMsgId.ledgerId)
+                .append(':')
+                .append(firstChunkMsgId.entryId)
+                .append(':')
+                .append(firstChunkMsgId.partitionIndex)
+                .append(';')
+
+                // Last chunk message id part
+                .append(ledgerId)
+                .append(':')
+                .append(entryId)
+                .append(':')
+                .append(partitionIndex)
+                .toString();
+    }
+
+    @Override
+    public byte[] toByteArray() {
+
+        // write last chunk message id
+        MessageIdData msgId = super.writeMessageIdData(null,-1, 0);

Review comment:
       ```suggestion
           MessageIdData msgId = super.writeMessageIdData(null, -1, 0);
   ```

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ChunkMessageIdImpl.java
##########
@@ -0,0 +1,90 @@
+/**
+ * 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.pulsar.client.impl;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.Objects;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.common.api.proto.MessageIdData;
+
+public class ChunkMessageIdImpl extends MessageIdImpl implements MessageId {
+    private final MessageIdImpl firstChunkMsgId;
+
+    public ChunkMessageIdImpl(MessageIdImpl firstChunkMsgId, MessageIdImpl 
lastChunkMsgId) {
+        super(lastChunkMsgId.getLedgerId(), lastChunkMsgId.getEntryId(), 
lastChunkMsgId.getPartitionIndex());
+        this.firstChunkMsgId = firstChunkMsgId;
+    }
+
+    public MessageIdImpl getFirstChunkMessageId() {
+        return firstChunkMsgId;
+    }
+
+    public MessageIdImpl getLastChunkMessageId() {
+        return this;
+    }
+
+    @Override
+    public String toString() {
+        return new StringBuilder()
+                // First chunk message id part
+                .append(firstChunkMsgId.ledgerId)
+                .append(':')
+                .append(firstChunkMsgId.entryId)
+                .append(':')
+                .append(firstChunkMsgId.partitionIndex)
+                .append(';')
+
+                // Last chunk message id part
+                .append(ledgerId)
+                .append(':')
+                .append(entryId)
+                .append(':')
+                .append(partitionIndex)
+                .toString();

Review comment:
       ```suggestion
           return firstChunkMsgId.toString() + "," + super.toString();
   ```
   
   The `StringBuilder` way is **TOO** long. BTW, there will be no performance 
gain via `StringBuilder` because of the compiler optimization. See 
https://stackoverflow.com/questions/1532461/stringbuilder-vs-string-concatenation-in-tostring-in-java
 for related discussion.

##########
File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java
##########
@@ -1987,6 +1995,9 @@ public void seek(Function<String, Object> function) 
throws PulsarClientException
                 ackSet.recycle();
 
                 seek = Commands.newSeek(consumerId, requestId, 
msgId.getLedgerId(), msgId.getEntryId(), ackSetArr);
+            } else if(messageId instanceof ChunkMessageIdImpl){

Review comment:
       ```suggestion
               } else if (messageId instanceof ChunkMessageIdImpl){
   ```




-- 
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]


Reply via email to