wy96f commented on a change in pull request #2666: ARTEMIS-2336 Use zero copy
to replicate journal/page/large message file
URL: https://github.com/apache/activemq-artemis/pull/2666#discussion_r283251599
##########
File path:
artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
##########
@@ -345,21 +351,41 @@ private boolean canWrite(final int requiredCapacity) {
return canWrite;
}
+ private Object getFileObject(FileDelegatedChannelBufferWrapper fileBuffer) {
+ if (channel.pipeline().get(SslHandler.class) == null) {
+ return new DefaultFileRegion(fileBuffer.getFile(),
fileBuffer.getOffset(), fileBuffer.getDataSize());
+ } else {
+ try {
+ RandomAccessFile raf = new RandomAccessFile(fileBuffer.getFile(),
"r");
+ return new ChunkedFile(raf, fileBuffer.getOffset(),
fileBuffer.getDataSize(), 8192);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
@Override
public final void write(ActiveMQBuffer buffer,
final boolean flush,
final boolean batched,
final ChannelFutureListener futureListener) {
- final int readableBytes = buffer.readableBytes();
+ //no need to lock because the Netty's channel is thread-safe
+ //and the order of write is ensured by the order of the write calls
+ final Channel channel = this.channel;
+
+ int readableBytes = buffer.readableBytes();
+ Object fileObject = null;
+ if (buffer instanceof FileDelegatedChannelBufferWrapper) {
+ readableBytes +=
((FileDelegatedChannelBufferWrapper)buffer).getDataSize();
+ fileObject = getFileObject((FileDelegatedChannelBufferWrapper)buffer);
Review comment:
Good point. I'll work on it:)
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services