pione 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (366) hide show
  1. data/.gitignore +14 -0
  2. data/Gemfile +5 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +94 -0
  5. data/Rakefile +118 -0
  6. data/bin/pione-broker +5 -0
  7. data/bin/pione-clean +5 -0
  8. data/bin/pione-client +5 -0
  9. data/bin/pione-eval +111 -0
  10. data/bin/pione-relay +5 -0
  11. data/bin/pione-relay-account-db +5 -0
  12. data/bin/pione-relay-client-db +5 -0
  13. data/bin/pione-search-log +30 -0
  14. data/bin/pione-syntax-checker +5 -0
  15. data/bin/pione-task-worker +5 -0
  16. data/bin/pione-tuple-space-provider +5 -0
  17. data/bin/pione-tuple-space-receiver +5 -0
  18. data/bin/pione-tuple-space-viewer +5 -0
  19. data/demo/demo.rb +311 -0
  20. data/demo/public/base.css +94 -0
  21. data/demo/public/demo.js +107 -0
  22. data/demo/public/index.html +91 -0
  23. data/demo/public/jquery-1.8.3.min.js +2 -0
  24. data/example/CountChar/CountChar.pione +64 -0
  25. data/example/CountChar/misc/CountChar.rb +22 -0
  26. data/example/CountChar/text/aidokushono_insho.txt +32 -0
  27. data/example/CountChar/text/aikokuka_shokan.txt +108 -0
  28. data/example/CountChar/text/carlyle_hakubutsukan.txt +58 -0
  29. data/example/CountChar/text/dark_minister.txt +2440 -0
  30. data/example/CountChar/text/kaikano_otto.txt +61 -0
  31. data/example/CountChar/text/kaikon.txt +30 -0
  32. data/example/CountChar/text/nagashimano_shi.txt +45 -0
  33. data/example/CountChar/text/saikachibuchi.txt +80 -0
  34. data/example/CountChar/text/saikonihonno_josei.txt +91 -0
  35. data/example/CountChar/text/taishojugonenno_bundan.txt +21 -0
  36. data/example/FeatureExample/FeatureExample.pione +7 -0
  37. data/example/Fib/Fib.pione +56 -0
  38. data/example/Fib/FibBC.pione +56 -0
  39. data/example/HelloWorld/HelloWorld.pione +5 -0
  40. data/example/LucasNumber/LucasNumber.pione +64 -0
  41. data/example/MakePair/MakePair.pione +14 -0
  42. data/example/MakePair/data/1.i +0 -0
  43. data/example/MakePair/data/2.i +0 -0
  44. data/example/MakePair/data/3.i +0 -0
  45. data/example/MakePair/data/4.i +0 -0
  46. data/example/MakePair/data/5.i +0 -0
  47. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +61 -0
  48. data/example/SingleParticlesWithRef/Makefile +289 -0
  49. data/example/SingleParticlesWithRef/SingleParticlesWithRef.Makefile +153 -0
  50. data/example/SingleParticlesWithRef/SingleParticlesWithRef.pione +116 -0
  51. data/example/SingleParticlesWithRef/SingleParticlesWithRefFull.pione +400 -0
  52. data/example/SingleParticlesWithRef/data/121p-shift-0-0-0.roi +0 -0
  53. data/example/SingleParticlesWithRef/data/121p-shift-0-120-0.roi +0 -0
  54. data/example/SingleParticlesWithRef/data/121p-shift-0-180-0.roi +0 -0
  55. data/example/SingleParticlesWithRef/data/121p-shift-0-240-0.roi +0 -0
  56. data/example/SingleParticlesWithRef/data/121p-shift-0-300-0.roi +0 -0
  57. data/example/SingleParticlesWithRef/data/121p-shift-0-60-0.roi +0 -0
  58. data/example/SingleParticlesWithRef/data/121p-shift-120-0-0.roi +0 -0
  59. data/example/SingleParticlesWithRef/data/121p-shift-120-120-0.roi +0 -0
  60. data/example/SingleParticlesWithRef/data/121p-shift-120-180-0.roi +0 -0
  61. data/example/SingleParticlesWithRef/data/121p-shift-120-240-0.roi +0 -0
  62. data/example/SingleParticlesWithRef/data/121p-shift-120-300-0.roi +0 -0
  63. data/example/SingleParticlesWithRef/data/121p-shift-120-60-0.roi +0 -0
  64. data/example/SingleParticlesWithRef/data/121p-shift-180-0-0.roi +0 -0
  65. data/example/SingleParticlesWithRef/data/121p-shift-180-120-0.roi +0 -0
  66. data/example/SingleParticlesWithRef/data/121p-shift-180-180-0.roi +0 -0
  67. data/example/SingleParticlesWithRef/data/121p-shift-180-240-0.roi +0 -0
  68. data/example/SingleParticlesWithRef/data/121p-shift-180-300-0.roi +0 -0
  69. data/example/SingleParticlesWithRef/data/121p-shift-180-60-0.roi +0 -0
  70. data/example/SingleParticlesWithRef/data/121p-shift-240-0-0.roi +0 -0
  71. data/example/SingleParticlesWithRef/data/121p-shift-240-120-0.roi +0 -0
  72. data/example/SingleParticlesWithRef/data/121p-shift-240-180-0.roi +0 -0
  73. data/example/SingleParticlesWithRef/data/121p-shift-240-240-0.roi +0 -0
  74. data/example/SingleParticlesWithRef/data/121p-shift-240-300-0.roi +0 -0
  75. data/example/SingleParticlesWithRef/data/121p-shift-240-60-0.roi +0 -0
  76. data/example/SingleParticlesWithRef/data/121p-shift-300-0-0.roi +0 -0
  77. data/example/SingleParticlesWithRef/data/121p-shift-300-120-0.roi +0 -0
  78. data/example/SingleParticlesWithRef/data/121p-shift-300-180-0.roi +0 -0
  79. data/example/SingleParticlesWithRef/data/121p-shift-300-240-0.roi +0 -0
  80. data/example/SingleParticlesWithRef/data/121p-shift-300-300-0.roi +0 -0
  81. data/example/SingleParticlesWithRef/data/121p-shift-300-60-0.roi +0 -0
  82. data/example/SingleParticlesWithRef/data/121p-shift-60-0-0.roi +0 -0
  83. data/example/SingleParticlesWithRef/data/121p-shift-60-120-0.roi +0 -0
  84. data/example/SingleParticlesWithRef/data/121p-shift-60-180-0.roi +0 -0
  85. data/example/SingleParticlesWithRef/data/121p-shift-60-240-0.roi +0 -0
  86. data/example/SingleParticlesWithRef/data/121p-shift-60-300-0.roi +0 -0
  87. data/example/SingleParticlesWithRef/data/121p-shift-60-60-0.roi +0 -0
  88. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-0-0.roi +0 -0
  89. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-120-0.roi +0 -0
  90. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-180-0.roi +0 -0
  91. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-240-0.roi +0 -0
  92. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-300-0.roi +0 -0
  93. data/example/SingleParticlesWithRef/data/121p-shift-noise-0-60-0.roi +0 -0
  94. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-0-0.roi +0 -0
  95. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-120-0.roi +0 -0
  96. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-180-0.roi +0 -0
  97. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-240-0.roi +0 -0
  98. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-300-0.roi +0 -0
  99. data/example/SingleParticlesWithRef/data/121p-shift-noise-120-60-0.roi +0 -0
  100. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-0-0.roi +0 -0
  101. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-120-0.roi +0 -0
  102. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-180-0.roi +0 -0
  103. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-240-0.roi +0 -0
  104. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-300-0.roi +0 -0
  105. data/example/SingleParticlesWithRef/data/121p-shift-noise-180-60-0.roi +0 -0
  106. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-0-0.roi +0 -0
  107. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-120-0.roi +0 -0
  108. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-180-0.roi +0 -0
  109. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-240-0.roi +0 -0
  110. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-300-0.roi +0 -0
  111. data/example/SingleParticlesWithRef/data/121p-shift-noise-240-60-0.roi +0 -0
  112. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-0-0.roi +0 -0
  113. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-120-0.roi +0 -0
  114. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-180-0.roi +0 -0
  115. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-240-0.roi +0 -0
  116. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-300-0.roi +0 -0
  117. data/example/SingleParticlesWithRef/data/121p-shift-noise-300-60-0.roi +0 -0
  118. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-0-0.roi +0 -0
  119. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-120-0.roi +0 -0
  120. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-180-0.roi +0 -0
  121. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-240-0.roi +0 -0
  122. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-300-0.roi +0 -0
  123. data/example/SingleParticlesWithRef/data/121p-shift-noise-60-60-0.roi +0 -0
  124. data/example/SingleParticlesWithRef/data/121p-shift.pdb +3381 -0
  125. data/example/SingleParticlesWithRef/data/all.ref2d +0 -0
  126. data/example/SingleParticlesWithRef/data/all.ref3d +0 -0
  127. data/example/Sum/Sum.pione +52 -0
  128. data/example/SyntaxError/call_rule_error.pione +6 -0
  129. data/example/SyntaxError/feature_line_error.pione +7 -0
  130. data/example/SyntaxError/flow_block_error.pione +5 -0
  131. data/example/SyntaxError/input_line_error.pione +6 -0
  132. data/example/SyntaxError/invalid_rule_name.pione +6 -0
  133. data/example/SyntaxError/param_line_error.pione +7 -0
  134. data/example/SyntaxError/variable-binding-error.pione +11 -0
  135. data/lib/pione.rb +241 -0
  136. data/lib/pione/agent/basic-agent.rb +333 -0
  137. data/lib/pione/agent/broker.rb +274 -0
  138. data/lib/pione/agent/command-listener.rb +47 -0
  139. data/lib/pione/agent/input-generator.rb +194 -0
  140. data/lib/pione/agent/logger.rb +65 -0
  141. data/lib/pione/agent/process-manager.rb +38 -0
  142. data/lib/pione/agent/rule-provider.rb +64 -0
  143. data/lib/pione/agent/task-worker.rb +274 -0
  144. data/lib/pione/agent/trivial-routine-worker.rb +28 -0
  145. data/lib/pione/agent/tuple-space-client.rb +146 -0
  146. data/lib/pione/agent/tuple-space-server-client-life-checker.rb +29 -0
  147. data/lib/pione/command-option/basic-option.rb +42 -0
  148. data/lib/pione/command-option/child-process-option.rb +17 -0
  149. data/lib/pione/command-option/common-option.rb +29 -0
  150. data/lib/pione/command-option/daemon-option.rb +12 -0
  151. data/lib/pione/command-option/presence-notifier-option.rb +15 -0
  152. data/lib/pione/command-option/task-worker-owner-option.rb +17 -0
  153. data/lib/pione/command-option/tuple-space-provider-option.rb +26 -0
  154. data/lib/pione/command-option/tuple-space-provider-owner-option.rb +16 -0
  155. data/lib/pione/command-option/tuple-space-receiver-option.rb +12 -0
  156. data/lib/pione/command/basic-command.rb +126 -0
  157. data/lib/pione/command/child-process.rb +43 -0
  158. data/lib/pione/command/daemon-process.rb +18 -0
  159. data/lib/pione/command/front-owner-command.rb +37 -0
  160. data/lib/pione/command/pione-broker.rb +53 -0
  161. data/lib/pione/command/pione-clean.rb +16 -0
  162. data/lib/pione/command/pione-client.rb +273 -0
  163. data/lib/pione/command/pione-relay-account-db.rb +85 -0
  164. data/lib/pione/command/pione-relay-client-db.rb +80 -0
  165. data/lib/pione/command/pione-relay.rb +47 -0
  166. data/lib/pione/command/pione-syntax-checker.rb +103 -0
  167. data/lib/pione/command/pione-task-worker.rb +123 -0
  168. data/lib/pione/command/pione-tuple-space-provider.rb +87 -0
  169. data/lib/pione/command/pione-tuple-space-receiver.rb +55 -0
  170. data/lib/pione/command/pione-tuple-space-viewer.rb +151 -0
  171. data/lib/pione/command/tuple-space-provider-owner.rb +6 -0
  172. data/lib/pione/front/basic-front.rb +64 -0
  173. data/lib/pione/front/broker-front.rb +30 -0
  174. data/lib/pione/front/client-front.rb +28 -0
  175. data/lib/pione/front/relay-front.rb +19 -0
  176. data/lib/pione/front/task-worker-front.rb +16 -0
  177. data/lib/pione/front/task-worker-owner.rb +42 -0
  178. data/lib/pione/front/tuple-space-provider-front.rb +22 -0
  179. data/lib/pione/front/tuple-space-provider-owner.rb +11 -0
  180. data/lib/pione/front/tuple-space-receiver-front.rb +18 -0
  181. data/lib/pione/model/assignment.rb +89 -0
  182. data/lib/pione/model/basic-model.rb +395 -0
  183. data/lib/pione/model/binary-operator.rb +80 -0
  184. data/lib/pione/model/block.rb +233 -0
  185. data/lib/pione/model/boolean.rb +138 -0
  186. data/lib/pione/model/call-rule.rb +69 -0
  187. data/lib/pione/model/data-expr.rb +360 -0
  188. data/lib/pione/model/feature-expr.rb +794 -0
  189. data/lib/pione/model/float.rb +107 -0
  190. data/lib/pione/model/integer.rb +140 -0
  191. data/lib/pione/model/list.rb +104 -0
  192. data/lib/pione/model/message.rb +80 -0
  193. data/lib/pione/model/package.rb +48 -0
  194. data/lib/pione/model/parameters.rb +282 -0
  195. data/lib/pione/model/rule-expr.rb +120 -0
  196. data/lib/pione/model/rule-io.rb +166 -0
  197. data/lib/pione/model/rule.rb +294 -0
  198. data/lib/pione/model/string.rb +111 -0
  199. data/lib/pione/model/undefined-value.rb +24 -0
  200. data/lib/pione/model/variable-table.rb +315 -0
  201. data/lib/pione/model/variable.rb +87 -0
  202. data/lib/pione/parser/block-parser.rb +83 -0
  203. data/lib/pione/parser/common-parser.rb +145 -0
  204. data/lib/pione/parser/document-parser.rb +58 -0
  205. data/lib/pione/parser/error-message.yml +4 -0
  206. data/lib/pione/parser/expr-parser.rb +266 -0
  207. data/lib/pione/parser/feature-expr-parser.rb +105 -0
  208. data/lib/pione/parser/flow-element-parser.rb +181 -0
  209. data/lib/pione/parser/literal-parser.rb +182 -0
  210. data/lib/pione/parser/rule-definition-parser.rb +163 -0
  211. data/lib/pione/parser/syntax-error.rb +61 -0
  212. data/lib/pione/patch/array-patch.rb +3 -0
  213. data/lib/pione/patch/drb-patch.rb +467 -0
  214. data/lib/pione/patch/monitor-patch.rb +16 -0
  215. data/lib/pione/patch/rinda-patch.rb +759 -0
  216. data/lib/pione/patch/uri-patch.rb +66 -0
  217. data/lib/pione/relay/receiver-socket.rb +69 -0
  218. data/lib/pione/relay/relay-account-db.rb +55 -0
  219. data/lib/pione/relay/relay-client-db.rb +53 -0
  220. data/lib/pione/relay/relay-socket.rb +215 -0
  221. data/lib/pione/relay/trampoline.rb +22 -0
  222. data/lib/pione/relay/transmitter-socket.rb +167 -0
  223. data/lib/pione/resource/basic-resource.rb +92 -0
  224. data/lib/pione/resource/dropbox-resource.rb +106 -0
  225. data/lib/pione/resource/ftp.rb +84 -0
  226. data/lib/pione/resource/local.rb +113 -0
  227. data/lib/pione/rule-handler/action-handler.rb +184 -0
  228. data/lib/pione/rule-handler/basic-handler.rb +217 -0
  229. data/lib/pione/rule-handler/flow-handler.rb +339 -0
  230. data/lib/pione/rule-handler/root-handler.rb +23 -0
  231. data/lib/pione/rule-handler/system-handler.rb +13 -0
  232. data/lib/pione/system/common.rb +22 -0
  233. data/lib/pione/system/config.rb +20 -0
  234. data/lib/pione/system/document.rb +81 -0
  235. data/lib/pione/system/file-cache.rb +150 -0
  236. data/lib/pione/system/global.rb +346 -0
  237. data/lib/pione/system/identifier.rb +61 -0
  238. data/lib/pione/system/init.rb +16 -0
  239. data/lib/pione/system/object.rb +35 -0
  240. data/lib/pione/transformer/block-transformer.rb +23 -0
  241. data/lib/pione/transformer/document-transformer.rb +36 -0
  242. data/lib/pione/transformer/expr-transformer.rb +89 -0
  243. data/lib/pione/transformer/feature-expr-transformer.rb +56 -0
  244. data/lib/pione/transformer/flow-element-transformer.rb +66 -0
  245. data/lib/pione/transformer/literal-transformer.rb +76 -0
  246. data/lib/pione/transformer/rule-definition-transformer.rb +62 -0
  247. data/lib/pione/transformer/transformer-module.rb +37 -0
  248. data/lib/pione/tuple-space/data-finder.rb +165 -0
  249. data/lib/pione/tuple-space/presence-notifier.rb +83 -0
  250. data/lib/pione/tuple-space/relay.rb +9 -0
  251. data/lib/pione/tuple-space/tuple-space-provider.rb +85 -0
  252. data/lib/pione/tuple-space/tuple-space-receiver.rb +140 -0
  253. data/lib/pione/tuple-space/tuple-space-server-interface.rb +60 -0
  254. data/lib/pione/tuple-space/tuple-space-server.rb +156 -0
  255. data/lib/pione/tuple-space/update-criteria.rb +96 -0
  256. data/lib/pione/tuple/agent-tuple.rb +10 -0
  257. data/lib/pione/tuple/attribute-tuple.rb +7 -0
  258. data/lib/pione/tuple/base-uri-tuple.rb +9 -0
  259. data/lib/pione/tuple/basic-tuple.rb +317 -0
  260. data/lib/pione/tuple/bye-tuple.rb +9 -0
  261. data/lib/pione/tuple/command-tuple.rb +9 -0
  262. data/lib/pione/tuple/data-tuple.rb +18 -0
  263. data/lib/pione/tuple/dry-run-tuple.rb +8 -0
  264. data/lib/pione/tuple/exception-tuple.rb +11 -0
  265. data/lib/pione/tuple/finished-tuple.rb +17 -0
  266. data/lib/pione/tuple/foreground-tuple.rb +7 -0
  267. data/lib/pione/tuple/log-tuple.rb +14 -0
  268. data/lib/pione/tuple/process-info-tuple.rb +9 -0
  269. data/lib/pione/tuple/request-rule-tuple.rb +9 -0
  270. data/lib/pione/tuple/rule-tuple.rb +10 -0
  271. data/lib/pione/tuple/shift-tuple.rb +13 -0
  272. data/lib/pione/tuple/task-tuple.rb +36 -0
  273. data/lib/pione/tuple/task-worker-resource-tuple.rb +9 -0
  274. data/lib/pione/tuple/working-tuple.rb +13 -0
  275. data/lib/pione/uri-scheme/basic-scheme.rb +40 -0
  276. data/lib/pione/uri-scheme/broadcast-scheme.rb +11 -0
  277. data/lib/pione/uri-scheme/dropbox-scheme.rb +9 -0
  278. data/lib/pione/uri-scheme/local-scheme.rb +28 -0
  279. data/lib/pione/util/error-report.rb +12 -0
  280. data/lib/pione/util/log.rb +79 -0
  281. data/lib/pione/util/message.rb +155 -0
  282. data/lib/pione/util/misc.rb +73 -0
  283. data/lib/pione/util/terminal.rb +78 -0
  284. data/lib/pione/util/waiter-table.rb +53 -0
  285. data/lib/pione/version.rb +3 -0
  286. data/misc/env.sh +2 -0
  287. data/misc/test-drb-stop-service.rb +34 -0
  288. data/misc/test-ensure-and-thread-kill.rb +40 -0
  289. data/misc/test-many-waiters-client.rb +56 -0
  290. data/misc/test-many-waiters-server.rb +14 -0
  291. data/misc/write_and_take_test.png +0 -0
  292. data/misc/write_and_take_test.rb +36 -0
  293. data/pione.gemspec +49 -0
  294. data/test/agent/spec_basic-agent.rb +170 -0
  295. data/test/agent/spec_broker.rb +36 -0
  296. data/test/agent/spec_command-listener.rb +30 -0
  297. data/test/agent/spec_input-generator.rb +123 -0
  298. data/test/agent/spec_logger.rb +71 -0
  299. data/test/agent/spec_rule-provider.rb +65 -0
  300. data/test/agent/spec_task-worker.rb +307 -0
  301. data/test/agent/spec_tuple-space-client.rb +30 -0
  302. data/test/model/spec_assignment.rb +51 -0
  303. data/test/model/spec_binary-operator.rb +39 -0
  304. data/test/model/spec_block.rb +154 -0
  305. data/test/model/spec_boolean.rb +115 -0
  306. data/test/model/spec_call-rule.rb +23 -0
  307. data/test/model/spec_data-expr.rb +312 -0
  308. data/test/model/spec_feature-expr.rb +359 -0
  309. data/test/model/spec_feature-expr.yml +16 -0
  310. data/test/model/spec_float.rb +141 -0
  311. data/test/model/spec_integer.rb +141 -0
  312. data/test/model/spec_list.rb +26 -0
  313. data/test/model/spec_message.rb +42 -0
  314. data/test/model/spec_package.rb +15 -0
  315. data/test/model/spec_parameters.rb +148 -0
  316. data/test/model/spec_rule-expr.rb +66 -0
  317. data/test/model/spec_rule-io.rb +32 -0
  318. data/test/model/spec_rule.rb +158 -0
  319. data/test/model/spec_string.rb +106 -0
  320. data/test/model/spec_variable-table.rb +117 -0
  321. data/test/model/spec_variable.rb +84 -0
  322. data/test/parser/spec_block-parser.rb +5 -0
  323. data/test/parser/spec_block-parser.yml +85 -0
  324. data/test/parser/spec_common-parser.rb +281 -0
  325. data/test/parser/spec_expr-parser.rb +6 -0
  326. data/test/parser/spec_expr-parser.yml +82 -0
  327. data/test/parser/spec_feature-expr-parser.rb +32 -0
  328. data/test/parser/spec_feature-expr-parser.yml +25 -0
  329. data/test/parser/spec_flow-element-parser.rb +5 -0
  330. data/test/parser/spec_flow-element-parser.yml +180 -0
  331. data/test/parser/spec_literal-parser.rb +5 -0
  332. data/test/parser/spec_literal-parser.yml +123 -0
  333. data/test/parser/spec_rule-definition-parser.rb +5 -0
  334. data/test/parser/spec_rule-definition-parser.yml +93 -0
  335. data/test/patch/spec_rinda-patch.rb +32 -0
  336. data/test/patch/spec_uri-patch.rb +23 -0
  337. data/test/rule-handler/spec_action-handler.rb +135 -0
  338. data/test/rule-handler/spec_flow-handler.rb +127 -0
  339. data/test/spec_common.rb +14 -0
  340. data/test/spec_data-finder.rb +88 -0
  341. data/test/spec_data-finder.yml +115 -0
  342. data/test/spec_document.rb +76 -0
  343. data/test/spec_identifier.rb +29 -0
  344. data/test/spec_log.rb +52 -0
  345. data/test/spec_object.rb +20 -0
  346. data/test/spec_resource.rb +73 -0
  347. data/test/spec_update-criteria.rb +83 -0
  348. data/test/test-util.rb +223 -0
  349. data/test/transformer/spec_block-transformer.rb +26 -0
  350. data/test/transformer/spec_expr-transformer.rb +106 -0
  351. data/test/transformer/spec_feature-expr-transformer.rb +21 -0
  352. data/test/transformer/spec_flow-element-transformer.rb +154 -0
  353. data/test/transformer/spec_literal-transformer.rb +58 -0
  354. data/test/transformer/spec_rule-definition-transformer.rb +168 -0
  355. data/test/tuple-space/spec_tuple-space-provider.rb +36 -0
  356. data/test/tuple-space/spec_tuple-space-receiver.rb +32 -0
  357. data/test/tuple-space/spec_tuple-space-server.rb +49 -0
  358. data/test/tuple/spec_basic-tuple.rb +87 -0
  359. data/test/tuple/spec_data-tuple.rb +85 -0
  360. data/test/tuple/spec_finished-tuple.rb +61 -0
  361. data/test/tuple/spec_task-tuple.rb +127 -0
  362. data/test/tuple/spec_working-tuple.rb +58 -0
  363. data/test/uri-scheme/spec_broadcast-scheme.rb +40 -0
  364. data/test/uri-scheme/spec_dropbox-scheme.rb +31 -0
  365. data/test/uri-scheme/spec_local-scheme.rb +69 -0
  366. metadata +660 -0
