public class Aeron
extends java.lang.Object
implements java.lang.AutoCloseable
Publication
s and Subscription
s.
Use an Aeron.Context
to configure the Aeron object.
A client application requires only one Aeron object per Media Driver.
Note: If Aeron.Context.errorHandler(ErrorHandler)
is not set and a DriverTimeoutException
occurs then the process will face the wrath of System.exit(int)
.
See Aeron.Configuration.DEFAULT_ERROR_HANDLER
.
Modifier and Type | Class and Description |
---|---|
static class |
Aeron.Configuration
Configuration options for the
Aeron client. |
static class |
Aeron.Context
This class provides configuration for the
Aeron class via the connect(Aeron.Context)
method and its overloads. |
Modifier and Type | Field and Description |
---|---|
static int |
NULL_VALUE
Used to represent a null value for when some value is not yet set.
|
Modifier and Type | Method and Description |
---|---|
Counter |
addCounter(int typeId,
org.agrona.DirectBuffer keyBuffer,
int keyOffset,
int keyLength,
org.agrona.DirectBuffer labelBuffer,
int labelOffset,
int labelLength)
Allocate a counter on the media driver and return a
Counter for it. |
Counter |
addCounter(int typeId,
java.lang.String label)
Allocate a counter on the media driver and return a
Counter for it. |
ExclusivePublication |
addExclusivePublication(java.lang.String channel,
int streamId)
Add an
ExclusivePublication for publishing messages to subscribers from a single thread. |
ConcurrentPublication |
addPublication(java.lang.String channel,
int streamId)
Add a
Publication for publishing messages to subscribers. |
Subscription |
addSubscription(java.lang.String channel,
int streamId)
Add a new
Subscription for subscribing to messages from publishers. |
Subscription |
addSubscription(java.lang.String channel,
int streamId,
AvailableImageHandler availableImageHandler,
UnavailableImageHandler unavailableImageHandler)
Add a new
Subscription for subscribing to messages from publishers. |
long |
clientId()
Get the client identity that has been allocated for communicating with the media driver.
|
void |
close()
Clean up and release all Aeron client resources and shutdown conductor thread if not using
Aeron.Context.useConductorAgentInvoker(boolean) . |
org.agrona.concurrent.AgentInvoker |
conductorAgentInvoker()
Get the
AgentInvoker for the client conductor. |
static Aeron |
connect()
Create an Aeron instance and connect to the media driver with a default
Aeron.Context . |
static Aeron |
connect(Aeron.Context ctx)
Create an Aeron instance and connect to the media driver.
|
Aeron.Context |
context()
Get the
Aeron.Context that is used by this client. |
org.agrona.concurrent.status.CountersReader |
countersReader()
Get the
CountersReader for the Aeron media driver counters. |
boolean |
isClosed()
Has the client been closed? If not then the CnC file may not be unmapped.
|
long |
nextCorrelationId()
Generate the next correlation id that is unique for the connected Media Driver.
|
void |
printCounters(java.io.PrintStream out)
Print out the values from
countersReader() which can be useful for debugging. |
public static final int NULL_VALUE
public static Aeron connect()
Aeron.Context
.
Threads required for interacting with the media driver are created and managed within the Aeron instance.
Aeron
instance connected to the Media Driver.public static Aeron connect(Aeron.Context ctx)
Threads required for interacting with the media driver are created and managed within the Aeron instance.
If an exception occurs while trying to establish a connection then the Aeron.Context.close()
method
will be called on the passed context.
ctx
- for configuration of the client.Aeron
instance connected to the Media Driver.public void printCounters(java.io.PrintStream out)
countersReader()
which can be useful for debugging.out
- to where the counters get printed.public boolean isClosed()
public Aeron.Context context()
Aeron.Context
that is used by this client.Aeron.Context
that is use by this client.public long clientId()
public org.agrona.concurrent.AgentInvoker conductorAgentInvoker()
AgentInvoker
for the client conductor.AgentInvoker
for the client conductor.public void close()
Aeron.Context.useConductorAgentInvoker(boolean)
.
This will close all currently open Publication
s, Subscription
s, and Counter
s created
from this client.
close
in interface java.lang.AutoCloseable
public ConcurrentPublication addPublication(java.lang.String channel, int streamId)
Publication
for publishing messages to subscribers. The publication returned is threadsafe.channel
- for sending the messages known to the media layer.streamId
- within the channel scope.ConcurrentPublication
.public ExclusivePublication addExclusivePublication(java.lang.String channel, int streamId)
ExclusivePublication
for publishing messages to subscribers from a single thread.channel
- for sending the messages known to the media layer.streamId
- within the channel scope.ExclusivePublication
.public Subscription addSubscription(java.lang.String channel, int streamId)
Subscription
for subscribing to messages from publishers.
The method will set up the Subscription
to use the
Aeron.Context.availableImageHandler(AvailableImageHandler)
and
Aeron.Context.unavailableImageHandler(UnavailableImageHandler)
from the Aeron.Context
.
channel
- for receiving the messages known to the media layer.streamId
- within the channel scope.Subscription
for the channel and streamId pair.public Subscription addSubscription(java.lang.String channel, int streamId, AvailableImageHandler availableImageHandler, UnavailableImageHandler unavailableImageHandler)
Subscription
for subscribing to messages from publishers.
This method will override the default handlers from the Aeron.Context
, i.e.
Aeron.Context.availableImageHandler(AvailableImageHandler)
and
Aeron.Context.unavailableImageHandler(UnavailableImageHandler)
. Null values are valid and will
result in no action being taken.
channel
- for receiving the messages known to the media layer.streamId
- within the channel scope.availableImageHandler
- called when Image
s become available for consumption. Null is valid if no
action is to be taken.unavailableImageHandler
- called when Image
s go unavailable for consumption. Null is valid if no
action is to be taken.Subscription
for the channel and streamId pair.public long nextCorrelationId()
This is useful generating correlation identifiers for pairing requests with responses in a clients own application protocol.
This method is thread safe and will work across processes that all use the same media driver.
public org.agrona.concurrent.status.CountersReader countersReader()
CountersReader
for the Aeron media driver counters.CountersReader
for the Aeron media driver in use.public Counter addCounter(int typeId, org.agrona.DirectBuffer keyBuffer, int keyOffset, int keyLength, org.agrona.DirectBuffer labelBuffer, int labelOffset, int labelLength)
Counter
for it.
The counter should be freed by calling Counter.close()
.
typeId
- for the counter.keyBuffer
- containing the optional key for the counter.keyOffset
- within the keyBuffer at which the key begins.keyLength
- of the key in the keyBuffer.labelBuffer
- containing the mandatory label for the counter. The label should not be length prefixed.labelOffset
- within the labelBuffer at which the label begins.labelLength
- of the label in the labelBuffer.CountersManager.allocate(int, DirectBuffer, int, int, DirectBuffer, int, int)
public Counter addCounter(int typeId, java.lang.String label)
Counter
for it.
The counter should be freed by calling Counter.close()
.
typeId
- for the counter.label
- for the counter. It should be US-ASCII.CountersManager.allocate(String, int)
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.