Class: Roma::Event::Handler
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Roma::Event::Handler
- Defined in:
- lib/roma/event/handler.rb
Direct Known Subclasses
Constant Summary collapse
- @@ev_list =
{}
- @@system_commands =
{}
- @@ccl_start =
200- @@ccl_rate =
30- @@ccl_full =
300- @@connections =
{}
- @@connection_expire_time =
60- @@timeout =
10
Instance Attribute Summary collapse
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#connected ⇒ Object
readonly
Returns the value of attribute connected.
-
#last_access ⇒ Object
readonly
Returns the value of attribute last_access.
-
#lastcmd ⇒ Object
readonly
Returns the value of attribute lastcmd.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
- .connection_expire_time ⇒ Object
- .connection_expire_time=(t) ⇒ Object
- .connections ⇒ Object
- .ev_list ⇒ Object
- .get_ccl ⇒ Object
- .set_ccl(ccl) ⇒ Object
- .system_commands ⇒ Object
- .timeout ⇒ Object
- .timeout=(n) ⇒ Object
Instance Method Summary collapse
-
#initialize(storages, rttable) ⇒ Handler
constructor
A new instance of Handler.
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(storages, rttable) ⇒ Handler
Returns a new instance of Handler.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/roma/event/handler.rb', line 69 def initialize(storages, rttable) @rbuf='' unless has_event? public_methods.each{|m| if m.to_s.start_with?('ev_') add_event(m.to_s[3..-1],m) end } end @th1 = 100 @close_rate = 70 @th2 = 200 @storages = storages @rttable = rttable @log = Roma::Logging::RLogger.instance @last_access = Time.now end |
Instance Attribute Details
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
67 68 69 |
# File 'lib/roma/event/handler.rb', line 67 def addr @addr end |
#connected ⇒ Object (readonly)
Returns the value of attribute connected.
64 65 66 |
# File 'lib/roma/event/handler.rb', line 64 def connected @connected end |
#last_access ⇒ Object (readonly)
Returns the value of attribute last_access.
66 67 68 |
# File 'lib/roma/event/handler.rb', line 66 def last_access @last_access end |
#lastcmd ⇒ Object (readonly)
Returns the value of attribute lastcmd.
65 66 67 |
# File 'lib/roma/event/handler.rb', line 65 def lastcmd @lastcmd end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
67 68 69 |
# File 'lib/roma/event/handler.rb', line 67 def port @port end |
Class Method Details
.connection_expire_time ⇒ Object
51 52 53 |
# File 'lib/roma/event/handler.rb', line 51 def self.connection_expire_time @@connection_expire_time end |
.connection_expire_time=(t) ⇒ Object
47 48 49 |
# File 'lib/roma/event/handler.rb', line 47 def self.connection_expire_time=(t) @@connection_expire_time = t end |
.connections ⇒ Object
44 |
# File 'lib/roma/event/handler.rb', line 44 def self.connections; @@connections; end |
.ev_list ⇒ Object
18 |
# File 'lib/roma/event/handler.rb', line 18 def self.ev_list; @@ev_list; end |
.get_ccl ⇒ Object
26 27 28 |
# File 'lib/roma/event/handler.rb', line 26 def self.get_ccl "#{@@ccl_start}:#{@@ccl_rate}:#{@@ccl_full}" end |
.set_ccl(ccl) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/roma/event/handler.rb', line 30 def self.set_ccl(ccl) if ccl =~ /^(\d+):(\d+):(\d+)$/ s,r,f = $1.to_i,$2.to_i,$3.to_i return false if(s < 0 || f < 0 || r < 0 || r > 100 || s > f) @@ccl_start = s @@ccl_rate = r @@ccl_full = f return true else return false end end |
.system_commands ⇒ Object
20 |
# File 'lib/roma/event/handler.rb', line 20 def self.system_commands; @@system_commands; end |
.timeout ⇒ Object
60 61 62 |
# File 'lib/roma/event/handler.rb', line 60 def self.timeout @@timeout end |
.timeout=(n) ⇒ Object
56 57 58 |
# File 'lib/roma/event/handler.rb', line 56 def self.timeout=(n) @@timeout = n end |
Instance Method Details
#post_init ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/roma/event/handler.rb', line 88 def post_init @port, @addr = Socket.unpack_sockaddr_in(get_peername) @log.info("Connected from #{@addr}:#{@port}. I have #{EM.connection_count} connections.") @connected = true @last_access = Time.now @@connections[self] = @last_access @fiber = Fiber.new { dispatcher } rescue Exception =>e @log.error("#{__FILE__}:#{__LINE__}:#{e.inspect} #{$@}") end |
#receive_data(data) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/roma/event/handler.rb', line 99 def receive_data(data) @rbuf << data @last_access = Time.now @fiber.resume rescue Exception =>e @log.error("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} #{e.inspect} #{$@}") end |
#unbind ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/roma/event/handler.rb', line 107 def unbind @connected=false begin @fiber.resume rescue FiberError end EventMachine::stop_event_loop if @stop_event_loop @@connections.delete(self) if @enter_time # hilatency check ps = Time.now - @enter_time if ps > @stats.hilatency_warn_time @log.warn("#{@lastcmd} has incompleted, passage of #{ps} seconds") end end @log.info("Disconnected from #{@addr}:#{@port}") rescue Exception =>e @log.warn("#{__FILE__}:#{__LINE__}:#{@addr}:#{@port} #{e.inspect} #{$@}") end |