Class: EC2APIProxy::Backend

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/ec2-api-proxy/backend.rb

Instance Method Summary collapse

Constructor Details

#initialize(proxy, memcached_key) ⇒ Backend

Returns a new instance of Backend.



5
6
7
8
9
10
# File 'lib/ec2-api-proxy/backend.rb', line 5

def initialize(proxy, memcached_key)
  @proxy = proxy
  @logger = proxy.logger
  @memcached_key = memcached_key
  @data_list = []
end

Instance Method Details

#receive_data(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ec2-api-proxy/backend.rb', line 34

def receive_data(data)
  if not @proxy or @proxy.error?
    @logger.error("backend: proxy connection error: #{data.inspect}")
    close_proxy_connection
    close_connection_after_writing
  else
    @data_list << data
    @proxy.send_data(data)
  end
end

#unbindObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ec2-api-proxy/backend.rb', line 12

def unbind
  if @proxy and @proxy.options[:debug]
    @logger.debug("backend: unbind connection")
  end

  if @memcached_key and not @data_list.empty?
    data = @data_list.join

    if /<Response>\s*<Errors>\s*<Error>/ =~ data
      if @proxy and @proxy.options[:debug]
        @logger.debug("backend: error response: #{data}")
      end
    else
      @proxy.memcached.set(@memcached_key, data, @proxy.options[:expires])
    end

    if @proxy and @proxy.options[:debug]
      @logger.debug("backend: set cache (length=#{data.length})")
    end
  end
end