Class: RightScale::CloudApi::Manager
Overview
The class is the parent class for all the cloud based thread-safe managers.
The main purpose of the manager is to check if the current thread or fiber has a thread-unsafe ApiManager instance created or not. If not them the manager creates than instance of ApiManager in the current thread/fiber and feeds the method and parameters to it.
Instance Method Summary collapse
-
#api_manager ⇒ ..::MyCoolCloudNamespace::ApiManager
Returns the an instance of ApiManager for the current thread/fiber.
-
#initialize(*args) {|Any| ... } ⇒ Manager
constructor
The initializer.
-
#method_missing(m, *args, &block) ⇒ Object
Feeds all unknown methods to the ApiManager instance.
Constructor Details
#initialize(*args) {|Any| ... } ⇒ Manager
The initializer.
96 97 98 99 100 101 |
# File 'lib/base/manager.rb', line 96 def initialize(*args, &block) @args, @block = args, block = args.last.is_a?(Hash) ? args.last : {} @api_manager_class = [:api_manager_class] || self.class.name.sub(/::Manager$/, '::ApiManager')._constantize @api_manager_storage = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Feeds all unknown methods to the ApiManager instance.
116 117 118 |
# File 'lib/base/manager.rb', line 116 def method_missing(m, *args, &block) api_manager.__send__(m, *args, &block) end |
Instance Method Details
#api_manager ⇒ ..::MyCoolCloudNamespace::ApiManager
Returns the an instance of ApiManager for the current thread/fiber. The method creates a new ApiManager instance ubless it exist.
108 109 110 111 112 |
# File 'lib/base/manager.rb', line 108 def api_manager # Delete dead threads and their managers from the list. Utils::remove_dead_fibers_and_threads_from_storage(@api_manager_storage) @api_manager_storage[Utils::current_thread_and_fiber] ||= @api_manager_class::new(*@args, &@block) end |