clebertsuconic commented on code in PR #4101:
URL: https://github.com/apache/activemq-artemis/pull/4101#discussion_r895716470


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PageReadWriter.java:
##########
@@ -0,0 +1,281 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.core.paging.impl;
+
+import java.nio.ByteBuffer;
+import java.util.function.Consumer;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper;
+import org.apache.activemq.artemis.core.io.SequentialFile;
+import org.apache.activemq.artemis.core.io.SequentialFileFactory;
+import org.apache.activemq.artemis.core.paging.PagedMessage;
+import org.apache.activemq.artemis.core.persistence.StorageManager;
+import org.apache.activemq.artemis.core.server.LargeServerMessage;
+import org.apache.activemq.artemis.utils.DataConstants;
+import org.apache.activemq.artemis.utils.Env;
+import org.jboss.logging.Logger;
+
+public class PageReadWriter {
+
+
+   private static Logger logger = Logger.getLogger(PageReadWriter.class);
+
+   public static final int SIZE_RECORD = DataConstants.SIZE_BYTE + 
DataConstants.SIZE_INT + DataConstants.SIZE_BYTE;
+
+   private static final byte START_BYTE = (byte) '{';
+
+   private static final byte END_BYTE = (byte) '}';
+
+   //sizeOf(START_BYTE) + sizeOf(MESSAGE LENGTH) + sizeOf(END_BYTE)
+   private static final int HEADER_AND_TRAILER_SIZE = DataConstants.SIZE_INT + 
2;
+   private static final int MINIMUM_MSG_PERSISTENT_SIZE = 
HEADER_AND_TRAILER_SIZE;
+   private static final int HEADER_SIZE = HEADER_AND_TRAILER_SIZE - 1;
+   private static final int MIN_CHUNK_SIZE = Env.osPageSize();
+
+   public interface SuspectFileCallback {
+      void onSuspect(String fileName, int position, int msgNumber);
+   }
+
+   public interface PageRecordFilter {
+      boolean skip(ActiveMQBuffer buffer);
+   }
+
+   public interface ReadCallback {
+      void readComple(int size);
+   }
+
+   public static final PageRecordFilter ONLY_LARGE = (buffer) -> 
!PagedMessageImpl.isLargeMessage(buffer);
+
+   public static final PageRecordFilter NO_SKIP = (buffer) -> false;
+
+   public static final PageRecordFilter SKIP_ALL = (buffer) -> true;
+
+   public static int writeMessage(PagedMessage message, SequentialFileFactory 
fileFactory, SequentialFile file) throws Exception {
+      final int messageEncodedSize = message.getEncodeSize();
+      final int bufferSize = messageEncodedSize + SIZE_RECORD;
+      final ByteBuffer buffer = fileFactory.newBuffer(bufferSize);
+      ChannelBufferWrapper activeMQBuffer = new 
ChannelBufferWrapper(Unpooled.wrappedBuffer(buffer));
+      activeMQBuffer.clear();
+      activeMQBuffer.writeByte(START_BYTE);
+      activeMQBuffer.writeInt(messageEncodedSize);
+      message.encode(activeMQBuffer);
+      activeMQBuffer.writeByte(END_BYTE);
+      assert (activeMQBuffer.readableBytes() == bufferSize) : 
"messageEncodedSize is different from expected";
+      //buffer limit and position are the same
+      assert (buffer.remaining() == bufferSize) : "buffer position or limit 
are changed";
+      file.writeDirect(buffer, false);
+      return bufferSize;
+   }
+
+
+

Review Comment:
   I am just moving what was on Page here. not new code!
   
   It's not my original code, but I will see where I would do some spaces.



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