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
data/lib/pione/front.rb CHANGED
@@ -5,9 +5,11 @@ end
5
5
 
6
6
  require 'pione/front/front-exception'
7
7
  require 'pione/front/basic-front'
8
+ require 'pione/front/notification-recipient-interface'
8
9
  require 'pione/front/client-front'
9
- require 'pione/front/broker-front'
10
10
  require 'pione/front/task-worker-front'
11
+ require 'pione/front/task-worker-broker-front'
11
12
  require 'pione/front/tuple-space-provider-front'
12
- require 'pione/front/tuple-space-receiver-front'
13
+ require 'pione/front/notification-listener-front'
13
14
  require 'pione/front/relay-front'
15
+ require 'pione/front/diagnosis-notification-front'
@@ -1,19 +1,20 @@
1
1
  module Pione
2
2
  module Front
3
3
  # This is base class for all PIONE front classes. PIONE fronts exist in each
4
- # command and behave as remote interface.
4
+ # command and behave as remote control interface.
5
5
  class BasicFront < PioneObject
6
6
  include DRbUndumped
7
7
 
8
8
  attr_reader :uri # front server's URI string
9
- attr_reader :attrs
10
- attr_reader :child # child process table
11
9
 
12
10
  # Creates a front server as druby's service.
13
- def initialize(port)
14
- @uri = start_service(port, {}) # port is number or range
15
- @attrs = {}
11
+ def initialize(cmd, port)
12
+ @cmd = cmd
13
+ @uri = URI.parse(start_service(port, {})) # port is number or range
14
+ @attr = {}
16
15
  @child = {}
16
+ @child_lock = Mutex.new
17
+ @child_watchers = ThreadGroup.new
17
18
  end
18
19
 
19
20
  # Return PID of the process.
@@ -22,26 +23,82 @@ module Pione
22
23
  end
23
24
 
24
25
  def [](name)
25
- @attrs[name]
26
+ @attr[name]
26
27
  end
27
28
 
28
29
  def []=(name, val)
29
- @attrs[name] = val
30
+ @attr[name] = val
30
31
  end
31
32
 
32
- # Add child process.
33
- def add_child(pid, front_uri)
34
- @child[pid] = front_uri
33
+ # Register the process as a child of this process. It is unregistered when
34
+ # the child is terminated.
35
+ #
36
+ # @param pid [String]
37
+ # child process's PID
38
+ # @param front_uri [String]
39
+ # child process's front URI
40
+ # @return [void]
41
+ def register_child(pid, front_uri)
42
+ unless @cmd.current_phase == :termination
43
+ # register child's PID
44
+ @child_lock.synchronize {@child[pid] = front_uri}
45
+
46
+ # unregister automatically when the child is terminated
47
+ thread = Thread.new do
48
+ Util.ignore_exception(Errno::ECHILD) do
49
+ Process.waitpid(pid)
50
+ unregister_child(pid)
51
+ end
52
+ end
53
+ thread[:pid] = pid
54
+ @child_watchers.add(thread)
55
+
56
+ return nil
57
+ else
58
+ raise ChildRegistrationError.new
59
+ end
60
+ end
61
+
62
+ # Unregister the child process.
63
+ #
64
+ # @param pid [String]
65
+ # child's PID to be removed
66
+ def unregister_child(pid)
67
+ # unregister the pid
68
+ @child_lock.synchronize {@child.delete(pid)}
69
+
70
+ # kill the watcher thread
71
+ @child_watchers.list.each do |thread|
72
+ if thread[:pid] == pid
73
+ thread.kill
74
+ break
75
+ end
76
+ end
77
+ end
78
+
79
+ # Return list of child process's PIDs.
80
+ #
81
+ # @return [Array]
82
+ # list of child command's PIDs.
83
+ def child_pids
84
+ @child.keys
35
85
  end
36
86
 
37
- # Delete child process.
38
- def remove_child(pid)
39
- @child.delete(pid)
87
+ # Return a front URI of the child PID.
88
+ #
89
+ # @return [String]
90
+ # URI of the child PID
91
+ def child_front_uri(pid)
92
+ @child[pid]
93
+ end
94
+
95
+ def system_logger
96
+ Log::SystemLog.logger
40
97
  end
