Class: Bixby::WebSocket::Client

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/bixby-agent/websocket/client.rb

Overview

WebSocket Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, handler) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
# File 'lib/bixby-agent/websocket/client.rb', line 18

def initialize(url, handler)
  @url = url
  @handler = handler
  @tries = 0
  @exiting = false
  @thread_pool = Bixby::ThreadPool.new(:min_size => 1, :max_size => 4)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



16
17
18
# File 'lib/bixby-agent/websocket/client.rb', line 16

def api
  @api
end

#wsObject (readonly)

Returns the value of attribute ws.



16
17
18
# File 'lib/bixby-agent/websocket/client.rb', line 16

def ws
  @ws
end

Instance Method Details

#startObject

Start the Client thread

NOTE: This call never returns!



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bixby-agent/websocket/client.rb', line 29

def start

  @exiting = false

  Kernel.trap("EXIT") do
    # :nocov:
    @exiting = true
    # :nocov:
  end

  logger.debug "connecting to #{@url}"
  EM.run {
    connect()
  }
end

#stopObject



45
46
47
48
# File 'lib/bixby-agent/websocket/client.rb', line 45

def stop
  @exiting = true
  EM.stop_event_loop if EM.reactor_running?
end