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
@@ -2,8 +2,10 @@ module Pione
2
2
  module Location
3
3
  class HTTPSLocation < HTTPLocation
4
4
  set_scheme "https"
5
- set_real_appendable false
6
- set_writable false
5
+
6
+ define(:need_caching, true)
7
+ define(:real_appendable, false)
8
+ define(:writable, false)
7
9
 
8
10
  # Send a request HTTPS Get and evaluate the block with the response.
9
11
  def http_get(&b)
@@ -3,7 +3,10 @@ module Pione
3
3
  # LocalLocation represents local disk locations.
4
4
  class LocalLocation < DataLocation
5
5
  set_scheme "local"
6
- set_real_appendable true
6
+
7
+ define(:need_caching, false)
8
+ define(:real_appendable, true)
9
+ define(:writable, true)
7
10
 
8
11
  def initialize(uri)
9
12
  super(uri.absolute)
@@ -174,7 +177,7 @@ module Pione
174
177
  # modify mtime
175
178
  begin
176
179
  dest.mtime = self.mtime if option[:keep_mtime]
177
- rescue NotImplemented
180
+ rescue NotImplementedError
178
181
  msg = "the location operation faild to keep mtime: copy from %s to %s"
179
182
  Log::SystemLog.debug(msg % [address, dest.address])
180
183
  end
@@ -189,7 +192,7 @@ module Pione
189
192
  end
190
193
 
191
194
  def turn(dest)
192
- if dest.kind_of?(LocalLocation)
195
+ if Global.file_sliding and dest.kind_of?(LocalLocation)
193
196
  move(dest)
194
197
  link(dest)
195
198
  else
@@ -46,5 +46,17 @@ module Pione
46
46
  "the location \"%s\" should local location" % @location.address
47
47
  end
48
48
  end
49
+
50
+ # `DropboxLocationUnavailable` is raised when Dropbox location isn't
51
+ # unavailable.
52
+ class DropboxLocationUnavailable < LocationError
53
+ def initialize(message)
54
+ @message = message
55
+ end
56
+
57
+ def message
58
+ @message
59
+ end
60
+ end
49
61
  end
50
62
  end
@@ -0,0 +1,46 @@
1
+ module Pione
2
+ module Location
3
+ # `NotificationBroadcastScheme` is a scheme for PIONE notification protocol
4
+ # using UDP broadcast.
5
+ #
6
+ # @example
7
+ # URI.parse("pnb://255.255.255.255:56000")
8
+ class NotificationBroadcastScheme < LocationScheme('pnb')
9
+ COMPONENT = [:scheme, :host, :port]
10
+ end
11
+
12
+ # `NotificationUnicastScheme` is a scheme for PIONE notification protocol
13
+ # using UDP unicast.
14
+ #
15
+ # @example
16
+ # URI.parse("pnu://192.168.100.10:56000")
17
+ class NotificationUnicastScheme < LocationScheme('pnu')
18
+ COMPONENT = [:scheme, :host, :port]
19
+ end
20
+
21
+ # `NotificationMulticastScheme` is a scheme for PIONE notification protocol
22
+ # using UDP multicast.
23
+ #
24
+ # @example
25
+ # URI.parse("pnm://239.1.2.3:56000")
26
+ # URI.parse("pnm://239.1.2.4.56000?if=192.168.100.100")
27
+ class NotificationMulticastScheme < LocationScheme('pnm')
28
+ COMPONENT = [:scheme, :host, :port, :query] # path is fake
29
+
30
+ def interface
31
+ query_table["if"] if query
32
+ end
33
+
34
+ private
35
+
36
+ def query_table
37
+ if query
38
+ query.split("&").each_with_object({}) do |part, table|
39
+ key, val = part.split("=")
40
+ table[key] = val
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
data/lib/pione/log.rb CHANGED
@@ -4,11 +4,12 @@ module Pione
4
4
  end
5
5
  end
6
6
 
7
- require 'pione/log/system-log' # system log framwork
8
- require 'pione/log/debug' # debug message utility
9
- require 'pione/log/message-log' # user messages from rule engine
10
- require 'pione/log/process-record' # record of event log
11
- require 'pione/log/process-log' # event log of processing
12
- require 'pione/log/xes-log' # XES format
13
- require 'pione/log/domain-log' # domain informations in tuple space
7
+ require 'pione/log/system-log' # system log framwork
8
+ require 'pione/log/debug' # debug message utility
9
+ require 'pione/log/message-log' # user messages from rule engine
10
+ require 'pione/log/message-log-receiver' # message log receiver
11
+ require 'pione/log/process-record' # record of event log
12
+ require 'pione/log/process-log' # event log of processing
13
+ require 'pione/log/xes-log' # XES format
14
+ require 'pione/log/domain-log' # domain informations in tuple space
14
15
 