41
98
 
42
99
  # Terminate the front server. This method assumes to be not called from
43
- # other process. Note that front servers have no responsibility of killing
44
- # child processes.
100
+ # other processes. Note that front servers have no responsibility of
101
+ # killing child processes.
45
102
  def terminate
46
103
  DRb.stop_service
47
104
  end
@@ -50,7 +107,7 @@ module Pione
50
107
  # process cannot tell its termination to caller, so it returns true
51
108
  # immediately.
52
109
  def terminate_command
53
- Thread.new {Global.command.terminate}
110
+ Thread.new {@cmd.terminate}
54
111
  return true
55
112
  end
56
113
 
@@ -61,25 +118,31 @@ module Pione
61
118
  if port.kind_of?(Range)
62
119
  enum = port.each
63
120
  begin
64
- DRb.start_service(build_front_server_uri(enum.next), self, config)
121
+ DRb.start_service(build_uri(enum.next), self, config)
65
122
  rescue StopIteration => e
66
123
  raise
67
124
  rescue
68
125
  retry
69
126
  end
70
127
  else
71
- DRb.start_service(build_front_server_uri(port), self, config)
128
+ DRb.start_service(build_uri(port), self, config)
72
129
  end
73
130
 
74
131
  return DRb.uri
75
132
  rescue => e
76
- raise FrontError.new(self, e)
133
+ raise FrontServerError.new(self, e)
134
+ end
135
+
136
+ # This provides non blocking API.
137
+ def non_blocking(&b)
138
+ Thread.new {b.call}
139
+ return nil
77
140
  end
78
141
 
79
142
  # Build front server URI. Note that the address is configured by
80
- # +Global.my_ip_address+.
81
- def build_front_server_uri(port)
82
- "druby://%s:%s" % [Global.my_ip_address, port]
143
+ # `Global.communication_address`.
144
+ def build_uri(port)
145
+ "druby://%s:%s" % [Global.communication_address, port]
83
146
  end
84
147
  end
85
148
  end
@@ -3,8 +3,8 @@ module Pione
3
3
  # ClientFront is a front interface for +pione-client+ command.
4
4
  class ClientFront < BasicFront
5
5
  # Create a new front.
6
- def initialize
7
- super(Global.client_front_port_range)
6
+ def initialize(cmd)
7
+ super(cmd, Global.client_front_port_range)
8
8
  end
9
9
 
10
10
  def set_tuple_space(tuple_space)
@@ -0,0 +1,40 @@
1
+ module Pione
2
+ module Front
3
+ # `DiagnosisNotificationFront` is a front server for diagnosis test about
4
+ # sending notifications.
5
+ class DiagnosisNotificationFront < BasicFront
6
+ LOCK = Mutex.new
7
+
8
+ def initialize(cmd)
9
+ super(cmd, Global.diagnosis_notification_front_port_range)
10
+ @transmitting_threads = ThreadGroup.new
11
+ end
12
+
13
+ # If the front is touched, notification diagnosis is success.
14
+ #
15
+ # @param transmitter_id [String]
16
+ # transmitter ID, this is a string of transmitter's target URI
17
+ # @return [void]
18
+ def touch(transmitter_id)
19
+ LOCK.synchronize do
20
+ @transmitting_threads.list.each do |thread|
21
+ if thread[:transmitter_id] == transmitter_id and thread.alive?
22
+ thread.terminate
23
+ end
24
+ end
25
+ end
26
+ return true
27
+ end
28
+
29
+ # Register the transmitting thread for test.
30
+ #
31
+ # @param thread [Thread]
32
+ # a transmitting thread,
33
+ # see `Pione::Command::PioneDiagnosisNotification`
34
+ # @return [void]
35
+ def register_transmitting_thread(thread)
36
+ LOCK.synchronize {@transmitting_threads.add(thread)}
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,7 +1,10 @@
1
1
  module Pione
2
2
  module Front
3
+ # `Front::Error` is a base exception class.
4
+ class Error < StandardError; end
5
+
3
6
  # FrontError is raised when front server cannnot start.
4
- class FrontError < StandardError
7
+ class FrontServerError < Error
5
8
  def initialize(front, exception)
6
9
  @front = front
7
10
  @exception = exception
