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



27
28
29
30
31
32
33
34
35
36
# File 'lib/ec2-api-proxy/backend.rb', line 27

def receive_data(data)
  if not @proxy or @proxy.error?
    @logger.info("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
# File 'lib/ec2-api-proxy/backend.rb', line 12

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

  unless @data_list.empty?
    data = @data_list.join
    @proxy.memcached.set(@memcached_key, data, @proxy.options[:expires])

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