class Aws::EndpointCache

a LRU cache caching endpoints data
@api private

def [](key)

Returns:
  • (Endpoint) -

Parameters:
  • key (String) --
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

def []=(key, value)

Parameters:
  • value (Hash) --
  • key (String) --
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

def _endpoint_operation_identifier(ctx)

def _endpoint_operation_identifier(ctx)
  return @require_identifier unless @require_identifier.nil?
  operation_name = ctx.config.api.endpoint_operation
  operation = ctx.config.api.operation(operation_name)
  @require_identifier = operation.input.shape.members.any?
end

def _request_endpoint(ctx)

def _request_endpoint(ctx)
  params = {}
  if _endpoint_operation_identifier(ctx)
    # build identifier params when available
    params[:operation] = ctx.operation.name
    ctx.operation.input.shape.members.inject(params) do |p, (name, ref)|
      if ref['endpointdiscoveryid']
        p[:identifiers] ||= {}
        p[:identifiers][ref.location_name] = ctx.params[name]
      end
      p
    end
  end
  begin
    endpoint_operation_name = ctx.config.api.endpoint_operation
    ctx.client.send(endpoint_operation_name, params)
  rescue Aws::Errors::ServiceError
    nil
  end
end

def delete(key)

Parameters:
  • key (String) --
def delete(key)
  @mutex.synchronize do
    @entries.delete(key)
  end
end

def delete_polling_thread(key)

Parameters:
  • key (String) --
def delete_polling_thread(key)
  Thread.kill(@pool[key]) if threads_key?(key)
  @pool.delete(key)
end

def extract_key(ctx)

Returns:
  • (String) -

Parameters:
  • ctx (RequestContext) --
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

def initialize(options = {})

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

def key?(key)

Returns:
  • (Boolean) -

Parameters:
  • key (String) --
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

def stop_polling!

kill all polling threads
def stop_polling!
  @pool.each { |_, t| Thread.kill(t) }
  @pool = {}
end

def threads_key?(key)

Returns:
  • (Boolean) -

Parameters:
  • key (String) --
def threads_key?(key)
  @pool.key?(key)
end

def update(key, ctx)

Parameters:
  • ctx (RequestContext) --
  • key (String) --
def update(key, ctx)
  resp = _request_endpoint(ctx)
  if resp && resp.endpoints
    resp.endpoints.each { |e| self[key] = e }
  end
end

def update_polling_pool(key, thread)

param [Thread] thread
param [String] key
update polling threads pool
def update_polling_pool(key, thread)
  unless @pool.size < @max_threads
    _, thread = @pool.shift
    Thread.kill(thread)
  end
  @pool[key] = thread
end