pub struct M2mLoopback { /* private fields */ }
Expand description
Loopback transport service for in-process M2M communication.
M2mLoopback
provides a transport implementation that routes M2M requests
to local middleware instances within the same process. It maintains a
registry of middleware instances indexed by IP address and supports
configurable network delay simulation.
§Network Simulation
The service can simulate network latency by introducing delays before processing requests. This includes both a base delay and random jitter to simulate real network conditions.
§Thread Safety
The service is thread-safe and can be safely cloned and used across multiple concurrent tasks. All internal state is protected by appropriate synchronization primitives.
Implementations§
Source§impl M2mLoopback
impl M2mLoopback
Sourcepub fn new(base_delay_ms: u64, jitter_max_ms: u64) -> Self
pub fn new(base_delay_ms: u64, jitter_max_ms: u64) -> Self
Creates a new loopback transport with the specified delay characteristics.
§Arguments
base_delay_ms
- Base delay to add to all requests in millisecondsjitter_max_ms
- Maximum random additional delay in milliseconds
Sourcepub async fn register_middleware(
&self,
ip: String,
middleware: M2mApiDefaultStack,
)
pub async fn register_middleware( &self, ip: String, middleware: M2mApiDefaultStack, )
Registers a middleware instance with the specified IP address.
This allows the loopback transport to route requests to the appropriate middleware instance based on the target IP address extracted from requests.
§Arguments
ip
- IP address identifier for the middlewaremiddleware
- The middleware service instance to register
Sourcepub async fn get_middleware(
&self,
ip: String,
) -> Result<M2mApiDefaultStack, TraceabilityError>
pub async fn get_middleware( &self, ip: String, ) -> Result<M2mApiDefaultStack, TraceabilityError>
Trait Implementations§
Source§impl Clone for M2mLoopback
impl Clone for M2mLoopback
Source§fn clone(&self) -> M2mLoopback
fn clone(&self) -> M2mLoopback
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for M2mLoopback
impl Default for M2mLoopback
Source§impl Service<M2mRequest> for M2mLoopback
impl Service<M2mRequest> for M2mLoopback
Source§type Response = M2mResponse
type Response = M2mResponse
Source§type Error = TraceabilityError
type Error = TraceabilityError
Source§type Future = Pin<Box<dyn Future<Output = Result<<M2mLoopback as Service<M2mRequest>>::Response, <M2mLoopback as Service<M2mRequest>>::Error>> + Send>>
type Future = Pin<Box<dyn Future<Output = Result<<M2mLoopback as Service<M2mRequest>>::Response, <M2mLoopback as Service<M2mRequest>>::Error>> + Send>>
Source§fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Poll::Ready(Ok(()))
when the service is able to process requests. Read moreSource§fn call(&mut self, request: M2mRequest) -> Self::Future
fn call(&mut self, request: M2mRequest) -> Self::Future
Auto Trait Implementations§
impl Freeze for M2mLoopback
impl !RefUnwindSafe for M2mLoopback
impl Send for M2mLoopback
impl Sync for M2mLoopback
impl Unpin for M2mLoopback
impl !UnwindSafe for M2mLoopback
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered
].§impl<T> Pointable for T
impl<T> Pointable for T
§impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
impl<S, R> ServiceExt<R> for Swhere
S: Service<R>,
§fn into_make_service(self) -> IntoMakeService<S>
fn into_make_service(self) -> IntoMakeService<S>
MakeService
, that is a [Service
] whose
response is another service. Read more§fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
fn handle_error<F, T>(self, f: F) -> HandleError<Self, F, T>
HandleError
, that will handle errors
by converting them into responses. Read more§impl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
impl<T, Request> ServiceExt<Request> for Twhere
T: Service<Request> + ?Sized,
§fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
fn ready(&mut self) -> Ready<'_, Self, Request>where
Self: Sized,
§fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
fn ready_oneshot(self) -> ReadyOneshot<Self, Request>where
Self: Sized,
§fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
fn oneshot(self, req: Request) -> Oneshot<Self, Request>where
Self: Sized,
Service
, calling it with the provided request once it is ready.§fn and_then<F>(self, f: F) -> AndThen<Self, F>
fn and_then<F>(self, f: F) -> AndThen<Self, F>
poll_ready
method. Read more§fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
fn map_response<F, Response>(self, f: F) -> MapResponse<Self, F>
poll_ready
method. Read more§fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
fn map_err<F, Error>(self, f: F) -> MapErr<Self, F>
poll_ready
method. Read more§fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
fn map_result<F, Response, Error>(self, f: F) -> MapResult<Self, F>
Result<Self::Response, Self::Error>
)
to a different value, regardless of whether the future succeeds or
fails. Read more§fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
§fn filter<F, NewRequest>(self, filter: F) -> Filter<Self, F>where
Self: Sized,
F: Predicate<NewRequest>,
fn filter<F, NewRequest>(self, filter: F) -> Filter<Self, F>where
Self: Sized,
F: Predicate<NewRequest>,
§fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F>where
Self: Sized,
F: AsyncPredicate<NewRequest>,
fn filter_async<F, NewRequest>(self, filter: F) -> AsyncFilter<Self, F>where
Self: Sized,
F: AsyncPredicate<NewRequest>,
AsyncFilter
that conditionally accepts or
rejects requests based on an [async predicate]. Read more