Class: ScoutApm::Remote::Server
- Inherits:
-
Object
- Object
- ScoutApm::Remote::Server
- Defined in:
- lib/scout_apm/remote/server.rb
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
-
#initialize(bind, port, router, logger) ⇒ Server
constructor
A new instance of Server.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(bind, port, router, logger) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 |
# File 'lib/scout_apm/remote/server.rb', line 11 def initialize(bind, port, router, logger) @router = router @logger = logger @bind = bind @port = port @server = nil end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
7 8 9 |
# File 'lib/scout_apm/remote/server.rb', line 7 def bind @bind end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/scout_apm/remote/server.rb', line 9 def logger @logger end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/scout_apm/remote/server.rb', line 8 def port @port end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
6 7 8 |
# File 'lib/scout_apm/remote/server.rb', line 6 def router @router end |
Instance Method Details
#running? ⇒ Boolean
49 50 51 52 |
# File 'lib/scout_apm/remote/server.rb', line 49 def running? @thread.alive? @server && @server.status == :Running end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/scout_apm/remote/server.rb', line 19 def start require 'webrick' @server = WEBrick::HTTPServer.new( :BindAddress => bind, :Port => port, :AccessLog => [], :Logger => @logger ) @server.mount_proc '/' do |request, response| router.handle(request.body) # arbitrary response, client doesn't expect anything in particular response.body = 'Ok' end @thread = Thread.new do begin logger.debug("Remote: Starting Server on #{bind}:#{port}") @server.start logger.debug("Remote: Server returned after #start call, thread exiting") rescue => e logger.debug("Remote: Server Exception, #{e},\n#{e.backtrace.join("\n\t")}") end end end |
#stop ⇒ Object
54 55 56 57 |
# File 'lib/scout_apm/remote/server.rb', line 54 def stop @server.stop @thread.kill end |