Class: Fairy::PBasicMGroupBy
- Defined in:
- lib/fairy/node/p-basic-group-by.rb
Constant Summary collapse
- ST_ALL_IMPORTED =
:ST_ALL_IMPORTED
- ST_WAIT_EXPORT_FINISH =
:ST_WAIT_EXPORT_FINISH
- ST_EXPORT_FINISH =
:ST_EXPORT_FINISH
Constants inherited from PIOFilter
Fairy::PIOFilter::ST_WAIT_IMPORT
Constants inherited from PFilter
Fairy::PFilter::END_OF_STREAM, Fairy::PFilter::ST_ACTIVATE, Fairy::PFilter::ST_FINISH, Fairy::PFilter::ST_INIT
Instance Attribute Summary
Attributes inherited from PFilter
#IGNORE_EXCEPTION, #id, #log_id, #ntask
Instance Method Summary collapse
- #add_export(key, export) ⇒ Object
-
#initialize(id, ntask, bjob, opts, block_source) ⇒ PBasicMGroupBy
constructor
A new instance of PBasicMGroupBy.
- #start_export ⇒ Object
- #terminate ⇒ Object
-
#wait_export_finish ⇒ Object
for key in keys export = @exports unless export export = Export.new(policy) export.add_key(key) add_export(key, export) end export.push e end end @exports.each{|key, export| export.push END_OF_STREAM} wait_export_finish end end.
Methods inherited from PIOFilter
Methods inherited from PFilter
#abort_running, #basic_start, #break_running, #each, #global_break, #global_break_from_other, #handle_exception, #key, #key=, #next, #no, #no=, #notice_status, #processor, #start, #start_watch_status, #status=, #terminate_proc
Constructor Details
#initialize(id, ntask, bjob, opts, block_source) ⇒ PBasicMGroupBy
Returns a new instance of PBasicMGroupBy.
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fairy/node/p-basic-group-by.rb', line 124 def initialize(id, ntask, bjob, opts, block_source) super @block_source = block_source # @key_proc = eval("proc{#{@block_source}}", TOPLEVEL_BINDING) # @key_proc = @context.create_proc(@block_source) @key_proc = BBlock.new(@block_source, @context, self) @exports = {} @exports_queue = XThread::Queue.new # start_watch_exports end |
Instance Method Details
#add_export(key, export) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/fairy/node/p-basic-group-by.rb', line 137 def add_export(key, export) @exports[key] = export # @exports_queue.push [key, export] # [BUG#171]同期処理でないとまずい. @bjob.add_exports(key, export, self) end |
#start_export ⇒ Object
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 |
# File 'lib/fairy/node/p-basic-group-by.rb', line 144 def start_export Log::debug(self, "START_EXPORT") start do hash_opt = @opts[:grouping_optimize] hash_opt = CONF.GROUP_BY_GROUPING_OPTIMIZE if hash_opt.nil? if hash_opt @key_proc = eval("proc{#{@block_source.source}}", @context.binding) else @key_proc = BBlock.new(@block_source, @context, self) end policy = @opts[:postqueuing_policy] begin @input.each do |e| keys = @key_proc.yield(e) keys = [keys] unless keys.kind_of?(Array) for key in keys if Import::CTLTOKEN_NULLVALUE === key next end export = @exports[key] unless export export = Export.new(policy) export.njob_id = @id export.add_key(key) add_export(key, export) end export.push e end end rescue Log::debug_exception(self) raise ensure @exports_queue.push nil @exports.each_pair do |key, export| next unless export export.push END_OF_STREAM end end end end |
#terminate ⇒ Object
190 191 192 193 194 |
# File 'lib/fairy/node/p-basic-group-by.rb', line 190 def terminate @wait_cv = @terminate_mon.new_cv wait_export_finish super end |
#wait_export_finish ⇒ Object
for key in keys export = @exports unless export export = Export.new(policy) export.add_key(key) add_export(key, export) end export.push e end end @exports.each{|key, export| export.push END_OF_STREAM} wait_export_finish
end
end
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/fairy/node/p-basic-group-by.rb', line 219 def wait_export_finish Log::debug(self, "G1") self.status = ST_ALL_IMPORTED Log::debug(self, "G2") # すべての, exportのoutputが設定されるまで待っている # かなりイマイチ # for key, export in @exports # export.output # end # ここの位置が重要 self.status = ST_WAIT_EXPORT_FINISH # ここもいまいち Log::debug(self, "G3") @exports.each_pair do |key, export| next unless export Log::debug(self, "G4.WAIT #{key}") @terminate_mon.synchronize do export.fib_wait_finish(@wait_cv) end end Log::debug(self, "G5") self.status = ST_EXPORT_FINISH end |