class Roma::Client::Proxy::Conpool
Attributes
maxlength[RW]
Public Class Methods
new()
click to toggle source
# File lib/roma/client/proxy/daemon.rb 79 def initialize 80 @pool = {} 81 @maxlength = 10 82 @lock = Mutex.new 83 end
Public Instance Methods
close_all()
click to toggle source
# File lib/roma/client/proxy/daemon.rb 111 def close_all 112 @pool.each_key{|ap| close_at(ap) } 113 end
close_at(ap)
click to toggle source
# File lib/roma/client/proxy/daemon.rb 115 def close_at(ap) 116 return unless @pool.key?(ap) 117 @lock.synchronize { 118 while(@pool[ap].length > 0) 119 begin 120 @pool[ap].shift.close_connection 121 rescue =>e 122 $log.error("#{e} #{$@}") 123 end 124 end 125 @pool.delete(ap) 126 } 127 end
create_connection(ap, handler)
click to toggle source
# File lib/roma/client/proxy/daemon.rb 104 def create_connection(ap, handler) 105 addr,port = ap.split('_') 106 con = EventMachine::connect(addr, port, handler) 107 con.ap = ap 108 con 109 end
get_connection(ap, handler)
click to toggle source
# File lib/roma/client/proxy/daemon.rb 85 def get_connection(ap, handler) 86 ret = @pool[ap].shift if @pool.key?(ap) && @pool[ap].length > 0 87 ret = create_connection(ap, handler) if ret == nil 88 ret 89 end
return_connection(con)
click to toggle source
# File lib/roma/client/proxy/daemon.rb 91 def return_connection(con) 92 return unless con.connected 93 if @pool.key?(con.ap) && @pool[con.ap].length > 0 94 if @pool[con.ap].length > @maxlength 95 con.close_connection 96 else 97 @pool[con.ap] << con 98 end 99 else 100 @pool[con.ap] = [con] 101 end 102 end