pione 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (304) hide show
  1. data/.gitignore +2 -0
  2. data/.s3cfg +42 -0
  3. data/.travis.yml +18 -4
  4. data/.yardopts +1 -0
  5. data/Gemfile +3 -0
  6. data/History.txt +14 -0
  7. data/Procfile +7 -0
  8. data/Rakefile +25 -0
  9. data/bin/pione-interactive +6 -0
  10. data/bin/{pione-compiler → pione-notification-listener} +1 -1
  11. data/bin/{pione-broker → pione-task-worker-broker} +1 -1
  12. data/doc/man/pione-list-param.md +36 -0
  13. data/example/ActionError/ActionError.pione +9 -0
  14. data/example/ActionError/pione-package.json +15 -0
  15. data/example/CountChar/CountChar.pione +1 -1
  16. data/example/ScoreAggregation/ScoreAggregation.pione +1 -1
  17. data/example/Touch/pione-package.json +15 -0
  18. data/lib/pione.rb +12 -0
  19. data/lib/pione/agent.rb +3 -3
  20. data/lib/pione/agent/basic-agent.rb +10 -4
  21. data/lib/pione/agent/input-generator.rb +3 -3
  22. data/lib/pione/agent/{process-manager.rb → job-manager.rb} +10 -7
  23. data/lib/pione/agent/job-terminator.rb +2 -2
  24. data/lib/pione/agent/logger.rb +3 -3
  25. data/lib/pione/agent/messenger.rb +20 -9
  26. data/lib/pione/agent/notification-listener.rb +88 -0
  27. data/lib/pione/agent/task-worker-broker.rb +84 -0
  28. data/lib/pione/agent/task-worker.rb +3 -2
  29. data/lib/pione/agent/tuple-space-client.rb +1 -0
  30. data/lib/pione/agent/tuple-space-provider.rb +17 -35
  31. data/lib/pione/command.rb +33 -15
  32. data/lib/pione/command/action.rb +105 -0
  33. data/lib/pione/command/basic-command.rb +34 -376
  34. data/lib/pione/command/command-exception.rb +12 -11
  35. data/lib/pione/command/common.rb +198 -0
  36. data/lib/pione/command/option.rb +159 -204
  37. data/lib/pione/command/pione-action-exec.rb +85 -0
  38. data/lib/pione/command/pione-action-list.rb +43 -19
  39. data/lib/pione/command/pione-action-print.rb +79 -0
  40. data/lib/pione/command/pione-action.rb +8 -67
  41. data/lib/pione/command/pione-clean.rb +88 -68
  42. data/lib/pione/command/pione-client.rb +475 -332
  43. data/lib/pione/command/pione-command.rb +14 -31
  44. data/lib/pione/command/pione-compile.rb +90 -0
  45. data/lib/pione/command/pione-config-get.rb +53 -0
  46. data/lib/pione/command/pione-config-list.rb +64 -0
  47. data/lib/pione/command/pione-config-set.rb +59 -0
  48. data/lib/pione/command/pione-config-unset.rb +50 -0
  49. data/lib/pione/command/pione-config.rb +61 -0
  50. data/lib/pione/command/pione-diagnosis-notification.rb +235 -0
  51. data/lib/pione/command/pione-diagnosis.rb +21 -0
  52. data/lib/pione/command/pione-interactive.rb +188 -0
  53. data/lib/pione/command/pione-lang-check-syntax.rb +163 -0
  54. data/lib/pione/command/pione-lang-interactive.rb +146 -0
  55. data/lib/pione/command/pione-lang.rb +22 -0
  56. data/lib/pione/command/pione-log-format.rb +163 -0
  57. data/lib/pione/command/pione-log-list-id.rb +48 -0
  58. data/lib/pione/command/pione-log.rb +19 -101
  59. data/lib/pione/command/pione-notification-listener.rb +95 -0
  60. data/lib/pione/command/pione-package-add.rb +137 -0
  61. data/lib/pione/command/pione-package-build.rb +122 -0
  62. data/lib/pione/command/pione-package-show.rb +96 -0
  63. data/lib/pione/command/pione-package-update.rb +59 -0
  64. data/lib/pione/command/pione-package.rb +11 -139
  65. data/lib/pione/command/pione-task-worker-broker.rb +88 -0
  66. data/lib/pione/command/pione-task-worker.rb +148 -98
  67. data/lib/pione/command/pione-tuple-space-provider.rb +62 -54
  68. data/lib/pione/command/pione-tuple-space-viewer.rb +105 -83
  69. data/lib/pione/command/pione-val.rb +39 -39
  70. data/lib/pione/command/spawner.rb +34 -27
  71. data/lib/pione/front.rb +4 -2
  72. data/lib/pione/front/basic-front.rb +86 -23
  73. data/lib/pione/front/client-front.rb +2 -2
  74. data/lib/pione/front/diagnosis-notification-front.rb +40 -0
  75. data/lib/pione/front/front-exception.rb +7 -1
  76. data/lib/pione/front/notification-listener-front.rb +36 -0
  77. data/lib/pione/front/notification-recipient-interface.rb +19 -0
  78. data/lib/pione/front/relay-front.rb +4 -4
  79. data/lib/pione/front/task-worker-broker-front.rb +19 -0
  80. data/lib/pione/front/task-worker-front.rb +2 -2
  81. data/lib/pione/front/tuple-space-provider-front.rb +3 -2
  82. data/lib/pione/global.rb +3 -1
  83. data/lib/pione/global/client-variable.rb +1 -1
  84. data/lib/pione/global/config.rb +63 -7
  85. data/lib/pione/global/diagnosis-variable.rb +26 -0
  86. data/lib/pione/global/item.rb +28 -5
  87. data/lib/pione/global/log-variable.rb +6 -5
  88. data/lib/pione/global/network-variable.rb +75 -4
  89. data/lib/pione/global/path-variable.rb +1 -1
  90. data/lib/pione/global/system-variable.rb +12 -12
  91. data/lib/pione/global/task-worker-broker-variable.rb +43 -0
  92. data/lib/pione/global/tuple-space-notifier-variable.rb +3 -55
  93. data/lib/pione/lang/boolean.rb +4 -0
  94. data/lib/pione/lang/data-expr.rb +1 -1
  95. data/lib/pione/lang/integer.rb +1 -1
  96. data/lib/pione/lang/string.rb +4 -0
  97. data/lib/pione/lang/type.rb +1 -1
  98. data/lib/pione/location.rb +1 -0
  99. data/lib/pione/location/data-location.rb +41 -13
  100. data/lib/pione/location/dropbox-location.rb +175 -56
  101. data/lib/pione/location/ftp-location.rb +4 -1
  102. data/lib/pione/location/http-location.rb +5 -3
  103. data/lib/pione/location/https-location.rb +4 -2
  104. data/lib/pione/location/local-location.rb +6 -3
  105. data/lib/pione/location/location-exception.rb +12 -0
  106. data/lib/pione/location/notification-scheme.rb +46 -0
  107. data/lib/pione/log.rb +8 -7
  108. data/lib/pione/log/debug.rb +9 -9
  109. data/lib/pione/log/domain-log.rb +6 -1
  110. data/lib/pione/log/message-log-receiver.rb +32 -0
  111. data/lib/pione/log/system-log.rb +62 -141
  112. data/lib/pione/model.rb +7 -0
  113. data/lib/pione/model/notification-listener-model.rb +29 -0
  114. data/lib/pione/model/task-worker-broker-model.rb +129 -0
  115. data/lib/pione/notification.rb +13 -0
  116. data/lib/pione/notification/address.rb +104 -0
  117. data/lib/pione/notification/exception.rb +10 -0
  118. data/lib/pione/notification/message.rb +109 -0
  119. data/lib/pione/notification/receiver.rb +90 -0
  120. data/lib/pione/notification/recipient.rb +68 -0
  121. data/lib/pione/notification/task-worker-broker-recipient.rb +85 -0
  122. data/lib/pione/notification/transmitter.rb +84 -0
  123. data/lib/pione/pnml.rb +35 -0
  124. data/lib/pione/pnml/annotation-extractor.rb +47 -0
  125. data/lib/pione/pnml/compiler.rb +176 -0
  126. data/lib/pione/pnml/input-merge-complement.rb +78 -0
  127. data/lib/pione/pnml/input-parallelization-complement.rb +75 -0
  128. data/lib/pione/pnml/input-reduction.rb +80 -0
  129. data/lib/pione/pnml/invalid-arc-elimination.rb +41 -0
  130. data/lib/pione/pnml/io-expansion.rb +88 -0
  131. data/lib/pione/pnml/isolated-element-elimination.rb +32 -0
  132. data/lib/pione/pnml/net-rewriter.rb +44 -0
  133. data/lib/pione/pnml/output-decomposition-complement.rb +77 -0
  134. data/lib/pione/pnml/output-reduction.rb +86 -0
  135. data/lib/pione/pnml/output-synchronization-complement.rb +77 -0
  136. data/lib/pione/pnml/pione-model.rb +417 -0
  137. data/lib/pione/pnml/pnml-exception.rb +23 -0
  138. data/lib/pione/pnml/pnml-model.rb +368 -0
  139. data/lib/pione/pnml/reader.rb +51 -0
  140. data/lib/pione/rule-engine/action-handler.rb +8 -6
  141. data/lib/pione/rule-engine/basic-handler.rb +5 -5
  142. data/lib/pione/rule-engine/engine-exception.rb +7 -6
  143. data/lib/pione/rule-engine/flow-handler.rb +27 -18
  144. data/lib/pione/system.rb +3 -1
  145. data/lib/pione/system/domain-dump.rb +34 -0
  146. data/lib/pione/system/file-cache.rb +92 -13
  147. data/lib/pione/system/init.rb +3 -0
  148. data/lib/pione/system/normalizer.rb +40 -0
  149. data/lib/pione/system/status.rb +5 -5
  150. data/lib/pione/system/system-exception.rb +14 -1
  151. data/lib/pione/task-worker-broker.rb +7 -0
  152. data/lib/pione/task-worker-broker/basic-provider.rb +20 -0
  153. data/lib/pione/task-worker-broker/easy-provider.rb +65 -0
  154. data/lib/pione/test-helper.rb +27 -0
  155. data/lib/pione/test-helper/command-helper.rb +9 -101
  156. data/lib/pione/tuple-space/basic-tuple.rb +1 -1
  157. data/lib/pione/tuple-space/tuple-definition.yml +4 -6
  158. data/lib/pione/tuple-space/tuple-space-interface.rb +3 -45
  159. data/lib/pione/tuple-space/tuple-space-server.rb +45 -0
  160. data/lib/pione/util.rb +1 -2
  161. data/lib/pione/util/boolean-value.rb +62 -0
  162. data/lib/pione/util/completion.rb +111 -0
  163. data/lib/pione/util/evaluatable.rb +13 -27
  164. data/lib/pione/util/package-parameters-list.rb +15 -27
  165. data/lib/pione/util/zip.rb +8 -3
  166. data/lib/pione/version.rb +1 -1
  167. data/lib/rootage.rb +20 -0
  168. data/lib/rootage/action.rb +114 -0
  169. data/lib/rootage/argument.rb +46 -0
  170. data/lib/rootage/command.rb +218 -0
  171. data/lib/rootage/core.rb +532 -0
  172. data/lib/rootage/exception.rb +107 -0
  173. data/lib/rootage/help.rb +148 -0
  174. data/lib/rootage/help.txt.erb +31 -0
  175. data/lib/rootage/log.rb +226 -0
  176. data/lib/rootage/normalizer.rb +184 -0
  177. data/lib/rootage/option.rb +152 -0
  178. data/lib/rootage/scenario-test-result.erb +39 -0
  179. data/lib/rootage/scenario.rb +362 -0
  180. data/lib/rootage/test-helper.rb +115 -0
  181. data/man/pione-list-param.1 +44 -0
  182. data/misc/clock.rb +9 -0
  183. data/misc/machine-info.sh +21 -0
  184. data/misc/pione-completion.bash +238 -0
  185. data/misc/pione-completion.erb +53 -0
  186. data/misc/pione-completion.zsh +238 -0
  187. data/misc/pione.god +22 -0
  188. data/misc/ui.xml +23 -0
  189. data/pione.gemspec +3 -1
  190. data/test/agent/spec_basic-agent.rb +1 -1
  191. data/test/agent/spec_input-generator.rb +2 -2
  192. data/test/agent/spec_messenger.rb +6 -9
  193. data/test/agent/spec_notification-listener.rb +80 -0
  194. data/test/agent/{spec_broker.rb → spec_task-worker-broker.rb} +13 -10
  195. data/test/agent/spec_tuple-space-provider.rb +10 -6
  196. data/test/command/command-behavior.rb +3 -11
  197. data/test/command/data/pione-list-param/AdvancedParameters.pione +12 -0
  198. data/test/command/data/pione-list-param/BasicParameters.pione +12 -0
  199. data/test/command/spec_pione-action-exec.rb +16 -0
  200. data/test/command/spec_pione-action-list.rb +15 -10
  201. data/test/command/spec_pione-action-print.rb +14 -0
  202. data/test/command/spec_pione-action.rb +6 -19
  203. data/test/command/spec_pione-clean.rb +29 -46
  204. data/test/command/spec_pione-client.rb +29 -36
  205. data/test/command/spec_pione-command.rb +6 -6
  206. data/test/command/{spec_pione-compiler.rb → spec_pione-compile.rb} +11 -13
  207. data/test/command/spec_pione-config-get.rb +47 -0
  208. data/test/command/spec_pione-config-list.rb +42 -0
  209. data/test/command/spec_pione-config-set.rb +38 -0
  210. data/test/command/spec_pione-config-unset.rb +44 -0
  211. data/test/command/spec_pione-config.rb +11 -0
  212. data/test/command/spec_pione-diagnosis-notification.rb +23 -0
  213. data/test/command/spec_pione-diagnosis.rb +11 -0
  214. data/test/command/spec_pione-lang-check-syntax.rb +12 -0
  215. data/test/command/spec_pione-lang.rb +11 -0
  216. data/test/command/spec_pione-log-format.rb +29 -0
  217. data/test/command/spec_pione-log-list-id.rb +17 -0
  218. data/test/command/spec_pione-log.rb +6 -20
  219. data/test/command/spec_pione-package-add.rb +55 -0
  220. data/test/command/spec_pione-package-build.rb +57 -0
  221. data/test/command/spec_pione-package-show.rb +72 -0
  222. data/test/command/{spec_pione-update-package-info.rb → spec_pione-package-update.rb} +12 -13
  223. data/test/command/spec_pione-package.rb +4 -104
  224. data/test/command/spec_pione-val.rb +10 -7
  225. data/test/global/spec_config.rb +50 -0
  226. data/test/global/spec_item.rb +1 -1
  227. data/test/literate-action/data/HelloWorld.md +1 -1
  228. data/test/location/location-behavior.rb +1 -1
  229. data/test/location/spec_dropbox-location.rb +39 -0
  230. data/test/location/spec_notification-scheme.rb +37 -0
  231. data/test/log/spec_debug.rb +5 -4
  232. data/test/log/spec_message-log-receiver.rb +13 -0
  233. data/test/log/spec_message-log.rb +6 -9
  234. data/test/log/spec_system-log.rb +5 -3
  235. data/test/notification/spec_address.rb +229 -0
  236. data/test/notification/spec_message.rb +30 -0
  237. data/test/notification/spec_receiver.rb +36 -0
  238. data/test/notification/spec_transmitter.rb +37 -0
  239. data/test/pnml/data/ConditionalBranchIf.pnml +270 -0
  240. data/test/pnml/data/ConditionalBranchIfElse.pnml +309 -0
  241. data/test/pnml/data/IOExpansionComplex.pnml +363 -0
  242. data/test/pnml/data/IOExpansionSimple.pnml +140 -0
  243. data/test/pnml/data/InputMergeComplementComplex.pnml +381 -0
  244. data/test/pnml/data/InputMergeComplementSimple.pnml +248 -0
  245. data/test/pnml/data/InputParallelizationComplementComplex.pnml +433 -0
  246. data/test/pnml/data/InputParallelizationComplementSimple.pnml +288 -0
  247. data/test/pnml/data/InputReductionComplex.pnml +192 -0
  248. data/test/pnml/data/InputReductionLong.pnml +344 -0
  249. data/test/pnml/data/InputReductionSimple.pnml +140 -0
  250. data/test/pnml/data/IsolatedElementElimination.pnml +171 -0
  251. data/test/pnml/data/OutputDecompositionComplementComplex.pnml +381 -0
  252. data/test/pnml/data/OutputDecompositionComplementSimple.pnml +242 -0
  253. data/test/pnml/data/OutputReductionComplex.pnml +186 -0
  254. data/test/pnml/data/OutputReductionLong.pnml +344 -0
  255. data/test/pnml/data/OutputReductionSimple.pnml +140 -0
  256. data/test/pnml/data/OutputSynchronizationComplementComplex.pnml +498 -0
  257. data/test/pnml/data/OutputSynchronizationComplementSimple.pnml +347 -0
  258. data/test/pnml/data/SampleNet.pnml +238 -0
  259. data/test/pnml/spec_input-merge-complement.rb +40 -0
  260. data/test/pnml/spec_input-parallelization-complement.rb +50 -0
  261. data/test/pnml/spec_input-reduction.rb +113 -0
  262. data/test/pnml/spec_invalid-arc-elimination.rb +33 -0
  263. data/test/pnml/spec_io-expansion.rb +126 -0
  264. data/test/pnml/spec_isolated-element-elimination.rb +25 -0
  265. data/test/pnml/spec_output-decomposition-complement.rb +40 -0
  266. data/test/pnml/spec_output-reduction.rb +114 -0
  267. data/test/pnml/spec_output-synchronization-complement.rb +62 -0
  268. data/test/pnml/spec_pione-element.rb +144 -0
  269. data/test/pnml/spec_pnml-element.rb +373 -0
  270. data/test/pnml/spec_reader.rb +16 -0
  271. data/test/rootage/spec_argument.rb +18 -0
  272. data/test/rootage/spec_command.rb +239 -0
  273. data/test/rootage/spec_core.rb +198 -0
  274. data/test/rootage/spec_scenario.rb +149 -0
  275. data/test/system/{spec_domain-info.rb → spec_domain-dump.rb} +6 -6
  276. data/test/system/spec_file-cache.rb +6 -9
  277. data/test/tuple-space/spec_finished-tuple.rb +1 -1
  278. data/test/util/{spec_package-parameters-list_1.pione → data/package-parameters-list/Param1.pione} +0 -0
  279. data/test/util/{spec_package-parameters-list_2.pione → data/package-parameters-list/Param2.pione} +0 -0
  280. data/test/util/{spec_package-parameters-list_3.pione → data/package-parameters-list/Param3.pione} +0 -0
  281. data/test/util/{spec_package-parameters-list_4.pione → data/package-parameters-list/Param4.pione} +0 -0
  282. data/test/util/spec_boolean-value.rb +32 -0
  283. data/test/util/spec_completion.rb +22 -0
  284. data/test/util/spec_package-parameters-list.rb +39 -52
  285. data/test/util/spec_zip.rb +28 -1
  286. metadata +288 -47
  287. data/bin/pione-tuple-space-receiver +0 -5
  288. data/lib/pione/agent/broker.rb +0 -304
  289. data/lib/pione/agent/tuple-space-receiver.rb +0 -137
  290. data/lib/pione/command/pione-broker.rb +0 -104
  291. data/lib/pione/command/pione-compiler.rb +0 -57
  292. data/lib/pione/command/pione-relay-account-db.rb +0 -141
  293. data/lib/pione/command/pione-relay-client-db.rb +0 -118
  294. data/lib/pione/command/pione-relay.rb +0 -59
  295. data/lib/pione/command/pione-syntax-checker.rb +0 -214
  296. data/lib/pione/command/pione-tuple-space-receiver.rb +0 -111
  297. data/lib/pione/command/pione-update-package-info.rb +0 -53
  298. data/lib/pione/front/broker-front.rb +0 -22
  299. data/lib/pione/front/tuple-space-receiver-front.rb +0 -11
  300. data/lib/pione/global/broker-variable.rb +0 -33
  301. data/lib/pione/system/domain-info.rb +0 -25
  302. data/lib/pione/util/pnml-compiler.rb +0 -168
  303. data/test/agent/spec_tuple-space-receiver.rb +0 -47
  304. data/test/util/spec_pnml-compiler.rb +0 -32
