Class: Buster::Host

Inherits:
Object
  • Object
show all
Defined in:
lib/buster/host.rb

Instance Method Summary collapse

Constructor Details

#initialize(routes, context, local_endpoint = nil) ⇒ Host

Returns a new instance of Host.



4
5
6
7
8
9
# File 'lib/buster/host.rb', line 4

def initialize(routes, context, local_endpoint = nil)
  @local_endpoint = local_endpoint ||"inproc://local_endpoint"
  @context = context
  @router = Buster::Router.new(@context, routes)
  @poller = Buster::Poller.new
end

Instance Method Details

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/buster/host.rb', line 11

def start
  frontend = @context.socket(ZMQ::ROUTER)
  frontend.bind(@local_endpoint)

  backend = @context.socket(ZMQ::DEALER)
  backend.bind("inproc://workers")

  @router.connect_routes backend, @poller

  Buster::Worker.start_worker @context

  @poller.pipe frontend, backend
  @poller.pipe backend, frontend

  poll_thread = Thread.new { @poller.start }
  poll_thread.join

  @context.terminate
end

#stopObject



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

def stop
  @poller.stop
end