@@ -1,11 +1,11 @@
1
1
  module Pione
2
2
  module Log
3
3
  # Debug is a log utility module for showing debug messages. Messages are
4
- # shown when according debug flags (system, rule_engine,
5
- # presence_notification, communication, ignored_exception) are available.
4
+ # shown when according debug flags (system, rule_engine, notification,
5
+ # communication, ignored_exception) are available.
6
6
  module Debug
7
7
  # Show a debug message about PIONE system activity. This message is
8
- # visible when +Global.debug_system+ is true.
8
+ # visible when `Global.debug_system` is true.
9
9
  def self.system(msg_or_exc=nil, pos=caller(1).first, &b)
10
10
  if Global.debug_system
11
11
  print(:system, msg_or_exc, pos, &b)
@@ -13,18 +13,18 @@ module Pione
13
13
  end
14
14
 
15
15
  # Show a debug message about rule engine activity. This message is visible
16
- # when +Global.debug_rule_engine+ is true in client side.
16
+ # when `Global.debug_rule_engine` is true in client side.
17
17
  def self.rule_engine(msg_or_exc=nil, pos=caller(1).first, &b)
18
18
  if Global.debug_rule_engine
19
19
  print(:rule_engine, msg_or_exc, pos, &b)
20
20
  end
21
21
  end
22
22
 
23
- # Show a debug message about presence notifier. This message is visible
24
- # when +Global.debug_presence_notification+ is true.
25
- def self.presence_notification(msg_or_exc=nil, pos=caller(1).first, &b)
26
- if Global.debug_presence_notification
27
- print(:presence_notifier, msg_or_exc, pos, &b)
23
+ # Show a debug message about notification. This message is visible when
24
+ # `Global.debug_notification` is true.
25
+ def self.notification(msg_or_exc=nil, pos=caller(1).first, &b)
26
+ if Global.debug_notification
27
+ print(:notification, msg_or_exc, pos, &b)
28
28
  end
29
29
  end
30
30
 
@@ -41,10 +41,15 @@ module Pione
41
41
  #
42
42
  # @return [void]
43
43
  def save
44
+ domain_info_location = @domain_location + FILENAME
44
45
  text = "== %s\n\n" % Time.now
45
46
  text << @record.map{|key, val| "- %s: %s" % [key,val]}.join("\n")
46
47
  text << "\n\n"
47
- (@domain_location + FILENAME).append(text)
48
+ if domain_info_location.exist?
49
+ domain_info_location.append(text)
50
+ else
51
+ domain_info_location.create(text)
52
+ end
48
53
  end
49
54
 
50
55
  private
@@ -0,0 +1,32 @@
1
+ module Pione
2
+ module Log
3
+ # MessageLogReceiver is an abstract class for message log receivers.
4
+ class MessageLogReceiver
5
+ # Receive the message with attributes.
6
+ #
7
+ # @param message [String]
8
+ # the message
9
+ # @param level [Integer]
10
+ # message depth level
11
+ # @param header [String]
12
+ # message header
13
+ # @param color [String]
14
+ # message color
15
+ def receiver(message, level, header, color)
16
+ raise NotImplementedError.new
17
+ end
18
+ end
19
+
20
+ # `CUIMessageLogReceiver` is a message log receiver for CUI
21
+ # environment. This receiver prints messages to stdout.
22
+ class CUIMessageLogReceiver < MessageLogReceiver
23
+ def initialize(out=$stdout)
24
+ @out = out
25
+ end
26
+
27
+ def receive(message, level, header, color)
28
+ @out.puts "%s%s %s" % [" "*level, ("%5s" % header).color(color), message]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,118 +1,33 @@
1
1
  module Pione
2
2
  module Log
3
- module SystemLog
4
- # Log the fatal message. This level is used when system will go to shutdown.
5
- def self.fatal(msg, pos=caller(1).first)
6
- Global.system_logger.fatal(msg, pos)
7
- end
8
-
9
- # Log the error message.
10
- def self.error(msg, pos=caller(1).first)
11
- Global.system_logger.error(msg, pos)
12
- end
13
-
14
- # Log the warn message.
15
- def self.warn(msg, pos=caller(1).first)
16
- Global.system_logger.warn(msg, pos)
17
- end
18
-
19
- # Log the info message.
20
- def self.info(msg, pos=caller(1).first)
21
- Global.system_logger.info(msg, pos)
22
- end
23
-
24
- # Log the debug message.
25
- def self.debug(msg, pos=caller(1).first)
26
- Global.system_logger.debug(msg, pos)
27
- end
28
-
29
- def self.terminate
30
- Global.system_logger.terminate
31
- end
32
- end
33
-
34
- # SystemLogger is a interface for system logger implementations.
35
- class SystemLogger
36
- @logger = {} # logger class table
3
+ SystemLog = Rootage::Log
4
+ SystemLog.set_logger_block {Global.system_logger}
37
5
 
