Class: Baykit::BayServer::Agent::SpinHandler
- Inherits:
-
Object
- Object
- Baykit::BayServer::Agent::SpinHandler
- Defined in:
- lib/baykit/bayserver/agent/spin_handler.rb
Direct Known Subclasses
Defined Under Namespace
Modules: SpinListener Classes: ListenerInfo
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#spin_count ⇒ Object
readonly
Returns the value of attribute spin_count.
Instance Method Summary collapse
- #ask_to_callback(lis) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(agt) ⇒ SpinHandler
constructor
A new instance of SpinHandler.
- #process_data ⇒ Object
- #stop_timeout_spins ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(agt) ⇒ SpinHandler
Returns a new instance of SpinHandler.
33 34 35 36 37 38 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 33 def initialize(agt) @listeners = [] @lock = Mutex.new @agent = agt @spin_count = 0 end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
30 31 32 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 30 def agent @agent end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
28 29 30 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 28 def listeners @listeners end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
29 30 31 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 29 def lock @lock end |
#spin_count ⇒ Object (readonly)
Returns the value of attribute spin_count.
31 32 33 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 31 def spin_count @spin_count end |
Instance Method Details
#ask_to_callback(lis) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 88 def ask_to_callback(lis) BayLog.debug("%s Ask to callback: %s", self, lis) found = false for ifo in @listeners do if ifo.listener == lis found = true break end end if found BayLog.error("Already registered") else @lock.synchronize do @listeners.append(ListenerInfo.new(lis, Time.now.tv_sec)) end end end |
#empty? ⇒ Boolean
108 109 110 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 108 def empty?() return @listeners.empty? end |
#process_data ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 44 def process_data() if @listeners.empty? return false end all_spun = true remove_list = [] @listeners.length.downto(1) do |i| lis = listeners[i-1].listener act, spun = lis.lap() case act when NextSocketAction::SUSPEND remove_list.append(i-1) when NextSocketAction::CLOSE remove_list.append(i-1) when NextSocketAction::CONTINUE next else raise Sink.new() end @listeners[i].last_access = Time.now.tv_sec() all_spun = all_spun & spun end if all_spun @spin_count += 1 if @spin_count > 10 sleep(0.01) else @spin_count = 0 end end remove_list.each do |i| @lock.synchronize do @listeners.delete_at(i) end end return true end |
#stop_timeout_spins ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 113 def stop_timeout_spins() if !@listeners.empty? return end remove_list = [] @lock.synchronize do now = Time.now.tv_sec @listeners.length.downto(1) do |i| ifo = @listeners[i-1] if ifo.listener.check_timeout(int(now - ifo.last_access)) ifo.listener.close() remove_list.append(i) end end end remove_list.each do |i| @lock.synchronize do self.listeners.pop(i) end end end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/baykit/bayserver/agent/spin_handler.rb', line 40 def to_s() return @agent.to_s() end |