@@ -0,0 +1,68 @@
1
+ module Pione
2
+ module Notification
3
+ # Recipient is a wrapper for notification recipients. This wraps a command
4
+ # and notifies messages to it when a notification listener receives
5
+ # notifications. Recipients should be registerd to listner periodically
6
+ # because the listener forgets recipients after some minites. Note that
7
+ # `Recipient` instance is registered to a listener after it is created
8
+ # immediately, so the listener is launched up to that time.
9
+ class Recipient
10
+ # @param front_uri [URI]
11
+ # URI of command front that receives messages
12
+ # @param listener_uri [URI]
13
+ # URI of notification listener
14
+ def initialize(front_uri, listener_uri)
15
+ @listener_uri = listener_uri
16
+ @front_uri = front_uri
17
+ @__listener_thread__ = keep_connection
18
+ @__connection__ = false
19
+ end
20
+
21
+ # Notify the message. This is a non-blocking method.
22
+ def notify(message)
23
+ name = ("receive_%s" % message.type).downcase
24
+ if respond_to?(name)
25
+ __send__(name, message)
26
+ end
27
+ end
28
+
29
+ def terminate
30
+ @__listerner_thread__.terminate if @__listener_thread__.alive?
31
+ disconnect
32
+ end
33
+
34
+ private
35
+
36
+ # Keep the listener connection. This is non-blocking.
37
+ #
38
+ # @return [Thread]
39
+ # a keeping thread
40
+ def keep_connection
41
+ Thread.new do
42
+ loop do
43
+ begin
44
+ listener = DRb::DRbObject.new_with_uri(@listener_uri)
45
+ listener.add(@front_uri.to_s)
46
+
47
+ unless @__connection__
48
+ Log::SystemLog.info('Notification recipient has connected to the listener "%s".' % @listener_uri)
49
+ end
50
+ @__connection__ = true
51
+ rescue Object => e
52
+ Log::SystemLog.warn('Notification recipient has failed to connect the listener "%s": %s' % [@listener_uri, e.message])
53
+ ensure
54
+ sleep 5
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def disconnect
61
+ Util.ignore_exception do
62
+ listener = DRb::DRbObject.new_with_uri(@listener_uri)
63
+ listener.delete(@front_uri.to_s)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,85 @@
1
+ module Pione
2
+ module Notification
3
+ # TaskWorkerBrokerRecipient is a recipient for task worker broker agent.
4
+ class TaskWorkerBrokerRecipient < Recipient
5
+ # @param model [TaskWorkerBrokerModel]
6
+ # task worker broker model
7
+ # @param front_uri [URI]
8
+ # URI of command front
9
+ # @param listener_uri [URI]
10
+ # URI of notification listener
11
+ def initialize(model, front_uri, listener_uri)
12
+ super(front_uri, listener_uri)
13
+
14
+ @model = model
15
+ @tuple_space = {}
16
+ @lock = Mutex.new
17
+
18
+ # update broker's tuple spaces
19
+ @thread = Thread.new do
20
+ while true
21
+ sleep 1
22
+ clean
23
+ update_broker
24
+ end
25
+ end
26
+ end
27
+
28
+ # Terminate the recipient.
29
+ def terminate
30
+ super
31
+ @thread.terminate
32
+ end
33
+
34
+ # Receive a "tupele space" message.
35
+ def receive_tuple_space(message)
36
+ uri = message["front"]
37
+ if @tuple_space.has_key?(uri)
38
+ @lock.synchronize {@tuple_space[uri][:last_time] = Time.now}
39
+ else
40
+ if tuple_space = get_tuple_space(uri)
41
+ @lock.synchronize do
42
+ @tuple_space[uri] = {:last_time => Time.now, :tuple_space => tuple_space}
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ #
49
+ # helper method
50
+ #
51
+
52
+ # Get a tuple space from front server at the URI.
53
+ def get_tuple_space(uri)
54
+ # build a reference to provider front
55
+ front = DRb::DRbObject.new_with_uri(uri)
56
+
57
+ # return the tuple space reference
58
+ Timeout.timeout(3) {front.tuple_space}
59
+ rescue Timeout::Error
60
+ Log::Debug.notification do
61
+ 'tuple_space notfication ignored the provider "%s" that seems to be something bad' % front.uri
62
+ end
63
+ rescue DRb::DRbConnError, DRbPatch::ReplyReaderError => e
64
+ Log::Debug.notification('The tuple space at "%s" disconnected: %s' % [front.uri, e.message])
65
+ end
66
+
67
+ # Clean tuple space table.
68
+ def clean
69
+ @lock.synchronize do
70
+ now = Time.now
71
+ dtime = Global.tuple_space_disconnection_time
72
+ @tuple_space.delete_if {|_, holder| (now - holder[:last_time]) > dtime}
73
+ end
74
+ end
75
+
76
+ # Update the tuple space list of broker.
77
+ def update_broker
78
+ @lock.synchronize do
79
+ tuple_spaces = @tuple_space.values.map {|holder| holder[:tuple_space]}
80
+ @model.update_tuple_spaces(tuple_spaces)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,84 @@
1
+ module Pione
2
+ module Notification
3
+ # `Notification::Transmitter` is a class for transmitting notification
4
+ # messages to target URI.
5
+ class Transmitter
6
+ # Transmit the notification message to the targets.
7
+ #
8
+ # @param message [Notification::Message]
9
+ # a notfication message
10
+ # @param targets [Array<URI>]
11
+ # target URIs
12
+ def self.transmit(message, targets=Global.notification_targets)
13
+ targets.each do |uri|
14
+ transmitter = self.new(uri)
15
+ begin
16
+ transmitter.transmit(message)
17
+ rescue => e
18
+ Log::SystemLog.warn('Notification transmitter has failed to transmit to "%s": %s' % [uri, e.message])
19
+ ensure
20
+ transmitter.close
21
+ end
22
+ end
23
+ end
24
+
25
+ # a lock for transmitting notification messages
26
+ LOCK = Mutex.new
27
+
28
+ # target URI that the transmitter transmits notification messages to
29
+ attr_reader :uri
30
+
31
+ # @param uri [URI]
32
+ # target URI
33
+ def initialize(uri)
34
+ # URI scheme should be "pnb"(UDP broadcast), "pnm"(UDP multicast), or
35
+ # "pnu"(UDP unicast)
36
+ unless ["pnb", "pnm", "pnu"].include?(uri.scheme)
37
+ raise ArgumentError.new(uri)
38
+ end
39
+
40
+ if uri.host.nil? or uri.port.nil?
41
+ raise ArgumentError.new(uri)
42
+ end
43
+
44
+ @uri = uri
45
+ open
46
+ end
47
+
48
+ # Transmit the notification message to target URI.
49
+ #
50
+ # @param message [Notification::Message]
51
+ # a notification message
52
+ # @return [void]
53
+ def transmit(message)
54
+ LOCK.synchronize do
55
+ @socket.send(message.dump, 0, @uri.host, @uri.port)
56
+ end
57
+ end
58
+
59
+ # Close the transmitter's socket.
60
+ def close
61
+ @socket.close
62
+ end
63
+
64
+ private
65
+
66
+ # Open a UPD socket and configure it by URI scheme.
67
+ def open
68
+ @socket = UDPSocket.open
69
+
70
+ case @uri.scheme
71
+ when "pnb"
72
+ # enable broadcast flag
73
+ @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, 1)
74
+ when "pnm"
75
+ if @uri.interface
76
+ # enable to bind interface
77
+ interface = IPAddr.new(@uri.interface).hton
78
+ @socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_IF, interface)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
data/lib/pione/pnml.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Pione
2
+ # `PNML` is a namespace for the compiler from PNML to PIONE.
3
+ module PNML; end
4
+ end
5
+
6
+ #
7
+ # language model
8
+ #
9
+
10
+ require 'pione/pnml/pnml-model' # source models
11
+ require 'pione/pnml/pione-model' # target models
12
+
13
+ #
14
+ # net rewriting rules
15
+ #
16
+
17
+ require 'pione/pnml/net-rewriter'
18
+ require 'pione/pnml/output-reduction'
19
+ require 'pione/pnml/input-reduction'
20
+ require 'pione/pnml/isolated-element-elimination'
21
+ require 'pione/pnml/input-merge-complement'
22
+ require 'pione/pnml/input-parallelization-complement'
23
+ require 'pione/pnml/output-decomposition-complement'
24
+ require 'pione/pnml/output-synchronization-complement'
25
+ require 'pione/pnml/io-expansion'
26
+ require 'pione/pnml/invalid-arc-elimination'
27
+
28
+ #
29
+ # utility
30
+ #
31
+
32
+ require 'pione/pnml/annotation-extractor'
33
+ require 'pione/pnml/reader'
34
+ require 'pione/pnml/compiler'
35
+
@@ -0,0 +1,47 @@
1
+ module Pione
2
+ module PNML
3
+ class AnnotationExtractor
4
+ def initialize(net, option)
5
+ @net = net
6
+ @flow_name = option[:flow_name] || "Main"
7
+ @package_name = option[:package_name]
8
+ @editor = option[:editor]
9
+ @tag = option[:tag]
10
+ end
11
+
12
+ # Extract an annotation from the place. If the place has the name that we
13
+ # can parse as an annotation declarartion sentence, return the name as
14
+ # is. Otherwise, return nil.
15
+
16
+ # Extract annotations from places.
17
+ def extract
18
+ package_annotations = []
19
+
20
+ @net.places.each do |place|
21
+ if line = extract_annotation(place)
22
+ package_annotations << line
23
+ end
24
+ end
25
+
26
+ package_annotations << ".@ PackageName :: \"%s\"" % @package_name if @package_name
27
+ package_annotations << ".@ Editor :: \"%s\"" % @editor if @editor
28
+ package_annotations << ".@ Tag :: \"%s\"" % @tag if @tag
29
+
30
+ return package_annotations
31
+ end
32
+
33
+ private
34
+
35
+ # Extract an annotation from the place. If the place has the name that we
36
+ # can parse as an annotation declarartion sentence, return the name as
37
+ # is. Otherwise, return nil.
38
+ def extract_annotation(place)
39
+ name = place.name
40
+ Lang::DocumentParser.new.annotation_sentence.parse(name)
41
+ return name
42
+ rescue Parslet::ParseFailed => e
43
+ return nil
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,176 @@
1
+ module Pione
2
+ module PNML
3
+ class Compiler
4
+ # Compile from the net to PIONE document.
5
+ #
6
+ # @param net [PNML::Net]
7
+ # source net
8
+ # @return [String]
9
+ # compiled PIONE document
10
+ def self.compile(net, option={})
11
+ new(net, option).compile
12
+ end
13
+
14
+ def initialize(net, option={})
15
+ @net = net
16
+ @option = option
17
+ @net_rewriter = NetRewriter.new do |rules|
18
+ rules << IsolatedElementElimination
19
+ rules << InvalidArcElimination
20
+ rules << OutputReduction
21
+ rules << InputReduction
22
+ rules << IOExpansion
23
+ rules << InputMergeComplement
24
+ rules << InputParallelizationComplement
25
+ rules << OutputDecompositionComplement
26
+ rules << OutputSynchronizationComplement
27
+ end
28
+ end
29
+
30
+ # Compile a PNML file into PIONE document as a string.
31
+ def compile
32
+ # annotations
33
+ annotations = AnnotationExtractor.new(@net, @option).extract
34
+
35
+ # apply net rewriting rules
36
+ @net_rewriter.rewrite(@net)
37
+
38
+ # build rules
39
+ rules, flow_elements = build_constituent_rule_definitions
40
+ definition_main = build_flow_rule_definition(@option[:flow_rule_name] || "Main", flow_elements)
41
+
42
+ # textize
43
+ [*annotations, "", definition_main.textize, *rules.map {|rule| rule.textize}].join("\n")
44
+ end
45
+
46
+ private
47
+
48
+ # Build constituent rule definitions by transitions in the net.
49
+ def build_constituent_rule_definitions
50
+ definition = @net.transitions.each_with_object({}) do |transition, table|
51
+ if Perspective.rule?(transition)
52
+ rule = RuleDefinition.new(transition.name)
53
+
54
+ # inputs
55
+ @net.find_all_places_by_target_id(transition.id).each do |place|
56
+ if Perspective.file?(place)
57
+ rule.inputs << Perspective.normalize_data_name(place.name)
58
+ end
59
+ end
60
+
61
+ @net.find_all_places_by_source_id(transition.id).each do |place|
62
+ # outputs
63
+ if Perspective.file?(place)
64
+ rule.outputs << Perspective.normalize_data_name(place.name)
65
+ end
66
+
67
+ # params
68
+ if Perspective.param?(place)
69
+ rule.params << Param.new(place.name, nil)
70
+ end
71
+ end
72
+
73
+ table[transition.id] = rule
74
+ end
75
+ end
76
+
77
+ # save all inner rules
78
+ rules = definition.values.compact
79
+ flow_elements = definition.values.compact
80
+
81
+ # conditional branch
82
+ @net.transitions.each do |transition|
83
+ places = @net.find_all_places_by_target_id(transition.id)
84
+ inputs = places.select {|place| Perspective.file?(place)}
85
+ inputs = inputs.map {|input| Perspective.normalize_data_name(input.name)}
86
+
87
+ case Perspective.normalize_data_name(transition.name)
88
+ when "if"
89
+ # if-branch
90
+ condition = @net.find_place_by_source_id(transition.id)
91
+
92
+ keywords = @net.find_all_transitions_by_source_id(condition.id)
93
+ key_then = keywords.find{|key| Perspective.compact(key.name) == "then"}
94
+ key_else = keywords.find{|key| Perspective.compact(key.name) == "else"}
95
+
96
+ branch = ConditionalBranch.new(:if, condition.name)
97
+
98
+ find_next_rules(key_then).each do |transition|
99
+ rule = definition[transition.id]
100
+ rule.inputs += inputs
101
+ flow_elements.delete(rule)
102
+ branch.table[:then] << rule
103
+ end
104
+
105
+ find_next_rules(key_else).each do |transition|
106
+ rule = definition[transition.id]
107
+ rule.inputs += inputs
108
+ flow_elements.delete(rule)
109
+ branch.table[:else] << rule
110
+ end
111
+
112
+ flow_elements << branch
113
+ when "case"
114
+ expr = @net.find_place_by_source_id(transition.id)
115
+
116
+ keywords = @net.find_all_transtions_by_source_id(expr.id)
117
+ keys_when = keywords.select{|key| Perspective.compact(key.name) == "then"}
118
+ key_else = keywords.find{|key| Perspective.compact(key.name) == "else"}
119
+
120
+ branch = ConditionalBranch.new(:case, expr.name)
121
+
122
+ keys_when.each do |key|
123
+ find_next_rules(key).each do |transition|
124
+ rule = definition[transition.id]
125
+ rule.inputs += inputs
126
+ flow_elements.delete(rule)
127
+ branch.table[key.name] << rule
128
+ end
129
+ end
130
+
131
+ find_next_rules(key_else).each do |transition|
132
+ rule = definition[transition.id]
133
+ rule.inputs += inputs
134
+ flow_elements.delete(rule)
135
+ branch.table[:else] << rule
136
+ end
137
+
138
+ flow_elements << branch
139
+ end
140
+ end
141
+
142
+ return [rules, flow_elements]
143
+ end
144
+
145
+ # Make a main rule.
146
+ def build_flow_rule_definition(name, flow_elements)
147
+ inputs = @net.places.select {|place| Perspective.file?(place) and Perspective.net_input?(place)}
148
+ inputs = inputs.map {|input| Perspective.normalize_data_name(input.name)}
149
+
150
+ outputs = @net.places.select {|place| Perspective.file?(place) and Perspective.net_output?(place)}
151
+ outputs = outputs.map {|output| Perspective.normalize_data_name(output.name)}
152
+
153
+ option = {
154
+ :inputs => inputs,
155
+ :outputs => outputs,
156
+ :params => @net.places.select {|place| Perspective.param?(place) and Perspective.net_input?},
157
+ :flow_elements => flow_elements,
158
+ }
159
+
160
+ RuleDefinition.new(name, option)
161
+ end
162
+
163
+ def find_next_rules(base_rule)
164
+ @net.find_all_places_by_source_id(base_rule.id).each_with_object([]) do |place, res|
165
+ @net.find_all_transitions_by_source_id(place.id).each do |transition|
166
+ if Perspective.rule?(transition)
167
+ res << transition
168
+ else
169
+ find_next_rules(transition)
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end