38
- # Return logger class of the type.
39
- def self.of(type)
40
- @logger[type]
41
- end
42
-
43
- # Register the logger class with the type.
44
- def self.register(type, logger_class)
45
- @logger[type] = logger_class
46
- end
47
-
48
- # Return the log level.
49
- def level
50
- raise NotImplementedError
51
- end
52
-
53
- # Set the log level.
54
- def level=(level)
55
- raise NotImplementedError
56
- end
57
-
58
- # Log the fatal message.
59
- def fatal(msg, pos=caller(1).first)
60
- raise NotImplementedError
61
- end
62
-
63
- # Log the error message.
64
- def error(msg, pos=caller(1).first)
65
- raise NotImplementedError
66
- end
67
-
68
- # Log the warn message.
69
- def warn(msg, pos=caller(1).first)
70
- raise NotImplementedError
71
- end
6
+ # `Log::PioneSystemLogger` is a PIONE original logger. This generates very
7
+ # colorful message for identifiability and detailed informations.
8
+ class PioneSystemLogger < Rootage::Logger
9
+ include DRbUndumped
72
10
 
73
- # Log the info message.
74
- def info(msg, pos=caller(1).first)
75
- raise NotImplementedError
76
- end
77
-
78
- # Log the debug message.
79
- def debug(msg, pos=caller(1).first)
80
- raise NotImplementedError
81
- end
82
-
83
- # Terminate the logger.
84
- def terminate
85
- raise NotImplementedError
86
- end
87
-
88
- # Return true if some messages are queued.
89
- def queued?
90
- raise NotImplementedError
91
- end
92
- end
93
-
94
- # PioneSystemLogger is a PIONE original logger. This generates very colorful
95
- # message for identifiability and detailed informations.
96
- class PioneSystemLogger < SystemLogger
97
11
  attr_accessor :level
98
12
 
99
- def initialize(out = $stdout)
13
+ def initialize(out = nil)
100
14
  @queue = Queue.new
101
15
  @thread = make_writer_thread
102
16
  @level = :info
17
+ @lock = Mutex.new
103
18
  @out = out
104
19
  end
105
20
 
106
- def fatal(msg, pos=caller(1).first); push(:fatal, msg, pos); end
107
- def error(msg, pos=caller(1).first); push(:error, msg, pos); end
108
- def warn (msg, pos=caller(1).first); push(:warn , msg, pos); end
109
- def info (msg, pos=caller(1).first); push(:info , msg, pos); end
110
- def debug(msg, pos=caller(1).first); push(:debug, msg, pos); end
21
+ def fatal(msg, pos=caller(1).first, pid=Process.pid); push(:fatal, msg, pos, pid); end
22
+ def error(msg, pos=caller(1).first, pid=Process.pid); push(:error, msg, pos, pid); end
23
+ def warn (msg, pos=caller(1).first, pid=Process.pid); push(:warn , msg, pos, pid); end
24
+ def info (msg, pos=caller(1).first, pid=Process.pid); push(:info , msg, pos, pid); end
25
+ def debug(msg, pos=caller(1).first, pid=Process.pid); push(:debug, msg, pos, pid); end
111
26
 
112
27
  def terminate
113
28
  timeout(3) do
114
29
  while @thread.alive?
115
- if @queue.empty?
30
+ if @queue.empty? and not(@lock.locked?)
116
31
  @thread.kill.join
117
32
  break
118
33
  else
@@ -121,11 +36,11 @@ module Pione
121
36
  end
122
37
  end
123
38
  rescue Timeout::Error
39
+ # don't use logger here because it is dead at this time
40
+ $stdout.puts("*** system logger has been terminated unsafety, some messages maybe lost ***")
41
+ ensure
124
42
  # kill writer thread
125
43
  @thread.kill if @thread.alive?
126
-
127
- # don't use logger because it is dead at this time
128
- @out.puts("*** system logger has been terminated unsafety, some messages maybe lost ***")
129
44
  end
130
45
 
131
46
  def queued?
@@ -134,75 +49,83 @@ module Pione
134
49
 
135
50
  private
136
51
 
52
+ def level_to_i(level)
53
+ case level
54
+ when :fatal; 0
55
+ when :error; 1
56
+ when :warn ; 2
57
+ when :info ; 3
58
+ when :debug; 4
59
+ end
60
+ end
61
+
137
62
  def make_writer_thread
138
63
  Thread.new do
139
64
  while true do
140
- level, msg, pos, time = @queue.pop
141
- print(level, msg, pos, time)
65
+ level, msg, pos, pid, time = @queue.pop
66
+ @lock.synchronize {print(level, msg, pos, pid, time)}
142
67
  end
