Class: RServiceBus::ConfigureMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/ConfigureMonitor.rb

Overview

Configure Monitors for an rservicebus host

Instance Method Summary collapse

Constructor Details

#initialize(host, resourceManager) ⇒ ConfigureMonitor

Constructor

Parameters:

  • host (RServiceBus::Host)

    instance

  • resourceManager (Hash)

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



15
16
17
18
19
20
21
# File 'lib/rservicebus/ConfigureMonitor.rb', line 15

def initialize( host, resourceManager )
    @host = host
    @resourceManager = resourceManager
    
    @handlerList = Hash.new
    @resourceList = Hash.new
end

Instance Method Details

#getMonitors(env) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rservicebus/ConfigureMonitor.rb', line 42

def getMonitors( env )
    monitors = Array.new

    env.each do |k,v|
        if v.is_a?(String) and
					k.start_with?('RSBOB_') then
            uri = URI.parse( v )
            name = k.sub( 'RSBOB_', '')
            monitor = nil?
            case uri.scheme
                when 'csvdir'
                require 'rservicebus/Monitor/CsvDir'
						monitor = Monitor_CsvDir.new( @host, name, uri )

                when 'xmldir'
                require 'rservicebus/Monitor/XmlDir'
						monitor = Monitor_XmlDir.new( @host, name, uri )

                when 'dir'
                require 'rservicebus/Monitor/Dir'
						monitor = Monitor_Dir.new( @host, name, uri )
                
                when 'dirnotifier'
                require 'rservicebus/Monitor/DirNotifier'
						monitor = Monitor_DirNotifier.new( @host, name, uri )

                when 'csvperlinedir'
                require 'rservicebus/Monitor/CsvPerLine'
						monitor = Monitor_CsvPerLineDir.new( @host, name, uri )
                else
						abort("Scheme, #{uri.scheme}, not recognised when configuring Monitor, #{k}=#{v}");
            end
            self.setAppResources( monitor )
            monitors << monitor
        end
        
    end
    
    return monitors
end

#setAppResources(monitor) ⇒ Object

Assigns appropriate resources to writable attributes in the handler that match keys in the resource hash

Parameters:

  • handler (RServiceBus::Handler)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rservicebus/ConfigureMonitor.rb', line 26

def setAppResources( monitor )
    RServiceBus.rlog "Checking app resources for: #{monitor.class.name}"
    RServiceBus.rlog "If your attribute is not getting set, check that it is in the 'attr_accessor' list"
    @resourceManager.getAll.each do |k,v|
        if monitor.class.method_defined?( k ) then
            monitor.instance_variable_set( "@#{k}", v.getResource() )
            @resourceList[monitor.class.name] = Array.new if @resourceList[monitor.class.name].nil?
            @resourceList[monitor.class.name] << v
            @host.log "App resource attribute, #{k}, set for: " + monitor.class.name
        end
    end
    
    return self
end