Skip to main content

NetworkDispatcher

Struct NetworkDispatcher 

Source
pub struct NetworkDispatcher { /* private fields */ }
Expand description

A network-capable dispatcher for sending messages to remote actors

Construct this using NetworkConfig.

This dispatcher automatically creates channels to requested target systems on demand and maintains them while in use.

The current implementation only supports TCP as a transport protocol.

If possible, this implementation will “reflect” messages to local actors directly back up, instead of serialising them first.

Implementations§

Source§

impl NetworkDispatcher

Source

pub fn new(notify_ready: KPromise<()>) -> Self

Create a new dispatcher with the default configuration

See also NetworkConfig.

§Example

This example binds to local host on a free port chosen by the operating system.

use kompact::prelude::*;
use kompact_net::NetworkDispatcher;

let mut conf = KompactConfig::default();
conf.system_components(DeadletterBox::new, NetworkDispatcher::new);
let system = conf.build().wait().expect("system");
Source

pub fn with_config(cfg: NetworkConfig, notify_ready: KPromise<()>) -> Self

Create a new dispatcher with the given configuration

For better readability in combination with system_components, use NetworkConfig::build instead.

Source

pub fn system_path_ref(&mut self) -> &SystemPath

Return a reference to the cached system path

Mutable, since it will update the cached value, if necessary.

Source§

impl NetworkDispatcher

Source

pub fn network_status_port(&mut self) -> &mut ProvidedPort<NetworkStatusPort>

Returns the provided network status port for this dispatcher.

Trait Implementations§

Source§

impl Actor for NetworkDispatcher

Source§

type Message = DispatchEnvelope

The type of local messages the actor accepts
Source§

fn receive_local(&mut self, msg: Self::Message) -> HandlerResult

Handle an incoming local message Read more
Source§

fn receive_network(&mut self, msg: NetMessage) -> HandlerResult

Handle an incoming network message Read more
Source§

impl ComponentDefinition for NetworkDispatcher

Source§

fn setup(&mut self, self_component: Arc<Component<Self>>)

Prepare the component for being run Read more
Source§

fn execute(&mut self, max_events: usize, skip: usize) -> ExecuteResult

Execute events on the component’s ports Read more
Source§

fn ctx_mut(&mut self) -> &mut ComponentContext<Self>

Return a mutable reference the component’s context field
Source§

fn ctx(&self) -> &ComponentContext<Self>

Return a reference the component’s context field
Source§

fn type_name() -> &'static str

Return the name of the component’s type Read more
Source§

fn spawn_local<F>( &mut self, f: impl FnOnce(ComponentDefinitionAccess<Self>) -> F, )
where Self: 'static, F: Future<Output = Result<Handled, HandlerError>> + Send + 'static,

Run a Future on this component, allowing it mutable access to the component’s internal state on every poll. Read more
Source§

fn spawn_off<R>( &self, future: impl Future<Output = R> + Send + 'static, ) -> Receiver<R>
where R: Send + 'static,

Run a Future on this system’s executor pool and return a handle to the result Read more
Source§

impl ComponentLifecycle for NetworkDispatcher

Source§

fn on_start(&mut self) -> HandlerResult

Gets invoked every time a component receives a Start event Read more
Source§

fn on_stop(&mut self) -> HandlerResult

Gets invoked every time a component receives a Stop event Read more
Source§

fn on_kill(&mut self) -> HandlerResult

Gets invoked every time a component receives a Kill event Read more
Source§

impl Dispatcher for NetworkDispatcher

Source§

fn system_path(&mut self) -> SystemPath

Generates a SystemPath from this dispatcher’s configuration

This is only possible after the socket is bound and will panic if attempted earlier!

Source§

impl DynamicPortAccess for NetworkDispatcher

Source§

fn get_provided_port_as_any(&mut self, port_id: TypeId) -> Option<&mut dyn Any>

Internal API. Dynamically obtain a mutable reference to a ProvidedPort if self provides a port of the type indicated by the passed port_id. Read more
Source§

fn get_required_port_as_any(&mut self, port_id: TypeId) -> Option<&mut dyn Any>

Internal API. Dynamically obtain a mutable reference to a RequiredPort if self requires a port of the type indicated by the passed port_id. Read more
Source§

impl Provide<NetworkStatusPort> for NetworkDispatcher

Source§

fn handle( &mut self, event: <NetworkStatusPort as Port>::Request, ) -> HandlerResult

Handle the port’s event Read more
Source§

impl ProvideRef<NetworkStatusPort> for NetworkDispatcher

Source§

fn provided_ref(&mut self) -> ProvidedRef<NetworkStatusPort>

Returns a provided reference to this component’s port instance of type P
Source§

fn connect_to_required(&mut self, req: RequiredRef<NetworkStatusPort>)

Connects this component’s provided port instance of type P to req
Source§

fn disconnect(&mut self, req: RequiredRef<NetworkStatusPort>)

Disconnects this component’s provided port instance of type P from req

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<CD> ActorPathFactory for CD
where CD: ComponentTraits,

Source§

fn actor_path(&self) -> ActorPath

Returns the associated actor path.
Source§

impl<A, M> ActorRaw for A
where M: MessageBounds, A: Actor<Message = M>,

Source§

type Message = M

The type of local messages the actor accepts
Source§

fn receive(&mut self, env: MsgEnvelope<M>) -> Result<Handled, HandlerError>

Handle an incoming message Read more
Source§

impl<CD> ActorRefFactory for CD

Source§

type Message = <CD as ActorRaw>::Message

The type of messages carried by references produced by this factory
Source§

fn actor_ref(&self) -> ActorRef<<CD as ActorRefFactory>::Message>

Returns the associated actor reference
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<CD> ComponentLogging for CD

Source§

fn log(&self) -> &Logger<Arc<Fuse<Async>>>

Returns a reference to the component’s logger instance Read more
Source§

impl<CD> Dispatching for CD
where CD: ComponentTraits,

Source§

fn dispatcher_ref(&self) -> ActorRefStrong<DispatchEnvelope>

Returns the associated dispatcher reference.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<M, T, A> Receiver<T> for A
where T: Debug + 'static, M: From<T> + MessageBounds, A: ActorRefFactory<Message = M>,

Source§

fn recipient(&self) -> Recipient<T>

Produce a recipient for T
Source§

impl<CD> Timer<CD> for CD
where CD: ComponentTraits,

Source§

fn schedule_once<F>(&mut self, timeout: Duration, action: F) -> ScheduledTimer

Schedule the action to be run once after timeout expires Read more
Source§

fn schedule_periodic<F>( &mut self, delay: Duration, period: Duration, action: F, ) -> ScheduledTimer
where F: Fn(&mut CD, ScheduledTimer) -> Result<Handled, HandlerError> + Send + 'static,

Schedule the action to be run every timeout time units Read more
Source§

fn cancel_timer(&mut self, handle: ScheduledTimer)

Cancel the timer indicated by the handle Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<CD> ComponentTraits for CD
where CD: ComponentDefinition + ActorRaw + 'static,

Source§

impl<T> DynamicComponentDefinition for T

Source§

impl<T> Erased for T