143
68
  end
144
69
  end
145
70
 
146
- def push(level, msg, pos)
147
- @queue.push([level, msg, pos, Time.now])
71
+ def push(level, msg, pos, pid)
72
+ if level_to_i(@level) >= level_to_i(level)
73
+ @queue.push([level, msg, pos, pid, Time.now])
74
+ end
148
75
  end
149
76
 
150
77
  def color_of(level)
151
78
  Global.send("pione_system_logger_%s" % level)
152
79
  end
153
80
 
154
- def print(level, msg, pos, time)
81
+ def print(level, msg, pos, pid, time)
82
+ out = @out || $stdout
155
83
  if level == :info
156
- @out.puts "%s: %s" % [level.to_s.color(color_of(level)), msg]
84
+ out.puts "%s: %s" % [level.to_s.color(color_of(level)), msg]
157
85
  else
158
- @out.puts "%s: %s [%s] (%s, #%s)" % [level.to_s.color(color_of(level)), msg, pos, time.iso8601(3), Process.pid]
86
+ out.puts "%s: %s [%s] (%s, #%s)" % [level.to_s.color(color_of(level)), msg, pos, time.iso8601(3), pid]
159
87
  end
160
88
  end
161
89
  end
162
90
 
163
- # StandardSystemLogger is a logger using Ruby standard Logger.
164
- class RubyStandardSystemLogger < SystemLogger
165
- forward! :@logger, :level, :level=
91
+ class DelegatableLogger < Rootage::Logger
92
+ include DRbUndumped
166
93
 
167
- def initialize(out = $stdout)
168
- @logger = Logger.new(out)
94
+ def initialize(logger)
95
+ @logger = logger
169
96
  end
170
97
 
171
- def fatal(msg, pos=caller(1).first); @logger.fatal(msg); end
172
- def error(msg, pos=caller(1).first); @logger.error(msg); end
173
- def warn (msg, pos=caller(1).first); @logger.warn(msg) ; end
174
- def info (msg, pos=caller(1).first); @logger.info(msg) ; end
175
- def debug(msg, pos=caller(1).first); @logger.debug(msg); end
176
-
177
- def terminate
178
- # ignore
98
+ def fatal(msg, pos=caller(1).first, pid=Process.pid)
99
+ send_message(msg, pos, pid) {@logger.fatal(msg, pos, pid)}
179
100
  end
180
101
 
181
- def queued?
182
- false
102
+ def error(msg, pos=caller(1).first, pid=Process.pid)
103
+ send_message(msg, pos, pid) {@logger.error(msg, pos, pid)}
183
104
  end
184
- end
185
105
 
186
- # SyslogSystemLogger is a logger using syslog("syslog-logger" gem).
187
- class SyslogSystemLogger < SystemLogger
188
- forward! :@logger, :level, :level=
106
+ def warn(msg, pos=caller(1).first, pid=Process.pid)
107
+ send_message(msg, pos, pid) {@logger.warn(msg, pos, pid)}
108
+ end
189
109
 
190
- def initialize
191
- @logger = Logger::Syslog.new('pione')
110
+ def info(msg, pos=caller(1).first, pid=Process.pid)
111
+ send_message(msg, pos, pid) {@logger.info(msg, pos, pid)}
192
112
  end
193
113
 
194
- def fatal(msg, pos=caller(1).first); @logger.fatal(msg); end
195
- def error(msg, pos=caller(1).first); @logger.error(msg); end
196
- def warn (msg, pos=caller(1).first); @logger.warn(msg) ; end
197
- def info (msg, pos=caller(1).first); @logger.info(msg) ; end
198
- def debug(msg, pos=caller(1).first); @logger.debug(msg); end
114
+ def debug(msg, pos=caller(1).first, pid=Process.pid)
115
+ send_message(msg, pos, pid) {@logger.debug(msg, pos, pid)}
116
+ end
199
117
 
200
118
  def terminate
201
- # ignore
119
+ @logger = nil
202
120
  end
203
121
 
204
- def queued?
205
- false
122
+ private
123
+
124
+ def send_message(msg, pos, pid, &block)
125
+ block.call
126
+ rescue Exception
127
+ # print stdout directly if the logger fails
128
+ $stdout.puts("%s (%s) #%s" % [msg, pos, pid])
206
129
  end
207
130
  end
208
131
 
@@ -210,8 +133,6 @@ module Pione
210
133
  # register loggers
211
134
  #
212
135
 
213
- SystemLogger.register(:pione, PioneSystemLogger)
214
- SystemLogger.register(:ruby, RubyStandardSystemLogger)
215
- SystemLogger.register(:syslog, SyslogSystemLogger)
136
+ Rootage::Logger.register(:pione, PioneSystemLogger)
216
137
  end
217
138
  end