Class: Hop::WssBearer::Admission

Inherits:
Object
  • Object
show all
Defined in:
lib/hop/wss_bearer.rb

Instance Method Summary collapse

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_allObject



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

#countObject



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