Class: MockDnsServer::ServerContext

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
MessageBuilder
Defined in:
lib/mock_dns_server/server_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageBuilder

axfr_request, dns_update, dummy_a_response, ixfr_request, ixfr_request_soa_rr, notify_message, ns, rr, serial_value, soa_answer, soa_request, soa_response, specified_a_response

Constructor Details

#initialize(server, options = {}) ⇒ ServerContext

Returns a new instance of ServerContext.



24
25
26
27
28
29
30
31
32
33
# File 'lib/mock_dns_server/server_context.rb', line 24

def initialize(server, options = {})
  @server = server
  @port = options[:port]
  @host = options[:host]
  @timeout_secs = options[:timeout_secs]
  @verbose = options[:verbose]
  @mutex = Mutex.new
  @conditional_actions = ConditionalActions.new(self)
  @history = History.new(self)
end

Instance Attribute Details

#conditional_actionsObject (readonly)

Returns the value of attribute conditional_actions.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def conditional_actions
  @conditional_actions
end

#historyObject (readonly)

Returns the value of attribute history.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def history
  @history
end

#hostObject (readonly)

Returns the value of attribute host.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def host
  @host
end

#mutexObject (readonly)

Returns the value of attribute mutex.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def mutex
  @mutex
end

#portObject (readonly)

Returns the value of attribute port.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def server
  @server
end

#timeout_secsObject (readonly)

Returns the value of attribute timeout_secs.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def timeout_secs
  @timeout_secs
end

#verboseObject (readonly)

Returns the value of attribute verbose.



17
18
19
# File 'lib/mock_dns_server/server_context.rb', line 17

def verbose
  @verbose
end

Instance Method Details

#with_mutex(&block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mock_dns_server/server_context.rb', line 36

def with_mutex(&block)

  start_time = Time.now
  duration = ->() do
    now = Time.now
    elapsed_in_usec = (now - start_time) * 1_000_000
    start_time = now
    "#{elapsed_in_usec} usec"
  end

  #puts "#{Thread.current}: Waiting for mutex..."
  mutex.synchronize do
    #puts "time to get mutex: #{duration.()}"
    block.call
    #puts "time using mutex: #{duration.()}"
  end
end