1

Good morning,

I am trying to understand the low lattency library aeron, I have an instance of the class Publication:

Publication publication=new Publication(CHANNEL, STREAM_ID);

Where:

CHANNEL=System.getProperty("aeron.sample.channel", "aeron:udp?endpoint=224.0.1.1:40456");

and

STREAM_ID=Integer.getInteger("aeron.sample.streamId", 10);

After creating the instance, to send a message what it does is:

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.

I want to understand how the last line of code works, Method offer() is at the following file: https://github.com/real-logic/aeron/blob/master/aeron-client/src/main/java/io/aeron/Publication.java

At line 373 There is the following method:

 public final long offer(final DirectBuffer buffer, final int offset, final int length)
 {
     return offer(buffer, offset, length, null);
 }

That returns a function, If I search for this function in the Publication.java file I only found the following:

public abstract long offer(DirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier);

It's an abstract method that I don't know where I could found the definition of it.

If someone could help me I will appreciate a lot to understand how this library works.

david.t_92
  • 1,971
  • 1
  • 11
  • 15
  • Why don't you open the source code of Aeron in an IDE and use its navigation features to move through the code? All Java IDEs can help you find implementations of an abstract method. – yole Mar 02 '18 at 09:53
  • Unrelated: avoid using // comments **after** code. Put them in the line above. Much better to read - and especially on SO it sucks when lines get to lengthy and people need to scroll. – GhostCat Mar 02 '18 at 09:55
  • From what i see, the `Publication` class you shared is an abstract class, that shouldn't be instanciated directly, but should be extended by a child class that defines the abstract methods. So the code for `offer` is not in this file, but in the child(ren) classe(s) that extend this abstract class – Kaddath Mar 02 '18 at 10:21
  • @Kaddath Thank you, I'll try to find the children class, thank you a lot – david.t_92 Mar 02 '18 at 10:24

1 Answers1

1

I bet you have found all answers but in case for future searchers:

There are 2 implementation of Publication class :

I can recomend to watch Martin's video about how Aeron works https://www.youtube.com/watch?v=tM4YskS94b0

QIvan
  • 652
  • 4
  • 13