Skip to main content

ServiceManager

Struct ServiceManager 

Source
pub struct ServiceManager<T: ServiceTask + 'static> { /* private fields */ }
Expand description

Runs a ServiceTask loop as a service task of an owned task group.

Each run is spawned in a rocketmq.service-manager child of the task group given at construction, so the owner’s shutdown report and diagnostics include it. A stopped manager can be started again.

Shutdown waits no longer than the earliest of the deadline passed to Self::shutdown_until and the deadline installed on the parent task group by an owner that is shutting down. When neither exists, it uses the runtime’s default shutdown budget. An interrupting shutdown is the one exception: it gives the aborted loop at least one second to confirm its destruction, so with less than a second left it can return up to one second after that deadline.

Implementations§

Source§

impl<T: ServiceTask + 'static> ServiceManager<T>

Source

pub fn new_with_task_group(service: T, parent_task_group: TaskGroup) -> Self

Creates a manager whose runs are owned by parent_task_group.

Source

pub fn new_arc_with_task_group( service: Arc<T>, parent_task_group: TaskGroup, ) -> Self

Creates a manager for a shared service whose runs are owned by parent_task_group.

Source

pub async fn start(&self) -> RuntimeResult<()>

Starts a run of the service loop.

Starting a manager whose loop is still active only logs a warning.

§Errors

Returns an error if the parent task group no longer accepts work.

Source

pub async fn shutdown(&self) -> RuntimeResult<()>

Stops the service and waits for its loop.

The wait ends at the deadline installed on the parent task group, or after the runtime’s default shutdown budget when there is none. A loop still running then is aborted.

§Errors

Currently always succeeds; the result is kept for callers that propagate shutdown failures.

Source

pub async fn shutdown_with_interrupt( &self, interrupt: bool, ) -> RuntimeResult<()>

Stops the service like Self::shutdown, aborting the loop at once when interrupt is set.

§Errors

Currently always succeeds; the result is kept for callers that propagate shutdown failures.

Source

pub async fn shutdown_until( &self, deadline: ShutdownDeadline, ) -> RuntimeResult<()>

Stops the service and waits for its loop no later than deadline.

§Errors

Currently always succeeds; the result is kept for callers that propagate shutdown failures.

Source

pub async fn shutdown_with_interrupt_until( &self, interrupt: bool, deadline: ShutdownDeadline, ) -> RuntimeResult<()>

Stops the service no later than deadline, aborting the loop at once when interrupt is set.

An interrupted loop is given at least one second to confirm the abort, so when less than a second of deadline remains the call can return up to one second after it.

§Errors

Currently always succeeds; the result is kept for callers that propagate shutdown failures.

Source

pub fn make_stop(&self)

Asks the loop to stop without waiting for it.

Source

pub fn wakeup(&self)

Wakes the loop if it is waiting, or makes its next wait return at once.

Source

pub fn get_lifecycle_state(&self) -> ServiceTaskState

Returns the current lifecycle state.

Source

pub fn last_task_group_shutdown_report(&self) -> Option<ShutdownReport>

Returns the shutdown report of the task group used by the last stopped run.

Trait Implementations§

Source§

impl<T: ServiceTask> AsRef<T> for ServiceManager<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.

Auto Trait Implementations§

§

impl<T> !Freeze for ServiceManager<T>

§

impl<T> !RefUnwindSafe for ServiceManager<T>

§

impl<T> !UnwindSafe for ServiceManager<T>

§

impl<T> Send for ServiceManager<T>
where Arc<T>: Send,

§

impl<T> Sync for ServiceManager<T>
where Arc<T>: Sync,

§

impl<T> Unpin for ServiceManager<T>
where Arc<T>: Unpin,

§

impl<T> UnsafeUnpin for ServiceManager<T>
where Arc<T>: UnsafeUnpin,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more