Module: OpenHAB::OSGi
- Defined in:
- lib/openhab/osgi.rb
Overview
OSGi services interface
Class Attribute Summary collapse
-
.bundle ⇒ org.osgi.framework.Bundle
readonly
The OSGi Bundle for ScriptExtension Class.
-
.bundle_context ⇒ org.osgi.framework.BundleContext
readonly
OSGi bundle context for ScriptExtension Class.
Class Method Summary collapse
-
.register_service(instance, *interfaces, bundle: nil, **properties) ⇒ org.osgi.framework.ServiceRegistration
Register a new service instance with OSGi.
- .service(name, filter: nil) ⇒ Object
-
.services(name, filter: nil) ⇒ Array<Object>
An array of services.
Class Attribute Details
.bundle ⇒ org.osgi.framework.Bundle (readonly)
Returns The OSGi Bundle for ScriptExtension Class.
68 69 70 |
# File 'lib/openhab/osgi.rb', line 68 def bundle @bundle ||= org.osgi.framework.FrameworkUtil.getBundle($scriptExtension.java_class) end |
.bundle_context ⇒ org.osgi.framework.BundleContext (readonly)
Returns OSGi bundle context for ScriptExtension Class.
62 63 64 |
# File 'lib/openhab/osgi.rb', line 62 def bundle_context @bundle_context ||= bundle.bundle_context end |
Class Method Details
.register_service(instance, *interfaces, bundle: nil, **properties) ⇒ org.osgi.framework.ServiceRegistration
Register a new service instance with OSGi
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/openhab/osgi.rb', line 45 def register_service(instance, *interfaces, bundle: nil, **properties) if interfaces.empty? interfaces = instance.class.ancestors.select { |k| k.respond_to?(:java_class) && k.java_class&.interface? } end bundle_class = interfaces.first.is_a?(Module) ? interfaces.first : instance bundle ||= org.osgi.framework.FrameworkUtil.get_bundle(bundle_class.java_class) interfaces.map! { |i| i.is_a?(String) ? i : i.java_class.name } bundle.bundle_context.register_service( interfaces.to_java(java.lang.String), instance, java.util.Hashtable.new(properties) ) end |
.service(name, filter: nil) ⇒ Object
15 16 17 |
# File 'lib/openhab/osgi.rb', line 15 def service(name, filter: nil) services(name, filter: filter).first end |
.services(name, filter: nil) ⇒ Array<Object>
Returns An array of services.
25 26 27 28 29 30 |
# File 'lib/openhab/osgi.rb', line 25 def services(name, filter: nil) (bundle_context.get_service_references(name, filter) || []).map do |reference| logger.trace "OSGi service found for '#{name}' using OSGi Service Reference #{reference}" bundle_context.get_service(reference) end end |