@@ -12,5 +15,8 @@ module Pione
12
15
  end
13
16
  end
14
17
 
18
+ # `ChildRegistrationError` is raised when child process failed to register to
19
+ # parent front.
20
+ class ChildRegistrationError < Error; end
15
21
  end
16
22
  end
@@ -0,0 +1,36 @@
1
+ module Pione
2
+ module Front
3
+ # `NotificationListenerFront` is a front interface for
4
+ # `pione-notification-listener` command.
5
+ class NotificationListenerFront < BasicFront
6
+ def initialize(cmd)
7
+ super(cmd, Global.notification_listener_front_port)
8
+ end
9
+
10
+ # Add the recipient that receives notification messages.
11
+ #
12
+ # @param uri [String]
13
+ # URI of the recipent's front
14
+ # @param recipient [Notification::Recipient]
15
+ # the recipient that receives notification messages
16
+ # @return [void]
17
+ def add(uri)
18
+ non_blocking do
19
+ @cmd.model.add_recipient(uri)
20
+ Log::SystemLog.debug 'Recipient "%s" has been added.' % uri
21
+ end
22
+ end
23
+
24
+ # Delete the recipient that receives notification messages.
25
+ #
26
+ # @param uri [String]
27
+ # URI of the recipent's front
28
+ def delete(uri)
29
+ non_blocking do
30
+ @cmd.model.delete_recipient(uri)
31
+ Log::SystemLog.debug 'Recipient "%s" has been deleted.' % uri
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module Pione
2
+ module Front
3
+ module NotificationRecipientInterface
4
+ def set_recipient(recipient)
5
+ @__recipient__ = recipient
6
+ end
7
+
8
+ # Notify the notification message to the recipient. This method is
9
+ # non-blocking.
10
+ #
11
+ # @param message [Notification::Message]
12
+ # notification message
13
+ # @return [void]
14
+ def notify(message)
15
+ non_blocking {@__recipient__.notify(message)}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,17 +1,17 @@
1
1
  module Pione
2
2
  module Front
3
3
  class RelayFront < BasicFront
4
- attr_reader :presence_port
4
+ attr_reader :notification_port
5
5
  attr_reader :tuple_space_server
6
6
 
7
7
  # Create a new front.
8
- def initialize(presence_port, tuple_space)
8
+ def initialize(notification_port, tuple_space)
9
9
  super(Global.relay_front_port_range)
10
- @presence_port = presence_port
10
+ @notification_port = notification_port
11
11
  @tuple_space = tuple_space
12
12
  end
13
13
 
14
- def presence_notifier
14
+ def notifier
15
15
  tuple_space_provider
16
16
  end
17
17
  end
@@ -0,0 +1,19 @@
1
+ module Pione
2
+ module Front
3
+ # `TaskWorkerBrokerFront` is a front interface for
4
+ # `pione-task-worker-broker` command.
5
+ class TaskWorkerBrokerFront < BasicFront
6
+ # this receives notification messages
7
+ include NotificationRecipientInterface
8
+
9
+ def initialize(cmd)
10
+ super(cmd, Global.task_worker_broker_front_port_range)
11
+ set_recipient(Notification::TaskWorkerBrokerRecipient.new(cmd.model, uri, Global.notification_listener))
12
+ end
13
+
14
+ def get_tuple_space(tuple_space_id)
15
+ @cmd.model.get_tuple_space(tuple_space_id)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,8 +2,8 @@ module Pione
2
2
  module Front
3
3
  # TaskWorkerFront is a front interface for pione-task-worker command.
4
4
  class TaskWorkerFront < BasicFront
5
- def initialize
6
- super(Global.task_worker_front_port_range)
5
+ def initialize(cmd)
6
+ super(cmd, Global.task_worker_front_port_range)
7
7
  end
8
8
  end
9
9
  end
@@ -5,8 +5,9 @@ module Pione
5
5
  class TupleSpaceProviderFront < BasicFront
6
6
  attr_reader :tuple_space
7
7
 
8
- def initialize(tuple_space)
9
- super(Global.tuple_space_provider_front_port_range)
8
+ def initialize(cmd)
9
+ tuple_space = cmd.model[:parent_front].get_tuple_space(nil)
10
+ super(cmd, Global.tuple_space_provider_front_port_range)
10
11
  @tuple_space = tuple_space
