Class: TorqueBox::Configuration::GlobalConfiguration

Inherits:
Configuration
  • Object
show all
Defined in:
lib/torquebox/configuration/global.rb

Constant Summary collapse

ENTRY_MAP =
lambda do
  destination_entry =
    ThingWithOptionsEntry.with_settings(:validate => {
                                          :optional => [
                                                        { :create => [true, false] },
                                                        { :durable => [true, false] },
                                                        :processor,
                                                        :remote_host
                                                       ]
                                        })
  {
    :authentication => ThingWithOptionsEntry.with_settings( :validate => {
                                                              :required => [:domain],
                                                              :optional => [:credential]
                                                            }),
    :credential  => ThingsEntry.with_settings(:require_parent => [:authentication],
                                             :discrete => true),
    :environment => OptionsEntry,
    :injection   => OptionsEntry.with_settings(:validate => {
                                                 :required => [{ :enabled => [true, false] }]
                                               }),
    :config => OptionsEntry,
    :job         => ThingWithOptionsEntry.with_settings(:discrete => true,
                                                        :validate => {
                                                          :required => [:cron],
                                                          :optional => [
                                                                        :config,
                                                                        :name,
                                                                        { :singleton => [true, false] }
                                                                       ]
                                                        }),
    :options_for => ThingWithOptionsEntry.with_settings(:validate => {
                                                          :optional => [
                                                                        :concurrency,
                                                                        { :disabled => [true, false] },
                                                                        :default_message_encoding
                                                                       ]
                                                        }),
    :pool        => ThingWithOptionsEntry.with_settings(:validate => {
                                                          :required => [{ :type => [:bounded, :shared] }],
                                                          :optional => [:min, :max, { :lazy => [true, false] }]
                                                        }),
    :processor   => ThingWithOptionsEntry.with_settings(:require_parent => [:queue, :topic],
                                                        :discrete => true,
                                                        :validate => {
                                                          :optional => [
                                                                        :concurrency,
                                                                        { :singleton => [true, false] },
                                                                        { :durable => [true, false] },
                                                                        :client_id,
                                                                        :config,
                                                                        :selector,
                                                                        :name
                                                                       ]
                                                        }),
    :queue       => destination_entry,
    :ruby        => OptionsEntry.with_settings(:validate => {
                                                 :optional => [{ :version => ['1.8', '1.9'] },
                                                               { :compile_mode => [:force, :jit, :off,
                                                                                   'force', 'jit', 'off'] },
                                                               { :debug => [true, false] },
                                                               { :interactive => [true, false] },
                                                               { :profile_api => [true, false] }
                                                              ]
                                               }),
    :service     => ThingWithOptionsEntry.with_settings(:discrete => true,
                                                        :validate => {
                                                          :optional => [
                                                                        :config,
                                                                        :name,
                                                                        { :singleton => [true, false] }
                                                                       ]
                                                        }),
    :stomp       => OptionsEntry.with_settings(:validate => { :required => [:host] } ),
    :stomplet    => ThingWithOptionsEntry.with_settings( :discrete => true,
                                                         :validate => {
                                                           :required => [ :route ],
                                                           :optional => [ :config, :name ] } ),
    
    :topic       => destination_entry,
    :web         => OptionsEntry.with_settings(:validate => {
                                                 :optional => [:context, :host, :rackup, :static, :'session-timeout' ]
                                               })
  }
end.call

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Configuration

#initialize

Constructor Details

This class inherits a constructor from TorqueBox::Configuration::Configuration

Class Method Details

.load_configuration(file) ⇒ Object



24
25
26
27
28
# File 'lib/torquebox/configuration/global.rb', line 24

def self.load_configuration(file)
  config = new
  TorqueBox::Configuration.load_configuration( file, config, ENTRY_MAP )
  config.
end

Instance Method Details

#array_to_arraylist(array) ⇒ Object



226
227
228
229
230
231
232
# File 'lib/torquebox/configuration/global.rb', line 226

