fairy 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +674 -0
- data/Makefile +116 -0
- data/README +15 -0
- data/bin/fairy +582 -0
- data/bin/fairy-cat +74 -0
- data/bin/fairy-cp +128 -0
- data/bin/fairy-rm +122 -0
- data/bin/subcmd/controller +41 -0
- data/bin/subcmd/inspector +81 -0
- data/bin/subcmd/master +43 -0
- data/bin/subcmd/node +47 -0
- data/bin/subcmd/processor +54 -0
- data/doc/programming-interface.html +240 -0
- data/doc/programming-interface.rd +300 -0
- data/etc/fairy.conf.tmpl +118 -0
- data/ext/simple_hash/extconf.rb +4 -0
- data/ext/simple_hash/simple_hash.c +42 -0
- data/fairy.gemspec +60 -0
- data/lib/fairy/client/addins.rb +20 -0
- data/lib/fairy/client/barrier.rb +29 -0
- data/lib/fairy/client/basic-group-by.rb +52 -0
- data/lib/fairy/client/cat.rb +41 -0
- data/lib/fairy/client/direct-product.rb +51 -0
- data/lib/fairy/client/equijoin.rb +79 -0
- data/lib/fairy/client/exec.rb +54 -0
- data/lib/fairy/client/filter.rb +62 -0
- data/lib/fairy/client/find.rb +35 -0
- data/lib/fairy/client/group-by.rb +194 -0
- data/lib/fairy/client/here.rb +84 -0
- data/lib/fairy/client/inject.rb +70 -0
- data/lib/fairy/client/input-file.rb +53 -0
- data/lib/fairy/client/input-iota.rb +49 -0
- data/lib/fairy/client/input-local-file.rb +188 -0
- data/lib/fairy/client/input-varray.rb +30 -0
- data/lib/fairy/client/input.rb +42 -0
- data/lib/fairy/client/io-filter.rb +26 -0
- data/lib/fairy/client/junction.rb +31 -0
- data/lib/fairy/client/map.rb +34 -0
- data/lib/fairy/client/merge-group-by.rb +71 -0
- data/lib/fairy/client/output-file.rb +64 -0
- data/lib/fairy/client/output-local-file.rb +60 -0
- data/lib/fairy/client/output-null.rb +47 -0
- data/lib/fairy/client/output-varray.rb +50 -0
- data/lib/fairy/client/output.rb +29 -0
- data/lib/fairy/client/roma-put.rb +62 -0
- data/lib/fairy/client/roma.rb +156 -0
- data/lib/fairy/client/seg-join.rb +61 -0
- data/lib/fairy/client/seg-map.rb +78 -0
- data/lib/fairy/client/seg-shuffle.rb +35 -0
- data/lib/fairy/client/seg-split.rb +27 -0
- data/lib/fairy/client/seg-zip.rb +60 -0
- data/lib/fairy/client/select.rb +38 -0
- data/lib/fairy/client/sort.rb +48 -0
- data/lib/fairy/client/sort18.rb +56 -0
- data/lib/fairy/client/sort19.rb +61 -0
- data/lib/fairy/client/there.rb +47 -0
- data/lib/fairy/client/top_n_into_roma.rb +34 -0
- data/lib/fairy/client/wc.rb +92 -0
- data/lib/fairy/controller.rb +1103 -0
- data/lib/fairy/logger.rb +107 -0
- data/lib/fairy/master/addins.rb +20 -0
- data/lib/fairy/master/atom.rb +17 -0
- data/lib/fairy/master/c-barrier.rb +283 -0
- data/lib/fairy/master/c-basic-group-by.rb +250 -0
- data/lib/fairy/master/c-cat.rb +159 -0
- data/lib/fairy/master/c-direct-product.rb +203 -0
- data/lib/fairy/master/c-exec.rb +68 -0
- data/lib/fairy/master/c-filter.rb +422 -0
- data/lib/fairy/master/c-find.rb +138 -0
- data/lib/fairy/master/c-group-by.rb +64 -0
- data/lib/fairy/master/c-here.rb +80 -0
- data/lib/fairy/master/c-inject.rb +119 -0
- data/lib/fairy/master/c-input-file.rb +46 -0
- data/lib/fairy/master/c-input-iota.rb +66 -0
- data/lib/fairy/master/c-input-local-file.rb +117 -0
- data/lib/fairy/master/c-input-varray.rb +53 -0
- data/lib/fairy/master/c-input.rb +24 -0
- data/lib/fairy/master/c-inputtable.rb +31 -0
- data/lib/fairy/master/c-inputtable18.rb +36 -0
- data/lib/fairy/master/c-inputtable19.rb +35 -0
- data/lib/fairy/master/c-io-filter.rb +28 -0
- data/lib/fairy/master/c-junction.rb +54 -0
- data/lib/fairy/master/c-map.rb +27 -0
- data/lib/fairy/master/c-merge-group-by.rb +241 -0
- data/lib/fairy/master/c-output-file.rb +84 -0
- data/lib/fairy/master/c-output-local-file.rb +19 -0
- data/lib/fairy/master/c-output-null.rb +45 -0
- data/lib/fairy/master/c-output-varray.rb +57 -0
- data/lib/fairy/master/c-output.rb +20 -0
- data/lib/fairy/master/c-seg-join.rb +141 -0
- data/lib/fairy/master/c-seg-map.rb +26 -0
- data/lib/fairy/master/c-seg-shuffle.rb +87 -0
- data/lib/fairy/master/c-seg-split.rb +110 -0
- data/lib/fairy/master/c-seg-zip.rb +132 -0
- data/lib/fairy/master/c-select.rb +27 -0
- data/lib/fairy/master/c-sort.rb +108 -0
- data/lib/fairy/master/c-there.rb +57 -0
- data/lib/fairy/master/c-wc.rb +232 -0
- data/lib/fairy/master/job-interpriter.rb +19 -0
- data/lib/fairy/master/scheduler.rb +24 -0
- data/lib/fairy/master.rb +329 -0
- data/lib/fairy/node/addins.rb +19 -0
- data/lib/fairy/node/p-barrier.rb +95 -0
- data/lib/fairy/node/p-basic-group-by.rb +252 -0
- data/lib/fairy/node/p-direct-product.rb +153 -0
- data/lib/fairy/node/p-exec.rb +30 -0
- data/lib/fairy/node/p-filter.rb +363 -0
- data/lib/fairy/node/p-find.rb +111 -0
- data/lib/fairy/node/p-group-by.rb +1534 -0
- data/lib/fairy/node/p-here.rb +21 -0
- data/lib/fairy/node/p-identity.rb +24 -0
- data/lib/fairy/node/p-inject.rb +127 -0
- data/lib/fairy/node/p-input-file.rb +108 -0
- data/lib/fairy/node/p-input-iota.rb +39 -0
- data/lib/fairy/node/p-input-local-file.rb +61 -0
- data/lib/fairy/node/p-input-varray.rb +26 -0
- data/lib/fairy/node/p-io-filter.rb +28 -0
- data/lib/fairy/node/p-map.rb +40 -0
- data/lib/fairy/node/p-merger-group-by.rb +48 -0
- data/lib/fairy/node/p-output-file.rb +104 -0
- data/lib/fairy/node/p-output-local-file.rb +14 -0
- data/lib/fairy/node/p-output-null.rb +32 -0
- data/lib/fairy/node/p-output-varray.rb +41 -0
- data/lib/fairy/node/p-seg-join.rb +82 -0
- data/lib/fairy/node/p-seg-map.rb +34 -0
- data/lib/fairy/node/p-seg-split.rb +61 -0
- data/lib/fairy/node/p-seg-zip.rb +79 -0
- data/lib/fairy/node/p-select.rb +40 -0
- data/lib/fairy/node/p-single-exportable.rb +90 -0
- data/lib/fairy/node/p-sort.rb +195 -0
- data/lib/fairy/node/p-task.rb +113 -0
- data/lib/fairy/node/p-there.rb +44 -0
- data/lib/fairy/node/p-wc.rb +266 -0
- data/lib/fairy/node.rb +187 -0
- data/lib/fairy/processor.rb +510 -0
- data/lib/fairy/share/base-app.rb +114 -0
- data/lib/fairy/share/block-source.rb +234 -0
- data/lib/fairy/share/conf.rb +396 -0
- data/lib/fairy/share/debug.rb +21 -0
- data/lib/fairy/share/encoding.rb +17 -0
- data/lib/fairy/share/fast-tempfile.rb +93 -0
- data/lib/fairy/share/file-place.rb +176 -0
- data/lib/fairy/share/hash-1.rb +20 -0
- data/lib/fairy/share/hash-md5.rb +28 -0
- data/lib/fairy/share/hash-murmur.rb +69 -0
- data/lib/fairy/share/hash-rb18.rb +20 -0
- data/lib/fairy/share/hash-simple-hash.rb +28 -0
- data/lib/fairy/share/inspector.rb +16 -0
- data/lib/fairy/share/lc/exceptions.rb +82 -0
- data/lib/fairy/share/lc/ja/exceptions.rb +81 -0
- data/lib/fairy/share/locale.rb +17 -0
- data/lib/fairy/share/log.rb +215 -0
- data/lib/fairy/share/pool-dictionary.rb +53 -0
- data/lib/fairy/share/port-marshaled-queue.rb +347 -0
- data/lib/fairy/share/port.rb +1697 -0
- data/lib/fairy/share/reference.rb +45 -0
- data/lib/fairy/share/stdout.rb +56 -0
- data/lib/fairy/share/tr.rb +16 -0
- data/lib/fairy/share/varray.rb +147 -0
- data/lib/fairy/share/vfile.rb +183 -0
- data/lib/fairy/version.rb +8 -0
- data/lib/fairy.rb +206 -0
- data/sample/grep.rb +46 -0
- data/sample/ping.rb +19 -0
- data/sample/sort.rb +102 -0
- data/sample/wordcount.rb +61 -0
- data/spec/README +12 -0
- data/spec/fairy1_spec.rb +31 -0
- data/spec/fairy2_spec.rb +42 -0
- data/spec/fairy3_spec.rb +126 -0
- data/spec/fairy4_spec.rb +63 -0
- data/spec/fairy5_spec.rb +45 -0
- data/spec/fairy6_spec.rb +52 -0
- data/spec/fairy7_spec.rb +58 -0
- data/spec/fairy8_spec.rb +48 -0
- data/spec/mkdat.rb +148 -0
- data/spec/run_all.sh +65 -0
- data/test/testc.rb +7111 -0
- data/tools/cap_recipe/Capfile +144 -0
- data/tools/cap_recipe/cluster.yml.sample +14 -0
- data/tools/fairy_perf_graph.rb +444 -0
- data/tools/git-tag +44 -0
- data/tools/log-analysis.rb +62 -0
- data/tools/svn-ls-diff +38 -0
- data/tools/svn-tags +37 -0
- metadata +298 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
require "fairy/node/p-single-exportable"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
class PSelect<PSingleExportFilter
|
11
|
+
Processor.def_export self
|
12
|
+
|
13
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
14
|
+
super
|
15
|
+
@block_source = block_source
|
16
|
+
end
|
17
|
+
|
18
|
+
# def start
|
19
|
+
# super do
|
20
|
+
# @map_proc = BBlock.new(@block_source, @context, self)
|
21
|
+
# @import.each do |e|
|
22
|
+
# if @map_proc.yield(e)
|
23
|
+
# @export.push e
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
29
|
+
def basic_each(&block)
|
30
|
+
@map_proc = BBlock.new(@block_source, @context, self)
|
31
|
+
@input.each do |e|
|
32
|
+
# if !(v = @map_proc.yield(e)) || v.kind_of?(Import::CTLTOKEN_NULLVALUE)
|
33
|
+
if !(v = @map_proc.yield(e)) || Import::CTLTOKEN_NULLVALUE === v
|
34
|
+
next
|
35
|
+
end
|
36
|
+
block.call e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
|
8
|
+
module Fairy
|
9
|
+
module PSingleExportable
|
10
|
+
include Enumerable
|
11
|
+
|
12
|
+
END_OF_STREAM = PFilter::END_OF_STREAM
|
13
|
+
|
14
|
+
ST_WAIT_EXPORT_FINISH = :ST_WAIT_EXPORT_FINISH
|
15
|
+
ST_EXPORT_FINISH = :ST_EXPORT_FINISH
|
16
|
+
|
17
|
+
def initialize(id, ntask, bjob, opts=nil, *rests)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :export
|
22
|
+
|
23
|
+
# def no=(no)
|
24
|
+
# super
|
25
|
+
# @export.no = no
|
26
|
+
# end
|
27
|
+
|
28
|
+
# とりあえず
|
29
|
+
# def start(&block)
|
30
|
+
# super do
|
31
|
+
# begin
|
32
|
+
# if @import
|
33
|
+
# @export.add_key(@import.key)
|
34
|
+
# end
|
35
|
+
# block.call
|
36
|
+
# ensure
|
37
|
+
# @export.push END_OF_STREAM
|
38
|
+
# wait_export_finish
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
|
43
|
+
def start_export
|
44
|
+
Log::debug(self, "START_EXPORT")
|
45
|
+
|
46
|
+
policy = @opts[:postqueuing_policy]
|
47
|
+
@export = Export.new(policy)
|
48
|
+
@export.njob_id = @id
|
49
|
+
@export.no = @no
|
50
|
+
@export.key = @key
|
51
|
+
|
52
|
+
start do
|
53
|
+
each{|e| @export.push e}
|
54
|
+
@export.push END_OF_STREAM
|
55
|
+
end
|
56
|
+
|
57
|
+
@export
|
58
|
+
end
|
59
|
+
|
60
|
+
def start(&block)
|
61
|
+
super do
|
62
|
+
begin
|
63
|
+
block.call
|
64
|
+
ensure
|
65
|
+
# @export.push END_OF_STREAM
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def terminate
|
71
|
+
@wait_cv = @terminate_mon.new_cv
|
72
|
+
wait_export_finish
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
def wait_export_finish
|
77
|
+
self.status = ST_WAIT_EXPORT_FINISH
|
78
|
+
@export.fib_wait_finish(@wait_cv)
|
79
|
+
self.status = ST_EXPORT_FINISH
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class PSingleExportFilter<PIOFilter
|
84
|
+
include PSingleExportable
|
85
|
+
end
|
86
|
+
|
87
|
+
class PSingleExportInput<PIOFilter
|
88
|
+
include PSingleExportable
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-io-filter"
|
7
|
+
require "fairy/node/p-basic-group-by"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
module PSort
|
11
|
+
class PPreSort<PBasicGroupBy
|
12
|
+
Processor.def_export self
|
13
|
+
|
14
|
+
ST_ALL_IMPORTED = :ST_ALL_IMPORTED
|
15
|
+
ST_WAIT_EXPORT_FINISH = :ST_WAIT_EXPORT_FINISH
|
16
|
+
ST_EXPORT_FINISH = :ST_EXPORT_FINISH
|
17
|
+
|
18
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
19
|
+
super
|
20
|
+
@block_source = block_source
|
21
|
+
|
22
|
+
@exports = []
|
23
|
+
def @exports.each_pair(&block)
|
24
|
+
each_with_index do |item, idx|
|
25
|
+
block.call(idx, item) if item
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@exports_queue = Queue.new
|
29
|
+
|
30
|
+
@counter = []
|
31
|
+
|
32
|
+
@pvs = nil
|
33
|
+
if @opts[:pvs]
|
34
|
+
@pvs = @opts[:pvs].dc_deep_copy
|
35
|
+
end
|
36
|
+
|
37
|
+
#start_watch_exports
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_export(key, export)
|
41
|
+
@exports[key] = export
|
42
|
+
# @exports_queue.push [key, export]
|
43
|
+
# [BUG#171]同期処理でないとまずい.
|
44
|
+
@bjob.add_exports(key, export, self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def start_export
|
48
|
+
Log::debug(self, "START_EXPORT")
|
49
|
+
|
50
|
+
start do
|
51
|
+
sample_line_no = @opts[:sampling_max]
|
52
|
+
sample_line_no ||= CONF.SORT_SAMPLING_MAX
|
53
|
+
|
54
|
+
hash_opt = @opts[:cmp_optimize]
|
55
|
+
hash_opt = CONF.SORT_CMP_OPTIMIZE if hash_opt.nil?
|
56
|
+
|
57
|
+
if hash_opt
|
58
|
+
@key_proc = eval("proc{#{@block_source.source}}", @context.binding)
|
59
|
+
else
|
60
|
+
@key_proc = BBlock.new(@block_source, @context, self)
|
61
|
+
end
|
62
|
+
|
63
|
+
buf = []
|
64
|
+
no = 0
|
65
|
+
begin
|
66
|
+
if @pvs
|
67
|
+
sampling = false
|
68
|
+
Log::debugf(self, "%s", @pvs.inspect)
|
69
|
+
init_exports
|
70
|
+
elsif self.no == 0
|
71
|
+
sampling = true
|
72
|
+
else
|
73
|
+
sampling = false
|
74
|
+
@pvs = @bjob.get_pvs
|
75
|
+
Log::debugf(self, "%s", @pvs.inspect)
|
76
|
+
init_exports
|
77
|
+
end
|
78
|
+
|
79
|
+
@input.each do |e|
|
80
|
+
if sampling
|
81
|
+
no += 1
|
82
|
+
buf.push e
|
83
|
+
if no >= sample_line_no
|
84
|
+
sampling = false
|
85
|
+
@pvs = @bjob.get_pvs(buf)
|
86
|
+
Log::debugf(self, "%s", @pvs.inspect)
|
87
|
+
init_exports
|
88
|
+
buf.each{|e| hashing(e)}
|
89
|
+
end
|
90
|
+
else
|
91
|
+
hashing(e)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
if sampling
|
95
|
+
@pvs = @bjob.get_pvs(buf)
|
96
|
+
Log::debugf(self, "%s", @pvs.inspect)
|
97
|
+
init_exports
|
98
|
+
buf.each{|e| hashing(e)}
|
99
|
+
end
|
100
|
+
rescue
|
101
|
+
Log::debug_exception(self)
|
102
|
+
raise
|
103
|
+
ensure
|
104
|
+
@exports_queue.push nil
|
105
|
+
@exports.each_pair do |key, export|
|
106
|
+
next unless export
|
107
|
+
Log::debug(self, "G0 #{key} => #{@counter[key]}")
|
108
|
+
export.push END_OF_STREAM
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def init_exports
|
115
|
+
policy = @opts[:postqueuing_policy]
|
116
|
+
(@pvs.size+1).times do |idx|
|
117
|
+
export = Export.new(policy)
|
118
|
+
@exports[idx] = export
|
119
|
+
|
120
|
+
export.njob_id = @id
|
121
|
+
export.no = idx
|
122
|
+
export.add_key(idx)
|
123
|
+
add_export(idx, export)
|
124
|
+
@counter[idx] = 0
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def hashing(e)
|
129
|
+
if Import::CTLTOKEN_NULLVALUE === (key = @key_proc.call(e))
|
130
|
+
return
|
131
|
+
end
|
132
|
+
|
133
|
+
unless idx = @pvs.find_index{|pv| key < @key_proc.call(pv)}
|
134
|
+
idx = @pvs.size
|
135
|
+
end
|
136
|
+
|
137
|
+
#Log::debug(self, "#{@pvs.inspect}")
|
138
|
+
#Log::debug(self, "#{idx}")
|
139
|
+
|
140
|
+
|
141
|
+
export = @exports[idx]
|
142
|
+
export.push e
|
143
|
+
@counter[idx] += 1
|
144
|
+
end
|
145
|
+
|
146
|
+
def hash_key(e)
|
147
|
+
@key_proc.yield(e)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class PPostSort<PSingleExportFilter
|
152
|
+
Processor.def_export self
|
153
|
+
|
154
|
+
def initialize(id, ntask, bjob, opts, block_source)
|
155
|
+
super
|
156
|
+
@block_source = block_source
|
157
|
+
|
158
|
+
@buffering_policy = @opts[:buffering_policy]
|
159
|
+
@buffering_policy ||= CONF.SORT_BUFFERING_POLICY
|
160
|
+
|
161
|
+
unless CONF.BUG234
|
162
|
+
@cmp_optimize = CONF.SORT_CMP_OPTIMIZE
|
163
|
+
@cmp_optimize = opts[:cmp_optimize] if opts.key?(:cmp_optimize)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def basic_each(&block)
|
168
|
+
@key_value_buffer =
|
169
|
+
eval("#{@buffering_policy[:buffering_class]}").new(self, @buffering_policy)
|
170
|
+
if @cmp_optimize
|
171
|
+
@hash_proc = eval("proc{#{@block_source.source}}")
|
172
|
+
else
|
173
|
+
@hash_proc = BBlock.new(@block_source, @context, self)
|
174
|
+
end
|
175
|
+
|
176
|
+
@input.each do |e|
|
177
|
+
@key_value_buffer.push(e)
|
178
|
+
e = nil
|
179
|
+
end
|
180
|
+
@key_value_buffer.each do |values|
|
181
|
+
values.each(&block)
|
182
|
+
end
|
183
|
+
@key_value_buffer = nil
|
184
|
+
end
|
185
|
+
|
186
|
+
def hash_key(e)
|
187
|
+
@hash_proc.yield(e)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Fairy
|
7
|
+
class PTask
|
8
|
+
Processor.def_export self
|
9
|
+
|
10
|
+
END_OF_STREAM = :END_OF_STREAM
|
11
|
+
|
12
|
+
ST_INIT = :ST_INIT
|
13
|
+
ST_ACTIVATE = :ST_ACTIVATE
|
14
|
+
ST_FINISH = :ST_FINISH
|
15
|
+
|
16
|
+
def initialize(id, processor)
|
17
|
+
@id = id
|
18
|
+
Log::info self, "CREATE PTask"
|
19
|
+
|
20
|
+
@processor = processor
|
21
|
+
|
22
|
+
@njobs = []
|
23
|
+
@njob_seq = -1
|
24
|
+
@njob_seq_mutex = Mutex.new
|
25
|
+
|
26
|
+
@status = ST_INIT
|
27
|
+
@status_mon = processor.njob_mon
|
28
|
+
@status_cv = @status_mon.new_cv
|
29
|
+
|
30
|
+
start_watch_status
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_reader :processor
|
34
|
+
|
35
|
+
def log_id
|
36
|
+
"PTask[#{@id}]"
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# njob methods
|
41
|
+
#
|
42
|
+
def njob_next_id
|
43
|
+
@njob_seq_mutex.synchronize do
|
44
|
+
@njob_seq += 1
|
45
|
+
|
46
|
+
format("%02d-%02d", @id, @njob_seq)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_njob(njob_class_name, bjob, opts, *rests)
|
51
|
+
klass = @processor.import(njob_class_name)
|
52
|
+
#Log::debugf(self, "KKKKKKKKKKLAS: %s", klass)
|
53
|
+
njob = klass.new(njob_next_id, self, bjob, opts, *rests)
|
54
|
+
@njobs.push njob
|
55
|
+
Log.debugf(self, "Njob number of %d", @njobs.size)
|
56
|
+
njob
|
57
|
+
end
|
58
|
+
DeepConnect.def_method_spec(self, "REF create_njob(VAL, REF, VAL, *DEFAULT)")
|
59
|
+
|
60
|
+
def abort_running
|
61
|
+
@status_mon.synchronize do
|
62
|
+
@njobs.last.abort_running unless [ST_INIT, ST_FINISH].include?(@status)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# status methods.
|
68
|
+
#
|
69
|
+
def status=(val)
|
70
|
+
@status_mon.synchronize do
|
71
|
+
@status = val
|
72
|
+
@status_cv.broadcast
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def start_watch_status
|
77
|
+
# 初期状態通知
|
78
|
+
notice_status(@status)
|
79
|
+
|
80
|
+
@processor.njob_mon.entry do
|
81
|
+
@status_mon.synchronize do
|
82
|
+
old_status = nil
|
83
|
+
loop do
|
84
|
+
@status_cv.wait_while{old_status == @status}
|
85
|
+
old_status = @status
|
86
|
+
notice_status(@status)
|
87
|
+
break if @status == ST_FINISH
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_status(node, st)
|
95
|
+
self.status = st
|
96
|
+
end
|
97
|
+
|
98
|
+
def notice_status(st)
|
99
|
+
# @status_mon.entry do
|
100
|
+
@processor.update_status(self, st)
|
101
|
+
# end
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
"#<#{self.class}:##{@id} #{@njobs.collect{|f| f.class.to_s}.join('-').gsub(/Fairy::/, "")}>"
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "fairy/node/p-filter"
|
7
|
+
require "fairy/node/p-single-exportable"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
class PThere<PFilter
|
11
|
+
Processor.def_export self
|
12
|
+
|
13
|
+
include PSingleExportable
|
14
|
+
|
15
|
+
def initialize(id, ntask, bjob, opts)
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def open(nthere_place)
|
20
|
+
self.no = nthere_place.no
|
21
|
+
@enumerable = nthere_place.enumerable
|
22
|
+
end
|
23
|
+
|
24
|
+
def basic_each(&block)
|
25
|
+
@enumerable.each do |e|
|
26
|
+
if e.__deep_connect_reference? && !PORT_KEEP_IDENTITY_CLASS_SET[e.class]
|
27
|
+
e = e.deep_connect_deep_copy
|
28
|
+
end
|
29
|
+
block.call e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# def start
|
34
|
+
# super do
|
35
|
+
# @enumerable.each do |e|
|
36
|
+
# if e.__deep_connect_reference? && !PORT_KEEP_IDENTITY_CLASS_SET[e.class]
|
37
|
+
# e = e.deep_connect_deep_copy
|
38
|
+
# end
|
39
|
+
# @export.push e
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
end
|