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.
12 13 14 15 16 17 18 19 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 12 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.
22 23 24 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 22 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.
25 26 27 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 25 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
28 29 30 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 28 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.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 32 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.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 46 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 self.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
78 79 80 81 82 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 78 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
86 87 88 89 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 86 def delete_polling_thread(key) Thread.kill(@pool[key]) if self.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
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 105 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
62 63 64 65 66 67 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 62 def key?(key) if @entries.key?(key) && (@entries[key].nil? || @entries[key].expired?) self.delete(key) end @entries.key?(key) 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
131 132 133 134 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 131 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
72 73 74 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 72 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)
95 96 97 98 99 100 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 95 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
122 123 124 125 126 127 128 |
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 122 def update_polling_pool(key, thread) unless @pool.size < @max_threads _, thread = @pool.shift Thread.kill(thread) end @pool[key] = thread end |