class Glottis::Handlers::RemoteInputHandler
This class manages a TCP connection with a valyx server.
Constants
- PROTOCOL
- READ_TIMEOUT
- REMOTE_PATHS
- STREAM_DELIMITER
Public Class Methods
new(incoming, host, port)
click to toggle source
Calls superclass method
# File lib/glottis/handlers/remote_input_handler.rb, line 17 def initialize(incoming, host, port) @incoming = incoming @host = host @port = port setup_http super do @http.start read_loop end end
Public Instance Methods
cleanup()
click to toggle source
# File lib/glottis/handlers/remote_input_handler.rb, line 30 def cleanup @http.finish if @http.started? end
Private Instance Methods
read_loop()
click to toggle source
# File lib/glottis/handlers/remote_input_handler.rb, line 42 def read_loop Client.logger.info('reading stream...') @http.get(REMOTE_PATHS.fetch(:get_message_stream)) do |chunk| Client.logger.debug("got chunk of length: #{chunk.length}") chunk.split(STREAM_DELIMITER).each do |msg_data| @incoming.push(JSON.parse(msg_data)) end # each end # get end
setup_http()
click to toggle source
# File lib/glottis/handlers/remote_input_handler.rb, line 36 def setup_http @http = Net::HTTP.new(@host, @port) @http.open_timeout = 1 @http.read_timeout = READ_TIMEOUT end