public
Description: Modular ruby RPC library with blocking and evented API (using EventMachine)
Homepage:
Clone URL: git://github.com/oleganza/emrpc.git
Click here to lend your support to: emrpc and make a donation at www.pledgie.com !
emrpc /
name age message
file .gitignore Fri Oct 03 11:26:20 -0700 2008 added emrpc.gemspec and a rake task for generat... [oleganza]
file MIT-LICENSE Thu Sep 11 02:54:19 -0700 2008 added license stuff, refactored Rakefile a bit [oleganza]
file README Mon Sep 22 07:27:10 -0700 2008 updated README, TODO [oleganza]
file Rakefile Fri Oct 03 11:26:20 -0700 2008 added emrpc.gemspec and a rake task for generat... [oleganza]
file TODO Thu Sep 25 03:20:23 -0700 2008 TODO: notes about Rev issues [oleganza]
directory bin/ Thu Sep 18 02:58:38 -0700 2008 renamed bin/em_console to bin/emrpc, simplified... [oleganza]
file emrpc.gemspec Fri Oct 03 11:26:20 -0700 2008 added emrpc.gemspec and a rake task for generat... [oleganza]
directory lib/ Fri Sep 11 05:43:57 -0700 2009 removed obsolete comment [oleganza]
directory spec/ Thu Nov 27 02:08:17 -0800 2008 refactored MarshalProtocol: now accepting any o... [oleganza]
README
EMRPC is a EventMachine-based remote procedure call library.
It looks like DRb, but is much more efficient and provides
asynchronous erlang-like interface along with blocking synchronous interface. 

Author: Oleg Andreev <oleganza@gmail.com>


FEATURES

0. Object-oriented evented API based on lightweight processes called Pids.
1. Automatically reconnecting clients (blocking and evented).
2. Support for both TCP and Unix sockets. (Use "emrpc://host:port" or "unix:///path/to/my.sock")
3. Modularity and good specs coverage: EMRPC is easy to learn, extend and optimize.


VERSION AND STATUS

This is v0.3 alpha. It is being used in several projects of my own, but is not tested on many interesting cases.
It has also several issues with performance and specs stability (see TODO file).


THANKS TO

* linkfeed.ru for the real-world EMRPC-based application.
* pierlis.com for the table/chair/wifi in Paris.


EXAMPLES

You may try out examples using bin/emrpc IRB session.
Just open the console and paste the code.

-------------------------------------------------------------------------------

HELLO WORLD (BLOCKING API)

  class HelloWorld
    def action
      "Hello!"
    end
  end
    
  server = EMRPC::Server.new(:address => 'emrpc://localhost:4000/', 
                             :backend => HelloWorld.new)
  EM::safe_run(:background) { }
  
  server.start
  
  client = EMRPC::Client.new('emrpc://localhost:4000/')
  client.action == "Hello!" #=> true


-------------------------------------------------------------------------------

HELLO WORLD (EVENTED API)

  class HelloWorld
    include Pid
    def action(sender)
      puts "HelloWorld replies to the sender #{sender}..."
      sender.reply(self, "Hello!")
    end
  end

  class User
    include Pid
    def connected(pid)
      puts "Pid #{pid} connected with the user."
      pid.action(self)
    end
    def reply(pid, msg)
      puts "Pid #{pid} replied: #{msg}"
    end
  end
    
  EM::run do
    hw = HelloWorld.new
    hw.bind('emrpc://localhost:4000/')  # bind a pid to the address 
    
    oleg = User.new
    oleg.connect('emrpc://localhost:4000/') # connect to that address
  end
  
  # Output:
  Pid #<EMRPC::RemotePid:0x143b740> connected with the user.
  HelloWorld replies to the sender #<User:0x143b4d4>...
  Pid #<HelloWorld:0x143d540> replied: Hello!

-------------------------------------------------------------------------------

HELLO WORLD (EVENTED WRAPPER, MIXED API)

  # in first process:
  class HelloWorld
    def action
      "Hello!"
    end
  end
  
  server = EMRPC::Server.new(:address => 'emrpc://localhost:4000/', 
                             :backend => HelloWorld.new)
  
  EM::run do
    server.start
  end
  
  # in the other process (actually, this works in the same process with the server too):
  class User
    include Pid
    def connected(pid)
      puts "Pid #{pid} connected to the user."
      pid.send(self, :action)
    end
    def on_return(pid, msg)
      puts "Pid #{pid} replied: #{msg}"
    end
  end
  
  EM::run do
    oleg = User.new
    oleg.connect('emrpc://localhost:4000/') # connect to that address
  end

  # Output:
  Pid #<EMRPC::RemotePid:0x143b740> connected to the user.
  Pid #<HelloWorld:0x143d540> replied: Hello!

-------------------------------------------------------------------------------