Class: ScoutApm::Remote::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/remote/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bindObject (readonly)

Returns the value of attribute bind.



7
8
9
# File 'lib/scout_apm/remote/server.rb', line 7

def bind
  @bind
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/scout_apm/remote/server.rb', line 9

def logger
  @logger
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/scout_apm/remote/server.rb', line 8

def port
  @port
end

#routerObject (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

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/scout_apm/remote/server.rb', line 49

def running?
  @thread.alive?
  @server && @server.status == :Running
end

#startObject



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

#stopObject



54
55
56
57
# File 'lib/scout_apm/remote/server.rb', line 54

def stop
  @server.stop
  @thread.kill
end