[][src]Struct axiom::actors::ActorId

pub struct ActorId { /* fields omitted */ }

Encapsulates an ID to an actor and is often referred to as an aid.

This is a unique reference to the actor within the entire cluster and can be used to send messages to the actor regardless of location. The ActorId does the heavy lifting of deciding where the actor is and sending the message. However it is important that the user at least has some notion of where the actor is for developing an efficient actor architecture. This id can also be serialized to a remote system transparently.

Methods

impl ActorId[src]

pub fn send(&self, message: Message)[src]

A helper to invoke ActorId::try_send and simply panic if an error occurs. Note that if there is an error that is possible in the send, the user should call try_send instead and handle the error. Panics in Axiom have the capability of taking down the whole actor system and process. The standard practices of Rust are different than Erlang or other actor systems. In Rust the user is expected to handle and manage potential errors. For this reason an intentional decision was made to allow panics to take out the process. Rust developers, suspecting an error, should design around this.

Examples

use axiom::actors::*;
use axiom::message::*;
use std::sync::Arc;

let system = ActorSystem::create(ActorSystemConfig::default());
system.init_current();

let aid = system.spawn(
    0 as usize,
    |_state: &mut usize, _aid: ActorId, _message: &Message| Status::Processed,
 );

aid.send(Message::new(11));

pub fn try_send(&self, message: Message) -> Result<(), ActorError>[src]

Attempts to send a message to the actor with the given ActorId and returns [std::Result::Ok] when the send was successful or [std::Result::Err<ActorError>] error if something went wrong with the send.

This is useful when the user wants to send a message and feels that there is a possibility of an error and that possibility has to be handled gracefully. Note that as with send if a user just calls try_send(msg).unwrap(), a panic could take down the whole process. See the documentation on send for a longer explanation.

Examples

use axiom::actors::*;
use axiom::message::*;
use std::sync::Arc;

let system = ActorSystem::create(ActorSystemConfig::default());
system.init_current();

let aid = system.spawn(
    0 as usize,
    |_state: &mut usize, _aid: ActorId, message: &Message| Status::Processed,
 );

match aid.try_send(Message::new(11)) {
    Ok(_) => println!("OK Then!"),
    Err(e) => println!("Ooops {:?}", e),
}

pub fn uuid(&self) -> Uuid[src]

The unique UUID for this actor within the entire cluster.

pub fn system_uuid(&self) -> Uuid[src]

The unique UUID for the actor system that this actor lives on.

pub fn name(&self) -> Option<String>[src]

The name of the actor as assigned by the user at spawn time if any. Note that this name is guaranteed to be unique only within the actor system in which the actor was started, no guarantees are made that the name will be unique within a cluster of actor systems.

pub fn is_local(&self) -> bool[src]

Determines if this actor lives on actor system in the calling thread.

pub fn sent(&self) -> usize[src]

Returns the total number of messages that have been sent to the actor regardless of whether or not they have been received or processed by the actor. FIXME Move these metrics to be retreived by via a system message because this won't work remote.

pub fn received(&self) -> usize[src]

Returns the total number of messages that have been received by the actor. Note that this doesn't mean that the actor did anything with the message, just that it was received and handled. FIXME Move to be retreived by via a system message because this won't work remote.

pub fn receivable(&self) -> usize[src]

Returns the number of messages that are currently receivable by the actor. This count will not include any messages that have been skipped until the skip is reset. FIXME Move to be retreived by via a system message because this won't work remote.

pub fn pending(&self) -> usize[src]

Returns the total number of messages that are pending in the actor's channel. This should include messages that have been skipped by the actor as well as those that are receivable. FIXME Move to be retreived by via a system message because this won't work remote.

pub fn is_stopped(&self) -> bool[src]

Checks to see if the actor referenced by this ActorId is stopped. FIXME Move to be retreived by via a system message because this won't work remote.

Trait Implementations

impl Clone for ActorId[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl PartialEq<ActorId> for ActorId[src]

#[must_use] fn ne(&self, other: &Rhs) -> bool1.0.0[src]

This method tests for !=.

impl Eq for ActorId[src]

impl Debug for ActorId[src]

impl Hash for ActorId[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Serialize for ActorId[src]

impl<'de> Deserialize<'de> for ActorId[src]

Auto Trait Implementations

impl Sync for ActorId

impl Send for ActorId

impl Unpin for ActorId

impl !RefUnwindSafe for ActorId

impl !UnwindSafe for ActorId

Blanket Implementations

impl<T> ActorMessage for T where
    T: 'static + Serialize + DeserializeOwned + Sync + Send + Any + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]