[−][src]Struct kompact::messaging::NetMessage
An incoming message from the networking subsystem
Provides actor paths for the sender
of the message and the
receiver
in addition to the actual data
.
It is recommend to use try_deserialise or try_deserialise_unchecked to unpack the contained data to the appropriate type. These methods abstract over whether or not the data is actually serialised or simply heap-allocated.
Fields
sender: ActorPath
The sender of the message
More concretely, this is the actor path that was supplied as a source by the original sender.
receiver: ActorPath
The receiver of the message
More concretely, this is the actor path that was used as a destination for the message. In particular, of the message was sent to a named path for the current component, instead of the unique path, then this will be the named path.
data: NetData
The actual data of the message
Implementations
impl NetMessage
[src]
pub fn with_box(
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: Box<dyn Serialisable>
) -> NetMessage
[src]
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: Box<dyn Serialisable>
) -> NetMessage
Create a network message with heap-allocated data
pub fn with_bytes(
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: Bytes
) -> NetMessage
[src]
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: Bytes
) -> NetMessage
Create a network message with serialised data
pub fn with_chunk_lease(
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: ChunkLease
) -> NetMessage
[src]
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: ChunkLease
) -> NetMessage
Create a network message with a ChunkLease, pooled buffers.
For outgoing network messages the data inside the data
should be both serialised and (framed)crate::net::frames.
pub fn with_chunk_ref(
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: ChunkRef
) -> NetMessage
[src]
ser_id: SerId,
sender: ActorPath,
receiver: ActorPath,
data: ChunkRef
) -> NetMessage
Create a network message with a ChunkLease, pooled buffers.
For outgoing network messages the data inside the data
should be both serialised and (framed)crate::net::frames.
pub fn sender(&self) -> &ActorPath
[src]
Return a reference to the sender
field
pub fn try_into_deserialised<T: 'static, D>(
self
) -> Result<DeserialisedMessage<T>, UnpackError<Self>> where
D: Deserialiser<T>,
[src]
self
) -> Result<DeserialisedMessage<T>, UnpackError<Self>> where
D: Deserialiser<T>,
Try to deserialise the data into a value of type T
wrapped into a message
This method attempts to deserialise the contents into an
instance of T
using the deserialiser D
.
It will only do so after verifying that ser_id == D::SER_ID
.
If the serialisation id does not match, this message is returned unaltered wrapped in an UnpackError.
Example
use kompact::prelude::*; use bytes::BytesMut; let test_str = "Test me".to_string(); // serialise the string let mut mbuf = BytesMut::with_capacity(test_str.size_hint().expect("size hint")); test_str.serialise(&mut mbuf).expect("serialise"); // create a net message let buf = mbuf.freeze(); let msg = NetMessage::with_bytes(String::SER_ID, some_path, some_path2, buf); // try to deserialise it again match msg.try_into_deserialised::<u64, u64>() { Ok(_) => unreachable!("It's definitely not a u64..."), Err(UnpackError::NoIdMatch(msg_again)) => { match msg_again.try_into_deserialised::<String, String>() { Ok(test_msg) => assert_eq!(test_str, test_msg.content), Err(_) => unreachable!("It's definitely a string..."), } } Err(error) => panic!("Not the error we expected: {:?}", error), }
pub fn try_deserialise<T: 'static, D>(self) -> Result<T, UnpackError<Self>> where
D: Deserialiser<T>,
[src]
D: Deserialiser<T>,
Try to deserialise the data into a value of type T
This method attempts to deserialise the contents into an
instance of T
using the deserialiser D
.
It will only do so after verifying that ser_id == D::SER_ID
.
If the serialisation id does not match, this message is returned unaltered wrapped in an UnpackError.
Example
use kompact::prelude::*; use bytes::BytesMut; let test_str = "Test me".to_string(); // serialise the string let mut mbuf = BytesMut::with_capacity(test_str.size_hint().expect("size hint")); test_str.serialise(&mut mbuf).expect("serialise"); // create a net message let buf = mbuf.freeze(); let msg = NetMessage::with_bytes(String::SER_ID, some_path, some_path2, buf); // try to deserialise it again match msg.try_deserialise::<u64, u64>() { Ok(_) => unreachable!("It's definitely not a u64..."), Err(UnpackError::NoIdMatch(msg_again)) => { match msg_again.try_deserialise::<String, String>() { Ok(test_res) => assert_eq!(test_str, test_res), Err(_) => unreachable!("It's definitely a string..."), } } Err(error) => panic!("Not the error we expected: {:?}", error), }
Note
If you need the sender or the receiver to be owned after deserialisation, either use
msg.data.try_deserialise<...>(...)
instead,
or use try_into_deserialised.
pub fn try_deserialise_unchecked<T: 'static, D>(
self
) -> Result<T, UnpackError<Self>> where
D: Deserialiser<T>,
[src]
self
) -> Result<T, UnpackError<Self>> where
D: Deserialiser<T>,
Try to deserialise the data into a value of type T
This method attempts to deserialise the contents into an
instance of T
using the deserialiser D
without checking the ser_id
first for a match.
Only use this, if you have already verified that ser_id == D::SER_ID
!
Otherwise use try_deserialise.
Example
use kompact::prelude::*; use bytes::BytesMut; let test_str = "Test me".to_string(); // serialise the string let mut mbuf = BytesMut::with_capacity(test_str.size_hint().expect("size hint")); test_str.serialise(&mut mbuf).expect("serialise"); // create a net message let buf = mbuf.freeze(); let msg = NetMessage::with_bytes(String::SER_ID, some_path, some_path2, buf); // try to deserialise it again match msg.ser_id() { &u64::SER_ID => unreachable!("It's definitely not a u64..."), &String::SER_ID => { let test_res = msg.try_deserialise_unchecked::<String, String>().expect("deserialised"); assert_eq!(test_str, test_res); } _ => unreachable!("It's definitely not...whatever this is..."), }
Note
The match_deser macro generates code that is approximately equivalent to the example above with some nicer syntax.
If you need the sender or the receiver to be owned after deserialisation, either use
msg.data.try_deserialise_unchecked<...>(...)
instead,
or use try_into_deserialised.
pub fn ser_id(&self) -> &SerId
[src]
Returns a reference to the serialisation id of this message
Trait Implementations
impl Debug for NetMessage
[src]
impl RoutingPolicy<DynActorRef, NetMessage> for RoundRobinRouting
[src]
fn route(
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
[src]
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
fn boxed_clone(
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
[src]
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
fn broadcast(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
fn select(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
impl<H: BuildHasher + Clone + Send + Sync + 'static> RoutingPolicy<DynActorRef, NetMessage> for SenderHashBucketRouting<H>
[src]
fn route(
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
[src]
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
fn boxed_clone(
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
[src]
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
fn broadcast(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
fn select(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
impl RoutingPolicy<DynActorRef, NetMessage> for BroadcastRouting
[src]
fn route(
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
[src]
&self,
members: &[&DynActorRef],
msg: NetMessage,
logger: &KompactLogger
)
fn boxed_clone(
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
[src]
&self
) -> Box<dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync>
fn broadcast(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
fn select(
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
[src]
&self
) -> Option<&(dyn RoutingPolicy<DynActorRef, NetMessage> + Send + Sync)>
impl Sink<NetMessage> for DynActorRef
[src]
Helper for forwarding MsgEnvelopes to actor references
type Error = ()
The type of value produced by the sink when an error occurs.
fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn start_send(self: Pin<&mut Self>, item: NetMessage) -> Result<(), Self::Error>
[src]
fn poll_flush(
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_close(
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
impl TryClone for NetMessage
[src]
Auto Trait Implementations
impl !RefUnwindSafe for NetMessage
impl Send for NetMessage
impl !Sync for NetMessage
impl Unpin for NetMessage
impl !UnwindSafe for NetMessage
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Erased for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,