Class: TorqueBox::Configuration::GlobalConfiguration Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

ENTRY_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

lambda do
  destination_entry =
    ThingWithOptionsEntry.with_settings(:validate => {
                                          :optional => [
                                                        { :create => [true, false] },
                                                        { :durable => [true, false] },
                                                        { :exported => [true, false] },
                                                        :processor,
                                                        :remote
                                                       ]
                                        })
  {
    :authentication => ThingWithOptionsEntry.with_settings( :validate => {
                                                              :required => [:domain],
                                                              :optional => [:credential]
                                                            }),
    :credential  => ThingsEntry.with_settings(:require_parent => [:authentication],
                                             :discrete => true),
    :environment => OptionsEntry,
    :config => OptionsEntry,
    :job         => ThingWithOptionsEntry.with_settings(:discrete => true,
                                                        :validate => {
                                                          :required => [:cron],
                                                          :optional => [
                                                                        :config,
                                                                        :name,
                                                                        :description,
                                                                        :timeout,
                                                                        { :singleton => [true, false] },
                                                                        { :stopped => [true, false] }
                                                                       ]
                                                        }),
    :options_for => ThingWithOptionsEntry.with_settings(:validate => {
                                                          :optional => [
                                                                        :concurrency,
                                                                        { :disabled => [true, false] },
                                                                        { :durable => [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] },
                                                                        { :synchronous => [true, false] },
                                                                        { :stopped => [true, false] },
                                                                        { :xa => [true, false] },
                                                                        :client_id,
                                                                        :config,
                                                                        :selector,
                                                                        :name
                                                                       ]
                                                        }),
    :queue       => destination_entry,
    :remote      => OptionsEntry.with_settings(:require_parent => [:queue, :topic],
                                               :validate => {
                                                  :required => [:host],
                                                  :optional => [:username, :password]
                                               }),
    :ruby        => OptionsEntry.with_settings(:validate => {
                                                 :optional => [{ :version => ['1.8', '1.9', '2.0'] },
                                                               { :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', :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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



232
233
234
235
236
237
238
# File 'lib/torquebox/configuration/global.rb', line 232

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



223
224
225
226
227
228
229
230
# File 'lib/torquebox/configuration/global.rb', line 223

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



212
213
214
215
216
217
218
219
220
221
# File 'lib/torquebox/configuration/global.rb', line 212

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
205
206
207
208
209
210
# File 'lib/torquebox/configuration/global.rb', line 128

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|
        ['pooling'][name] = data
      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