Git Product home page Git Product logo

node-stage's Introduction

stage

Node application server using the Actor model

Description

Stage is a clustered application server for two-way RPC-style communication with actors. An actor can be thought of as an object with properties and methods. In addition, properties are observable, meaning that a client can register interest in properties and receive messages when those properties change. All interactions are implemented through asynchronous message passing. A message is sent with an address, indicating the actor to be reached, and a message ID. The stage cluster is responsible for spawning actors, routing messages to them, sending responses back to the client, and persisting its properties.

Defining actor classes

To define a class of actors, use the define method of a stage instance:

var StageServer = require('stage');
var stage = new StageServer();

stage.define({
  pattern: 'players.{id}',
  constructor: Player
});

function Player(opts) {
  this.id = opts.id;
  this.hp = 100;
  this.armor = 0.5;
  this.isDead = false;
}

Player.prototype = {
  attack: function(damage) {
    var dr = Math.random() * this.armor * damage;
    damage = damage - dr;
    this.hp -= damage;
    this.isDead = this.hp <= 0;
  }
};

Each actor has an address; the pattern option defines the format of addresses to actors of this class. The constructor option specifies the constructor for the actor instances. The constructor receives the parameters specified in the pattern; it is called with new.

Methods and properties of the object created by the constructor are considered public; that is, they can be accessed by other actors and applications communicating with the stage instance. To create private properties or methods, prefix their names with an underscore.

Starting

To start stage, first create an instance:

var StageServer = require('stage');
var stage = new StageServer();

...then start it with its start method:

stage.start();

The start method can take an optional options argument to override the default settings. The following options are available:

Property Description
port The TCP port the stage instance will listen on

Stage Clusters

Stage servers can and should be clustered. A cluster is merely a set of instances which have been joined together. To join an instance to a cluster, you can either issue a join command, specify the cluster peers on the command line, or specify the cluster peers in a config file.

Protocols

A stage server is interacted with through its TCP port. It has three different protocol interfaces,

  1. The admin protocol, used for maintenance of the instance
  2. The cluster protocol, used for inter-node communication
  3. The client protocol, used for interacting with actors

Admin Protocol

The admin protocol is a set of commands that can be issued by an administrator.

join

join address[:port] [address:port ...]

The join command joins the stage instance to a cluster.

Client Protocol

The client protocol is a duplex stream of text-based messages passed between the client and server.


get

Use get to do a one-time read of a property:

Stage Clients

A stage client

Client Protocol

Plugins

node-stage's People

Contributors

apoco avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.