早上好,
我正在尝试了解低延迟库 aeron,我有一个 Publication 类的实例:
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);
这是一个抽象方法,我不知道在哪里可以找到它的定义。
如果有人可以帮助我,我将非常感谢了解这个库的工作原理。
最佳答案
我打赌您已经找到了所有答案,但以防万一将来的搜索者:
Publication 类有 2 个实现:
我可以推荐观看 Martin 关于 Aeron 工作原理的视频 https://www.youtube.com/watch?v=tM4YskS94b0
关于java - 我看不到方法在哪里执行 Aeron 低延迟库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49066631/