Skip to content

Java Programming Guide

mjpt777 edited this page Oct 30, 2014 · 53 revisions

Java Programming Guide

The Aeron API is designed to be as simple as possible and no simpler. In this guide, we will walk through a set of applications demonstrating specific points as we do. The entire applications can be found in the locations below.

Embedded Media Driver

The Aeron Media Driver can be run standalone and handle many applications. However, in some situations, it is desirable to run the media driver within the application.

In this case, a MediaDriver can be instantiated in the process. Only a single one is needed, but it does require some resources as discussed here.

When running an embedded media driver, it is recommended to set the following via system properties or directly via MediaDriver.Context passed into MediaDriver.launch:

  • Buffer Locations should point to a specific location as to not interfere with other Media Driver instances and
  • Threading Modes should be considered carefully as they will be spawned within the parent process.

An example of starting up an embedded Media Driver.

final MediaDriver driver = MediaDriver.launch();

Aeron

Aeron client applications need to coordinate operation with a running Media Driver. Either an embedded one or one that is standalone. This interaction handles creating Publications and Subscriptions and housekeeping. The interaction point for the application is the Aeron class.

final Aeron aeron = Aeron.connect(new Aeron.Context());

Settings for the instance may be changed via an Aeron.Context instance that is passed into the Aeron.connect method. As mentioned here, an Executor may be passed to this method to have the ClientConductor thread use said Executor.

Event Handling

Exception handler New/Inactive connection handler comes in from ClientConductor thread

DirectBuffer

DirectBuffer usage and differences between other buffer types.

  • DirectBuffer
  • MutableDirectBuffer
  • UnsafeBuffer

Subscription

Subscription instance creation and usage

DataHandler

DataHandler interface

Polling

Subscription.poll usage and considerations

Reassembler

Publication

Publication instance creation and usage Fragmentation handler for the application

Handling Offering Returning false

Publication.offer returning false

Monitoring

Walk through AeronStat

Use Case: Ping-Pong

Walk through Ping/Pong