Class: Unbound::QueryStore
- Inherits:
-
Object
- Object
- Unbound::QueryStore
- Defined in:
- lib/unbound/query_store.rb
Overview
Tracks in-flight queries for Resolver
Instance Method Summary collapse
-
#clear ⇒ Object
Clears all queries from the store.
-
#count ⇒ Integer
The number of queries in the store.
-
#delete_query(query) ⇒ Unbound::Query
Deletes a query object from the store, and frees any associated pointer (if nescessary).
-
#each ⇒ Object
Enumerates through each query.
-
#get_by_pointer(pointer) ⇒ Unbound::Query?
Retreives the query from the store via the provided pointer.
-
#initialize ⇒ QueryStore
constructor
A new instance of QueryStore.
-
#store(query) ⇒ FFI::Pointer
Stores a query object, and returns a pointer suitable for passing through Unbound::Context#resolve_async.
Constructor Details
#initialize ⇒ QueryStore
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
#clear ⇒ Object
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 |
#count ⇒ Integer
Returns 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).
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 |
#each ⇒ Object
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.
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.
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 |