Class: Glottis::Client

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

Overview

Client class used to interact with the specified host and port.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, opts = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
# File 'lib/glottis/client.rb', line 16

def initialize(host, port, opts = {})
  @host = host
  @port = port
  @outgoing = Queue.new
  @incoming = Queue.new
  @handlers = []
  Client.logger.level = opts[:verbose] ? Logger::DEBUG : Logger::WARN
end

Class Method Details

.loggerObject



12
13
14
# File 'lib/glottis/client.rb', line 12

def self.logger
  @logger ||= Logger.new($stdout)
end

Instance Method Details

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/glottis/client.rb', line 25

def run
  Client.logger.info('starting...')

  start_handlers
  @handlers.each(&:join)
rescue Glottis::Exceptions::UserExitedException
  Client.logger.info('User exited.')
rescue Interrupt
  Client.logger.info('Received interrupt signal. Exiting...')
rescue Errno::ECONNREFUSED => e
  Client.logger.error("Failed to connect to host: #{e.message}")
rescue StandardError => e
  Client.logger.warn("Shutting down due to error: #{e.message}")
ensure
  stop_handlers
end