Class: Quark::MdkProtocol::LamportClock
- Inherits:
-
Object
- Object
- Quark::MdkProtocol::LamportClock
- Extended by:
- DatawireQuarkCore::Static
- Defined in:
- lib/mdk_protocol.rb
Constant Summary
Constants included from DatawireQuarkCore::Static
DatawireQuarkCore::Static::Unassigned
Instance Attribute Summary collapse
-
#_mutex ⇒ Object
Returns the value of attribute _mutex.
-
#clocks ⇒ Object
Returns the value of attribute clocks.
Class Method Summary collapse
Instance Method Summary collapse
- #__init_fields__ ⇒ Object
- #_getClass ⇒ Object
- #_getField(name) ⇒ Object
- #_setField(name, value) ⇒ Object
-
#enter ⇒ Object
Enter a new level of causality.
-
#initialize ⇒ LamportClock
constructor
A new instance of LamportClock.
-
#key ⇒ Object
Return a neatly-formatted list of all of our clock elements (e.g. 1,2,4,1) for use as a name or a key.
-
#leave(popTo) ⇒ Object
Leave deeper levels of causality.
-
#tick ⇒ Object
Increment the clock for our current level of causality (which is always the last element in the list).
- #toString ⇒ Object
Methods included from DatawireQuarkCore::Static
_lazy_statics, static, unlazy_statics
Constructor Details
#initialize ⇒ LamportClock
142 143 144 145 146 147 |
# File 'lib/mdk_protocol.rb', line 142 def initialize() super() nil end |
Instance Attribute Details
#_mutex ⇒ Object
Returns the value of attribute _mutex.
135 136 137 |
# File 'lib/mdk_protocol.rb', line 135 def _mutex @_mutex end |
#clocks ⇒ Object
Returns the value of attribute clocks.
135 136 137 |
# File 'lib/mdk_protocol.rb', line 135 def clocks @clocks end |
Class Method Details
.decode(encoded) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/mdk_protocol.rb', line 152 def self.decode(encoded) return ::DatawireQuarkCore.cast(::Quark.mdk_protocol.Serializable.decodeClassName("mdk_protocol.LamportClock", encoded)) { ::Quark.mdk_protocol.LamportClock } nil end |
Instance Method Details
#__init_fields__ ⇒ Object
272 273 274 275 276 277 278 279 |
# File 'lib/mdk_protocol.rb', line 272 def __init_fields__() super self._mutex = ::DatawireQuarkCore::Lock.new() self.clocks = ::DatawireQuarkCore::List.new([]) nil end |
#_getClass ⇒ Object
240 241 242 243 244 245 |
# File 'lib/mdk_protocol.rb', line 240 def _getClass() return "mdk_protocol.LamportClock" nil end |
#_getField(name) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/mdk_protocol.rb', line 247 def _getField(name) if ((name) == ("_mutex")) return (self)._mutex end if ((name) == ("clocks")) return (self).clocks end return nil nil end |
#_setField(name, value) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/mdk_protocol.rb', line 260 def _setField(name, value) if ((name) == ("_mutex")) (self)._mutex = ::DatawireQuarkCore.cast(value) { ::DatawireQuarkCore::Lock } end if ((name) == ("clocks")) (self).clocks = ::DatawireQuarkCore.cast(value) { ::DatawireQuarkCore::List } end nil end |
#enter ⇒ Object
Enter a new level of causality. Returns the value to pass to later pass to leave to get back to the current level of causality.
195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/mdk_protocol.rb', line 195 def enter() @_mutex.acquire() current = -(1) ((self).clocks) << (0) current = ((self).clocks).size @_mutex.release() return current nil end |
#key ⇒ Object
Return a neatly-formatted list of all of our clock elements (e.g. 1,2,4,1) for use as a name or a key.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/mdk_protocol.rb', line 164 def key() @_mutex.acquire() tmp = ::DatawireQuarkCore::List.new([]) i = 0 while ((i) < (((self).clocks).size)) do (tmp) << ((((self).clocks)[i]).to_s) i = (i) + (1) end str = (tmp).join(",") @_mutex.release() return str nil end |
#leave(popTo) ⇒ Object
Leave deeper levels of causality. popTo should be the value returned when you enter()d this level.
211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/mdk_protocol.rb', line 211 def leave(popTo) @_mutex.acquire() current = -(1) (self).clocks = ::Quark.quark.ListUtil.new().slice((self).clocks, 0, popTo) current = ((self).clocks).size @_mutex.release() return current nil end |
#tick ⇒ Object
Increment the clock for our current level of causality (which is always the last element in the list). If there are no elements in our clock, do nothing.
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/mdk_protocol.rb', line 228 def tick() @_mutex.acquire() current = ((self).clocks).size if ((current) > (0)) ((self).clocks)[(current) - (1)] = ((((self).clocks)[(current) - (1)]) + (1)) end @_mutex.release() nil end |
#toString ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/mdk_protocol.rb', line 180 def toString() @_mutex.acquire() str = (("<LamportClock ") + (self.key())) + (">") @_mutex.release() return str nil end |