Class: Glottis::Handlers::RemoteInputHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/glottis/handlers/remote_input_handler.rb

Overview

Manages stream input from the remote valyx server.

Constant Summary collapse

PROTOCOL =
'http'
STREAM_DELIMITER =
"\0"
READ_TIMEOUT =
3600
REMOTE_PATHS =
{
  get_message_stream: '/api/v1/messages/stream',
  legacy_message_stream: '/api/messages/stream'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(incoming, host, port, cookie = nil) ⇒ RemoteInputHandler

Returns a new instance of RemoteInputHandler.



20
21
22
23
24
25
26
27
28
29
# File 'lib/glottis/handlers/remote_input_handler.rb', line 20

def initialize(incoming, host, port, cookie = nil)
  @incoming = incoming
  @host = host
  @port = port
  @cookie = cookie
  @running = false
  @thread = nil
  @buffer = String.new
  setup_http
end

Instance Method Details

#cleanupObject



44
45
46
47
48
# File 'lib/glottis/handlers/remote_input_handler.rb', line 44

def cleanup
  @running = false
  @http.finish if @http.started?
  @thread&.kill if @thread&.alive?
end

#joinObject



40
41
42
# File 'lib/glottis/handlers/remote_input_handler.rb', line 40

def join
  @thread&.join
end

#startObject



31
32
33
34
35
36
37
38
# File 'lib/glottis/handlers/remote_input_handler.rb', line 31

def start
  @running = true
  @thread = Thread.new do
    @http.start
    read_loop
  end
  self
end