11
12
  end
12
13
  end
data/lib/pione/global.rb CHANGED
@@ -5,6 +5,7 @@ module Pione
5
5
  module Global; end
6
6
  end
7
7
 
8
+ require 'pione/global/global-exception'
8
9
  require 'pione/global/item'
9
10
  require 'pione/global/config'
10
11
  require 'pione/global/system-variable'
@@ -14,7 +15,8 @@ require 'pione/global/log-variable'
14
15
  require 'pione/global/relay-variable'
15
16
  require 'pione/global/client-variable'
16
17
  require 'pione/global/task-worker-variable'
17
- require 'pione/global/broker-variable'
18
+ require 'pione/global/task-worker-broker-variable'
18
19
  require 'pione/global/input-generator-variable'
19
20
  require 'pione/global/tuple-space-notifier-variable'
20
21
  require 'pione/global/package-variable'
22
+ require 'pione/global/diagnosis-variable'
@@ -14,7 +14,7 @@ module Pione
14
14
 
15
15
  # This is port range for client's front.
16
16
  define_computed_item(:client_front_port_range, [:client_front_port_range_begin, :client_front_port_range_end]) do |item|
17
- item.desc = "port range of broker front"
17
+ item.desc = "port range of client front"
18
18
  item.define_updater do
19
19
  Range.new(
20
20
  Global.client_front_port_range_begin,
@@ -7,7 +7,7 @@ module Pione
7
7
  new(path).tap {|x| x.apply}
8
8
  end
9
9
 
10
- forward :@table, "[]"
10
+ forward! :@table, "[]", "each"
11
11
 
12
12
  # config file path
13
13
  attr_reader :path
@@ -15,21 +15,77 @@ module Pione
15
15
  # Create a new configuration.
16
16
  def initialize(path)
17
17
  @path = Pathname.new(path)
18
- @table = @path.exist? ? YAML.load(@path.read) : {}
18
+ @table = Hash.new
19
+ (@path.exist? ? JSON.load(@path.read) : {}).each do |key, val|
20
+ @table[key.to_sym] = val
21
+ end
19
22
  raise InvalidConfigFile.new(@path) unless @table.kind_of?(Hash)
20
23
  end
21
24
 
22
25
  # Apply config date to global settings.
23
26
  def apply
24
27
  @table.each do |key, val|
25
- key = key.to_sym
26
- if Global.item[key] and Global.item[key].configurable?
27
- Global.set(key, val)
28
- else
29
- raise UnconfigurableVariableError.new(key)
28
+ name = key.to_sym
29
+ if_configurable_item(name) do
30
+ Global.set(name, val)
30
31
  end
31
32
  end
32
33
  end
34
+
35
+ # Set the global item.
36
+ #
37
+ # @param name [String]
38
+ # item name
39
+ # @param value [Object]
40
+ # item value
41
+ # @return [void]
42
+ def set(name, value)
43
+ raise ArgumentError.new if value.nil?
44
+
45
+ name = name.to_sym
46
+ if_configurable_item(name) do
47
+ @table[name] = ValueConverter.convert(Global.item[name].type, value)
48
+ end
49
+ end
50
+
51
+ # Get the global item's value.
52
+ #
53
+ # @param name [String]
54
+ # item name
55
+ # @return [Object]
56
+ # item value
57
+ def get(name)
58
+ name = name.to_sym
59
+ if_configurable_item(name) do
60
+ @table[name]
61
+ end
62
+ end
63
+
64
+ def unset(name)
65
+ name = name.to_sym
66
+ @table.delete(name)
67
+ end
68
+
69
+ # Save the configuration items to the file.
70
+ #
71
+ # @param path [Pathname]
72
+ # file path
73
+ # @return [void]
74
+ def save(path=@path)
75
+ path.open("w+") do |file|
76
+ file.write(JSON.pretty_generate(@table))
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ def if_configurable_item(name, &b)
83
+ if Global.item[name] and Global.item[name].configurable?
84
+ b.call
85
+ else
86
+ raise UnconfigurableVariableError.new(name)
87
+ end
88
+ end
33
89
  end
34
90
  end
35
91
  end