Module: ASS

Defined in:
lib/ass.rb,
lib/ass.rb

Overview

TODO a way to specify serializer (json, marshal…)

Defined Under Namespace

Classes: Actor, CallbackFactory, Client, RPC, Server

Class Method Summary collapse

Class Method Details

.actor(name, opts = {}, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/ass.rb', line 24

def actor(name,opts={},&block)
  s = ASS::Actor.new(name,opts)
  if block
    s.react(&block)
  end
  s
end

.call(name, method, data, opts, meta) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ass.rb', line 64

def call(name,method,data,opts,meta)
  payload = {
    #:type => type,
    :method => method,
    :data => data,
    :meta => meta,
  }
  payload.merge(:version => opts[:version]) if opts.has_key?(:version)
  payload.merge(:meta => opts[:meta]) if opts.has_key?(:meta)
  dummy_exchange(name).publish(::Marshal.dump(payload),opts)
  true
end

.cast(name, method, data, opts, meta) ⇒ Object



60
61
62
# File 'lib/ass.rb', line 60

def cast(name,method,data,opts,meta)
  call(name,method,data,opts.merge(:reply_to => nil),meta)
end

.client(opts = {}) ⇒ Object

the opts is used to initiate an RPC



37
38
39
# File 'lib/ass.rb', line 37

def client(opts={})
  ASS::Client.new(opts)
end

.dummy_exchange(name) ⇒ Object

this would create a dummy MQ exchange object for the sole purpose of publishing the message. Will not clobber existing server already started in the process.



81
82
83
# File 'lib/ass.rb', line 81

def dummy_exchange(name)
  @mq.direct(name,:no_declare => true)
end

.mqObject



56
57
58
# File 'lib/ass.rb', line 56

def mq
  @mq
end

.rpc(opts = {}) ⇒ Object



32
33
34
# File 'lib/ass.rb', line 32

def rpc(opts={})
  ASS::RPC.new(opts)
end

.server(name, opts = {}, &block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/ass.rb', line 16

def server(name,opts={},&block)
  s = ASS::Server.new(name,opts)
  if block
    s.react(&block)
  end
  s
end

.start(settings = {}) ⇒ Object

MQ = nil



42
43
44
45
46
47
48
49
# File 'lib/ass.rb', line 42

def start(settings={})
  raise "should have one ASS per eventmachine" if EM.reactor_running? == true # allow ASS to restart if EM is not running.
  EM.run {
    @mq = ::MQ.new(AMQP.start(settings))
    # ASS and its worker threads (EM.threadpool) should share the same MQ instance.
    yield if block_given?
  }
end

.stopObject



51
52
53
54
# File 'lib/ass.rb', line 51

def stop
  AMQP.stop{ EM.stop }
  true
end