rbeai 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rbeai/GetLogic.rb +144 -0
- data/lib/rbeai/Main.rb +70 -0
- data/lib/rbeai/PipeTask.rb +216 -0
- data/lib/rbeai/PutLogic.rb +123 -0
- data/lib/rbeai/RouterLogic.rb +155 -0
- data/lib/rbeai/RouterPipeTask.rb +62 -0
- data/lib/rbeai/TasksLogic.rb +285 -0
- data/lib/rbeai/TransfLogic.rb +145 -0
- data/lib/rbeai/WorkerPool.rb +72 -0
- data/lib/rbeai/Workflow.rb +79 -0
- data/lib/rbeai/templates/csv2xml_nh.awk +14 -0
- data/lib/rbeai/templates/csv2xml_wh.awk +16 -0
- data/lib/rbeai.rb +13 -0
- data/rbeai-0.0.1.gem +0 -0
- data/rbeai.gemspec +20 -0
- data/test/config/conf.rb +2 -0
- data/test/test1.rb +4 -0
- data/test/test_files/empty_file.txt +0 -0
- data/test/test_files/empty_file.unused +0 -0
- data/test/test_files/test_router_1.txt +1 -0
- data/test/test_files/test_router_1.xml_91 +5 -0
- data/test/test_files/test_router_1.xml_92 +6 -0
- data/test/test_files/test_router_1.xml_fail +5 -0
- data/test/test_files/test_transf_1.xml +28 -0
- data/test/test_files/test_transf_2.txt +5 -0
- data/test/test_files/test_transf_3.xml +28 -0
- data/test/test_get_send_email.rb +11 -0
- data/test/test_get_send_file.rb +11 -0
- data/test/test_get_send_ftp.rb +11 -0
- data/test/test_router.rb +11 -0
- data/test/test_transf_1.rb +11 -0
- data/test/test_transf_2.awk +1 -0
- data/test/test_transf_2.rb +11 -0
- data/test/test_transf_3.rb +11 -0
- data/test/test_transf_3.xsl +10 -0
- data/test/tmp/test_get_send_file/1130328204.12500/getfile/empty_file.txt +0 -0
- data/test/tmp/test_get_send_ftp/1130328178.76500/getfile/empty_file.txt +0 -0
- data/test/workflows/test_get_send_email.wf +28 -0
- data/test/workflows/test_get_send_file.wf +21 -0
- data/test/workflows/test_get_send_ftp.wf +28 -0
- data/test/workflows/test_router_1.wf +35 -0
- data/test/workflows/test_start_end.wf +8 -0
- data/test/workflows/test_transf_1.wf +26 -0
- data/test/workflows/test_transf_2.wf +25 -0
- data/test/workflows/test_transf_3.wf +25 -0
- metadata +128 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'thread'
|
2
|
+
require 'thwait'
|
3
|
+
require 'rbeai/PipeTask'
|
4
|
+
|
5
|
+
module RbEAI
|
6
|
+
|
7
|
+
|
8
|
+
class RouterPipeTask < PipeTask
|
9
|
+
|
10
|
+
def initialize(inputQueue, task, control)
|
11
|
+
@inputQueue = inputQueue
|
12
|
+
@task = task
|
13
|
+
@control = control
|
14
|
+
@resultQueue = task.initQueues()
|
15
|
+
@bufferQueue = nil
|
16
|
+
@nextPipe = _getNextPipes()
|
17
|
+
@size = task.size
|
18
|
+
@threadPool = ThreadPool.new(@size, @task.method(:doJob), inputQueue, @resultQueue, @bufferQueue, control.controlQueue)
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(numItems = 1)
|
22
|
+
numItemsNext = @task.getItemsNext(numItems)
|
23
|
+
_RunNextPipes(numItemsNext)
|
24
|
+
@control.start(numItems, @threadPool)
|
25
|
+
@threadPool.start()
|
26
|
+
end
|
27
|
+
|
28
|
+
def waitToEnd()
|
29
|
+
_WaitToEndNextPipes()
|
30
|
+
#print "JOIN-#{@task.name}\n"
|
31
|
+
@control.waitJoin
|
32
|
+
print "END-#{@task.name}\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _getNextPipes()
|
38
|
+
controlQueue = Queue.new
|
39
|
+
nextPipeList = Hash.new(0)
|
40
|
+
@task.nextTask.each do | key, task |
|
41
|
+
inputQueue = @resultQueue[key]
|
42
|
+
control = Control.new(controlQueue, inputQueue)
|
43
|
+
nextPipeList[key] = getNextPipe(inputQueue, task, control)
|
44
|
+
end
|
45
|
+
return nextPipeList
|
46
|
+
end
|
47
|
+
|
48
|
+
def _RunNextPipes(numItemsNext)
|
49
|
+
@nextPipe.each do | key, pipe |
|
50
|
+
pipe.run(numItemsNext)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def _WaitToEndNextPipes()
|
55
|
+
@nextPipe.each do | key, pipe |
|
56
|
+
pipe.waitToEnd()
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end #module
|
@@ -0,0 +1,285 @@
|
|
1
|
+
require 'rio'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'rbeai/PipeTask'
|
4
|
+
require 'rbeai/RouterLogic'
|
5
|
+
require 'rbeai/TransfLogic'
|
6
|
+
require 'rbeai/GetLogic'
|
7
|
+
require 'rbeai/PutLogic'
|
8
|
+
|
9
|
+
module RbEAI
|
10
|
+
|
11
|
+
class Task
|
12
|
+
|
13
|
+
attr_accessor :nextTask, :status, :wflow, :size
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
public
|
17
|
+
|
18
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
19
|
+
@size = (pool_size = xmlDoc.attributes["pool"]) != nil ? pool_size.to_i : 1
|
20
|
+
@wflow = wflow
|
21
|
+
@name = xmlDoc.attributes["name"]
|
22
|
+
@status = 0
|
23
|
+
@nextTask = _getNextTask(wflow, xmlFull, xmlDoc)
|
24
|
+
print @name,"\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def doJob(resultQueue, obj)
|
28
|
+
resultQueue.enq(obj)
|
29
|
+
end
|
30
|
+
|
31
|
+
def getItemsNext(numItems)
|
32
|
+
return numItems
|
33
|
+
end
|
34
|
+
|
35
|
+
def persist(object)
|
36
|
+
bname = File.basename("#{object}")
|
37
|
+
rio("tmp/#{@wflow.instid}/#{@name}").mkdir
|
38
|
+
rio("#{object}") > rio("tmp/#{@wflow.instid}/#{@name}")
|
39
|
+
return rio("tmp/#{@wflow.instid}/#{@name}/#{bname}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def persistFtp(object)
|
43
|
+
bname = File.basename("#{object}")
|
44
|
+
rio("tmp/#{@wflow.instid}/#{@name}").mkdir
|
45
|
+
rio("#{object}") > rio("tmp/#{@wflow.instid}/#{@name}/#{bname}")
|
46
|
+
return rio("tmp/#{@wflow.instid}/#{@name}/#{bname}")
|
47
|
+
end
|
48
|
+
|
49
|
+
def persistStr(object, filename)
|
50
|
+
rio("tmp/#{@wflow.instid}/#{@name}").mkdir
|
51
|
+
ario = rio("tmp/#{@wflow.instid}/#{@name}/#{filename}")
|
52
|
+
ario.print(object).close
|
53
|
+
return ario
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
|
58
|
+
def _getNextTask(wflow, xmlFull, xmlDoc)
|
59
|
+
nextTaskName = xmlDoc.elements["next"].text
|
60
|
+
if nextTaskName != nil
|
61
|
+
xmlNextTask = XPath.first(xmlFull, "//task[@name='#{nextTaskName}']")
|
62
|
+
nextTaskType = xmlNextTask.attributes["type"]
|
63
|
+
return eval("#{nextTaskType}Task.new(#{:wflow},#{:xmlFull},#{:xmlNextTask})")
|
64
|
+
else
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# <task name="router" type="Router" pool="2">
|
73
|
+
# <next>
|
74
|
+
# <goto task="sendfile">
|
75
|
+
# <when filter="xpath:/test/status">91,92</when>
|
76
|
+
# <!--<when filter="name:test.txt"/>-->
|
77
|
+
# </goto>
|
78
|
+
# <goto task="sendftp">
|
79
|
+
# <when filter="sax:status">91,92</when>
|
80
|
+
# <!--<when filter="name:test_2.txt"/>-->
|
81
|
+
# </goto>
|
82
|
+
# <goto task="final"/>
|
83
|
+
# </next>
|
84
|
+
# </task>
|
85
|
+
|
86
|
+
class RouterTask < Task
|
87
|
+
|
88
|
+
attr_accessor :nextTask
|
89
|
+
|
90
|
+
public
|
91
|
+
|
92
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
93
|
+
@logic = RouterLogic.new(xmlDoc)
|
94
|
+
super(wflow, xmlFull, xmlDoc)
|
95
|
+
end
|
96
|
+
|
97
|
+
def doJob(resultQueueList, obj)
|
98
|
+
task = @logic.enroute(obj)
|
99
|
+
print task, "=> ", obj , "\n"
|
100
|
+
resultQueueList[task].enq(obj) if task != nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def initQueues()
|
104
|
+
resultQueueList = Hash.new(0)
|
105
|
+
@logic.destinations.each do | task, logic|
|
106
|
+
resultQueueList[task] = Queue.new
|
107
|
+
end
|
108
|
+
return resultQueueList
|
109
|
+
end
|
110
|
+
|
111
|
+
protected
|
112
|
+
|
113
|
+
def _getNextTask(wflow, xmlFull, xmlDoc)
|
114
|
+
nextTask = Hash.new(0)
|
115
|
+
@logic.destinations.each do | dest |
|
116
|
+
taskName = dest[0]
|
117
|
+
logic = dest[1]
|
118
|
+
xmlNextTask = XPath.first(xmlFull, "//task[@name='#{taskName}']")
|
119
|
+
nextTaskType = xmlNextTask.attributes["type"]
|
120
|
+
nextTask[taskName] = eval("#{nextTaskType}Task.new(#{:wflow},#{:xmlFull},#{:xmlNextTask})")
|
121
|
+
end
|
122
|
+
return nextTask
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
# <task name="transf" type="Transf" pool="3">
|
129
|
+
# <next>final</next>
|
130
|
+
# <transf ord="1" type="xsl" script="transf.xsl"/>
|
131
|
+
# <transf ord="2" type="awk" script="transf.awk"/>
|
132
|
+
# <!--<transf type="csv2xml" separator=" "/> -->
|
133
|
+
# <!--<transf type="xml2csv" separator="|"/> -->
|
134
|
+
# <!--<transf type="awk" script="transf.awk"/>-->
|
135
|
+
# </task>
|
136
|
+
|
137
|
+
class TransfTask < Task
|
138
|
+
|
139
|
+
attr_accessor :nextTask
|
140
|
+
|
141
|
+
public
|
142
|
+
|
143
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
144
|
+
@logic = TransfLogic.new(xmlDoc)
|
145
|
+
super(wflow, xmlFull, xmlDoc)
|
146
|
+
end
|
147
|
+
|
148
|
+
def doJob(resultQueue, source)
|
149
|
+
aux = persist(source) # Create room for the transformed file
|
150
|
+
dest = @logic.transform(aux)
|
151
|
+
resultQueue.enq(dest)
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
# <task name="inicio" type="Start">
|
157
|
+
# <next>final</next>
|
158
|
+
# </task>
|
159
|
+
class StartTask < Task
|
160
|
+
end
|
161
|
+
|
162
|
+
# <task name="inicio" type="Start">
|
163
|
+
# <next/>
|
164
|
+
# </task>
|
165
|
+
class EndTask < Task
|
166
|
+
|
167
|
+
def doJob(resultQueue, obj)
|
168
|
+
print "EndTask #{@name}: #{obj}\n"
|
169
|
+
super(resultQueue, obj)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
# <task name="getfile" type="Get" rate="1s" pool="2"> <!-- Valid units are: 's', 'm', 'h' -->
|
176
|
+
# <next>final</next>
|
177
|
+
# <protocol def="file"> <!-- Valid protocols are: 'file', 'pop3', 'http', 'ftp', 'queue' -->
|
178
|
+
# <location>.</location>
|
179
|
+
# <pattern>test*.txt</pattern>
|
180
|
+
# </protocol>
|
181
|
+
# </task>
|
182
|
+
class IOTask < Task
|
183
|
+
attr_accessor :location, :pattern, :rate, :files
|
184
|
+
|
185
|
+
public
|
186
|
+
|
187
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
188
|
+
super(wflow, xmlFull, xmlDoc)
|
189
|
+
@location = XPath.first(xmlDoc, "./protocol/location/text()")
|
190
|
+
@pattern = XPath.first(xmlDoc, "./protocol/pattern/text()")
|
191
|
+
@rate = _getRate(xmlDoc.attributes["rate"])
|
192
|
+
end
|
193
|
+
|
194
|
+
protected
|
195
|
+
|
196
|
+
def _getRate(rateTx)
|
197
|
+
re = Regexp.new('(\d+)(\D)')
|
198
|
+
mrate = re.match(rateTx)
|
199
|
+
value = mrate[1]
|
200
|
+
unit = mrate[2]
|
201
|
+
case unit
|
202
|
+
when "s"
|
203
|
+
return value
|
204
|
+
when "m"
|
205
|
+
return value * 60
|
206
|
+
when "h"
|
207
|
+
return value * 60 * 60
|
208
|
+
else
|
209
|
+
return nil
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
# <task name="getfile" type="Get" rate="1s" pool="2">
|
217
|
+
# <next>router</next>
|
218
|
+
# <protocol def="file">
|
219
|
+
# <location>.</location>
|
220
|
+
# <pattern>out.xml</pattern>
|
221
|
+
# </protocol>
|
222
|
+
# </task>
|
223
|
+
# <task name="getfile" type="Get" rate="1s" pool="2">
|
224
|
+
# <next>router</next>
|
225
|
+
# <protocol def="email">
|
226
|
+
# <location address="" port=""/>
|
227
|
+
# <account name="" pwd=""/>
|
228
|
+
# <pattern>out.xml</pattern>
|
229
|
+
# </protocol>
|
230
|
+
# </task>
|
231
|
+
|
232
|
+
|
233
|
+
class GetTask < IOTask
|
234
|
+
|
235
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
236
|
+
super(wflow, xmlFull, xmlDoc)
|
237
|
+
@logic = GetLogic.new(xmlDoc, self)
|
238
|
+
end
|
239
|
+
|
240
|
+
def doJob(resultQueue, obj)
|
241
|
+
files = @logic.getFiles()
|
242
|
+
files.each do |file|
|
243
|
+
resultQueue.enq("#{file}")
|
244
|
+
sleep(@rate.to_i)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
end
|
249
|
+
|
250
|
+
class PutTask < IOTask
|
251
|
+
|
252
|
+
def initialize(wflow, xmlFull, xmlDoc)
|
253
|
+
super(wflow, xmlFull, xmlDoc)
|
254
|
+
@logic = PutLogic.new(xmlDoc, self)
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
def doJob(resultQueue, obj)
|
259
|
+
if @rate.to_i != 0
|
260
|
+
super(resultQueue, obj)
|
261
|
+
else
|
262
|
+
print "Send doJob #{obj} > #{location}\n"
|
263
|
+
@logic.putFile(obj)
|
264
|
+
resultQueue.enq(obj)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def getItemsNext(numItems)
|
269
|
+
return numItems
|
270
|
+
end
|
271
|
+
|
272
|
+
def doBuffered(buffer)
|
273
|
+
buffer.size.times do
|
274
|
+
obj = buffer.deq
|
275
|
+
if @rate.to_i != 0
|
276
|
+
print "Send doBuffered #{obj} > #{location}\n"
|
277
|
+
@logic.putFile(obj)
|
278
|
+
sleep(@rate.to_i)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end #module
|
@@ -0,0 +1,145 @@
|
|
1
|
+
require 'rio'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
include REXML
|
5
|
+
|
6
|
+
module RbEAI
|
7
|
+
|
8
|
+
class TransfLogic
|
9
|
+
|
10
|
+
attr_accessor :destinations, :default
|
11
|
+
|
12
|
+
def initialize(xmlDoc)
|
13
|
+
@transfs = []
|
14
|
+
# Detect simple usage of one transformation not ordered
|
15
|
+
el = XPath.first(xmlDoc, "./transf[count(@ord) = 0]")
|
16
|
+
if el != nil
|
17
|
+
@transfs[0] = TransfScript.new(el)
|
18
|
+
else
|
19
|
+
# Case of multiple ordered transformations
|
20
|
+
XPath.each(xmlDoc, "./transf[count(@ord) > 0]") do |el|
|
21
|
+
order = el.attributes["ord"]
|
22
|
+
@transfs[order.to_i] = TransfScript.new(el)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def transform(file)
|
28
|
+
aux = file
|
29
|
+
@transfs.each do | trfilter |
|
30
|
+
aux = trfilter.transform(aux) if trfilter != nil
|
31
|
+
end
|
32
|
+
return aux
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class TransfScript
|
38
|
+
|
39
|
+
def initialize(xmlDoc)
|
40
|
+
@transf = _getParser(xmlDoc)
|
41
|
+
end
|
42
|
+
|
43
|
+
def transform(file)
|
44
|
+
@transf.transform(file)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def _getParser(node)
|
50
|
+
type = node.attributes["type"]
|
51
|
+
re = Regexp.new('(xsl|awk|csv2xml_nh|csv2xml_wh|xml2csv)')
|
52
|
+
mr = re.match(type)
|
53
|
+
case mr[1]
|
54
|
+
when 'xsl' then XslScript.new(node)
|
55
|
+
when 'awk' then AwkScript.new(node)
|
56
|
+
when 'csv2xml_nh' then Csv2XmlScript.new(node)
|
57
|
+
when 'csv2xml_wh' then Csv2XmlScript.new(node)
|
58
|
+
when 'xml2csv' then Xml2CsvScript.new(node)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
class Script
|
65
|
+
|
66
|
+
def initialize(node)
|
67
|
+
@script = node.attributes["script"]
|
68
|
+
@pos = (pos = node.attributes["ord"])!= nil ? pos : "0"
|
69
|
+
end
|
70
|
+
|
71
|
+
def transform(file)
|
72
|
+
newfilename = file.to_s+"."+@pos
|
73
|
+
rio("#{file}") > rio("#{newfilename}")
|
74
|
+
doTransform(file, newfilename)
|
75
|
+
return newfilename
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
def doTransform(file, newfilename)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
class XslScript < Script
|
86
|
+
|
87
|
+
def doTransform(file, newfilename)
|
88
|
+
print "xsltproc -o #{newfilename} #{@script} #{file} \n"
|
89
|
+
result = system("xsltproc -o #{newfilename} #{@script} #{file}")
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class AwkScript < Script
|
95
|
+
|
96
|
+
def initialize(node)
|
97
|
+
super(node)
|
98
|
+
@separator = (sep = node.attributes["separator"])!= nil ? "-F "+sep : ""
|
99
|
+
end
|
100
|
+
|
101
|
+
def doTransform(file, newfilename)
|
102
|
+
print "gawk -f #{@script} #{@separator} #{@file} > #{newfilename} \n"
|
103
|
+
result = system("gawk -f #{@script} #{@separator} #{file} > #{newfilename}")
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
class Csv2XmlScript < AwkScript
|
110
|
+
|
111
|
+
def initialize(node)
|
112
|
+
super(node)
|
113
|
+
@script = File.dirname(__FILE__)+"/templates/"+node.attributes["type"]+".awk"
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
class Xml2CsvScript < AwkScript
|
119
|
+
|
120
|
+
def initialize(node)
|
121
|
+
super(node)
|
122
|
+
@xprow = node.attributes["xprow"]
|
123
|
+
@xpitem = node.attributes["xpitem"]
|
124
|
+
@separator = (sep = node.attributes["separator"])!= nil ? sep : "\t"
|
125
|
+
end
|
126
|
+
|
127
|
+
def doTransform(file, newfilename)
|
128
|
+
csvarr = []
|
129
|
+
xmlDoc = Document.new(File.new(file))
|
130
|
+
XPath.each(xmlDoc, "#{@xprow}") do |el|
|
131
|
+
csvline = ""
|
132
|
+
bsep = false
|
133
|
+
XPath.each(el, "#{@xpitem}") do |el2|
|
134
|
+
csvline << @separator if bsep
|
135
|
+
csvline << el2.to_s
|
136
|
+
bsep = true
|
137
|
+
end
|
138
|
+
csvarr << csvline
|
139
|
+
end
|
140
|
+
rio("#{newfilename}").puts!(csvarr)
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end #module
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module RbEAI
|
4
|
+
|
5
|
+
class WorkerPool
|
6
|
+
|
7
|
+
def initialize(size, nmessages, inputQueue, resultQueue, method)
|
8
|
+
@size = size
|
9
|
+
@inputQueue = inputQueue
|
10
|
+
@resultQueue = resultQueue
|
11
|
+
@controlQueue = Queue.new
|
12
|
+
@control = Thread.new(nmessages) do |nmess|
|
13
|
+
Thread.stop()
|
14
|
+
print "Running control thread\n"
|
15
|
+
count = 0
|
16
|
+
begin
|
17
|
+
aux = @controlQueue.deq
|
18
|
+
count = count + 1
|
19
|
+
end until count == nmess
|
20
|
+
print "Finished control thread\n"
|
21
|
+
stop()
|
22
|
+
end
|
23
|
+
@threadlist = []
|
24
|
+
size.times do |i|
|
25
|
+
@threadlist << Thread.new(i) do |j|
|
26
|
+
Thread.stop()
|
27
|
+
print "Running th ",j,"\n"
|
28
|
+
begin
|
29
|
+
obj = @inputQueue.deq
|
30
|
+
if obj != :FINISH_WORK
|
31
|
+
method.call(obj, j)
|
32
|
+
@controlQueue.enq(:COUNT)
|
33
|
+
|
34
|
+
end
|
35
|
+
end until obj == :FINISH_WORK
|
36
|
+
print "Finished th ",j,"\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def run()
|
42
|
+
@control.run
|
43
|
+
@threadlist.each { |t| t.run}
|
44
|
+
end
|
45
|
+
|
46
|
+
def stop()
|
47
|
+
@size.times { |i| @inputQueue.enq(:FINISH_WORK) }
|
48
|
+
@threadlist.each { |t| t.join }
|
49
|
+
end
|
50
|
+
|
51
|
+
def stopcontrol()
|
52
|
+
@control.join
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class Hello
|
58
|
+
|
59
|
+
def sayHello(obj, i)
|
60
|
+
print obj.object_id,"-#{obj}-#{i}\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#h = Hello.new
|
65
|
+
#inputQ = Queue.new
|
66
|
+
#wp = WorkerPool.new(5, 1000, inputQ, Queue.new, h.method(:sayHello))
|
67
|
+
#wp.run()
|
68
|
+
#1000.times { |i| inputQ.enq(i) }
|
69
|
+
#wp.stopcontrol()
|
70
|
+
|
71
|
+
|
72
|
+
end #module
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'rio'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'rbeai/PipeTask'
|
4
|
+
require 'rbeai/TasksLogic'
|
5
|
+
|
6
|
+
include REXML
|
7
|
+
|
8
|
+
module RbEAI
|
9
|
+
|
10
|
+
class Workflow
|
11
|
+
|
12
|
+
attr_accessor :instid
|
13
|
+
|
14
|
+
def initialize(xmlStr)
|
15
|
+
@xmlDoc = Document.new(xmlStr)
|
16
|
+
aux = XPath.first(@xmlDoc, "./workflow")
|
17
|
+
@instid = ""
|
18
|
+
rate = _getRate(aux.attributes["rate"])
|
19
|
+
@name = aux.attributes["name"]
|
20
|
+
@inputQueue = Queue.new
|
21
|
+
@startPipe = _initPipeTask()
|
22
|
+
@thControl = _initProcess(rate.to_i)
|
23
|
+
end
|
24
|
+
|
25
|
+
def run()
|
26
|
+
@startPipe.run()
|
27
|
+
@thControl.run()
|
28
|
+
end
|
29
|
+
|
30
|
+
def finish()
|
31
|
+
@thControl.kill()
|
32
|
+
@startPipe.finish()
|
33
|
+
@startPipe.waitToEnd()
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def _initInstance()
|
39
|
+
t = Time.new
|
40
|
+
ts = "%10.5f" % t.to_f
|
41
|
+
@instid = @name+"/"+ts
|
42
|
+
rio("tmp/#{@instid}").mkpath
|
43
|
+
end
|
44
|
+
|
45
|
+
def _initPipeTask()
|
46
|
+
startTask = StartTask.new(self, @xmlDoc, XPath.first(@xmlDoc, "//task[@type='Start']"))
|
47
|
+
return PipeTask.new(@inputQueue, startTask, Control.new(Queue.new, @inputQueue))
|
48
|
+
end
|
49
|
+
|
50
|
+
def _initProcess(timer)
|
51
|
+
Thread.new(timer) do |timer|
|
52
|
+
Thread.stop()
|
53
|
+
loop do
|
54
|
+
_initInstance()
|
55
|
+
@inputQueue.enq(:start)
|
56
|
+
sleep(timer)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def _getRate(rateTx)
|
62
|
+
re = Regexp.new('(\d+)(\D)')
|
63
|
+
mrate = re.match(rateTx)
|
64
|
+
value = mrate[1]
|
65
|
+
unit = mrate[2]
|
66
|
+
case unit
|
67
|
+
when "s"
|
68
|
+
return value
|
69
|
+
when "m"
|
70
|
+
return value * 60
|
71
|
+
when "h"
|
72
|
+
return value * 60 * 60
|
73
|
+
else
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end #class
|
78
|
+
|
79
|
+
end #module
|
@@ -0,0 +1,16 @@
|
|
1
|
+
BEGIN{
|
2
|
+
print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
|
3
|
+
print "<all>"
|
4
|
+
getline
|
5
|
+
for(i=1;i<=NF;i++){elem[i]=$i}
|
6
|
+
}
|
7
|
+
|
8
|
+
{
|
9
|
+
print "\t<doc>"
|
10
|
+
for(i=1;i<=NF;i++){printf ("\t\t<%s>%s</%s>\n",elem[i],$i,elem[i])}
|
11
|
+
print "\t</doc>"
|
12
|
+
}
|
13
|
+
|
14
|
+
END{
|
15
|
+
print "</all>"
|
16
|
+
}
|
data/lib/rbeai.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module RbEAI
|
2
|
+
end
|
3
|
+
|
4
|
+
require 'rbeai/GetLogic'
|
5
|
+
require 'rbeai/Main'
|
6
|
+
require 'rbeai/PipeTask'
|
7
|
+
require 'rbeai/PutLogic'
|
8
|
+
require 'rbeai/RouterLogic'
|
9
|
+
require 'rbeai/RouterPipeTask'
|
10
|
+
require 'rbeai/TasksLogic'
|
11
|
+
require 'rbeai/TransfLogic'
|
12
|
+
require 'rbeai/WorkerPool'
|
13
|
+
require 'rbeai/Workflow'
|
data/rbeai-0.0.1.gem
ADDED
File without changes
|