SimpleActors
Simple Actor Model implementation.
Description
This implementation is inspired in Akka actor implementation.
This model encourage the writing of application consisting in actors that collaborates using message passing. In this module, method invocation is like a message passing operation, that not returns value. The application that uses actor model doesn't need continuation callbacks: each agent receives messages as method invocation, and produces new messages calling other agent methods.
Installation
Via npm on Node:
npm install simpleactors
Reference in your program:
var simpleactors = ;
Usage
Create a system application:
var system = simpleactors;
Create an object of class Downloader
, wrap it as an actor, and returns an actor reference:
var ref = system;
Alternatively, you can use an already create object as first parameter:
var downloader = ;var ref = system;
The second parameter is optional. A name is automatically assigned if the second parameter is missing.
Sends a message to an actor reference:
ref;
An object wrapped as an actor has:
context
: Actor context, with information about the actor environment.self
: This actor reference.
It should implement the function:
receive(msg)
: Process an incoming message
Example:
{ this { console; }} var system = simpleactors;var ref = system;ref;
How to create an actor in our actor object:
thiscontext;
How to get an actor reference in our actor object:
var ref = thiscontext;
Examples:
var refchild = thiscontext; // child of current actorvar refactor = thiscontext; // actor in current system
How to get an actor reference in a system:
var ref = system;
Example:
var ref = system; // actor in current systemref;
An actor system can run in many nodes (running process).
var node = simpleactors;
Example creating a node, a system, and two actors:
var node = simpleactors;var system = node;var actor1 = system;var actor2 = actor1context;// actor1.self.path === 'sactors://mysys@localhost:3000/actor1'// actor2.self.path === 'sactors://mysys@localhost:3000/actor1/actor2'
A node can refer to another running node. In node A:
var node = simpleactors;var system = node;var actor1 = system;nodestart;
In node B:
var node = simpleactors;var remotenode = node;var remotesystem = remotenode;var remoteref = remotesystem;remotenodestart { // after connection, you can tell messages to remote actors remoteref; };
Development
git clone git://github.com/ajlopez/SimpleActors.git
cd SimpleActors
npm install
npm test
Samples
Web Crawler sample shows how you can create an application that don't depend on calling a method and receiving a response: each agent does its works, receiving calls and sending calls to other agents.
Distributed Web Crawler sample has a server that launch the web crawling process, and many clients can be launched that collaborates with the download and harvest of new links to process. It uses a custom router.
Versions
- 0.0.1: Published
- 0.0.2: Under development, in master.
Contribution
Feel free to file issues and submit pull requests � contributions are welcome.
If you submit a pull request, please be sure to add or update corresponding
test cases, and ensure that npm test
continues to pass.
(Thanks to JSON5 by aseemk. This file is based on that project README.md).