Skip to main content

AeronSubscription

Struct AeronSubscription 

Source
pub struct AeronSubscription<S: ResourceStorage<aeron_subscription_t> = LiveCResource<aeron_subscription_t>> { /* private fields */ }

Implementations§

Source§

impl<S: ResourceStorage<aeron_subscription_t>> AeronSubscription<S>

Source

pub fn poll<AeronFragmentHandlerHandlerImpl: AeronFragmentHandlerCallback>( &self, handler: &mut AeronFragmentHandlerHandlerImpl, fragment_limit: usize, ) -> Result<i32, AeronCError>

Poll the images under the subscription for available message fragments.

Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.

To assemble messages that span multiple fragments then use FragmentAssembler.

§Parameters
  • handler for handling each message fragment as it is read.
  • fragment_limit number of message fragments to limit when polling across multiple images.
§Return

the number of fragments received or -1 for error.

Borrows the callback exclusively until this call returns. This method uses no callback allocation, reference count, runtime borrow check or mutex. The callback can borrow local state.

Source

pub fn poll_fn<AeronFragmentHandlerHandlerImpl: FnMut(&[u8], &AeronHeader<Borrowed<aeron_header_t>>)>( &self, handler: AeronFragmentHandlerHandlerImpl, fragment_limit: usize, ) -> Result<i32, AeronCError>

Poll the images under the subscription for available message fragments.

Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.

To assemble messages that span multiple fragments then use FragmentAssembler.

§Parameters
  • handler for handling each message fragment as it is read.
  • fragment_limit number of message fragments to limit when polling across multiple images.
§Return

the number of fragments received or -1 for error.

Stack-borrowed closure variant. The FnMut closure lives on the caller’s stack and is borrowed for this call only. The callback fires synchronously, so nothing is heap-allocated or stored and the closure may borrow local state. Generated only for callbacks C does not retain. Prefer it to the Handler form on the hot path

§Panics

A panic in the closure is passed to the caller. Fragments since the poll started (or the last COMMIT) are delivered again on the next poll

Source

pub fn controlled_poll<AeronControlledFragmentHandlerHandlerImpl: AeronControlledFragmentHandlerCallback>( &self, handler: &mut AeronControlledFragmentHandlerHandlerImpl, fragment_limit: usize, ) -> Result<i32, AeronCError>

Poll in a controlled manner the images under the subscription for available message fragments. Control is applied to fragments in the stream. If more fragments can be read on another stream they will even if BREAK or ABORT is returned from the fragment handler.

Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.

To assemble messages that span multiple fragments then use ControlledFragmentAssembler.

§Parameters
  • handler for handling each message fragment as it is read.
  • fragment_limit number of message fragments to limit when polling across multiple images.
§Return

the number of fragments received or -1 for error.

Borrows the callback exclusively until this call returns. This method uses no callback allocation, reference count, runtime borrow check or mutex. The callback can borrow local state.

Source

pub fn controlled_poll_fn<AeronControlledFragmentHandlerHandlerImpl: FnMut(&[u8], &AeronHeader<Borrowed<aeron_header_t>>) -> aeron_controlled_fragment_handler_action_t>( &self, handler: AeronControlledFragmentHandlerHandlerImpl, fragment_limit: usize, ) -> Result<i32, AeronCError>

Poll in a controlled manner the images under the subscription for available message fragments. Control is applied to fragments in the stream. If more fragments can be read on another stream they will even if BREAK or ABORT is returned from the fragment handler.

Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.

To assemble messages that span multiple fragments then use ControlledFragmentAssembler.

§Parameters
  • handler for handling each message fragment as it is read.
  • fragment_limit number of message fragments to limit when polling across multiple images.
§Return

the number of fragments received or -1 for error.

Stack-borrowed closure variant. The FnMut closure lives on the caller’s stack and is borrowed for this call only. The callback fires synchronously, so nothing is heap-allocated or stored and the closure may borrow local state. Generated only for callbacks C does not retain. Prefer it to the Handler form on the hot path

§Panics

A panic in the closure is passed to the caller. Fragments since the poll started (or the last COMMIT) are delivered again on the next poll

Source

pub fn block_poll<AeronBlockHandlerHandlerImpl: AeronBlockHandlerCallback>( &self, handler: &mut AeronBlockHandlerHandlerImpl, block_length_limit: usize, ) -> c_long

Poll the images under the subscription for available message fragments in blocks.

This method is useful for operations like bulk archiving and messaging indexing.

§Parameters
  • handler to receive a block of fragments from each image.
  • block_length_limit for each image polled.
§Return

the number of bytes consumed or -1 for error.

Borrows the callback exclusively until this call returns. This method uses no callback allocation, reference count, runtime borrow check or mutex. The callback can borrow local state.

