Class: Tidewave::BrowserControl::ClientRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/tidewave/browser_control.rb

Instance Method Summary collapse

Constructor Details

#initializeClientRegistry

Returns a new instance of ClientRegistry.



252
253
254
255
# File 'lib/tidewave/browser_control.rb', line 252

def initialize
  @mutex = Mutex.new
  @clients = {}
end

Instance Method Details

#register(name, owner) ⇒ Object

Registers owner under name. Returns false when a different live owner already holds the name.

The registry is per-process, so with a multi-process cable adapter the uniqueness check is best-effort (client-generated names carry enough entropy for collisions to be negligible).



263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/tidewave/browser_control.rb', line 263

def register(name, owner)
  @mutex.synchronize do
    current = @clients[name]

    if current.nil? || current.equal?(owner)
      @clients[name] = owner
      true
    else
      false
    end
  end
end

#unregister(name, owner) ⇒ Object



276
277
278
279
280
# File 'lib/tidewave/browser_control.rb', line 276

def unregister(name, owner)
  @mutex.synchronize do
    @clients.delete(name) if @clients[name].equal?(owner)
  end
end