Class: Unbound::QueryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/unbound/query_store.rb

Overview

Tracks in-flight queries for Resolver

Instance Method Summary collapse

Constructor Details

#initializeQueryStore

Returns a new instance of QueryStore.



6
7
8
# File 'lib/unbound/query_store.rb', line 6

def initialize
  @pointer_to_query_map = {}
end

Instance Method Details

#clearObject

Clears all queries from the store. No special actions taken.



18
19
20
# File 'lib/unbound/query_store.rb', line 18

def clear
  @pointer_to_query_map.clear
end

#countInteger

Returns the number of queries in the store.

Returns:

  • (Integer)

    the number of queries in the store.



23
24
25
# File 'lib/unbound/query_store.rb', line 23

def count
  @pointer_to_query_map.count
end

#delete_query(query) ⇒ Unbound::Query

Deletes a query object from the store, and frees any associated pointer (if nescessary).

Parameters:

Returns:



49
50
51
# File 'lib/unbound/query_store.rb', line 49

def delete_query(query)
  @pointer_to_query_map.delete(FFI::Pointer.new(query.object_id).address)
end

#eachObject

Enumerates through each query.



11
12
13
14
15
# File 'lib/unbound/query_store.rb', line 11

def each
  @pointer_to_query_map.each_value do |query|
    yield(query)
  end
end

#get_by_pointer(pointer) ⇒ Unbound::Query?

Retreives the query from the store via the provided pointer.

Parameters:

  • pointer (FFI::Pointer)

Returns:



30
31
32
33
# File 'lib/unbound/query_store.rb', line 30

def get_by_pointer(pointer)
  return nil if pointer.nil?
  @pointer_to_query_map[pointer.address]
end

#store(query) ⇒ FFI::Pointer

Stores a query object, and returns a pointer suitable for passing through Unbound::Context#resolve_async.

Parameters:

Returns:

  • (FFI::Pointer)

    the pointer



39
40
41
42
43
# File 'lib/unbound/query_store.rb', line 39

def store(query)
  oid_ptr = FFI::Pointer.new query.object_id
  @pointer_to_query_map[oid_ptr.address] = query
  oid_ptr
end