Source

pub fn block_poll_fn<AeronBlockHandlerHandlerImpl: FnMut(&[u8], i32, i32)>( &self, handler: AeronBlockHandlerHandlerImpl, block_length_limit: usize, ) -> c_long

Poll the images under the subscription for available message fragments in blocks.

This method is useful for operations like bulk archiving and messaging indexing.

§Parameters
  • handler to receive a block of fragments from each image.
  • block_length_limit for each image polled.
§Return

the number of bytes consumed or -1 for error.

Stack-borrowed closure variant. The FnMut closure lives on the caller’s stack and is borrowed for this call only. The callback fires synchronously, so nothing is heap-allocated or stored and the closure may borrow local state. Generated only for callbacks C does not retain. Prefer it to the Handler form on the hot path

§Panics

A panic in the closure is passed to the caller. Fragments since the poll started (or the last COMMIT) are delivered again on the next poll

Source

pub fn is_connected(&self) -> bool

Is this subscription connected by having at least one open publication image.

§Return

true if this subscription connected by having at least one open publication image.

Source

pub unsafe fn constants( &self, constants: &AeronSubscriptionConstants<impl ResourceStorage<aeron_subscription_constants_t>>, ) -> Result<i32, AeronCError>

Fill in a structure with the constants in use by a subscription.

§Parameters
  • constants structure to fill in with the constants
§Return

0 for success and -1 for error.

§Safety

The output may contain borrowed native pointers. Do not use those pointers after the queried handle is dropped or changed. Prefer the lifetime-bound get_constants, get_buffers or get_values method.

Source

pub fn get_constants( &self, ) -> Result<AeronSubscriptionConstants<ScopedInline<'_, aeron_subscription_constants_t>>, AeronCError>

Fill in a structure with the constants in use by a subscription.

Source

pub fn channel_status_indicator_id(&self) -> Result<i32, AeronCError>

get_constants()?.channel_status_indicator_id(). Call get_constants() once to read several fields

Source

pub fn image_count(&self) -> Result<i32, AeronCError>

Count of images associated to this subscription.

§Return

count of count associated to this subscription or -1 for error.

Source

pub unsafe fn image_retain( &self, image: &AeronImage<impl ResourceStorage<aeron_image_t>>, ) -> Result<i32, AeronCError>

Retain the given image for access in the application.

Note: A retain call must have a corresponding release call. Note: Subscriptions are not threadsafe and should not be shared between subscribers.

§Parameters
  • image to retain
§Return

0 for success and -1 for error.

§Safety

This bypasses Rust ownership. Keep all retained pointers valid until native cleanup. Initializers require exclusive access and must not overwrite live native state or invalidate borrowed views. After raw removal or deletion, prevent all further access and Rust cleanup through every alias. Prefer the owning handle’s constructor, close or cancel method.

Source

pub unsafe fn image_release( &self, image: &AeronImage<impl ResourceStorage<aeron_image_t>>, ) -> Result<i32, AeronCError>

Release the given image and relinquish desire to use the image directly.

Note: Subscriptions are not threadsafe and should not be shared between subscribers.

§Parameters
  • image to release
§Return

0 for success and -1 for error.

§Safety

This bypasses Rust ownership. Keep all retained pointers valid until native cleanup. Initializers require exclusive access and must not overwrite live native state or invalidate borrowed views. After raw removal or deletion, prevent all further access and Rust cleanup through every alias. Prefer the owning handle’s constructor, close or cancel method.

Source

pub fn is_closed(&self) -> bool

Is the subscription closed.

§Return

true if it has been closed otherwise false.

Source

pub fn channel_status(&self) -> i64

Get the status of the media channel for this subscription.

The status will be ERRORED (-1) if a socket exception occurs on setup and ACTIVE (1) if all is well.

§Return

1 for ACTIVE, -1 for ERRORED

Source

pub fn local_sockaddrs( &self, address_vec: &AeronIovec, address_vec_len: usize, ) -> Result<i32, AeronCError>

Get all of the local socket addresses for this subscription. Multiple addresses can occur if this is a multi-destination subscription. Addresses will a string representation in numeric form. IPv6 addresses will be surrounded by ‘[’ and ‘]’ so that the ‘:’ that separate the parts are distinguishable from the port delimiter. E.g. [fe80::7552:c06e:6bf4:4160]:12345. As of writing the maximum length for a formatted address is 54 bytes including the NULL terminator. AERON_CLIENT_MAX_LOCAL_ADDRESS_STR_LEN is defined to provide enough space to fit the returned string. Returned strings will be NULL terminated. If the buffer to hold the address can not hold enough of the message it will be truncated and the last character will be null.

