Skip to main content

Handler

Struct Handler 

Source
pub struct Handler<T, P: CallbackPolicy = LocalCallback> { /* private fields */ }
Expand description

A reference-counted callback that C stores and calls later.

Clones share one heap allocation. Local handlers use Rc; shared handlers use Arc. C uses the pointer from Handler::as_raw, so the callback must stay alive until C stops using it. Dropping a Handler does not unregister it, and the callback is freed when its last clone drops.

Owned resources retain handler clones until their last owner drops and C cleanup finishes. The client also retains publication, subscription and counter handlers, because the conductor can call them after close() returns. An archive connection copies handler pointers when it starts, so replacing a handler on the original context neither updates that copy nor frees the old handler. Borrowed wrappers retain nothing, so keep your Handler alive while C can call it.

Retaining handlers through cleanup prevents C from calling a freed handler, but keeps replaced closures and their captured values in memory too. An Arc alone cannot track the raw pointer copies C makes.

For retained callbacks, keep the SharedHandler returned by the setter and change its state with Self::lock. This waits for an active callback and must not be done from that callback itself. Use an AeronErrorHandlerSlot when replacement must not wait for an active call. Its set and clear methods free old callbacks after their last call.

Use *_fn or *_once for callbacks that run during the call. Their closures stay on the stack, can borrow local variables and need no heap allocation.

Handler is only for callbacks C keeps after the call returns, such as error, image, counter and close handlers. None of these run on the poll path. Polls never take a Handler: poll(&mut callback), poll_fn and the owned assemblers borrow the callback directly with no RefCell, mutex or reference count.

Handler<T> stays on its thread and uses RefCell to check mutable borrows, with no mutex or atomic operation. SharedHandler<T> uses a mutex and is Send + Sync when T: Send. It takes that mutex on each callback and can wait for another thread holding it. Use Self::lock to inspect or change callback state. Keep poll state in the callback passed to poll or in an owned assembler, not in a Handler

Implementations§

Source§

impl<T> Handler<T>

Source

pub fn borrow(&self) -> Ref<'_, T>

Read local callback state. The borrow must end before invoking the callback.

Acquiring and dropping this guard checks local borrows, with no mutex or atomic operation. It does not clone the handler or allocate memory.

Source

pub fn new(handler: T) -> Self

Source§

impl<T> Handler<T, SharedCallback>

Source

pub fn new_shared(handler: T) -> Self

Source§

impl<T, P: CallbackPolicy> Handler<T, P>

Source

pub fn as_raw(&self) -> *mut c_void

Source

pub fn lock(&self) -> P::Guard<'_, T>

Mutably access callback state. Release the guard before invoking this handler.

For a local Handler, this performs a RefCell borrow check on the current thread, with no mutex or atomic operation. For a SharedHandler, this acquires a mutex and may wait for a callback or another state guard. Neither form clones the handler or allocates memory to acquire the guard.

Polls never call this

Source

pub unsafe fn lock_raw<'a>(raw: *mut c_void) -> P::Guard<'a, T>

Called by the Handler trampolines for callbacks C retains. The poll trampolines borrow &mut F directly and never call this

§Safety

raw must come from a live Handler<T, P> and remain valid for the call.

Source

pub unsafe fn get_mut(&self) -> &mut T

§Safety

No callback or other reference may access the value while this reference is in use. Prefer Self::lock.

Trait Implementations§

Source§

impl<T: AeronAgentCloseFuncCallback, P: CallbackPolicy> AeronAgentCloseFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronAgentDoWorkFuncCallback, P: CallbackPolicy> AeronAgentDoWorkFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronAgentStartFuncCallback, P: CallbackPolicy> AeronAgentStartFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronAvailableCounterCallback, P: CallbackPolicy> AeronAvailableCounterCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_on_available_counter( &mut self, counters_reader: &AeronCountersReader<Borrowed<aeron_counters_reader_t>>, registration_id: i64, counter_id: i32, )

