Class: Glottis::Client
- Inherits:
-
Object
- Object
- Glottis::Client
- 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
-
#initialize(host, port, opts = {}) ⇒ Client
constructor
A new instance of Client.
- #run ⇒ Object
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
.logger ⇒ Object
12 13 14 |
# File 'lib/glottis/client.rb', line 12 def self.logger @logger ||= Logger.new($stdout) end |
Instance Method Details
#run ⇒ Object
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.}") rescue StandardError => e Client.logger.warn("Shutting down due to error: #{e.}") ensure stop_handlers end |