Class: LS4::FaultDetector
- Inherits:
-
Object
- Object
- LS4::FaultDetector
- Defined in:
- lib/ls4/logic/fault_detector.rb
Defined Under Namespace
Classes: Term
Instance Method Summary collapse
- #add_nid(nid) ⇒ Object
- #delete_nid(nid) ⇒ Object
- #forward_timer ⇒ Object
- #get_fault_nids ⇒ Object
-
#initialize ⇒ FaultDetector
constructor
A new instance of FaultDetector.
- #reset(nid) ⇒ Object
- #set_init(all_nids, fault_nids) ⇒ Object
- #set_nid(nid) ⇒ Object
- #update(nid) ⇒ Object
Constructor Details
#initialize ⇒ FaultDetector
Returns a new instance of FaultDetector.
115 116 117 118 119 120 |
# File 'lib/ls4/logic/fault_detector.rb', line 115 def initialize @period = 10 @detect = 5 @first_detect = 20 # FIXME @map = {} # {nid => Term} end |
Instance Method Details
#add_nid(nid) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/ls4/logic/fault_detector.rb', line 154 def add_nid(nid) if term = @map[nid] return nil end @map[nid] = Term.new(@period + @first_detect) return true end |
#delete_nid(nid) ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/ls4/logic/fault_detector.rb', line 170 def delete_nid(nid) if term = @map.delete(nid) if term.expired? on_change end return true end return nil end |
#forward_timer ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ls4/logic/fault_detector.rb', line 190 def forward_timer fault_nids = [] @map.each_pair {|nid,term| if term.forward_timer fault_nids << nid end } if !fault_nids.empty? on_change end fault_nids end |
#get_fault_nids ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/ls4/logic/fault_detector.rb', line 180 def get_fault_nids fault_nids = [] @map.each_pair {|nid,term| if term.expired? fault_nids << nid end } fault_nids end |
#reset(nid) ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/ls4/logic/fault_detector.rb', line 145 def reset(nid) if term = @map[nid] term.reset(@period + @detect) on_change return true end return nil end |
#set_init(all_nids, fault_nids) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ls4/logic/fault_detector.rb', line 122 def set_init(all_nids, fault_nids) map = {} all_nids.each {|nid| map[nid] = Term.new(@period + @first_detect) } fault_nids.each {|nid| if all_nids.include?(nid) map[nid] = Term.new(0) end } @map = map nil end |
#set_nid(nid) ⇒ Object
162 163 164 165 166 167 168 |
# File 'lib/ls4/logic/fault_detector.rb', line 162 def set_nid(nid) if @map.has_key?(nid) reset(nid) else add_nid(nid) end end |
#update(nid) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/ls4/logic/fault_detector.rb', line 136 def update(nid) term = @map[nid] if term && !term.expired? term.reset(@period + @detect) return @period end return nil end |