Class: UU::OS::Application::Config
- Inherits:
-
Object
- Object
- UU::OS::Application::Config
- Defined in:
- uu_os_application-server-2.7.3/lib/uu/os/application/config.rb
Overview
Class represent application global configuration, configuration is read from configuration files and environment variables. Configuration is merged in this order:
-
Configuration file <app-root>/config/app.rb
-
<uu-home>/config/uu-client.properties
-
Environment variable SERVER_CFG
-
Configuration made by block #load defined in file <app-root>/config/app.rb
Constant Summary
- DEFAULT_TTL =
Default ttl in seconds. TTL is period of time, while configuration is cached by application.
3600
Class Method Summary (collapse)
- + (Object) [](key)
- + (Object) []=(key, value)
- + (Object) clear
- + (Object) delete(key, &block)
- + (Boolean) has_key?(key)
-
+ (Object) load {|config| ... }
Method takes a block as parameter, this block is used for dynamic configuration loading.
- + (Object) merge!(other_hash, &block)
-
+ (void) reload
Force immediate configuration reload no matter to ttl expiration.
- + (Object) replace(other_hash)
-
+ (Fixnum) ttl
Returns configuration ttl (time to live) in seconds.
-
+ (void) ttl=(new_ttl)
Sets configuration ttl (time to live) in seconds.
Class Method Details
+ (Object) [](key)
61 62 63 64 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 61 def self.[](key) _reload if reload_necessary? @@ctx[key] end |
+ (Object) []=(key, value)
67 68 69 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 67 def self.[]=(key, value) @@ctx[key] = value end |
+ (Object) clear
92 93 94 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 92 def self.clear @@ctx.clear end |
+ (Object) delete(key, &block)
82 83 84 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 82 def self.delete(key, &block) @@ctx.delete(key, &block) end |
+ (Boolean) has_key?(key)
87 88 89 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 87 def self.has_key?(key) @@ctx.has_key?(key) end |
+ (Object) load {|config| ... }
This method should be defined in <app-root>/config/app.rb file.
Method takes a block as parameter, this block is used for dynamic configuration loading. Block is called every time when configuration expire (you can set configuration ttl). If configuration expire, this block is called when application try to read some value (by UU::OS::Application::Config).
Code used in block for loading must be fast, because if configuration expire so all requests are blocked until configuration is loaded.
If configuration load fails (exception is raised from block), then original configuration is restored and all changes made on config hash (hash that comes to block) are discarded. The next attempt to reload configuration after failure is made when normal ttl expire (no special behavior after failure).
In block, you must not set values by modifying UU::OS::Application::Config directly (e.g. UU::OS::Application::Config = 'value') but use config hash that comes to the block.
There is not guaranty which user (if any) will be logged on session when block starts. Every session change (login or logout) is valid only in this block execution scope and is discarded when block ends.
143 144 145 146 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 143 def self.load(&block) return unless block_given? @@load_callback = block end |
+ (Object) merge!(other_hash, &block)
72 73 74 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 72 def self.merge!(other_hash, &block) @@ctx.merge!(other_hash, &block) end |
+ (void) reload
This method returns an undefined value.
Force immediate configuration reload no matter to ttl expiration. Method waits until configuration is loaded. Reload in done by block defined by #load.
101 102 103 104 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 101 def self.reload _reload(true) return end |
+ (Object) replace(other_hash)
77 78 79 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 77 def self.replace(other_hash) @@ctx.replace(other_hash) end |
+ (Fixnum) ttl
Returns configuration ttl (time to live) in seconds. Default value is defined by DEFAULT_TTL constant. TTL is period of time, while configuration is cached by application.
155 156 157 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 155 def self.ttl @@ttl end |
+ (void) ttl=(new_ttl)
This method returns an undefined value.
Sets configuration ttl (time to live) in seconds. Default value is defined by DEFAULT_TTL constant. Value can be set in interval from 1 to Fixnum maximum. If you set value to zero or less (e.g. -1) it means infinite ttl and reload is performed only once.
169 170 171 |
# File 'uu_os_application-server-2.7.3/lib/uu/os/application/config.rb', line 169 def self.ttl=(new_ttl) @@ttl = new_ttl end |