Class: RightSpeed::Listener::RoundRobinListener

Inherits:
SimpleListener show all
Defined in:
lib/right_speed/listener.rb

Direct Known Subclasses

FairListener

Instance Attribute Summary collapse

Attributes inherited from SimpleListener

#sock

Instance Method Summary collapse

Methods inherited from SimpleListener

#initialize

Constructor Details

This class inherits a constructor from RightSpeed::Listener::SimpleListener

Instance Attribute Details

#ractorObject (readonly)

Returns the value of attribute ractor.



48
49
50
# File 'lib/right_speed/listener.rb', line 48

def ractor
  @ractor
end

Instance Method Details

#run(processor) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/right_speed/listener.rb', line 50

def run(processor)
  @running = true
  @ractor = Ractor.new(@host, @port, @backlog, processor) do |host, port, backlog, processor|
    logger = RightSpeed.logger
    sock = TCPServer.open(host, port)
    sock.listen(backlog) if backlog
    logger.info { "listening #{host}:#{port}" }
    while conn = sock.accept
      processor.process(conn)
    end
  end
end

#stopObject



67
68
69
70
# File 'lib/right_speed/listener.rb', line 67

def stop
  @running = false
  @ractor = nil # TODO: terminate the Ractor if possible
end

#waitObject



63
64
65
# File 'lib/right_speed/listener.rb', line 63

def wait
  @ractor.take
end