Class: Zack::Server
- Inherits:
-
Object
- Object
- Zack::Server
- Defined in:
- lib/zack/server.rb
Overview
Server side for RPC calls.
Defined Under Namespace
Classes: SimpleFactory
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#handle_request ⇒ Object
Handles exactly one request.
-
#initialize(tube_name, opts = {}) ⇒ Server
constructor
A new instance of Server.
-
#run(&block) ⇒ Object
Runs the server and keeps running until the world ends (or the process, whichever comes first).
Constructor Details
#initialize(tube_name, opts = {}) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zack/server.rb', line 11 def initialize(tube_name, opts={}) server = opts[:server] || 'beanstalk:11300' if opts.has_key? :factory @factory = opts[:factory] elsif opts.has_key? :simple @factory = SimpleFactory.new(opts[:simple]) else raise ArgumentError, "Either :factory or :simple argument must be given." end channel = Cod.beanstalk(server, tube_name) @service = Cod::Service.new(channel) end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
9 10 11 |
# File 'lib/zack/server.rb', line 9 def service @service end |
Instance Method Details
#handle_request ⇒ Object
Handles exactly one request.
28 29 30 31 32 33 34 |
# File 'lib/zack/server.rb', line 28 def handle_request service.one { |(sym, args)| instance = @factory.produce instance.send(sym, *args) } end |
#run(&block) ⇒ Object
Runs the server and keeps running until the world ends (or the process, whichever comes first).
39 40 41 42 43 44 45 |
# File 'lib/zack/server.rb', line 39 def run(&block) loop do exception_handling(block) do handle_request end end end |