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



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

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



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

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)
  # 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.
  @mq.direct(name,:no_declare => true).publish(::Marshal.dump(payload),opts)
  true
end

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



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

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



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

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

.mqObject



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

def mq
  @mq
end

.rpc(opts = {}) ⇒ Object



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

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

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



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

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

.start(settings = {}) ⇒ Object

MQ = nil



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

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



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

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