Class Aeron.Context
- All Implemented Interfaces:
Cloneable
- Enclosing class:
- Aeron
Aeron client via the
Aeron.connect(Aeron.Context) method and its overloads. It gives applications some control over
the interactions with the Aeron Media Driver. It can also set up error handling as well as application
callbacks for image information from the Media Driver.
A number of the properties are for testing and should not be set by end users.
Note: Do not reuse instances of the context across different Aeron clients.
The context will be owned by ClientConductor after a successful
Aeron.connect(Context) and closed via Aeron.close().
-
Nested Class Summary
Nested classes/interfaces inherited from class io.aeron.CommonContext
CommonContext.InferableBoolean -
Field Summary
Fields inherited from class io.aeron.CommonContext
AERON_DIR_PROP_DEFAULT, AERON_DIR_PROP_NAME, ALIAS_PARAM_NAME, CHANNEL_RECEIVE_TIMESTAMP_OFFSET_PARAM_NAME, CHANNEL_SEND_TIMESTAMP_OFFSET_PARAM_NAME, CONGESTION_CONTROL_PARAM_NAME, CONTROL_MODE_RESPONSE, DEBUG_TIMEOUT_PROP_NAME, DEFAULT_DRIVER_TIMEOUT_MS, DRIVER_TIMEOUT_MS, DRIVER_TIMEOUT_PROP_NAME, ENABLE_EXPERIMENTAL_FEATURES_PROP_NAME, ENDPOINT_PARAM_NAME, EOS_PARAM_NAME, FALLBACK_LOGGER_PROP_NAME, FLOW_CONTROL_PARAM_NAME, GROUP_PARAM_NAME, GROUP_TAG_PARAM_NAME, INITIAL_TERM_ID_PARAM_NAME, INTERFACE_PARAM_NAME, IPC_CHANNEL, IPC_MEDIA, LINGER_PARAM_NAME, MAX_RESEND_PARAM_NAME, MDC_CONTROL_MODE_DYNAMIC, MDC_CONTROL_MODE_MANUAL, MDC_CONTROL_MODE_PARAM_NAME, MDC_CONTROL_PARAM_NAME, MEDIA_RCV_TIMESTAMP_OFFSET_PARAM_NAME, MTU_LENGTH_PARAM_NAME, NAK_DELAY_PARAM_NAME, NULL_SESSION_ID, PRINT_CONFIGURATION_ON_START_PROP_NAME, PROTOTYPE_CORRELATION_ID, PUBLICATION_WINDOW_LENGTH_PARAM_NAME, RECEIVER_WINDOW_LENGTH_PARAM_NAME, REJOIN_PARAM_NAME, RELIABLE_STREAM_PARAM_NAME, RESERVED_OFFSET, RESPONSE_CORRELATION_ID_PARAM_NAME, RESPONSE_ENDPOINT_PARAM_NAME, SECURE_RANDOM_ALGORITHM_DEFAULT, SECURE_RANDOM_ALGORITHM_PROP_NAME, SESSION_ID_PARAM_NAME, SOCKET_RCVBUF_PARAM_NAME, SOCKET_SNDBUF_PARAM_NAME, SPARSE_PARAM_NAME, SPIES_SIMULATE_CONNECTION_PARAM_NAME, SPY_PREFIX, STREAM_ID_PARAM_NAME, TAG_PREFIX, TAGS_PARAM_NAME, TERM_ID_PARAM_NAME, TERM_LENGTH_PARAM_NAME, TERM_OFFSET_PARAM_NAME, TETHER_PARAM_NAME, TTL_PARAM_NAME, UDP_CHANNEL, UDP_MEDIA, UNTETHERED_LINGER_TIMEOUT_PARAM_NAME, UNTETHERED_RESTING_TIMEOUT_PARAM_NAME, UNTETHERED_WINDOW_LIMIT_TIMEOUT_PARAM_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaeronDirectoryName(String dirName) Set the top level Aeron directory used for communication between the client and Media Driver, and the location of the data buffers.Get the callback handler for when a counter is available.Set up a callback for when a counter is available.Get the default callback handler for notifying whenImages become available.Set up a default callback for when anImageis available.TheIdleStrategyto be used when awaiting a response from the Media Driver.awaitingIdleStrategy(IdleStrategy idleStrategy) Provides anIdleStrategyto be used when awaiting a response from the Media Driver.longclientId()Get the client identity that has been allocated for communicating with the media driver.Get theLockthat is used to provide mutual exclusion in the Aeron client.clientLock(Lock lock) TheLockthat is used to provide mutual exclusion in the Aeron client.Returns the name of this client.clientName(String clientName) Sets the name used to identify this client among other clients connected to the media driver.clone()Perform a shallow copy of the object.voidclose()Clean up all resources that the client uses to communicate with the Media Driver.Get theRunnablethat is called when the client is closed by timeout or normal means.closeHandler(Runnable handler) Set aRunnablethat is called when the client is closed by timeout or normal means.longDuration to linger on closing to allow publishers and subscribers time to notice closed resources.closeLingerDurationNs(long closeLingerDurationNs) Duration to linger on closing to allow publishers and subscribers time to notice closed resources.conclude()This is called automatically byAeron.connect(Aeron.Context)and its overloads.Get theAgentInvokerthat is used to run the Media Driver while awaiting a synchronous response.driverAgentInvoker(AgentInvoker driverAgentInvoker) Set theAgentInvokerfor the Media Driver to be used while awaiting a synchronous response.Get the proxy for communicating with the media driver.driverTimeoutMs(long value) Set the amount of time, in milliseconds, that this client will wait until it determines the Media Driver is unavailable.Get theEpochClockused by the client for the epoch time in milliseconds.epochClock(EpochClock clock) Set theEpochClockto be used for tracking wall clock time when interacting with the driver.Get the error handler that will be called for errors reported back from the media driver or during poll operations.errorHandler(ErrorHandler errorHandler) Handle Aeron exceptions in a callback method.intGet file page size from running media driver.longDuration to sleep when conductor is idle.idleSleepDurationNs(long idleSleepDurationNs) Duration to sleep when conductor is idle.Get theIdleStrategyemployed by the client for the client duty cycle.idleStrategy(IdleStrategy idleStrategy) Provides anIdleStrategyfor the thread responsible for the client duty cycle.longReturn the timeout between service calls to the duty cycle for the client.longGet the interval in nanoseconds for which the client will perform keep-alive operations.keepAliveIntervalNs(long value) Set the interval in nanoseconds for which the client will perform keep-alive operations.Get theNanoClockto be used for tracking high resolution time.Set theNanoClockto be used for tracking high resolution time.booleanShould mapped-memory be pre-touched to avoid soft page faults.preTouchMappedMemory(boolean preTouchMappedMemory) Should mapped-memory be pre-touched to avoid soft page faults.Get the handler to receive error frames that have been received by the local driver for publications added by this client.publicationErrorFrameHandler(PublicationErrorFrameHandler publicationErrorFrameHandler) Set the handler to receive error frames that have been received by the local driver for publications added by this client.longDuration to wait while lingering an entity such as anImagebefore deleting underlying resources such as memory mapped files.resourceLingerDurationNs(long resourceLingerDurationNs) Duration to wait while lingering an entity such as anImagebefore deleting underlying resources such as memory mapped files.This is the error handler which will be used if an error occurs during the callback for poll operations such asSubscription.poll(FragmentHandler, int).subscriberErrorHandler(ErrorHandler errorHandler) The error handler which will be used if an error occurs during the callback for poll operations such asSubscription.poll(FragmentHandler, int).The thread factory to be used to construct the conductor thread.threadFactory(ThreadFactory threadFactory) Specify the thread factory to use when starting the conductor thread.The buffer used for communicating from the media driver to the Aeron client.Get theRingBufferused for sending commands to the media driver.toString()Get the callback handler for when a counter is unavailable.Set up a callback for when a counter is unavailable.Get the callback handler for when anImageis unavailable.Set up a default callback for when anImageis unavailable.booleanShould anAgentInvokerbe used for running theClientConductorrather than run it on a thread with aAgentRunner.useConductorAgentInvoker(boolean useConductorAgentInvoker) Should anAgentInvokerbe used for running theClientConductorrather than run it on a thread with aAgentRunner.Methods inherited from class io.aeron.CommonContext
aeronDirectory, aeronDirectoryName, checkDebugTimeout, checkDebugTimeout, cncFile, concludeAeronDirectory, countersMetaDataBuffer, countersMetaDataBuffer, countersValuesBuffer, countersValuesBuffer, deleteAeronDirectory, driverFilePageSize, driverTimeoutMs, enableExperimentalFeatures, enableExperimentalFeatures, errorLogBuffer, fallbackLogger, generateRandomDirName, getAeronDirectoryName, getSecureRandomAlgorithm, isConcluded, isDriverActive, isDriverActive, isDriverActive, mapExistingCncFile, newCncFile, newDefaultCncFile, nextCorrelationId, printErrorLog, requestDriverTermination, saveErrorLog, saveErrorLog, saveExistingErrors, setupErrorHandler, shouldPrintConfigurationOnStart
-
Constructor Details
-
Context
public Context()
-
-
Method Details
-
clone
Perform a shallow copy of the object.- Overrides:
clonein classCommonContext- Returns:
- a shallow copy of the object.
-
conclude
This is called automatically byAeron.connect(Aeron.Context)and its overloads. There is no need to call it from a client application. It is responsible for providing default values for options that are not individually changed through field setters.- Overrides:
concludein classCommonContext- Returns:
- this for a fluent API.
-
clientId
public long clientId()Get the client identity that has been allocated for communicating with the media driver.- Returns:
- the client identity that has been allocated for communicating with the media driver.
-
clientName
Sets the name used to identify this client among other clients connected to the media driver.- Parameters:
clientName- to use.- Returns:
- this for a fluent API.
- Since:
- 1.44.0
- See Also:
-
clientName
Returns the name of this client.- Returns:
- name of this client or empty String if not configured.
- Since:
- 1.44.0
- See Also:
-
useConductorAgentInvoker
Should anAgentInvokerbe used for running theClientConductorrather than run it on a thread with aAgentRunner.- Parameters:
useConductorAgentInvoker- useAgentInvokerbe used for running theClientConductor?- Returns:
- this for a fluent API.
-
useConductorAgentInvoker
public boolean useConductorAgentInvoker()Should anAgentInvokerbe used for running theClientConductorrather than run it on a thread with aAgentRunner.- Returns:
- true if the
ClientConductorwill be run with anAgentInvokerotherwise false.
-
preTouchMappedMemory
Should mapped-memory be pre-touched to avoid soft page faults.- Parameters:
preTouchMappedMemory- true if mapped-memory should be pre-touched otherwise false.- Returns:
- this for a fluent API.
- See Also:
-
preTouchMappedMemory
public boolean preTouchMappedMemory()Should mapped-memory be pre-touched to avoid soft page faults.- Returns:
- true if mapped-memory should be pre-touched otherwise false.
- See Also:
-
driverAgentInvoker
Set theAgentInvokerfor the Media Driver to be used while awaiting a synchronous response.Useful for when running on a low thread count scenario.
- Parameters:
driverAgentInvoker- to be invoked while awaiting a response in the client.- Returns:
- this for a fluent API.
-
driverAgentInvoker
Get theAgentInvokerthat is used to run the Media Driver while awaiting a synchronous response.- Returns:
- the
AgentInvokerthat is used for running the Media Driver.
-
clientLock
TheLockthat is used to provide mutual exclusion in the Aeron client.If the
useConductorAgentInvoker()is set and only one thread accesses the client then the lock can be set toNoOpLockto elide the lock overhead.- Parameters:
lock- that is used to provide mutual exclusion in the Aeron client.- Returns:
- this for a fluent API.
-
clientLock
Get theLockthat is used to provide mutual exclusion in the Aeron client.- Returns:
- the
Lockthat is used to provide mutual exclusion in the Aeron client.
-
epochClock
Set theEpochClockto be used for tracking wall clock time when interacting with the driver.- Parameters:
clock-EpochClockto be used for tracking wall clock time when interacting with the driver.- Returns:
- this for a fluent API.
-
epochClock
Get theEpochClockused by the client for the epoch time in milliseconds.- Returns:
- the
EpochClockused by the client for the epoch time in milliseconds.
-
nanoClock
Set theNanoClockto be used for tracking high resolution time.- Parameters:
clock-NanoClockto be used for tracking high resolution time.- Returns:
- this for a fluent API.
-
nanoClock
Get theNanoClockto be used for tracking high resolution time.- Returns:
- the
NanoClockto be used for tracking high resolution time.
-
idleStrategy
Provides anIdleStrategyfor the thread responsible for the client duty cycle.- Parameters:
idleStrategy- Thread idle strategy for the client duty cycle.- Returns:
- this for a fluent API.
-
idleStrategy
Get theIdleStrategyemployed by the client for the client duty cycle.- Returns:
- the
IdleStrategyemployed by the client for the client duty cycle.
-
awaitingIdleStrategy
Provides anIdleStrategyto be used when awaiting a response from the Media Driver.- Parameters:
idleStrategy- Thread idle strategy for awaiting a response from the Media Driver.- Returns:
- this for a fluent API.
-
awaitingIdleStrategy
TheIdleStrategyto be used when awaiting a response from the Media Driver.This can be changed to a
BusySpinIdleStrategyorYieldingIdleStrategyfor lower response time, especially for adding counters or releasing resources, at the expense of CPU usage.- Returns:
- the
IdleStrategyto be used when awaiting a response from the Media Driver.
-
toClientBuffer
The buffer used for communicating from the media driver to the Aeron client.- Returns:
- the buffer used for communicating from the media driver to the Aeron client.
-
toDriverBuffer
Get theRingBufferused for sending commands to the media driver.- Returns:
- the
RingBufferused for sending commands to the media driver.
-
driverProxy
Get the proxy for communicating with the media driver.- Returns:
- the proxy for communicating with the media driver.
-
errorHandler
Handle Aeron exceptions in a callback method. The default behavior is defined byAeron.Configuration.DEFAULT_ERROR_HANDLER. This is the error handler which will be used if an error occurs during the callback for poll operations such asSubscription.poll(FragmentHandler, int).The error handler can be reset after
Aeron.connect()and the latest version will always be used so that the bootstrapping process can be performed such as replacing the default one with aCountedErrorHandler.- Parameters:
errorHandler- Method to handle objects of type Throwable.- Returns:
- this for a fluent API.
- See Also:
-
errorHandler
Get the error handler that will be called for errors reported back from the media driver or during poll operations.- Returns:
- the error handler that will be called for errors reported back from the media driver or poll operations.
-
subscriberErrorHandler
The error handler which will be used if an error occurs during the callback for poll operations such asSubscription.poll(FragmentHandler, int). The default will beerrorHandler()if not set.- Parameters:
errorHandler- Method to handle objects of type Throwable.- Returns:
- this for a fluent API.
- See Also:
-
subscriberErrorHandler
This is the error handler which will be used if an error occurs during the callback for poll operations such asSubscription.poll(FragmentHandler, int). The default will beerrorHandler()if not set. To haveSubscription.poll(FragmentHandler, int)not delegate then set withRethrowingErrorHandler.- Returns:
- the error handler that will be called for errors reported back from the media driver.
-
availableImageHandler
Set up a default callback for when anImageis available.- Parameters:
handler- Callback method for handling available image notifications.- Returns:
- this for a fluent API.
-
availableImageHandler
Get the default callback handler for notifying whenImages become available.- Returns:
- the callback handler for notifying when
Images become available.
-
availableCounterHandler
Set up a callback for when a counter is available. This will be added to the list first before additional handler are added withAeron.addAvailableCounterHandler(AvailableCounterHandler).- Parameters:
handler- to be called for handling available counter notifications.- Returns:
- this for a fluent API.
-
availableCounterHandler
Get the callback handler for when a counter is available.- Returns:
- the callback handler for when a counter is available.
-
closeHandler
Set aRunnablethat is called when the client is closed by timeout or normal means.It is not safe to call any API functions from any threads after this hook is called. In addition, any in flight calls may still cause faults. Thus treating this as a hard error and terminate the process in this hook as soon as possible is recommended.
- Parameters:
handler- that is called when the client is closed.- Returns:
- this for a fluent API.
-
closeHandler
Get theRunnablethat is called when the client is closed by timeout or normal means.- Returns:
- the
Runnablethat is called when the client is closed.
-
keepAliveIntervalNs
Set the interval in nanoseconds for which the client will perform keep-alive operations.- Parameters:
value- the interval in nanoseconds for which the client will perform keep-alive operations.- Returns:
- this for a fluent API.
-
keepAliveIntervalNs
public long keepAliveIntervalNs()Get the interval in nanoseconds for which the client will perform keep-alive operations.- Returns:
- the interval in nanoseconds for which the client will perform keep-alive operations.
-
driverTimeoutMs
Set the amount of time, in milliseconds, that this client will wait until it determines the Media Driver is unavailable. When this happens aDriverTimeoutExceptionwill be generated for the error handler.- Overrides:
driverTimeoutMsin classCommonContext- Parameters:
value- Number of milliseconds.- Returns:
- this for a fluent API.
- See Also:
-
interServiceTimeoutNs
public long interServiceTimeoutNs()Return the timeout between service calls to the duty cycle for the client.When exceeded,
errorHandler()will be called and the activePublications,Images, andCounters will be closed.This value is controlled by the driver and included in the CnC file. It can be configured by adjusting the
aeron.client.liveness.timeoutproperty set on the media driver.- Returns:
- the timeout in nanoseconds between service calls as an allowed maximum.
-
idleSleepDurationNs
Duration to sleep when conductor is idle.- Parameters:
idleSleepDurationNs- to sleep when conductor is idle.- Returns:
- this for a fluent API.
- See Also:
-
idleSleepDurationNs
public long idleSleepDurationNs()Duration to sleep when conductor is idle.- Returns:
- duration in nanoseconds to sleep when conductor is idle.
- See Also:
-
resourceLingerDurationNs
Duration to wait while lingering an entity such as anImagebefore deleting underlying resources such as memory mapped files.- Parameters:
resourceLingerDurationNs- to wait before deleting an expired resource.- Returns:
- this for a fluent API.
- See Also:
-
resourceLingerDurationNs
public long resourceLingerDurationNs()Duration to wait while lingering an entity such as anImagebefore deleting underlying resources such as memory mapped files.- Returns:
- duration in nanoseconds to wait before deleting an expired resource.
- See Also:
-
closeLingerDurationNs
Duration to linger on closing to allow publishers and subscribers time to notice closed resources.This value can be increased from the default to a few seconds to better cope with long GC pauses or resource starved environments. Issues could manifest as seg faults using files after they have been unmapped from publishers or subscribers not noticing the close in a timely fashion.
- Parameters:
closeLingerDurationNs- to wait before deleting resources when closing.- Returns:
- this for a fluent API.
- See Also:
-
closeLingerDurationNs
public long closeLingerDurationNs()Duration to linger on closing to allow publishers and subscribers time to notice closed resources.This value can be increased from the default to a few seconds to better cope with long GC pauses or resource starved environments. Issues could manifest as seg faults using files after they have been unmapped from publishers or subscribers not noticing the close in a timely fashion.
- Returns:
- duration in nanoseconds to wait before deleting resources when closing.
- See Also:
-
aeronDirectoryName
Set the top level Aeron directory used for communication between the client and Media Driver, and the location of the data buffers.- Overrides:
aeronDirectoryNamein classCommonContext- Parameters:
dirName- New top level Aeron directory.- Returns:
- this for a fluent API.
-
threadFactory
Specify the thread factory to use when starting the conductor thread.- Parameters:
threadFactory- thread factory to construct the thread.- Returns:
- this for a fluent API.
-
threadFactory
The thread factory to be used to construct the conductor thread.- Returns:
- the specified thread factory or
Thread(Runnable)if none is provided.
-
publicationErrorFrameHandler
public Aeron.Context publicationErrorFrameHandler(PublicationErrorFrameHandler publicationErrorFrameHandler) Set the handler to receive error frames that have been received by the local driver for publications added by this client.- Parameters:
publicationErrorFrameHandler- to be called back when an error frame is received.- Returns:
- this for a fluent API.
- Since:
- 1.47.0
-
publicationErrorFrameHandler
Get the handler to receive error frames that have been received by the local driver for publications added by this client.- Returns:
- the
PublicationErrorFrameHandlerto call back on to. - Since:
- 1.47.0
-
filePageSize
public int filePageSize()Get file page size from running media driver.- Returns:
- file page size or zero (if not connected to the media driver).
- Since:
- 1.48.0
-
close
public void close()Clean up all resources that the client uses to communicate with the Media Driver.- Overrides:
closein classCommonContext
-
toString
-