def array_to_arraylist(array)
  arraylist = java.util.ArrayList.new
  array.each do |value|
    arraylist.add( ruby_to_java( value ) )
  end
  arraylist
end

#hash_to_hashmap(hash) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/torquebox/configuration/global.rb', line 217

def hash_to_hashmap(hash)
  hashmap = java.util.HashMap.new
  hash.each do |key, value|
    value = ruby_to_java( value ) 
    hashmap[key.to_s] = value
  end
  hashmap
end

#ruby_to_java(object) ⇒ Object



206
207
208
209
210
211
212
213
214
215
# File 'lib/torquebox/configuration/global.rb', line 206

def ruby_to_java(object)
  r = object
  case ( object )
  when Hash
    r = hash_to_hashmap(object)
  when Array
    r = array_to_arraylist(object)
  end
  r
end

#to_metadata_hashObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/torquebox/configuration/global.rb', line 117

def 
   = Hash.new { |hash, key| hash[key] = Hash.new { |hash, key| hash[key] = { } } }

  self[TorqueBox::CONFIGURATION_ROOT].each do |entry_name, entry_data|
    case entry_name
    when 'authentication' # => auth:
      entry_data.each do |name, data|
        (data.delete('credential') || []).each do |user, password|
          data['credentials'] ||= {}
          data['credentials'][user] = password
        end
        ['auth'][name] = data
      end

    when 'torquebox_init' # runtime intialization
      [entry_name] = entry_data
    
    when 'job' # => jobs:
      entry_data.each do |klass, data|
        name = data.delete( :name ) || unique_name( klass.to_s, ['jobs'].keys )
        job = ['jobs'][name]
        job['job'] = klass.to_s
        job.merge!( data )
      end

    when 'options_for' # => tasks:, messaging:\n default_message_encoding:, jobs:\n concurrency:
      if (messaging_opts = entry_data.delete( 'messaging' )) &&
          (default_encoding = messaging_opts.delete( :default_message_encoding ))
        ['messaging']['default_message_encoding'] = default_encoding.to_s
      end

      if (job_opts = entry_data.delete( 'jobs' )) &&
          (concurrency = job_opts.delete( :concurrency ))
        ['jobs']['concurrency'] = concurrency.to_java(java.lang.Integer)
      end

      entry_data.each do |name, data|
        data[:concurrency] = 0 if data.delete( :disabled )
        data[:concurrency] &&= data[:concurrency].to_java(java.lang.Integer)
        ['tasks'][name] = data
      end

    when 'pool' # => pooling:
      entry_data.each do |name, data|
        pool_type = data.delete( :type )
        if pool_type.to_s == 'shared'
          ['pooling'][name] = 'shared'
        else
          ['pooling'][name] = data
        end
      end

    when 'queue', 'topic' # => queues:/topics: & messaging:
      entry_data.each do |name, data|
        [entry_name + 's'][name] = data unless data.delete( :create ) === false
        (data.delete( 'processor' ) || []).each do |processor|
          processor_class, processor_options = processor
          processor_options[:concurrency] &&= processor_options[:concurrency].to_java(java.lang.Integer)
          ['messaging'][name][processor_class] = processor_options
        end
      end

    when 'service' # => services:
      entry_data.each do |klass, data|
        name = data.delete( :name )
        if name
          data[:service] = klass.to_s
        else
          name = klass.to_s
        end
        ['services'][name] = data
      end

    when 'stomplet' 
      entry_data.each do |klass, data|
        name = data.delete( :name ) || unique_name( klass.to_s, ['stomp']['stomplets'].keys )
        stomplet = ['stomp']['stomplets'][name] = {}
        stomplet['class'] = klass.to_s
        stomplet.merge!( data )
      end

    else # => <entry_name>: (handles environment, ruby, stomp, web)
      [entry_name].merge!( entry_data )
    end
  end

  ruby_to_java(  )
end