From 0f43874079040384e410ae6323d0073524e565a8 Mon Sep 17 00:00:00 2001 From: Paul Loyd Date: Tue, 13 Aug 2024 19:24:15 +0400 Subject: [PATCH] feat(core/envelope): add `Envelope::request_id()` --- CHANGELOG.md | 1 + elfo-core/src/envelope.rs | 10 ++++++++++ elfo-core/src/lib.rs | 3 +-- elfo-network/src/codec/decode.rs | 6 +----- elfo-network/src/codec/format.rs | 3 +-- elfo-network/src/worker/requests.rs | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4459009..bfa7d329 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate ### Added - core/topology: add `Topology::set_node_no()` and `Topology::node_no()`. +- core/envelope: add `Envelope::request_id()`. ### Changed - **BREAKING** core/node: remove `node` module, `NodeNo` is moved to `addr`. diff --git a/elfo-core/src/envelope.rs b/elfo-core/src/envelope.rs index b3ccf560..c683237f 100644 --- a/elfo-core/src/envelope.rs +++ b/elfo-core/src/envelope.rs @@ -174,6 +174,16 @@ impl Envelope { } } + #[inline] + pub fn request_id(&self) -> Option { + match self.message_kind() { + MessageKind::Regular { .. } => None, + MessageKind::RequestAny(token) => Some(token.request_id()), + MessageKind::RequestAll(token) => Some(token.request_id()), + MessageKind::Response { request_id, .. } => Some(*request_id), + } + } + #[doc(hidden)] #[inline] pub fn type_id(&self) -> MessageTypeId { diff --git a/elfo-core/src/lib.rs b/elfo-core/src/lib.rs index 874259b9..8a05be63 100644 --- a/elfo-core/src/lib.rs +++ b/elfo-core/src/lib.rs @@ -20,7 +20,7 @@ pub use crate::{ group::{ActorGroup, Blueprint, TerminationPolicy}, local::{Local, MoveOwnership}, message::{AnyMessage, AnyMessageRef, Message, Request}, - request_table::ResponseToken, + request_table::{RequestId, ResponseToken}, restarting::{RestartParams, RestartPolicy}, source::{SourceHandle, UnattachedSource}, topology::Topology, @@ -86,7 +86,6 @@ pub mod _priv { message::*, object::{GroupVisitor, Object, OwnedObject}, permissions::{AtomicPermissions, Permissions}, - request_table::RequestId, }; pub use erased_serde; pub use idr_ebr::EbrGuard; diff --git a/elfo-network/src/codec/decode.rs b/elfo-network/src/codec/decode.rs index 39d7cc59..fe659e51 100644 --- a/elfo-network/src/codec/decode.rs +++ b/elfo-network/src/codec/decode.rs @@ -4,11 +4,7 @@ use byteorder::{LittleEndian, ReadBytesExt}; use eyre::{ensure, eyre, Error, WrapErr}; use tracing::error; -use elfo_core::{ - _priv::{AnyMessage, RequestId}, - errors::RequestError, - tracing::TraceId, -}; +use elfo_core::{errors::RequestError, tracing::TraceId, AnyMessage, RequestId}; use elfo_utils::likely; use crate::codec::format::{ diff --git a/elfo-network/src/codec/format.rs b/elfo-network/src/codec/format.rs index 951b78f6..cbd2d5e6 100644 --- a/elfo-network/src/codec/format.rs +++ b/elfo-network/src/codec/format.rs @@ -38,8 +38,7 @@ use elfo_core::{ addr::{Addr, NodeNo}, errors::RequestError, tracing::TraceId, - AnyMessage, Message, - _priv::RequestId, + AnyMessage, Message, RequestId, }; use elfo_utils::likely; diff --git a/elfo-network/src/worker/requests.rs b/elfo-network/src/worker/requests.rs index 6e81e130..bcafc2f9 100644 --- a/elfo-network/src/worker/requests.rs +++ b/elfo-network/src/worker/requests.rs @@ -2,7 +2,7 @@ use fxhash::FxHashMap; use metrics::{decrement_gauge, increment_gauge}; use tracing::error; -use elfo_core::{Addr, ResponseToken, _priv::RequestId}; +use elfo_core::{Addr, RequestId, ResponseToken}; #[derive(Default)] pub(super) struct OutgoingRequests {