Class: SensuGenerator::Server
- Inherits:
-
Object
- Object
- SensuGenerator::Server
- Defined in:
- lib/sensu_generator/server.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #listen_and_serve ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 13 14 |
# File 'lib/sensu_generator/server.rb', line 8 def initialize @config = Application.config @logger = Application.logger @trigger = Application.trigger logger.info "Server: starting server." listen_and_serve end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/sensu_generator/server.rb', line 6 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/sensu_generator/server.rb', line 6 def logger @logger end |
Instance Method Details
#close ⇒ Object
37 38 39 40 |
# File 'lib/sensu_generator/server.rb', line 37 def close @server.close @server = nil end |
#listen_and_serve ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sensu_generator/server.rb', line 16 def listen_and_serve @server = TCPServer.new(server_addr, server_port) logger.info "Server: started server on #{@server.addr}" while client = @server.accept logger.info "Server: client #{client.addr} connected" Thread.start(client) do begin data = client.read process data client.close rescue => e client&.close raise ServerError, "Server: error occured #{e.inspect} #{e.backtrace}\n" end end end rescue close end |