Class: Fairy::Fairy
- Inherits:
-
Object
- Object
- Fairy::Fairy
- Defined in:
- lib/fairy.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Class Method Summary collapse
- .create_subfairy(fairy) ⇒ Object
-
.def_fairy_interface(mod) ⇒ Object
external module loading.
- .def_filter_interface(mod) ⇒ Object
Instance Method Summary collapse
- #abort ⇒ Object
-
#def_pool_variable(vname, value = nil) ⇒ Object
pool variables.
-
#handle_exception(exp) ⇒ Object
exception handling.
-
#initialize(master_host = CONF.MASTER_HOST, master_port = CONF.MASTER_PORT, opts = {}) ⇒ Fairy
constructor
A new instance of Fairy.
- #initialize_subfairy(fairy) ⇒ Object
- #name2backend_class(backend_class_name) ⇒ Object
- #pool_variable(vname, *value) ⇒ Object
-
#stdout_write(str) ⇒ Object
debug print.
Constructor Details
#initialize(master_host = CONF.MASTER_HOST, master_port = CONF.MASTER_PORT, opts = {}) ⇒ Fairy
Returns a new instance of Fairy.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fairy.rb', line 59 def initialize(master_host = CONF.MASTER_HOST, master_port = CONF.MASTER_PORT, opts = {}) if master_host.kind_of?(Hash) opts = master_host master_host = CONF.MASTER_HOST master_port = CONF.MASTER_PORT end ::Fairy::REPLACE_CONF(Conf.new(CONF, opts)) Thread.abort_on_exception = CONF.DEBUG_THREAD_ABORT_ON_EXCEPTION @name2backend_class = {} @deep_connect = DeepConnect.start(0) @master_deepspace = @deep_connect.open_deepspace(master_host, master_port) @master = @master_deepspace.import("Master") @controller = @master.assgin_controller @controller.connect(self, CONF) @logger = @master.logger Log.type = "[c]" Log.pid = @controller.id Log.logger = @logger Log.set_local_output_dev Log::info self, "fairy connected!!" Log::info self, "\tfairy version: #{Version}" Log::info(self, "\t[Powered By #{RUBY_DESCRIPTION}]") @stdout_mutex = Mutex.new if CONF.DEBUG_MONITOR_ON Log::info self, "MONITOR NODE: ON" require "fairy/share/debug" Debug::njob_status_monitor_on(self) end end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
115 116 117 |
# File 'lib/fairy.rb', line 115 def controller @controller end |
Class Method Details
.create_subfairy(fairy) ⇒ Object
53 54 55 56 57 |
# File 'lib/fairy.rb', line 53 def self.create_subfairy(fairy) subfairy = Fairy.allocate subfairy.initialize_subfairy(fairy) subfairy end |
.def_fairy_interface(mod) ⇒ Object
external module loading
164 165 166 |
# File 'lib/fairy.rb', line 164 def self.def_fairy_interface(mod) include mod end |
.def_filter_interface(mod) ⇒ Object
15 16 17 |
# File 'lib/fairy/client/filter.rb', line 15 def Fairy.def_filter_interface(mod) ::Fairy.def_filter_interface(mod) end |
Instance Method Details
#abort ⇒ Object
117 118 119 |
# File 'lib/fairy.rb', line 117 def abort @master.terminate_controller(@controller) end |
#def_pool_variable(vname, value = nil) ⇒ Object
pool variables
133 134 135 |
# File 'lib/fairy.rb', line 133 def def_pool_variable(vname, value = nil) @controller.def_pool_variable(vname, value) end |
#handle_exception(exp) ⇒ Object
exception handling
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/fairy.rb', line 142 def handle_exception(exp) local_exp = nil Log::debug(self, "exception raised: #{exp.class}") Log::debug_exception(self, exp) begin local_exp = exp.dc_deep_copy rescue Exception Thread.main.raise exp raise exp end Thread.main.raise local_exp nil end |
#initialize_subfairy(fairy) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/fairy.rb', line 100 def initialize_subfairy(fairy) @name2backend_class = {} @deep_connect = fairy.instance_eval{@deep_connect} @master_deepspace = fairy.instance_eval{@master_deepspace} @master = fairy.instance_eval{@master} @controller = @master.assgin_controller @controller.connect(self, CONF) # Logは親と共有される # なので, IDは親と同じになる(process idなので当たり前) @stdout_mutex = fairy.instance_eval{@stdout_mutex} end |
#name2backend_class(backend_class_name) ⇒ Object
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/fairy.rb', line 121 def name2backend_class(backend_class_name) if klass = @name2backend_class[backend_class_name] return klass end if klass = @controller.import(backend_class_name) @name2backend_class[backend_class_name] = klass end klass end |
#pool_variable(vname, *value) ⇒ Object
137 138 139 |
# File 'lib/fairy.rb', line 137 def pool_variable(vname, *value) @controller.pool_variable(vname, *value) end |
#stdout_write(str) ⇒ Object
debug print
157 158 159 160 161 |
# File 'lib/fairy.rb', line 157 def stdout_write(str) @stdout_mutex.synchronize do $stdout.write(str) end end |