Class: Fairy::PBasicMGroupBy

Inherits:
PIOFilter show all
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

Methods inherited from PIOFilter

#input=

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.



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/fairy/node/p-basic-group-by.rb', line 116

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 = Queue.new

#      start_watch_exports
end

Instance Method Details

#add_export(key, export) ⇒ Object



129
130
131
132
133
134
# File 'lib/fairy/node/p-basic-group-by.rb', line 129

def add_export(key, export)
  @exports[key] = export
#      @exports_queue.push [key, export]
  # [BUG#171]同期処理でないとまずい.
  @bjob.add_exports(key, export, self)
end

#start_exportObject



136
137
138
139
140
141
142
143
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
# File 'lib/fairy/node/p-basic-group-by.rb', line 136

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

#terminateObject



182
183
184
185
186
# File 'lib/fairy/node/p-basic-group-by.rb', line 182

def terminate
  @wait_cv = @terminate_mon.new_cv
  wait_export_finish
  super
end

#wait_export_finishObject

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


211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/fairy/node/p-basic-group-by.rb', line 211

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}")
	export.fib_wait_finish(@wait_cv)
  end
Log::debug(self, "G5")
  self.status = ST_EXPORT_FINISH
end