Class: Aws::EndpointCache Private
- Inherits:
-
Object
- Object
- Aws::EndpointCache
- Defined in:
- lib/aws-sdk-core/endpoint_cache.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
a LRU cache caching endpoints data
Defined Under Namespace
Classes: Endpoint
Constant Summary collapse
- MAX_ENTRIES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
default cache entries limit
1000
- MAX_THREADS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
default max threads pool size
10
Instance Attribute Summary collapse
-
#max_entries ⇒ Integer
readonly
private
Max size limit of cache.
-
#max_threads ⇒ Integer
readonly
private
Max count of polling threads.
-
#pool ⇒ Object
readonly
private
return [Hash] Polling threads pool.
Instance Method Summary collapse
- #[](key) ⇒ Endpoint private
- #[]=(key, value) ⇒ Object private
-
#delete(key) ⇒ Object
private
remove entry only.
-
#delete_polling_thread(key) ⇒ Object
private
kill the old polling thread and remove it from pool.
-
#extract_key(ctx) ⇒ String
private
extract the key to be used in the cache from request context.
-
#initialize(options = {}) ⇒ EndpointCache
constructor
private
A new instance of EndpointCache.
-
#key?(key) ⇒ Boolean
private
checking whether an unexpired endpoint key exists in cache.
-
#stop_polling! ⇒ Object
private
kill all polling threads.
-
#threads_key?(key) ⇒ Boolean
private
checking whether an polling thread exist for the key.
-
#update(key, ctx) ⇒ Object
private
update cache with requests (using service endpoint operation) to fetch endpoint list (with identifiers when available).
-
#update_polling_pool(key, thread) ⇒ Object
private
update polling threads pool param [String] key param [Thread] thread.
Constructor Details
#initialize(options = {}) ⇒ EndpointCache
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EndpointCache.
14 15 16 17 18 19 20 21 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 14 def initialize( = {}) @max_entries = [:max_entries] || MAX_ENTRIES @entries = {} # store endpoints @max_threads = [:max_threads] || MAX_THREADS @pool = {} # store polling threads @mutex = Mutex.new @require_identifier = nil # whether endpoint operation support identifier end |
Instance Attribute Details
#max_entries ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Max size limit of cache.
24 25 26 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 24 def max_entries @max_entries end |
#max_threads ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Max count of polling threads.
27 28 29 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 27 def max_threads @max_threads end |
#pool ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
return [Hash] Polling threads pool
30 31 32 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 30 def pool @pool end |
Instance Method Details
#[](key) ⇒ Endpoint
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 34 def [](key) @mutex.synchronize do # fetching an existing endpoint delete it and then append it endpoint = @entries[key] if endpoint @entries.delete(key) @entries[key] = endpoint end endpoint end end |
#[]=(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 48 def []=(key, value) @mutex.synchronize do # delete the least recent used endpoint when cache is full unless @entries.size < @max_entries old_key, = @entries.shift delete_polling_thread(old_key) end # delete old value if exists @entries.delete(key) @entries[key] = Endpoint.new(value.to_hash) end end |
#delete(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
remove entry only
82 83 84 85 86 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 82 def delete(key) @mutex.synchronize do @entries.delete(key) end end |
#delete_polling_thread(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
kill the old polling thread and remove it from pool
90 91 92 93 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 90 def delete_polling_thread(key) Thread.kill(@pool[key]) if threads_key?(key) @pool.delete(key) end |
#extract_key(ctx) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
extract the key to be used in the cache from request context
109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 109 def extract_key(ctx) parts = [] # fetching from cred provider directly gives warnings parts << ctx.config.credentials.credentials.access_key_id if _endpoint_operation_identifier(ctx) parts << ctx.operation_name ctx.operation.input.shape.members.inject(parts) do |p, (name, ref)| p << ctx.params[name] if ref['endpointdiscoveryid'] p end end parts.join('_') end |
#key?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
checking whether an unexpired endpoint key exists in cache
64 65 66 67 68 69 70 71 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 64 def key?(key) @mutex.synchronize do if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?) @entries.delete(key) end @entries.key?(key) end end |
#stop_polling! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
kill all polling threads
135 136 137 138 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 135 def stop_polling! @pool.each { |_, t| Thread.kill(t) } @pool = {} end |
#threads_key?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
checking whether an polling thread exist for the key
76 77 78 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 76 def threads_key?(key) @pool.key?(key) end |
#update(key, ctx) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
update cache with requests (using service endpoint operation) to fetch endpoint list (with identifiers when available)
99 100 101 102 103 104 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 99 def update(key, ctx) resp = _request_endpoint(ctx) if resp && resp.endpoints resp.endpoints.each { |e| self[key] = e } end end |
#update_polling_pool(key, thread) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
update polling threads pool param [String] key param [Thread] thread
126 127 128 129 130 131 132 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 126 def update_polling_pool(key, thread) unless @pool.size < @max_threads _, thread = @pool.shift Thread.kill(thread) end @pool[key] = thread end |