Class: RServiceBus2::ConfigureMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/monitor_configure.rb

Overview

Configure Monitors for an rservicebus host

Instance Method Summary collapse

Constructor Details

#initialize(host, resource_manager) ⇒ ConfigureMonitor

Constructor

Parameters:

  • host (RServiceBus2::Host)

    instance

  • resourceManager (Hash)

    As hash where k is the name of a resource, and v is the resource



11
12
13
14
15
16
17
# File 'lib/rservicebus2/monitor_configure.rb', line 11

def initialize(host, resource_manager)
  @host = host
  @resource_manager = resource_manager

  @handler_list = {}
  @resource_list = {}
end

Instance Method Details

#get_monitors(env) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rservicebus2/monitor_configure.rb', line 39

def get_monitors(env)
  monitors = []

  env.each do |k, v|
    if v.is_a?(String) && k.start_with?('RSBOB_')
      uri = URI.parse(v)
      name = k.sub('RSBOB_', '')
      monitor = nil
      case uri.scheme
      when 'dir'
        require 'rservicebus2/monitor/dir'
        monitor = MonitorDir.new(@host, name, uri)
      when 'dirnotifier'
        require 'rservicebus2/monitor/dirnotifier'
        monitor = MonitorDirNotifier.new(@host, name, uri)
      else
        abort("Scheme, #{uri.scheme}, not recognised when configuring
          Monitor, #{k}=#{v}")
      end
      set_app_resources(monitor)
      monitors << monitor
    end
  end
  monitors
end

#set_app_resources(monitor) ⇒ Object

Assigns appropriate resources to writable attributes in the handler that

match keys in the resource hash

Parameters:

  • handler (RServiceBus2::Handler)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rservicebus2/monitor_configure.rb', line 22

def set_app_resources(monitor)
  RServiceBus2.rlog "Checking app resources for: #{monitor.class.name}"
  RServiceBus2.rlog "If your attribute is not getting set, check that it is
    in the 'attr_accessor' list"
  @resource_manager.get_all.each do |k, v|
    next unless monitor.class.method_defined?(k)

    monitor.instance_variable_set("@#{k}", v.get_resource)
    @resource_list[monitor.class.name] = [] if
      @resource_list[monitor.class.name].nil?
    @resource_list[monitor.class.name] << v
    @host.log "App resource attribute, #{k}, set for: " +
      monitor.class.name
  end
  self
end