acto-rs 0.5.0

Experimental actor library, under development. (renamed from minions_rs).
Documentation

acto-rs library

This library is a proof of concept, never run in any production setup and fairly untested. Use at your own risk. You were warned.


This library is a mixture of concepts to connect independent pieces together. These independent pieces can have:

These pieces (actors) are managed by a scheduler which has a predefined number of threads to run them. The number of input and output channels are determined by the type of the actor. Possible types are:

  • Source: 1 output
  • Sink: 1 input
  • Filter: 1 input, 1 output
  • Y-split: 1 input, 2 outputs of possible different types
  • Y-merge: 2 inputs of possible different types, 1 output
  • Scatter: 1 input, multiple outputs of the same type
  • Gather: multiple inputs of the same type, 1 output

The scheduling rule determines when to run an actor:

  • Loop - continously, round-robin with the other tasks of the scheduler
  • OnMessage - when a message arrives to one of its input channels
  • OnExternalEvent - when an external event is delivered via Scheduler::notify(..) (to integrate with MIO for example)
  • Periodic(PeriodLengthInUsec) - periodically

Usage

You need to design the topology of the components because the connections of the components need to be made before they are passed to the scheduler. The scheduler owns the components and you cannot change them afterwards from the outside.

When you pass the components to the scheduler you need to tell it how to schedule their execution based on one of the above rules. Finally you will need to start the scheduler. After you started the scheduler, you can still add new actors to it.

The crate

[dependencies]
acto-rs = "0.4.0"

Overview

  • Implement the actors based on one of the elem traits
  • Start/stop the scheduler
  • Pass the actor instances to the scheduler

Creating the actors

The actors need to implement one of the traits above. Examples:

Creating a source element

use actors::*;

pub struct ReadBytes {
  
}

impl source::Source for ReadBytes {
  type OutputType = u64;

  fn process(&mut self,
             _output: &mut Sender<Message<Self::OutputType>>,
             _stop: &mut bool)
  {
  }
}

Starting the scheduler

The scheduler allows adding new tasks while it is running or before it was started. The scheduler can only be started/stoped once. The tasks themselves decide when to stop and they will tell it to the scheduler via the stop flag passed to them at execution.

let mut sched1 = Scheduler::new();
sched1.start(); // this uses one single execution thread
sched1.stop();

// to use more threads, do:
let mut sched_multi = Scheduler::new();
sched_multi.start_with_threads(12);
sched_multi.stop();

License

MIT or Apache 2.0