Class: Glottis::Client
- Inherits:
-
Object
- Object
- Glottis::Client
- Defined in:
- lib/glottis/client.rb
Overview
Client class, used to interact with the host specified.
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.
15 16 17 18 19 20 21 |
# File 'lib/glottis/client.rb', line 15 def initialize(host, port, opts = {}) @host = host @port = port @outgoing = Queue.new @incoming = Queue.new Client.logger.level = opts[:verbose] ? Logger::DEBUG : Logger::WARN end |
Class Method Details
.logger ⇒ Object
11 12 13 |
# File 'lib/glottis/client.rb', line 11 def self.logger @logger ||= Logger.new(STDOUT) end |
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/glottis/client.rb', line 23 def run Client.logger.info('starting...') Thread.abort_on_exception = true @handlers = [ Handlers::ConsoleInputHandler.new(@outgoing), Handlers::ConsoleOutputHandler.new(@incoming), Handlers::RemoteInputHandler.new(@incoming, @host, @port), Handlers::RemoteOutputHandler.new(@outgoing, @host, @port) ] @handlers.each(&:join) rescue Errno::ECONNREFUSED => conn_ref Client.logger.error("failed to connect: #{conn_ref}") rescue StandardError => ex Client.logger.warn("shutting down: #{ex}") ensure @handlers.each(&:cleanup) exit(0) end |