Class: RSpec::OpenHAB::Core::Mocks::OSGiEventManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/openhab/core/mocks/event_admin.rb

Overview

reimplement to not use a thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(typed_event_factories, typed_event_subscribers) ⇒ OSGiEventManager

Returns a new instance of OSGiEventManager.



13
14
15
16
17
# File 'lib/rspec/openhab/core/mocks/event_admin.rb', line 13

def initialize(typed_event_factories, typed_event_subscribers)
  @typed_event_factories = typed_event_factories
  @typed_event_subscribers = typed_event_subscribers
  @logger = org.slf4j.LoggerFactory.get_logger("rspec.openhab.core.mocks.event_handler")
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/rspec/openhab/core/mocks/event_admin.rb', line 11

def logger
  @logger
end

Instance Method Details

#handle_event(osgi_event) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec/openhab/core/mocks/event_admin.rb', line 19

def handle_event(osgi_event)
  type = osgi_event.get_property("type")
  payload = osgi_event.get_property("payload")
  topic = osgi_event.get_property("topic")
  source = osgi_event.get_property("source")

  if type.is_a?(String) && payload.is_a?(String) && topic.is_a?(String)
    handle_event_internal(type, payload, topic, source) unless type.empty? || payload.empty? || topic.empty?
  else
    logger.error("The handled OSGi event is invalid. " \
                 "Expect properties as string named 'type', 'payload', and 'topic'. " \
                 "Received event properties are: #{osgi_event.property_names.inspect}")
  end
end