Class: RServiceBus::Config

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

Overview

Marshals configuration information for an rservicebus host

Direct Known Subclasses

ConfigFromEnv, ConfigFromSetter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
# File 'lib/rservicebus/Config.rb', line 21

def initialize()
    puts 'Cannot instantiate config directly.'
    puts 'For production, use ConfigFromEnv.'
    puts 'For debugging or testing, you could try ConfigFromSetter'
    abort()
end

Instance Attribute Details

#appNameObject (readonly)

Returns the value of attribute appName.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def appName
  @appName
end

#contractListObject (readonly)

Returns the value of attribute contractList.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def contractList
  @contractList
end

#errorQueueNameObject (readonly)

Returns the value of attribute errorQueueName.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def errorQueueName
  @errorQueueName
end

#forwardReceivedMessagesToObject (readonly)

Returns the value of attribute forwardReceivedMessagesTo.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def forwardReceivedMessagesTo
  @forwardReceivedMessagesTo
end

#forwardSentMessagesToObject (readonly)

Returns the value of attribute forwardSentMessagesTo.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def forwardSentMessagesTo
  @forwardSentMessagesTo
end

#handlerPathListObject (readonly)

Returns the value of attribute handlerPathList.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def handlerPathList
  @handlerPathList
end

#libListObject (readonly)

Returns the value of attribute libList.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def libList
  @libList
end

#maxRetriesObject (readonly)

Returns the value of attribute maxRetries.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def maxRetries
  @maxRetries
end

#messageEndpointMappingsObject (readonly)

Returns the value of attribute messageEndpointMappings.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def messageEndpointMappings
  @messageEndpointMappings
end

#mqHostObject (readonly)

Returns the value of attribute mqHost.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def mqHost
  @mqHost
end

#sagaPathListObject (readonly)

Returns the value of attribute sagaPathList.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def sagaPathList
  @sagaPathList
end

#statOutputCountdownObject (readonly)

Returns the value of attribute statOutputCountdown.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def statOutputCountdown
  @statOutputCountdown
end

#subscriptionUriObject (readonly)

Returns the value of attribute subscriptionUri.



5
6
7
# File 'lib/rservicebus/Config.rb', line 5

def subscriptionUri
  @subscriptionUri
end

Instance Method Details

#configureMqObject



150
151
152
153
# File 'lib/rservicebus/Config.rb', line 150

def configureMq
    @mqHost = self.getValue( 'MQ', 'beanstalk://localhost')
    return self
end

#ensureContractFileExists(path) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rservicebus/Config.rb', line 85

def ensureContractFileExists( path )
    unless File.exists?(path) ||
        File.exists?("#{path}.rb") then
      puts 'Error while processing contracts'
      puts "*** path, #{path}, provided does not exist as a file"
      abort()
    end
    unless File.extname(path) == "" ||
        File.extname(path) == ".rb" then
      puts 'Error while processing contracts'
      puts "*** path, #{path}, should point to a ruby file, with extention .rb"
      abort()
    end
end

#getValue(name, default = nil) ⇒ Object



32
33
34
35
36
# File 'lib/rservicebus/Config.rb', line 32

def getValue( name, default=nil )
    value = ( ENV[name].nil?  || ENV[name] == '') ? default : ENV[name];
    log "Env value: #{name}: #{value}"
    return value
end

#loadContractsObject

Marshals paths for contracts

Note. .rb extension is optional

Expected format; /one/two/Contracts



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rservicebus/Config.rb', line 106

def loadContracts()
    @contractList = Array.new

    #This is a guard clause in case no Contracts have been specified
    #If any guard clauses have been specified, then execution should drop to the second block
    if self.getValue('CONTRACTS').nil? then
        return self
    end

    self.getValue( 'CONTRACTS', './Contract').split(';').each do |path|
        self.ensureContractFileExists( path )
        @contractList << path
    end
    return self
end

#loadHandlerPathListObject

Marshals paths for message handlers

Note. trailing slashs will be stripped

Expected format; <path 1>;<path 2>



44
45
46
47
48
49
50
51
52
53
# File 'lib/rservicebus/Config.rb', line 44

def loadHandlerPathList()
    path = self.getValue( 'MSGHANDLERPATH', './MessageHandler')
    @handlerPathList = Array.new
    path.split(';').each do |path|
        path = path.strip.chomp('/')
        @handlerPathList << path
    end

    return self
end

#loadHostSectionObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rservicebus/Config.rb', line 66

def loadHostSection()
    @appName = self.getValue( 'APPNAME', 'RServiceBus')
    @errorQueueName = self.getValue( 'ERROR_QUEUE_NAME', 'error')
    @maxRetries = self.getValue( 'MAX_RETRIES', '5').to_i
    @statOutputCountdown = self.getValue( 'STAT_OUTPUT_COUNTDOWN', '100').to_i
    @subscriptionUri = self.getValue( 'SUBSCRIPTION_URI', "file:///tmp/#{appName}_subscriptions.yaml" )

    auditQueueName = self.getValue('AUDIT_QUEUE_NAME')
    if auditQueueName.nil? then
        @forwardSentMessagesTo = self.getValue('FORWARD_SENT_MESSAGES_TO')
        @forwardReceivedMessagesTo = self.getValue('FORWARD_RECEIVED_MESSAGES_TO')
        else
        @forwardSentMessagesTo = auditQueueName
        @forwardReceivedMessagesTo = auditQueueName
    end

    return self
end

#loadLibsObject

Marshals paths for lib

Note. .rb extension is optional

Expected format; /one/two/Contracts



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/rservicebus/Config.rb', line 128

def loadLibs()
    @libList = Array.new

    path = self.getValue('LIB')
    path = './lib' if path.nil? and File.exists?('./lib')
    if path.nil? then
        return self
    end

    path.split(';').each do |path|
        log "Loading libs from, #{path}"
        unless File.exists?(path) then
          puts 'Error while processing libs'
          puts "*** path, #{path}, should point to a ruby file, with extention .rb, or"
          puts "*** path, #{path}, should point to a directory than conatins ruby files, that have extention .rb"
          abort()
        end
        @libList << path
    end
    return self
end

#loadSagaPathListObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/rservicebus/Config.rb', line 55

def loadSagaPathList()
    path = self.getValue( 'SAGAPATH', './Saga')
    @sagaPathList = Array.new
    path.split(';').each do |path|
        path = path.strip.chomp('/')
        @sagaPathList << path
    end

    return self
end

#loadWorkingDirListObject

Marshals paths for working_dirs

Note. trailing slashs will be stripped

Expected format; <path 1>;<path 2>



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/rservicebus/Config.rb', line 161

def loadWorkingDirList()
    pathList = self.getValue('WORKING_DIR')
    return self if pathList.nil?

    pathList.split(';').each do |path|

        path = path.strip.chomp('/')

        unless Dir.exists?("#{path}") then
          puts 'Error while processing working directory list'
          puts "*** path, #{path}, does not exist"
          next
        end

        if Dir.exists?( "#{path}/MessageHandler" ) then
            @handlerPathList << "#{path}/MessageHandler"
        end

        if Dir.exists?( "#{path}/Saga" ) then
            @sagaPathList << "#{path}/Saga"
        end

        if File.exists?( "#{path}/Contract.rb" ) then
            @contractList << "#{path}/Contract.rb"
        end

        if File.exists?( "#{path}/lib" ) then
            @libList << "#{path}/lib"
        end
    end

    return self
end

#log(string) ⇒ Object



28
29
30
# File 'lib/rservicebus/Config.rb', line 28

def log( string )
    puts string
end