If the address_vec_len is less the total number of addresses available then the first addresses found up to that length will be placed into the address_vec. However the function will return the total number of addresses available so if if that is larger than the input array then the client code may wish to re-query with a larger array to get them all.

§Parameters
  • address_vec to hold the received addresses
  • address_vec_len available length of the vector to hold the addresses
§Return

number of addresses found or -1 if there is an error.

Source

pub fn resolved_endpoint(&self, address: &mut [u8]) -> Result<i32, AeronCError>

Retrieves the first local socket address for this subscription. If this is not MDS then it will be the one representing endpoint for this subscription.

§Parameters
  • address buffer to hold the resolved endooint.
§Return

-1 on error, 0 if address not found, 1 if address is found. @see aeron_subscription_local_sockaddrs

Source

pub fn resolved_endpoint_as_string( &self, max_length: usize, ) -> Result<String, AeronCError>

Retrieves the first local socket address for this subscription. If this is not MDS then it will be the one representing endpoint for this subscription.

§Parameters
  • address buffer to hold the resolved endooint.
§Return

-1 on error, 0 if address not found, 1 if address is found. @see aeron_subscription_local_sockaddrs

Source

pub fn resolved_endpoint_into( &self, dst_truncate_to_capacity: &mut String, ) -> Result<i32, AeronCError>

Retrieves the first local socket address for this subscription. If this is not MDS then it will be the one representing endpoint for this subscription.

§Parameters
  • address buffer to hold the resolved endooint.
§Return

-1 on error, 0 if address not found, 1 if address is found. @see aeron_subscription_local_sockaddrs NOTE: allocation friendly method, the string capacity must be set as it will truncate string to capacity it will never grow the string. So if you pass String::new() it will write 0 chars

Source

pub fn try_resolve_channel_endpoint_port( &self, uri: &mut [u8], ) -> Result<i32, AeronCError>

Retrieves the channel URI for this subscription with any wildcard ports filled in. If the channel is not UDP or does not have a wildcard port (0), then it will return the original URI.

§Parameters
  • uri buffer to hold the resolved uri.
§Return

-1 on failure or the number of bytes written to the buffer (excluding the NULL terminator). Writing is done on a per key basis, so if the buffer was truncated before writing completed, it will only include the byte count up to the key that overflowed. However, the invariant that if the number returned >= uri_len, then output will have been truncated.

Source

pub fn try_resolve_channel_endpoint_port_as_string( &self, max_length: usize, ) -> Result<String, AeronCError>

Retrieves the channel URI for this subscription with any wildcard ports filled in. If the channel is not UDP or does not have a wildcard port (0), then it will return the original URI.

§Parameters
  • uri buffer to hold the resolved uri.
§Return

-1 on failure or the number of bytes written to the buffer (excluding the NULL terminator). Writing is done on a per key basis, so if the buffer was truncated before writing completed, it will only include the byte count up to the key that overflowed. However, the invariant that if the number returned >= uri_len, then output will have been truncated.

Source

pub fn try_resolve_channel_endpoint_port_into( &self, dst_truncate_to_capacity: &mut String, ) -> Result<i32, AeronCError>

Retrieves the channel URI for this subscription with any wildcard ports filled in. If the channel is not UDP or does not have a wildcard port (0), then it will return the original URI.

§Parameters
  • uri buffer to hold the resolved uri.
§Return

-1 on failure or the number of bytes written to the buffer (excluding the NULL terminator). Writing is done on a per key basis, so if the buffer was truncated before writing completed, it will only include the byte count up to the key that overflowed. However, the invariant that if the number returned >= uri_len, then output will have been truncated. NOTE: allocation friendly method, the string capacity must be set as it will truncate string to capacity it will never grow the string. So if you pass String::new() it will write 0 chars

Source

pub fn as_ref(&self) -> Ref<'_, Self>

Borrow this handle without cloning its owner.

Source

pub fn get_inner(&self) -> *mut aeron_subscription_t

Source

pub unsafe fn get_inner_mut(&self) -> &mut aeron_subscription_t

Mutable access to the underlying C struct, minted from &self: nothing prevents two live &mut at once, so the caller must ensure exclusive access for the lifetime of the returned reference.

§Safety

No other reference (& or &mut) to the underlying struct may be alive while the returned &mut is in use.

Source

pub unsafe fn get_inner_ref(&self) -> &aeron_subscription_t

Borrow the native struct.

§Safety

No Rust or native call may mutate the struct while this reference is alive. Shared wrappers also require coordination with other threads.

Source§

impl AeronSubscription

Source

pub unsafe fn from_ptr( ptr: *mut aeron_subscription_t, ) -> AeronSubscription<Borrowed<aeron_subscription_t>>

