Class: Hop::WssBearer::Admission
- Inherits:
-
Object
- Object
- Hop::WssBearer::Admission
- Defined in:
- lib/hop/wss_bearer.rb
Instance Method Summary collapse
- #acquire(sock) ⇒ Object
- #close_all ⇒ Object
- #count ⇒ Object
-
#initialize(limit) ⇒ Admission
constructor
A new instance of Admission.
- #release(lease) ⇒ Object
- #replace(lease, sock) ⇒ Object
Constructor Details
#initialize(limit) ⇒ Admission
Returns a new instance of Admission.
182 183 184 185 186 |
# File 'lib/hop/wss_bearer.rb', line 182 def initialize(limit) @limit = limit @lock = Mutex.new @sockets = {} end |
Instance Method Details
#acquire(sock) ⇒ Object
188 189 190 191 192 193 194 195 196 |
# File 'lib/hop/wss_bearer.rb', line 188 def acquire(sock) @lock.synchronize do return nil if @sockets.size >= @limit lease = SocketLease.new(self, sock) @sockets[lease] = sock lease end end |
#close_all ⇒ Object
206 207 208 209 |
# File 'lib/hop/wss_bearer.rb', line 206 def close_all sockets = @lock.synchronize { @sockets.values.dup } sockets.each { |sock| sock.close rescue nil } end |
#count ⇒ Object
211 |
# File 'lib/hop/wss_bearer.rb', line 211 def count = @lock.synchronize { @sockets.size } |
#release(lease) ⇒ Object
202 203 204 |
# File 'lib/hop/wss_bearer.rb', line 202 def release(lease) @lock.synchronize { @sockets.delete(lease) } end |
#replace(lease, sock) ⇒ Object
198 199 200 |
# File 'lib/hop/wss_bearer.rb', line 198 def replace(lease, sock) @lock.synchronize { @sockets[lease] = sock if @sockets.key?(lease) } end |