Source§

impl<T: AeronAvailableImageCallback, P: CallbackPolicy> AeronAvailableImageCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronCloseClientCallback, P: CallbackPolicy> AeronCloseClientCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronCountersReaderForeachCounterFuncCallback, P: CallbackPolicy> AeronCountersReaderForeachCounterFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_counters_reader_foreach_counter_func( &mut self, value: i64, id: i32, type_id: i32, key: &[u8], label: &str, )

Source§

impl<T: AeronErrorHandlerCallback, P: CallbackPolicy> AeronErrorHandlerCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_error_handler(&mut self, errcode: c_int, message: &str)

Source§

impl<T: AeronErrorLogReaderFuncCallback, P: CallbackPolicy> AeronErrorLogReaderFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_error_log_reader_func( &mut self, observation_count: i32, first_observation_timestamp: i64, last_observation_timestamp: i64, error: &str, )

Source§

impl<T: AeronFprintfHandlerCallback, P: CallbackPolicy> AeronFprintfHandlerCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_fprintf_handler( &mut self, arg1: &str, arg2: u64, arg4: &str, arg5: *mut c_char, ) -> c_int

Source§

impl<T: AeronIdleStrategyFuncCallback, P: CallbackPolicy> AeronIdleStrategyFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronLossReporterReadEntryFuncCallback, P: CallbackPolicy> AeronLossReporterReadEntryFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_loss_reporter_read_entry_func( &mut self, observation_count: i64, total_bytes_lost: i64, first_observation_timestamp: i64, last_observation_timestamp: i64, session_id: i32, stream_id: i32, channel: &str, source: &str, )

Source§

impl<T: AeronNewPublicationCallback, P: CallbackPolicy> AeronNewPublicationCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_on_new_publication( &mut self, channel: &str, stream_id: i32, session_id: i32, correlation_id: i64, )

Source§

impl<T: AeronNewSubscriptionCallback, P: CallbackPolicy> AeronNewSubscriptionCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_on_new_subscription( &mut self, channel: &str, stream_id: i32, correlation_id: i64, )

Source§

impl<T: AeronNotificationCallback, P: CallbackPolicy> AeronNotificationCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronPublicationErrorFrameHandlerCallback, P: CallbackPolicy> AeronPublicationErrorFrameHandlerCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronReservedValueSupplierCallback, P: CallbackPolicy> AeronReservedValueSupplierCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_reserved_value_supplier(&mut self, buffer: &mut [u8]) -> i64

Source§

impl<T: AeronStrToPtrHashMapForEachFuncCallback, P: CallbackPolicy> AeronStrToPtrHashMapForEachFuncCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronUnavailableCounterCallback, P: CallbackPolicy> AeronUnavailableCounterCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_on_unavailable_counter( &mut self, counters_reader: &AeronCountersReader<Borrowed<aeron_counters_reader_t>>, registration_id: i64, counter_id: i32, )

Source§

impl<T: AeronUnavailableImageCallback, P: CallbackPolicy> AeronUnavailableImageCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

impl<T: AeronUriParseCallbackCallback, P: CallbackPolicy> AeronUriParseCallbackCallback for Handler<T, P>

Pass a Handler clone to share a callback across registrations.

Source§

fn handle_aeron_uri_parse_callback(&mut self, key: &str, value: &str) -> c_int

Source§

impl<T, P: CallbackPolicy> Clone for Handler<T, P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, P> Freeze for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: Freeze,

§

impl<T, P> RefUnwindSafe for Handler<T, P>

§

impl<T, P> Send for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: Send,

§

impl<T, P> Sync for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: Sync,

§

impl<T, P> Unpin for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: Unpin,

§

impl<T, P> UnsafeUnpin for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: UnsafeUnpin,

§

impl<T, P> UnwindSafe for Handler<T, P>
where <P as CallbackPolicy>::Owner<T>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.