Borrow a native pointer without taking ownership.

§Safety

The pointer must be non-null. It and its parents must remain live for every use. Calls must follow Aeron’s threading and aliasing rules.

Source§

impl AeronSubscription

Source

pub fn close(self) -> Result<(), AeronCError>

Releases this handle. Native cleanup waits for the last owning clone when the resource can be retained by another handle.

Source§

impl AeronSubscription

Source

pub fn close_with_handler<AeronNotificationHandlerImpl: AeronNotificationCallback + Send + 'static>( self, on_close_complete: Option<&SharedHandler<AeronNotificationHandlerImpl>>, ) -> Result<(), AeronCError>

Like Self::close, but calls on_close_complete from the conductor once the close finishes. Returns an error unless this is the last owning handle. The client keeps the SharedHandler alive until it has fired

Source§

impl AeronSubscription

Source

pub fn async_add_destination( &self, client: &Aeron, uri: &CStr, ) -> Result<AeronAsyncDestination, AeronCError>

Start a destination change. Dropping the operation does not cancel it.

Source

pub fn add_destination( &self, uri: &CStr, timeout: Duration, ) -> Result<(), AeronCError>

Wait for a destination change or the timeout. Drives an invoker conductor when needed. The handle retains its owning client. A timeout does not cancel the native operation.

Source

pub fn async_remove_destination( &self, client: &Aeron, uri: &CStr, ) -> Result<AeronAsyncDestination, AeronCError>

Start a destination change. Dropping the operation does not cancel it.

Source

pub fn remove_destination( &self, uri: &CStr, timeout: Duration, ) -> Result<(), AeronCError>

Wait for a destination change or the timeout. Drives an invoker conductor when needed. The handle retains its owning client. A timeout does not cancel the native operation.

Source§

impl AeronSubscription

Source

pub fn image_at_index(&self, index: usize) -> Option<AeronImage>

A retained image handle for index, or None when no such image exists.

The returned AeronImage releases the image when it drops. Until then the image stays valid even once it becomes unavailable: AeronImage::is_closed turns true, polling reads nothing more, and its log buffer stays mapped. The image keeps the native subscription open, so Self::close waits for the image to drop

Each call returns a new handle, and every handle to the same image shares one position with the subscription, which the borrow checker cannot see. Do not poll one handle inside a poll of another handle to the same image or of its subscription, and do not keep polling it on this thread after the subscription moves to another thread. Either one races on the image position and can deliver fragments twice. Aeron Java and C++ do not check for this either

The image is one publisher session: a publisher that reconnects with a new session is a new image, so poll the subscription, or fetch the new image, to follow it. To keep an image passed to an image callback, whose arguments are valid only during the call, retain it here (or with Self::image_by_session_id) on your own subscription.

Source

pub fn image_by_session_id(&self, session_id: i32) -> Option<AeronImage>

A retained image handle for session_id, or None when no such image exists. Same automatic-release semantics as Self::image_at_index.

Source

pub fn for_each_image<F: FnMut(&AeronImageRef)>(&self, f: F)

Borrow-scoped iteration over the current images, with zero retain/release bookkeeping. The borrowed AeronImage is only valid inside the closure; call Self::image_at_index / Self::image_by_session_id for a handle that outlives it.

Source§

impl<S: ResourceStorage<aeron_subscription_t>> AeronSubscription<S>

Source

pub fn status(&self) -> AeronStatus

High-level connection state derived from the subscription handle.

Source

pub fn stream_id(&self) -> Result<i32, AeronCError>

Accessor for the stream id (no direct C accessor exists for subscriptions; backed by Self::get_constants). For a hot loop, call Self::get_constants once and reuse the returned AeronSubscriptionConstants.

Source

pub fn channel(&self) -> Result<String, AeronCError>

Accessor for the channel (see Self::stream_id).

Source

pub fn registration_id(&self) -> Result<i64, AeronCError>

Accessor for the registration id (see Self::stream_id).

Trait Implementations§

Source§

impl<S: ResourceStorage<aeron_subscription_t>> Debug for AeronSubscription<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: ResourceStorage<aeron_subscription_t>> From<&AeronSubscription<S>> for *mut aeron_subscription_t

Source§

fn from(value: &AeronSubscription<S>) -> Self

Converts to this type from the input type.
Source§

impl<S: ResourceStorage<aeron_subscription_t>> From<AeronSubscription<S>> for *mut aeron_subscription_t

Source§

fn from(value: AeronSubscription<S>) -> Self

Converts to this type from the input type.
Source§

impl Send for AeronSubscription<LiveCResource<aeron_subscription_t>>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.