Class: Fairy::Fairy

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master_host = CONF.MASTER_HOST, master_port = CONF.MASTER_PORT, opts = {}) ⇒ Fairy

Returns a new instance of Fairy.



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
99
100
101
102
103
104
105
106
107
108
# File 'lib/fairy.rb', line 61

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}]") 


  begin
  require "fairy.so"
  Log::warn self, "\t Load fairy.so"
  rescue LoadError
  Log::warn self, "Can't load fairy.so. Can't use this feature"
  end

  @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

#controllerObject (readonly)

Returns the value of attribute controller.



125
126
127
# File 'lib/fairy.rb', line 125

def controller
  @controller
end

Class Method Details

.create_subfairy(fairy) ⇒ Object



55
56
57
58
59
# File 'lib/fairy.rb', line 55

def self.create_subfairy(fairy)
  subfairy = Fairy.allocate
  subfairy.initialize_subfairy(fairy)
  subfairy
end

.def_fairy_interface(mod) ⇒ Object

external module loading



174
175
176
# File 'lib/fairy.rb', line 174

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

#abortObject



127
128
129
# File 'lib/fairy.rb', line 127

def abort
  @master.terminate_controller(@controller)
end

#def_pool_variable(vname, value = nil) ⇒ Object

pool variables



143
144
145
# File 'lib/fairy.rb', line 143

def def_pool_variable(vname, value = nil)
  @controller.def_pool_variable(vname, value)
end

#handle_exception(exp) ⇒ Object

exception handling



152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/fairy.rb', line 152

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fairy.rb', line 110

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



131
132
133
134
135
136
137
138
139
140
# File 'lib/fairy.rb', line 131

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



147
148
149
# File 'lib/fairy.rb', line 147

def pool_variable(vname, *value)
  @controller.pool_variable(vname, *value)
end

#stdout_write(str) ⇒ Object

debug print



167
168
169
170
171
# File 'lib/fairy.rb', line 167

def stdout_write(str)
  @stdout_mutex.synchronize do
  $stdout.write(str)
  end
end