早上好,
我正在尝试了解低延迟库 aeron,我有一个发布类的实例:
Publication publication=new Publication(CHANNEL, STREAM_ID);
在哪里:
CHANNEL=System.getProperty("aeron.sample.channel", "aeron:udp?endpoint=224.0.1.1:40456");
和
STREAM_ID=Integer.getInteger("aeron.sample.streamId", 10);
创建实例后,要发送消息,它的作用是:
String a="What I want to send"; //Text that I want to send
bytes[] aBytes=a.getBytes(); // Convert the string to an array of bytes
UnsafeBuffer BUFFER = new UnsafeBuffer(BufferUtil.allocateDirectAligned(256, 64)); //Create an UnsafeBuffer (https://github.com/real-logic/agrona/blob/master/agrona/src/main/java/org/agrona/concurrent/UnsafeBuffer.java)
BUFFER.putBytes(0, aBytes); //Put the Bytes of the array of bytes that contains the text intro tje BUFFER
final long result = publication.offer(BUFFER, 0, messageBytes.length); //This is the last line of the code to send the message, so I guess that this line is used to send the message to the mediaDriver.
我想了解最后一行代码是如何工作的,方法 offer() 在以下文件中:https ://github.com/real-logic/aeron/blob/master/aeron-client/src/main/java/ io/aeron/Publication.java
在第 373 行有以下方法:
public final long offer(final DirectBuffer buffer, final int offset, final int length)
{
return offer(buffer, offset, length, null);
}
这将返回一个函数,如果我在 Publication.java 文件中搜索此函数,我只会找到以下内容:
public abstract long offer(DirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier);
这是一种抽象方法,我不知道在哪里可以找到它的定义。
如果有人可以帮助我,我将非常感谢了解这个库是如何工作的。