Class: Ticketing::Ticket
- Inherits:
-
Object
- Object
- Ticketing::Ticket
- Defined in:
- lib/ticketing/broker.rb
Overview
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
The locked key.
-
#token ⇒ Object
readonly
The fencing token for this grant — a value that strictly increases with every acquisition of any key.
Instance Method Summary collapse
-
#close ⇒ Object
Releases the lock in the background if it was not already released.
-
#initialize(broker, conn, key, token, logger) ⇒ Ticket
constructor
A new instance of Ticket.
-
#release ⇒ Object
Releases the lock.
Constructor Details
#initialize(broker, conn, key, token, logger) ⇒ Ticket
Returns a new instance of Ticket.
176 177 178 179 180 181 182 183 184 |
# File 'lib/ticketing/broker.rb', line 176 def initialize(broker, conn, key, token, logger) @broker = broker @conn = conn @key = key @token = token @logger = logger @released = false @mutex = Mutex.new end |
Instance Attribute Details
#key ⇒ Object (readonly)
The locked key.
169 170 171 |
# File 'lib/ticketing/broker.rb', line 169 def key @key end |
#token ⇒ Object (readonly)
The fencing token for this grant — a value that strictly increases with every acquisition of any key. Pass it to the resource you protect and reject stale (lower) tokens.
174 175 176 |
# File 'lib/ticketing/broker.rb', line 174 def token @token end |
Instance Method Details
#close ⇒ Object
Releases the lock in the background if it was not already released.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/ticketing/broker.rb', line 194 def close should_release = @mutex.synchronize do next false if @released @released = true true end return unless should_release Thread.new do begin @broker.release_lock(@conn, @key) rescue StandardError @logger.error("auto-release #{@key} failed — lease will expire it") end end nil end |
#release ⇒ Object
Releases the lock. Returns true if the server still held it, false if
it had already expired.
188 189 190 191 |
# File 'lib/ticketing/broker.rb', line 188 def release @mutex.synchronize { @released = true } @broker.release_lock(@conn, @key) end |