Class: RProxy::ProxyServer

Inherits:
Object
  • Object
show all
Defined in:
lib/r_proxy/proxy_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(sock, config, instance_id) ⇒ ProxyServer

Returns a new instance of ProxyServer.



3
4
5
6
7
8
9
# File 'lib/r_proxy/proxy_server.rb', line 3

def initialize(sock, config, instance_id)
  @sock = sock
  @config = config
  @cache_pool = RProxy::CachePool.new
  @logger = @config.logger
  @instance_id = instance_id
end

Instance Method Details

#run!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/r_proxy/proxy_server.rb', line 11

def run!
  Signal.trap("TERM") { exit! }
  EventMachine.run do

    if @config.enable_cache
      @period_timer = EventMachine.add_periodic_timer(30) do
        @cache_pool.disable_write!

        tmp = @cache_pool.flush

        report_and_clean_cache(tmp)

        @cache_pool.enable_write!
      end
    end

    EventMachine.attach_server(@sock, RProxy::ConnectionHandler, @config, @cache_pool)
  end
end