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,60 @@
1
+ module Pione
2
+ module TupleSpaceServerInterface
3
+
4
+ # Define tuple space operation.
5
+ def self.tuple_space_operation(name)
6
+ define_method(name) do |*args, &b|
7
+ @__tuple_space_server__.__send__(name, *args, &b)
8
+ end
9
+ end
10
+
11
+ # define tuple space operations
12
+ tuple_space_operation :read
13
+ tuple_space_operation :read_all
14
+ tuple_space_operation :take
15
+ tuple_space_operation :write
16
+ tuple_space_operation :count_tuple
17
+ tuple_space_operation :notify
18
+
19
+ # Return the tuple space server.
20
+ def tuple_space_server
21
+ @__tuple_space_server__
22
+ end
23
+
24
+ private
25
+
26
+ # Reads a tuple without waiting.
27
+ # @return [Tuple]
28
+ def read0(tuple)
29
+ read(tuple, 0)
30
+ end
31
+
32
+ # Takes a tuple without wainting.
33
+ # @return [Tuple]
34
+ def take0(tuple)
35
+ take(tuple, 0)
36
+ end
37
+
38
+ # Log a message.
39
+ # @return [void]
40
+ def log
41
+ msg = Log.new
42
+ yield msg
43
+ write(Tuple[:log].new(msg))
44
+ end
45
+
46
+ # Set tuple space server which provides operations.
47
+ # @return [void]
48
+ def set_tuple_space_server(server)
49
+ @__tuple_space_server__ = server
50
+
51
+ # override #to_s as it's uri because dead remote objects cause exceptions
52
+ # when you try to watch the object
53
+ if server.methods.include?(:__drburi)
54
+ def @__tuple_space_server__.to_s
55
+ __drburi
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,156 @@
1
+ module Pione
2
+ module TupleSpace
3
+ module TupleSpaceServerMethod
4
+ def self.tuple_space_interface(name, opt={})
5
+ define_method(name) do |*args, &b|
6
+ # convert tuple space form
7
+ _args = args.map do |obj|
8
+ tuple_form = obj.respond_to?(:to_tuple_space_form)
9
+ tuple_form ? obj.to_tuple_space_form : obj
10
+ end
11
+ # check arguments
12
+ if opt.has_key?(:validator)
13
+ opt[:validator].call(args)
14
+ end
15
+ # send a message to the tuple space
16
+ result = @ts.__send__(name, *_args, &b)
17
+ # convert the result to tuple object
18
+ if converter = opt[:result]
19
+ converter.call(result)
20
+ else
21
+ result
22
+ end
23
+ end
24
+ end
25
+
26
+ # Define tuple space interfaces.
27
+ tuple_space_interface :read, :result => lambda{|t|
28
+ Tuple.from_array(t).tap{|x| x.timestamp = t.timestamp}
29
+ }
30
+ tuple_space_interface :read_all, :result => lambda{|list|
31
+ list.map{|t|
32
+ Tuple.from_array(t).tap{|x| x.timestamp = t.timestamp}
33
+ }
34
+ }
35
+ tuple_space_interface :take, :result => lambda{|t|
36
+ Tuple.from_array(t).tap{|x| x.timestamp = t.timestamp}
37
+ }
38
+ tuple_space_interface :write, :validator => Proc.new {|*args|
39
+ args.first.writable? if args.first.kind_of?(Tuple::BasicTuple)
40
+ }, :result => lambda{|t|
41
+ # don't return raw tuple entry in PIONE
42
+ nil
43
+ }
44
+ tuple_space_interface :notify
45
+ end
46
+
47
+ class TupleSpaceServer < PioneObject
48
+ include DRbUndumped
49
+ include TupleSpaceServerMethod
50
+
51
+ attr_reader :tuple_space
52
+
53
+ def initialize(data={})
54
+ @__ts__ = Rinda::TupleSpace.new
55
+ @tuple_space = @__ts__
56
+ @ts = Rinda::TupleSpaceProxy.new(@__ts__)
57
+ def @ts.to_s;"#<Rinda::TupleSpace>" end
58
+
59
+ # check task worker resource
60
+ resource = data[:task_worker_resource] || 1
61
+ write(Tuple[:task_worker_resource].new(number: resource))
62
+
63
+ @terminated = false
64
+
65
+ # base uri
66
+ if data.has_key?(:base_uri)
67
+ uri = data[:base_uri]
68
+ write(Tuple[:base_uri].new(uri: uri))
69
+ end
70
+
71
+ # start agents
72
+ @client_life_checker = Agent::TupleSpaceServerClientLifeChecker.start(self)
73
+ end
74
+
75
+ def set_base_uri(uri)
76
+ write(Tuple[:base_uri].new(uri: uri))
77
+ end
78
+
79
+ def drburi
80
+ @remote_object ||= DRb.start_service(nil, self)
81
+ @remote_object.__drburi
82
+ end
83
+
84
+ def alive?
85
+ not(@terminated)
86
+ end
87
+
88
+ # Return pid
89
+ def pid
90
+ Process.pid
91
+ end
92
+
93
+ def now
94
+ Time.now
95
+ end
96
+
97
+ # Return common base uri of the space.
98
+ def base_uri
99
+ URI.parse(read(Tuple[:base_uri].any).uri)
100
+ end
101
+
102
+ # Return the worker resource size of the server.
103
+ def task_worker_resource
104
+ read(Tuple[:task_worker_resource].any).number
105
+ end
106
+
107
+ # Return the number of tuples matched with specified tuple.
108
+ def count_tuple(tuple)
109
+ read_all(tuple).size
110
+ end
111
+
112
+ # Return the current worker size of the server.
113
+ def current_task_worker_size
114
+ tuple = Tuple[:agent].any
115
+ tuple.agent_type = :task_worker
116
+ read_all(tuple).size
117
+ end
118
+
119
+ # Return all tuples of the tuple space.
120
+ def all_tuples(*args)
121
+ @__ts__.all_tuples(*args).compact
122
+ end
123
+
124
+ def task_size
125
+ @__ts__.task_size
126
+ end
127
+
128
+ def working_size
129
+ @__ts__.working_size
130
+ end
131
+
132
+ def finished_size
133
+ @__ts__.finished_size
134
+ end
135
+
136
+ def data_size
137
+ @__ts__.data_size
138
+ end
139
+
140
+ # Shutdown the server.
141
+ def finalize
142
+ @terminated = true
143
+ write(Tuple[:command].new("terminate", nil))
144
+ @client_life_checker.terminate
145
+ @client_life_checker.running_thread.join
146
+ sleep 1
147
+ end
148
+
149
+ alias :terminate :finalize
150
+
151
+ def inspect
152
+ "#<Pione::TupleSpace::TupleSpaceServer:%s>" % object_id
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,96 @@
1
+ # UpdateCriteria repesents rule application criteria.
2
+ module Pione::UpdateCriteria
3
+ class << self
4
+ # Return true if we need to update because of no output rule.
5
+ # @param [Rule] rule
6
+ # rule
7
+ # @param [Tuple::Data] inputs
8
+ # input tuples
9
+ # @param [Tuple::Data] outputs
10
+ # output tuples
11
+ # @param [VariableTable] vtable
12
+ # variable table
13
+ # @return [Boolean]
14
+ # true if outputs are empty
15
+ def no_output_rules?(rule, inputs, outputs, vtable)
16
+ rule.outputs.empty?
17
+ end
18
+
19
+ # Return true if we need to update because of lacking some ouputs.
20
+ # @param [Rule] rule
21
+ # rule
22
+ # @param [Tuple::Data] inputs
23
+ # input tuples
24
+ # @param [Tuple::Data] outputs
25
+ # output tuples
26
+ # @param [VariableTable] vtable
27
+ # variable table
28
+ # @return [Boolean]
29
+ # true if some outputs lack
30
+ def not_exist_output?(rule, inputs, outputs, vtable)
31
+ return true if outputs.empty?
32
+ result = false
33
+ rule.outputs.each_with_index do |data_expr, i|
34
+ data_expr = data_expr.eval(vtable)
35
+ case data_expr.modifier
36
+ when :all
37
+ if outputs[i].select{|data| data_expr.match(data.name)}.empty?
38
+ result = true
39
+ end
40
+ when :each
41
+ unless data_expr.match(outputs[i].name)
42
+ result = true
43
+ end
44
+ end
45
+ break if result
46
+ end
47
+ return result
48
+ end
49
+
50
+ # Return true if we need to update because of newer inputs.
51
+ # @param [Rule] rule
52
+ # rule
53
+ # @param [Tuple::Data] inputs
54
+ # input tuples
55
+ # @param [Tuple::Data] outputs
56
+ # output tuples
57
+ # @param [VariableTable] vtable
58
+ # variable table
59
+ # @return [Boolean]
60
+ # true if inputs are newer than outputs
61
+ def exist_newer_input?(rule, inputs, outputs, vtable)
62
+ # get output oldest time
63
+ output_oldest_time = outputs.flatten.map{|output| output.time}.sort.last
64
+
65
+ # get input last time
66
+ input_last_time = inputs.flatten.map{|input| input.time}.sort.last
67
+
68
+ # criteria
69
+ return false unless output_oldest_time
70
+ return false unless input_last_time
71
+ return output_oldest_time < input_last_time
72
+ end
73
+
74
+ # Returns true if we need to update.
75
+ # @param [Rule] rule
76
+ # rule
77
+ # @param [Tuple::Data] inputs
78
+ # input tuples
79
+ # @param [Tuple::Data] outputs
80
+ # output tuples
81
+ # @param [VariableTable] vtable
82
+ # variable table
83
+ # @return [Boolean]
84
+ # true if inputs are newer than outputs
85
+ def satisfy?(rule, inputs, outputs, vtable)
86
+ CRITERIAS.any?{|name| self.send(name, rule, inputs, outputs, vtable)}
87
+ end
88
+
89
+ # @api private
90
+ CRITERIAS = [
91
+ :no_output_rules?,
92
+ :not_exist_output?,
93
+ :exist_newer_input?
94
+ ]
95
+ end
96
+ end
@@ -0,0 +1,10 @@
1
+ module Pione
2
+ module Tuple
3
+ # AgentTuple represents agents information in a tuple space server.
4
+ class AgentTuple < BasicTuple
5
+ # uuid : uuid of the agent
6
+ # agent_type : agent type
7
+ define_format [:agent, :uuid, :agent_type]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Pione
2
+ module Tuple
3
+ class AttributeTuple < BasicTuple
4
+ define_format [:attribute, [:key, String], :value]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Pione
2
+ module Tuple
3
+ # BaseURITuple represents base location information of resource.
4
+ class BaseURITuple < BasicTuple
5
+ # base uri of all resources on the server
6
+ define_format [:base_uri, :uri]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,317 @@
1
+ module Pione
2
+ module Tuple
3
+ # tuple type table
4
+ # @api private
5
+ TABLE = Hash.new
6
+
7
+ # FormatError is raised when tuple format is invalid.
8
+ class FormatError < StandardError
9
+ # Creates an error.
10
+ # @param [Array<Object>] invalid_data
11
+ # invalid data
12
+ # @param [Symbol] identifier
13
+ # tuple identifier
14
+ def initialize(invalid_data, identifier=nil)
15
+ @invalid_data = invalid_data
16
+ @identifier = identifier
17
+ end
18
+
19
+ # Returns a message of this error.
20
+ # @return [String]
21
+ # message string with invalid data and tuple identifier
22
+ # @api private
23
+ def message
24
+ msg = @invalid_data.inspect
25
+ msg += " in %s" % @identifier if @identifier
26
+ return msg
27
+ end
28
+ end
29
+
30
+ # Type represents tuple's field data type. Type has simple and complex form,
31
+ # the latter is consisted by types or-relation. The method +===+ is used by
32
+ # matching field data and type.
33
+ # @example
34
+ # # create simple type
35
+ # simple_type = Type.new(String)
36
+ # simple_type === "abc" #=> true
37
+ # # create complex type
38
+ # complex_type = Type.new(String, Symbol)
39
+ # complex_type === "abc" #=> true
40
+ # complex_type === :abc #=> true
41
+ class Type < PioneObject
42
+ class << self
43
+ alias :or :new
44
+ end
45
+
46
+ # Creates a tuple field type.
47
+ # @param [Array<Object>] types
48
+ # tuple field types
49
+ def initialize(*types)
50
+ raise ArgumentError.new(types) unless types.size > 0
51
+ @types = types
52
+ end
53
+
54
+ # Returns true if the type is simple.
55
+ # @return [Boolean]
56
+ # true if the type is simple, or false
57
+ def simple?
58
+ @types.size == 1
59
+ end
60
+
61
+ # Returns true if the type is complex.
62
+ # @return [Boolean]
63
+ # true if the type is complex, or false
64
+ def complex?
65
+ not(simple?)
66
+ end
67
+
68
+ # @api private
69
+ def ===(other)
70
+ @types.find {|t| t === other}
71
+ end
72
+ end
73
+
74
+ module TupleDefinition
75
+ # Defines a tuple format and create a class representing it.
76
+ # @return [void]
77
+ def define_format(format)
78
+ raise ScriptError if @format
79
+ @format = format
80
+
81
+ identifier = format.first
82
+ set_attr_accessors
83
+
84
+ # check arguments: format is a list of symbols
85
+ format.each do |name, _|
86
+ unless Symbol === name
87
+ raise FormatError.new(name, identifier)
88
+ end
89
+ end
90
+
91
+ # forbid to define same identifier and different format
92
+ if TABLE.has_key?(identifier)
93
+ if not(TABLE[identifier].format == format)
94
+ raise FormatError.new(format, identifier)
95
+ else
96
+ return TABLE[identifier]
97
+ end
98
+ end
99
+
100
+ # make a class and set it in a table
101
+ TABLE[identifier] = self
102
+ end
103
+
104
+ # Deletes a tuple format definition.
105
+ # @return [void]
106
+ def delete_format(identifier)
107
+ if TABLE.has_key?(identifier)
108
+ name = TABLE[identifier].name.split('::').last
109
+ TABLE.delete(identifier)
110
+ remove_const(name)
111
+ end
112
+ end
113
+
114
+ # Returns tuple's format.
115
+ # @return [Array]
116
+ # tuple's format
117
+ def format
118
+ @format
119
+ end
120
+
121
+ # Returns the identifier.
122
+ # @return [Symbol]
123
+ # identifier of the tuple
124
+ def identifier
125
+ @format.first
126
+ end
127
+
128
+ # Returns a respresentation for matching any tuples of same type.
129
+ # @return [TupleObject]
130
+ # a query tuple that matches any tuples has the identifier
131
+ def any
132
+ new
133
+ end
134
+
135
+ # Returns domain position of the format.
136
+ # @return [Integer, nil]
137
+ # position number of domain field, or nil
138
+ # @api private
139
+ def domain_position
140
+ position_of(:domain)
141
+ end
142
+
143
+ # Returns uri position of the format.
144
+ # @return [Integer, nil]
145
+ # position number of URI field, or nil
146
+ # @api private
147
+ def uri_position
148
+ position_of(:uri)
149
+ end
150
+
151
+ private
152
+
153
+ # Sets the tuple format and creates accessor methods.
154
+ # @param [Array] definition
155
+ # tuple format
156
+ # @return [void]
157
+ def set_attr_accessors
158
+ @format.each do |key, _|
159
+ define_method(key) {@data[key]}
160
+ define_method("%s=" % key) {|val| @data[key] = val}
161
+ end
162
+ end
163
+
164
+ # @api private
165
+ def position_of(name)
166
+ @format.each_with_index do |key, i|
167
+ key = key.kind_of?(Array) ? key.first : key
168
+ return i if key == name
169
+ end
170
+ return nil
171
+ end
172
+ end
173
+
174
+ # TupleObject is a superclass for all tuple classes.
175
+ class BasicTuple < PioneObject
176
+ def self.inherited(klass)
177
+ klass.extend TupleDefinition
178
+ end
179
+
180
+ attr_accessor :timestamp
181
+
182
+ # Creates new tuple object.
183
+ # @param [Hash] data
184
+ # tuple data
185
+ def initialize(*data)
186
+ @data = {}
187
+ return if data.empty?
188
+
189
+ format = self.class.format
190
+ format_keys = format.map{|key,_| key}
191
+ format_table = Hash[*format[1..-1].select{|item|
192
+ item.kind_of?(Array)
193
+ }.flatten(1)]
194
+ if data.first.kind_of?(Hash)
195
+ _data = data.first
196
+ _data.keys.each do |key|
197
+ # key check
198
+ unless format_keys.include?(key)
199
+ raise FormatError.new(key, format.first)
200
+ end
201
+ # type check
202
+ if _data[key] && not(format_table[key].nil?)
203
+ unless format_table[key] === _data[key]
204
+ raise FormatError.new(_data[key], format.first)
205
+ end
206
+ end
207
+ end
208
+ @data = _data
209
+ else
210
+ # length check
211
+ unless data.size == format.size - 1
212
+ raise FormatError.new(data, format.first)
213
+ end
214
+ # type check
215
+ data.each_with_index do |key, i|
216
+ if format[i+1].kind_of?(Array)
217
+ # type specified
218
+ unless format[i+1][1] === data[i] or data[i].nil?
219
+ raise FormatError.new(data[i], format.first)
220
+ end
221
+ end
222
+ end
223
+ @data = Hash[format_keys[1..-1].zip(data)]
224
+ end
225
+ end
226
+
227
+ # @api private
228
+ def ==(other)
229
+ return false unless self.class == other.class
230
+ to_tuple_space_form == other.to_tuple_space_form
231
+ end
232
+
233
+ alias :eql? :"=="
234
+
235
+ # @api private
236
+ def hash
237
+ @data.hash
238
+ end
239
+
240
+ # Returns the identifier.
241
+ # @return [Symbol]
242
+ # tuple identifier
243
+ def identifier
244
+ self.class.identifier
245
+ end
246
+
247
+ # Converts the tuple to string form.
248
+ # @api private
249
+ def to_s
250
+ "#<#<#{self.class.name}> #{to_tuple_space_form.to_s}>"
251
+ end
252
+
253
+ # Convert to plain tuple form.
254
+ # @return [Array<Object>]
255
+ # tuple data array for Rinda's tuple space
256
+ def to_tuple_space_form
257
+ self.class.format[1..-1].map{|key, _| @data[key]}.unshift(identifier)
258
+ end
259
+
260
+ # Converts the tuple to json form.
261
+ # @return [String]
262
+ # json form of the tuple
263
+ def to_json(*a)
264
+ @data.merge({"tuple" => self.class.identifier}).to_json(*a)
265
+ end
266
+
267
+ # Returns the value of the specified position.
268
+ # @param [Integer] i
269
+ # field position to get
270
+ # @return
271
+ # the value
272
+ def value(i = 0)
273
+ @data[i]
274
+ end
275
+
276
+ # Returns true if the field writable.
277
+ # @return [Boolean]
278
+ def writable?
279
+ self.class.format.map do |symbol|
280
+ @data.has_key?(symbol)
281
+ end.unique == [true]
282
+ end
283
+ end
284
+
285
+ class << self
286
+ # Returns a tuple class corresponding to a tuple identifier.
287
+ # @return [Class]
288
+ # tuple class
289
+ def [](identifier)
290
+ TABLE[identifier]
291
+ end
292
+
293
+ # Returns identifiers.
294
+ # @return [Array<Symbol>]
295
+ # all tuple identifiers in PIONE system.
296
+ def identifiers
297
+ TABLE.keys
298
+ end
299
+
300
+ # Return a tuple data object converted from an array.
301
+ # @return [TupleObject]
302
+ # tuple object
303
+ def from_array(ary)
304
+ raise FormatError.new(ary) unless ary.size > 0
305
+ raise FormatError.new(ary) unless ary.kind_of?(Enumerable)
306
+ _ary = ary.to_a
307
+ identifier = _ary.first
308
+ raise FormatError.new(identifier) unless TABLE.has_key?(identifier)
309
+ args = _ary[1..-1]
310
+ TABLE[identifier].new(*args)
311
+ end
312
+ end
313
+
314
+ # parent_agent: agent tree information
315
+ # define_format [:parent_agent, :parent_id, :child_id]
316
+ end
317
+ end