@@ -0,0 +1,274 @@
1
+ module Pione
2
+ module Agent
3
+ class Broker < BasicAgent
4
+ # Balancer is a base class for balancing task workers.
5
+ class Balancer < PioneObject
6
+ # Create a new balancer.
7
+ def initialize(broker)
8
+ @broker = broker
9
+ end
10
+
11
+ def balance
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+
16
+ # EasyBalancer is a balancer by ratios of tuple space server and task worker.
17
+ class EasyBalancer < Balancer
18
+ # see Balancer.new
19
+ def initialize(broker)
20
+ @broker = broker
21
+ end
22
+
23
+ # Balances by killing a task worker in max tuple server.
24
+ def balance
25
+ ratios = calc_resource_ratios
26
+ min = ratios.values.min
27
+ max = ratios.values.max
28
+ min_server = ratios.key(min)
29
+ max_server = ratios.key(max)
30
+
31
+ return unless min_server
32
+ return unless max_server
33
+
34
+ if @broker.excess_task_workers > 0 and min_server
35
+ create_task_worker(min_server)
36
+ else
37
+ adjust_task_worker(min_server, max_server)
38
+ end
39
+ end
40
+
41
+ # Calculates resource ratios of tuple space servers.
42
+ def calc_resource_ratios(revision={})
43
+ ratio = {}
44
+ # make ratio table
45
+ @broker.tuple_space_servers.each do |ts|
46
+ begin
47
+ rev = revision.has_key?(ts) ? revision[ts] : 0
48
+ current = timeout(1){ts.current_task_worker_size} + rev
49
+ resource = ts.task_worker_resource
50
+ # minimum resource is 1
51
+ resource = 1.0 unless resource > 0
52
+ ratio[ts] = current / resource.to_f
53
+ rescue Exception
54
+ # ignore
55
+ end
56
+ end
57
+ return ratio
58
+ end
59
+
60
+ # Creates a new task worker.
61
+ def create_task_worker(min_server)
62
+ @broker.create_task_worker(min_server)
63
+
64
+ if Pione.debug_mode?
65
+ puts "create a new task worker in #{min_server}"
66
+ end
67
+ end
68
+
69
+ # Adjusts task worker size between tuple space servers.
70
+ def adjust_task_worker(min_server, max_server)
71
+ revision = {min_server => 1, max_server => -1}
72
+ new_ratios = calc_resource_ratios(revision)
73
+
74
+ return unless new_ratios.has_key?(min_server)
75
+ return unless new_ratios.has_key?(max_server)
76
+
77
+ if new_ratios[min_server] < new_ratios[max_server]
78
+ # move worker from max server to min server
79
+ max_workers = @broker.task_workers.select do |worker|
80
+ worker.tuple_space_server == max_server && worker.task_waiting?
81
+ end
82
+ if not(max_workers.empty?)
83
+ max_workers.first.terminate
84
+
85
+ # for degging
86
+ if Pione.debug_mode?
87
+ puts "worker #{worker.uuid} moved from #{max_server} to #{min_server}"
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ module BrokerMethod
95
+ # Adds the tuple space server.
96
+ def add_tuple_space_server(tuple_space_server)
97
+ @tuple_space_server_lock.synchronize do
98
+ @tuple_space_servers << tuple_space_server
99
+ end
100
+ end
101
+
102
+ # Gets a tuple space server by connection id.
103
+ def get_tuple_space_server(connection_id)
104
+ @assignment_table[connection_id]
105
+ end
106
+
107
+ # Return excess number of workers belongs to this broker.
108
+ def excess_task_workers
109
+ @task_worker_resource - @task_workers.size
110
+ end
111
+
112
+ # Return task wainting workers.
113
+ def task_waiting_workers
114
+ @task_workers.select {|worker| worker.status.task_waiting?}
115
+ end
116
+
117
+ # Return task processing workers.
118
+ def task_processing_workers
119
+ @task_workers.select {|worker| worker.status.task_processing?}
120
+ end
121
+
122
+ # Return terminated task workers.
123
+ def terminated_task_workers
124
+ @task_workers.select {|worker| worker.status.terminated?}
125
+ end
126
+
127
+ # Create a task worker for the server.
128
+ def create_task_worker(tuple_space_server)
129
+ connection_id = Util.generate_uuid
130
+ @assignment_table[connection_id] = tuple_space_server
131
+ Agent[:task_worker].spawn(Global.front, connection_id)
132
+ end
133
+
134
+ # Deletes unavilable tuple space servers.
135
+ def check_tuple_space_servers
136
+ @tuple_space_server_lock.synchronize do
137
+ @tuple_space_servers.select! do |ts|
138
+ begin
139
+ timeout(1) { ts.ping }
140
+ rescue Exception
141
+ false
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ # Update tuple space server list.
148
+ def update_tuple_space_servers(tuple_space_servers)
149
+ @tuple_space_server_lock.synchronize do
150
+ del_targets = @tuple_space_servers - tuple_space_servers
151
+ add_targets = tuple_space_servers - @tuple_space_servers
152
+
153
+ # bye
154
+ #del_targets.each do |ts_server|
155
+ # ts_server.write(Tuple[:bye].new(agent_type: agent_type, uuid: uuid))
156
+ #end
157
+ # hello
158
+ #add_targets.each do |ts_server|
159
+ # ts_server.write(Tuple[:agent].new(agent_type: agent_type, uuid: uuid))
160
+ #end
161
+
162
+ # update
163
+ @tuple_space_servers = tuple_space_servers
164
+
165
+ if Global.show_presence_notifier
166
+ timeout(1) do
167
+ puts "broker's tuple space servers: %s" % [@tuple_space_servers]
168
+ end
169
+ end
170
+ end
171
+ rescue Exception
172
+ check_tuple_space_servers
173
+ end
174
+ end
175
+
176
+ include BrokerMethod
177
+
178
+ set_agent_type :broker
179
+
180
+ define_state :count_tuple_space_servers
181
+ define_state :creating_task_worker
182
+ define_state :balancing_task_worker
183
+ define_state :sleeping
184
+ define_state :checking_tuple_space_servers
185
+
186
+ define_state_transition :initialized => :count_tuple_space_servers
187
+ define_state_transition :count_tuple_space_servers => lambda {|agent, res|
188
+ res > 0 ? :balancing_task_worker : :sleeping
189
+ }
190
+ define_state_transition :balancing_task_worker => :sleeping
191
+ define_state_transition :sleeping => :count_tuple_space_servers
192
+ define_state_transition :checking_tuple_space_servers => :count_tuple_space_servers
193
+
194
+ define_exception_handler Exception => :checking_tuple_space_servers
195
+
196
+ attr_accessor :task_workers
197
+ attr_reader :tuple_space_servers
198
+ attr_reader :task_worker_resource
199
+
200
+ # @api private
201
+ def initialize(data={})
202
+ super()
203
+ @task_workers = []
204
+ @tuple_space_servers = []
205
+ @task_worker_resource = data[:task_worker_resource] || 1
206
+ @sleeping_time = data[:sleeping_time] || 1
207
+ @assignment_table = {}
208
+ @tuple_space_server_lock = Mutex.new
209
+
210
+ # balancer
211
+ @balancer = EasyBalancer.new(self)
212
+
213
+ # start agents
214
+ @task_worker_checker = Agent::TrivialRoutineWorker.new(
215
+ Proc.new do
216
+ @task_workers.delete_if do |worker|
217
+ begin
218
+ timeout(3) { worker.terminated? }
219
+ rescue Exception
220
+ true
221
+ end
222
+ end
223
+ sleep 1
224
+ end
225
+ )
226
+ end
227
+
228
+ # @api private
229
+ def start
230
+ super
231
+ @task_worker_checker.start
232
+ end
233
+
234
+ # Sends bye message to tuple space servers when the broker is destroyed.
235
+ def finalize
236
+ @tuple_space_server_lock.synchronize do
237
+ @tuple_space_servers.each do |ts_server|
238
+ begin
239
+ ts_server.bye
240
+ rescue Exception
241
+ # ignore
242
+ end
243
+ end
244
+ end
245
+ super
246
+ end
247
+
248
+ private
249
+
250
+ # @api private
251
+ def transit_to_initialized
252
+ end
253
+
254
+ def transit_to_count_tuple_space_servers
255
+ @tuple_space_servers.size
256
+ end
257
+
258
+ def transit_to_balancing_task_worker
259
+ @balancer.balance
260
+ end
261
+
262
+ def transit_to_checking_tuple_space_servers
263
+ check_tuple_space_servers
264
+ end
265
+
266
+ # Transits to the state +sleeping+.
267
+ def transit_to_sleeping
268
+ sleep 1
269
+ end
270
+ end
271
+
272
+ set_agent Broker
273
+ end
274
+ end
@@ -0,0 +1,47 @@
1
+ module Pione
2
+ module Agent
3
+ class CommandListener < TupleSpaceClient
4
+ set_agent_type :command_listener
5
+
6
+ define_state :waiting_command
7
+ define_state :doing_command
8
+
9
+ define_state_transition :initialized => :waiting_command
10
+ define_state_transition :waiting_command => :doing_command
11
+ define_state_transition :doing_command => :waiting_command
12
+
13
+ define_exception_handler Exception => :error
14
+
15
+ def hello
16
+ end
17
+
18
+ def bye
19
+ end
20
+
21
+ def initialize(tuple_space_server, target)
22
+ @target = target
23
+ super(tuple_space_server)
24
+ end
25
+
26
+ def transit_to_waiting_command
27
+ return read(Tuple[:command].any)
28
+ end
29
+
30
+ def transit_to_doing_command(cmd=nil)
31
+ return unless cmd # the case we got null command
32
+ return unless cmd.kind_of?(Tuple::Command)
33
+ case cmd.type
34
+ when "terminate"
35
+ @target.terminate
36
+ terminate
37
+ end
38
+ end
39
+
40
+ def transit_to_error(e)
41
+ terminate
42
+ end
43
+ end
44
+
45
+ set_agent CommandListener
46
+ end
47
+ end
@@ -0,0 +1,194 @@
1
+ module Pione
2
+ module Agent
3
+ class InputGenerator < TupleSpaceClient
4
+ set_agent_type :input_generator
5
+
6
+ InputData = Struct.new(:name, :uri, :time)
7
+ DOMAIN = "input"
8
+
9
+ # Base class for generator methods.
10
+ class GeneratorMethod
11
+ def initialize(ts_server)
12
+ @tuple_space_server = ts_server
13
+ end
14
+
15
+ def now
16
+ @tuple_space_server.now
17
+ end
18
+
19
+ # Generates an input.
20
+ def generate
21
+ raise RuntimeError
22
+ end
23
+
24
+ # Return true if the generator is stream.
25
+ # @return [Boolean]
26
+ # true if the generator is stream mode
27
+ def stream?
28
+ return false
29
+ end
30
+ end
31
+
32
+ # Directory based generator.
33
+ class DirGeneratorMethod < GeneratorMethod
34
+ # Create a generator.
35
+ # @param [TupleSpaceServer] ts_server
36
+ # tuple space server
37
+ # @param [URI] dir_path
38
+ # directory URI for loading target
39
+ def initialize(ts_server, dir_path)
40
+ raise TypeError.new(dir_path) unless dir_path.kind_of?(URI) or dir_path.nil?
41
+ super(ts_server)
42
+ @dir_path = dir_path
43
+ if dir_path
44
+ @gen = Resource[@dir_path].entries.to_enum
45
+ else
46
+ @gen = [].each
47
+ end
48
+ end
49
+
50
+ def generate
51
+ item = @gen.next
52
+ InputData.new(item.basename, item.uri, item.mtime)
53
+ end
54
+ end
55
+
56
+ # StreamGeneratorMethod handles stream inputs.
57
+ class StreamGeneratorMethod < GeneratorMethod
58
+ def initialize(ts_server, dir_path)
59
+ raise TypeError.new(dir_path) unless dir_path.kind_of?(URI) or dir_path.nil?
60
+ super(ts_server)
61
+ @dir_path = dir_path
62
+ @table = Hash.new
63
+ init
64
+ end
65
+
66
+ def generate
67
+ item = @gen.next
68
+ if generate_new_file?(item.basename, item.mtime)
69
+ @table[item.basename] = item.mtime
70
+ return InputData.new(item.basename, item.uri, item.mtime)
71
+ else
72
+ return nil
73
+ end
74
+ end
75
+
76
+ # Initializes the generator. This method is called when root rule is
77
+ # requested in stream mode.
78
+ # @retrun [void]
79
+ def init
80
+ if @dir_path
81
+ @gen = Resource[@dir_path].entries.to_enum
82
+ else
83
+ @gen = [].each
84
+ end
85
+ end
86
+
87
+ # @api private
88
+ def stream?
89
+ return true
90
+ end
91
+
92
+ private
93
+
94
+ # Return true if it is new file.
95
+ # return [Boolean]
96
+ # return true if the file is new.
97
+ def generate_new_file?(name, mtime)
98
+ return false if ['.', '..'].include?(name)
99
+ return true unless @table.has_key?(name)
100
+ mtime > @table[name]
101
+ end
102
+ end
103
+
104
+ # Create a input generator agent by simple method.
105
+ def self.start_by_simple(ts_server, *args)
106
+ start(ts_server, SimpleGeneratorMethod.new(ts_server, ts_server.base_uri, *args))
107
+ end
108
+
109
+ # Create a input generator agent by directory method.
110
+ def self.start_by_dir(ts_server, *args)
111
+ start(ts_server, DirGeneratorMethod.new(ts_server, *args))
112
+ end
113
+
114
+ # Create a input generator agent by stream method.
115
+ def self.start_by_stream(ts_server, *args)
116
+ start(ts_server, StreamGeneratorMethod.new(ts_server, *args))
117
+ end
118
+
119
+ define_state :generating
120
+ define_state :sleeping
121
+ define_state :stop_iteration
122
+
123
+ define_state_transition :initialized => :reading_base_uri
124
+ define_state_transition :reading_base_uri => :generating
125
+ define_state_transition :generating => :generating
126
+ define_state_transition :stop_iteration => lambda{|agent, res|
127
+ agent.stream? ? :sleeping : :terminated
128
+ }
129
+ define_state_transition :sleeping => :generating
130
+
131
+ define_exception_handler StopIteration => :stop_iteration
132
+
133
+ attr_reader :generator
134
+
135
+ # Initialize the agent.
136
+ def initialize(ts_server, generator)
137
+ raise ArgumentError unless generator.kind_of?(GeneratorMethod)
138
+ super(ts_server)
139
+ @generator = generator
140
+ @inputs = []
141
+ end
142
+
143
+ # Return true if generator of the agent is stream type.
144
+ def stream?
145
+ @generator.stream?
146
+ end
147
+
148
+ private
149
+
150
+ def transit_to_reading_base_uri
151
+ @base_uri = read(Tuple[:base_uri].any).uri
152
+ end
153
+
154
+ # State generating generates a data from generator and puts it into tuple
155
+ # space.
156
+ def transit_to_generating
157
+ if input = @generator.generate
158
+ @inputs << input
159
+ # log
160
+ log do |msg|
161
+ msg.add_record(agent_type, "action", "generate_input_data")
162
+ msg.add_record(agent_type, "uuid", uuid)
163
+ msg.add_record(agent_type, "object", input.name)
164
+ end
165
+ # upload the file
166
+ input_uri = @base_uri + File.join("input", input.name)
167
+ Resource[input_uri].create(Resource[input.uri].read)
168
+ # make the tuple
169
+ write(Tuple[:data].new(DOMAIN, input.name, input_uri, input.time))
170
+ end
171
+ end
172
+
173
+ # State stop_iteration. StopIteration exception is ignored because it
174
+ # means the input generation was completed.
175
+ def transit_to_stop_iteration(e)
176
+ # start root rule
177
+ if not(@inputs.empty?) or not(stream?)
178
+ write(Tuple[:command].new("start-root-rule", nil))
179
+ end
180
+ terminate unless stream?
181
+ end
182
+
183
+ def transit_to_sleeping
184
+ sleep Global.input_generator_stream_check_timespan
185
+
186
+ # init stream generator
187
+ @generator.init
188
+ @inputs = []
189
+ end
190
+ end
191
+
192
+ set_agent InputGenerator
193
+ end
194
+ end