Class: OpenHAB::Core::Registry Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/registry.rb

Overview

This class is abstract.

The base class for all registries in openHAB.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#providersEnumerable<org.openhab.core.common.registry.Provider> (readonly)



43
44
45
# File 'lib/openhab/core/registry.rb', line 43

def providers
  providerToElements.keys
end

Instance Method Details

#provider_for(key) ⇒ org.openhab.core.common.registry.Provider

Determines which provider an element is associated with.

Parameters:

  • key (Object)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/openhab/core/registry.rb', line 20

def provider_for(key)
  elementReadLock.lock
  if key.is_a?(org.openhab.core.common.registry.Identifiable)
    return unless (provider = elementToProvider[key])

    # The HashMap lookup above uses java's hashCode() which has been overridden
    # by GenericItem and ThingImpl to return object's uid, e.g. item's name, thing uid
    # so it will return a provider even for an unmanaged object having the same uid
    # as an existing managed object.

    # So take an extra step to verify that the provider really holds the given instance.
    # by using equal? to compare the object's identity.
    # Only ManagedProviders have a #get method to look up the object by uid.
    provider if !provider.is_a?(ManagedProvider) || provider.get(key.uid).equal?(key)
  elsif (element = identifierToElement[key])
    elementToProvider[element]
  end
ensure
  elementReadLock.unlock
end