Class: Aws::EndpointCache Private

Inherits:
Object
  • Object
show all
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

API:

  • private

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

API:

  • private

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

API:

  • private

10

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

API:

  • private



14
15
16
17
18
19
20
21
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 14

def initialize(options = {})
  @max_entries = options[:max_entries] || MAX_ENTRIES
  @entries = {} # store endpoints
  @max_threads = options[:max_threads] || MAX_THREADS
  @pool = {} # store polling threads
  @mutex = Mutex.new
  @require_identifier = nil # whether endpoint operation support identifier
end

Instance Attribute Details

#max_entriesInteger (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.

Returns:

  • Max size limit of cache

API:

  • private



24
25
26
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 24

def max_entries
  @max_entries
end

#max_threadsInteger (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.

Returns:

  • Max count of polling threads

API:

  • private



27
28
29
# File 'lib/aws-sdk-core/endpoint_cache.rb', line 27

def max_threads
  @max_threads
end

#poolObject (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

API:

  • private



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.

Parameters:

Returns:

API:

  • private



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.

Parameters:

API:

  • private



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

Parameters:

API:

  • private



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

Parameters:

API:

  • private



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

Parameters:

Returns:

API:

  • private



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

Parameters:

Returns:

API:

  • private



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

API:

  • private



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

Parameters:

Returns:

API:

  • private



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)

Parameters:

API:

  • private



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

API:

  • private



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