pub struct Serf<T, D = DefaultDelegate<T>>{ /* private fields */ }
Expand description
Serf is a single node that is part of a single cluster that gets events about joins/leaves/failures/etc. It is created with the Create method.
All functions on the Serf structure are safe to call concurrently.
Implementations§
Source§impl<T> Serf<T>where
T: Transport,
impl<T> Serf<T>where
T: Transport,
Sourcepub async fn new(
transport: T::Options,
opts: Options,
) -> Result<Self, Error<T, DefaultDelegate<T>>>
pub async fn new( transport: T::Options, opts: Options, ) -> Result<Self, Error<T, DefaultDelegate<T>>>
Creates a new Serf instance with the given transport and options.
Sourcepub async fn with_event_producer(
transport: T::Options,
opts: Options,
ev: EventProducer<T, DefaultDelegate<T>>,
) -> Result<Self, Error<T, DefaultDelegate<T>>>
pub async fn with_event_producer( transport: T::Options, opts: Options, ev: EventProducer<T, DefaultDelegate<T>>, ) -> Result<Self, Error<T, DefaultDelegate<T>>>
Creates a new Serf instance with the given transport and options.
Source§impl<T, D> Serf<T, D>
impl<T, D> Serf<T, D>
Sourcepub async fn with_delegate(
transport: T::Options,
opts: Options,
delegate: D,
) -> Result<Self, Error<T, D>>
pub async fn with_delegate( transport: T::Options, opts: Options, delegate: D, ) -> Result<Self, Error<T, D>>
Creates a new Serf instance with the given transport and options.
Sourcepub async fn with_event_producer_and_delegate(
transport: T::Options,
opts: Options,
ev: EventProducer<T, D>,
delegate: D,
) -> Result<Self, Error<T, D>>
pub async fn with_event_producer_and_delegate( transport: T::Options, opts: Options, ev: EventProducer<T, D>, delegate: D, ) -> Result<Self, Error<T, D>>
Creates a new Serf instance with the given transport, options, event sender, and delegate.
Sourcepub fn advertise_node(&self) -> Node<T::Id, T::ResolvedAddress>
pub fn advertise_node(&self) -> Node<T::Id, T::ResolvedAddress>
Returns the local node’s ID and the advertised address
Sourcepub fn encryption_enabled(&self) -> bool
Available on crate feature encryption
only.
pub fn encryption_enabled(&self) -> bool
encryption
only.A predicate that determines whether or not encryption is enabled, which can be possible in one of 2 cases:
- Single encryption key passed at agent start (no persistence)
- Keyring file provided at agent start
Sourcepub fn shutdown_rx(&self) -> Receiver<()>
pub fn shutdown_rx(&self) -> Receiver<()>
Returns a receiver that can be used to wait for Serf to shutdown.
Sourcepub async fn members(&self) -> OneOrMore<Member<T::Id, T::ResolvedAddress>>
pub async fn members(&self) -> OneOrMore<Member<T::Id, T::ResolvedAddress>>
Returns a point-in-time snapshot of the members of this cluster.
Sourcepub async fn num_members(&self) -> usize
pub async fn num_members(&self) -> usize
Returns the number of nodes in the serf cluster, regardless of their health or status.
Sourcepub fn key_manager(&self) -> &KeyManager<T, D>
Available on crate feature encryption
only.
pub fn key_manager(&self) -> &KeyManager<T, D>
encryption
only.Returns the key manager for the current serf instance
Sourcepub async fn local_member(&self) -> Member<T::Id, T::ResolvedAddress>
pub async fn local_member(&self) -> Member<T::Id, T::ResolvedAddress>
Returns the Member information for the local node
Used to dynamically update the tags associated with the local node. This will propagate the change to the rest of the cluster. Blocks until a the message is broadcast out.
Sourcepub async fn user_event(
&self,
name: impl Into<SmolStr>,
payload: impl Into<Bytes>,
coalesce: bool,
) -> Result<(), Error<T, D>>
pub async fn user_event( &self, name: impl Into<SmolStr>, payload: impl Into<Bytes>, coalesce: bool, ) -> Result<(), Error<T, D>>
Used to broadcast a custom user event with a given name and payload. If the configured size limit is exceeded and error will be returned. If coalesce is enabled, nodes are allowed to coalesce this event.
Sourcepub async fn query(
&self,
name: impl Into<SmolStr>,
payload: impl Into<Bytes>,
params: Option<QueryParam<T::Id>>,
) -> Result<QueryResponse<T::Id, T::ResolvedAddress>, Error<T, D>>
pub async fn query( &self, name: impl Into<SmolStr>, payload: impl Into<Bytes>, params: Option<QueryParam<T::Id>>, ) -> Result<QueryResponse<T::Id, T::ResolvedAddress>, Error<T, D>>
Used to broadcast a new query. The query must be fairly small, and an error will be returned if the size limit is exceeded. Query parameters are optional, and if not provided, a sane set of defaults will be used.
Sourcepub async fn join(
&self,
node: Node<T::Id, MaybeResolvedAddress<T::Address, T::ResolvedAddress>>,
ignore_old: bool,
) -> Result<Node<T::Id, T::ResolvedAddress>, Error<T, D>>
pub async fn join( &self, node: Node<T::Id, MaybeResolvedAddress<T::Address, T::ResolvedAddress>>, ignore_old: bool, ) -> Result<Node<T::Id, T::ResolvedAddress>, Error<T, D>>
Joins an existing Serf cluster. Returns the id of node
successfully contacted. If ignore_old
is true, then any
user messages sent prior to the join will be ignored.
Sourcepub async fn join_many(
&self,
existing: impl Iterator<Item = Node<T::Id, MaybeResolvedAddress<T::Address, T::ResolvedAddress>>>,
ignore_old: bool,
) -> Result<SmallVec<Node<T::Id, T::ResolvedAddress>>, (SmallVec<Node<T::Id, T::ResolvedAddress>>, Error<T, D>)>
pub async fn join_many( &self, existing: impl Iterator<Item = Node<T::Id, MaybeResolvedAddress<T::Address, T::ResolvedAddress>>>, ignore_old: bool, ) -> Result<SmallVec<Node<T::Id, T::ResolvedAddress>>, (SmallVec<Node<T::Id, T::ResolvedAddress>>, Error<T, D>)>
Joins an existing Serf cluster. Returns the id of nodes
successfully contacted. If ignore_old
is true, then any
user messages sent prior to the join will be ignored.
Sourcepub async fn leave(&self) -> Result<(), Error<T, D>>
pub async fn leave(&self) -> Result<(), Error<T, D>>
Gracefully exits the cluster. It is safe to call this multiple times. If the Leave broadcast timeout, Leave() will try to finish the sequence as best effort.
Sourcepub async fn remove_failed_node(&self, id: T::Id) -> Result<(), Error<T, D>>
pub async fn remove_failed_node(&self, id: T::Id) -> Result<(), Error<T, D>>
Forcibly removes a failed node from the cluster immediately, instead of waiting for the reaper to eventually reclaim it. This also has the effect that Serf will no longer attempt to reconnect to this node.
Sourcepub async fn remove_failed_node_prune(
&self,
id: T::Id,
) -> Result<(), Error<T, D>>
pub async fn remove_failed_node_prune( &self, id: T::Id, ) -> Result<(), Error<T, D>>
Forcibly removes a failed node from the cluster immediately, instead of waiting for the reaper to eventually reclaim it. This also has the effect that Serf will no longer attempt to reconnect to this node.
Sourcepub async fn shutdown(&self) -> Result<(), Error<T, D>>
pub async fn shutdown(&self) -> Result<(), Error<T, D>>
Forcefully shuts down the Serf instance, stopping all network activity and background maintenance associated with the instance.
This is not a graceful shutdown, and should be preceded by a call to Leave. Otherwise, other nodes in the cluster will detect this node’s exit as a node failure.
It is safe to call this method multiple times.
Sourcepub fn cooridate(&self) -> Result<Coordinate, Error<T, D>>
pub fn cooridate(&self) -> Result<Coordinate, Error<T, D>>
Returns the network coordinate of the local node.
Sourcepub fn cached_coordinate(
&self,
id: &T::Id,
) -> Result<Option<Coordinate>, Error<T, D>>
pub fn cached_coordinate( &self, id: &T::Id, ) -> Result<Option<Coordinate>, Error<T, D>>
Returns the network coordinate for the node with the given
name. This will only be valid if disable_coordinates
is set to false
.
Sourcepub fn memberlist(&self) -> &Memberlist<T, SerfDelegate<T, D>>
pub fn memberlist(&self) -> &Memberlist<T, SerfDelegate<T, D>>
Returns the underlying Memberlist
instance
Source§impl<T, D> Serf<T, D>
impl<T, D> Serf<T, D>
Sourcepub async fn default_query_timeout(&self) -> Duration
pub async fn default_query_timeout(&self) -> Duration
Returns the default timeout value for a query Computed as
gossip_interval * query_timeout_mult * log(N+1)
Sourcepub async fn default_query_param(&self) -> QueryParam<T::Id>
pub async fn default_query_param(&self) -> QueryParam<T::Id>
Used to return the default query parameters
Trait Implementations§
Auto Trait Implementations§
impl<T, D> Freeze for Serf<T, D>
impl<T, D = CompositeDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>> !RefUnwindSafe for Serf<T, D>
impl<T, D> Send for Serf<T, D>
impl<T, D> Sync for Serf<T, D>
impl<T, D> Unpin for Serf<T, D>
impl<T, D = CompositeDelegate<<T as Transport>::Id, <<T as Transport>::Resolver as AddressResolver>::ResolvedAddress>> !UnwindSafe for Serf<T, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more