public class Aeron extends Object implements AutoCloseable
Publications and Subscriptions.
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
Provides a means to override configuration for an
Aeron client 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 |
|---|---|
long |
addAvailableCounterHandler(AvailableCounterHandler handler)
Add a handler to the list be called when
Counters become available. |
long |
addCloseHandler(Runnable handler)
Add a handler to the list be called when the Aeron client is closed.
|
Counter |
addCounter(int typeId,
DirectBuffer keyBuffer,
int keyOffset,
int keyLength,
DirectBuffer labelBuffer,
int labelOffset,
int labelLength)
Allocate a counter on the media driver and return a
Counter for it. |
Counter |
addCounter(int typeId,
String label)
Allocate a counter on the media driver and return a
Counter for it. |
ExclusivePublication |
addExclusivePublication(String channel,
int streamId)
Add an
ExclusivePublication for publishing messages to subscribers from a single thread. |
ConcurrentPublication |
addPublication(String channel,
int streamId)
Add a
Publication for publishing messages to subscribers. |
Subscription |
addSubscription(String channel,
int streamId)
Add a new
Subscription for subscribing to messages from publishers. |
Subscription |
addSubscription(String channel,
int streamId,
AvailableImageHandler availableImageHandler,
UnavailableImageHandler unavailableImageHandler)
Add a new
Subscription for subscribing to messages from publishers. |
long |
addUnavailableCounterHandler(UnavailableCounterHandler handler)
Add a handler to the list be called when
Counters become unavailable. |
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). |
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. |
CountersReader |
countersReader()
Get the
CountersReader for the Aeron media driver counters. |
boolean |
hasActiveCommands()
Does the client have any active asynchronous commands?
|
boolean |
isClosed()
Has the client been closed? If not then the CnC file may not be unmapped.
|
boolean |
isCommandActive(long correlationId)
Is the command still active for a given correlation id.
|
long |
nextCorrelationId()
Generate the next correlation id that is unique for the connected Media Driver.
|
void |
printCounters(PrintStream out)
Print out the values from
countersReader() which can be useful for debugging. |
boolean |
removeAvailableCounterHandler(AvailableCounterHandler handler)
Deprecated.
please use
removeAvailableCounterHandler(long). |
boolean |
removeAvailableCounterHandler(long registrationId)
Remove a previously added handler to the list be called when
Counters become available. |
boolean |
removeCloseHandler(long registrationId)
Remove a previously added handler to the list be called when the Aeron client is closed.
|
boolean |
removeCloseHandler(Runnable handler)
Deprecated.
please use
removeCloseHandler(long). |
boolean |
removeUnavailableCounterHandler(long registrationId)
Remove a previously added handler to the list be called when
Counters become unavailable. |
boolean |
removeUnavailableCounterHandler(UnavailableCounterHandler handler)
Deprecated.
please use
removeUnavailableCounterHandler(long). |
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(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 AgentInvoker conductorAgentInvoker()
AgentInvoker for the client conductor.AgentInvoker for the client conductor.public boolean isCommandActive(long correlationId)
correlationId - to check if it is still active.Publication.asyncAddDestination(String),
Subscription.asyncAddDestination(String),
hasActiveCommands()public boolean hasActiveCommands()
When close operations are performed on Publications, Subscriptions, and Counters the
commands are sent asynchronously to the driver. The client tracks active commands in case errors need to be
reported. If you wish to wait for acknowledgement of close operations then wait for this method to return false.
public void close()
Aeron.Context.useConductorAgentInvoker(boolean).
This will close all currently open Publications, Subscriptions, and Counters created
from this client. To check for the command being acknowledged by the driver
close in interface AutoCloseablepublic ConcurrentPublication addPublication(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(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(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(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 Images become available for consumption. Null is valid if no
action is to be taken.unavailableImageHandler - called when Images 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 CountersReader countersReader()
CountersReader for the Aeron media driver counters.CountersReader for the Aeron media driver in use.public Counter addCounter(int typeId, DirectBuffer keyBuffer, int keyOffset, int keyLength, 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, 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)public long addAvailableCounterHandler(AvailableCounterHandler handler)
Counters become available.handler - to be called when Counters become available.public boolean removeAvailableCounterHandler(long registrationId)
Counters become available.registrationId - to be removed which was returned from add method.@Deprecated public boolean removeAvailableCounterHandler(AvailableCounterHandler handler)
removeAvailableCounterHandler(long).Counters become available.handler - to be removed.public long addUnavailableCounterHandler(UnavailableCounterHandler handler)
Counters become unavailable.handler - to be called when Counters become unavailable.public boolean removeUnavailableCounterHandler(long registrationId)
Counters become unavailable.registrationId - to be removed which was returned from add method.@Deprecated public boolean removeUnavailableCounterHandler(UnavailableCounterHandler handler)
removeUnavailableCounterHandler(long).Counters become unavailable.handler - to be removed.public long addCloseHandler(Runnable handler)
handler - to be called when the Aeron client is closed.public boolean removeCloseHandler(long registrationId)
registrationId - of the handler from when it was added.@Deprecated public boolean removeCloseHandler(Runnable handler)
removeCloseHandler(long).handler - to be removed.Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.