lib/proxymachine.rb in fizx-proxymachine-1.7.1 vs lib/proxymachine.rb in fizx-proxymachine-1.8.0

- old
+ new

@@ -26,19 +26,21 @@ def self.count @@counter end - def self.incr + def self.incr(client = nil) + @@incr_callback && @@incr_callback.call(client) @@totalcounter += 1 @@counter += 1 @@maxcounter = @@counter if @@counter > @@maxcounter self.update_procline @@counter end - def self.decr + def self.decr(client = nil) + @@decr_callback &&@@decr_callback.call(client) @@counter -= 1 if $server.nil? $logger.info "Waiting for #{@@counter} connections to finish." end self.update_procline @@ -84,19 +86,35 @@ end def self.set_inactivity_error_callback(&block) @@inactivity_error_callback = block end - + def self.set_inactivity_warning_callback(&block) @@inactivity_warning_callback = block end + def self.set_incr_callback(&block) + @@incr_callback = block + end + + def self.set_decr_callback(&block) + @@decr_callback = block + end + + def self.incr_callback(&block) + @@incr_callback + end + + def self.decr_callback(&block) + @@decr_callback + end + def self.inactivity_error_callback @@inactivity_error_callback end - + def self.inactivity_warning_callback @@inactivity_warning_callback end def self.run(name, host, port) @@ -106,10 +124,13 @@ @@name = name @@listen = "#{host}:#{port}" @@connect_error_callback ||= proc { |remote| } @@inactivity_error_callback ||= proc { |remote| } @@inactivity_warning_callback ||= proc { |remote| } + @@incr_callback ||= proc { |remote| } + @@decr_callback ||= proc { |remote| } + self.update_procline EM.epoll EM.run do ProxyMachine::ClientConnection.start(host, port) @@ -136,11 +157,11 @@ end def proxy_inactivity_error(&block) ProxyMachine.set_inactivity_error_callback(&block) end - + def proxy_inactivity_warning(&block) ProxyMachine.set_inactivity_warning_callback(&block) end - + end