pione 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +2 -1
  2. data/History.txt +11 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +1 -1
  5. data/bin/pione-log +5 -0
  6. data/example/CountChar/CountChar.pione +1 -1
  7. data/example/SieveOfEratosthenes/SieveOfEratosthenes.pione +39 -38
  8. data/lib/pione.rb +14 -35
  9. data/lib/pione/agent/input-generator.rb +38 -40
  10. data/lib/pione/agent/logger.rb +52 -19
  11. data/lib/pione/agent/rule-provider.rb +5 -8
  12. data/lib/pione/agent/task-worker.rb +25 -32
  13. data/lib/pione/agent/tuple-space-client.rb +22 -14
  14. data/lib/pione/command.rb +21 -0
  15. data/lib/pione/command/basic-command.rb +267 -84
  16. data/lib/pione/command/child-process.rb +21 -18
  17. data/lib/pione/command/daemon-process.rb +9 -8
  18. data/lib/pione/command/front-owner-command.rb +8 -25
  19. data/lib/pione/command/pione-broker.rb +27 -24
  20. data/lib/pione/command/pione-clean.rb +6 -6
  21. data/lib/pione/command/pione-client.rb +143 -128
  22. data/lib/pione/command/pione-log.rb +61 -0
  23. data/lib/pione/command/pione-relay-account-db.rb +40 -38
  24. data/lib/pione/command/pione-relay-client-db.rb +38 -42
  25. data/lib/pione/command/pione-relay.rb +19 -20
  26. data/lib/pione/command/pione-syntax-checker.rb +70 -45
  27. data/lib/pione/command/pione-task-worker.rb +56 -66
  28. data/lib/pione/command/pione-tuple-space-provider.rb +36 -45
  29. data/lib/pione/command/pione-tuple-space-receiver.rb +34 -32
  30. data/lib/pione/command/pione-tuple-space-viewer.rb +63 -47
  31. data/lib/pione/location.rb +10 -0
  32. data/lib/pione/location/basic-location.rb +272 -0
  33. data/lib/pione/location/dropbox-location.rb +139 -0
  34. data/lib/pione/location/ftp-location.rb +156 -0
  35. data/lib/pione/location/local-location.rb +116 -0
  36. data/lib/pione/log.rb +10 -0
  37. data/lib/pione/log/domain-info.rb +72 -0
  38. data/lib/pione/log/process-log.rb +176 -0
  39. data/lib/pione/log/process-record.rb +189 -0
  40. data/lib/pione/log/xes-log.rb +105 -0
  41. data/lib/pione/model/assignment.rb +88 -80
  42. data/lib/pione/model/binary-operator.rb +74 -68
  43. data/lib/pione/model/block.rb +218 -207
  44. data/lib/pione/model/boolean.rb +123 -112
  45. data/lib/pione/model/call-rule.rb +72 -65
  46. data/lib/pione/model/data-expr.rb +596 -290
  47. data/lib/pione/model/float.rb +108 -103
  48. data/lib/pione/model/integer.rb +133 -129
  49. data/lib/pione/model/message.rb +79 -72
  50. data/lib/pione/model/package.rb +42 -38
  51. data/lib/pione/model/parameters.rb +265 -236
  52. data/lib/pione/model/rule-expr.rb +247 -242
  53. data/lib/pione/model/rule-io.rb +137 -133
  54. data/lib/pione/model/rule.rb +307 -292
  55. data/lib/pione/model/string.rb +110 -99
  56. data/lib/pione/model/variable-table.rb +300 -271
  57. data/lib/pione/model/variable.rb +88 -83
  58. data/lib/pione/option.rb +13 -0
  59. data/lib/pione/option/child-process-option.rb +19 -0
  60. data/lib/pione/{command-option → option}/common-option.rb +6 -5
  61. data/lib/pione/option/option-interface.rb +73 -0
  62. data/lib/pione/{command-option → option}/presence-notifier-option.rb +4 -3
  63. data/lib/pione/option/task-worker-owner-option.rb +24 -0
  64. data/lib/pione/{command-option → option}/tuple-space-provider-option.rb +6 -4
  65. data/lib/pione/option/tuple-space-provider-owner-option.rb +18 -0
  66. data/lib/pione/option/tuple-space-receiver-option.rb +8 -0
  67. data/lib/pione/parser/common-parser.rb +3 -2
  68. data/lib/pione/parser/expr-parser.rb +6 -1
  69. data/lib/pione/patch/em-ftpd-patch.rb +21 -0
  70. data/lib/pione/patch/rinda-patch.rb +31 -23
  71. data/lib/pione/rule-handler/action-handler.rb +35 -25
  72. data/lib/pione/rule-handler/basic-handler.rb +92 -18
  73. data/lib/pione/rule-handler/flow-handler.rb +104 -98
  74. data/lib/pione/rule-handler/root-handler.rb +11 -0
  75. data/lib/pione/system/common.rb +10 -0
  76. data/lib/pione/system/file-cache.rb +103 -84
  77. data/lib/pione/system/global.rb +67 -12
  78. data/lib/pione/system/init.rb +20 -0
  79. data/lib/pione/transformer/expr-transformer.rb +6 -1
  80. data/lib/pione/tuple-space/data-finder.rb +33 -6
  81. data/lib/pione/tuple-space/tuple-space-receiver.rb +4 -3
  82. data/lib/pione/tuple-space/tuple-space-server-interface.rb +58 -13
  83. data/lib/pione/tuple-space/tuple-space-server.rb +13 -11
  84. data/lib/pione/tuple-space/update-criteria.rb +8 -7
  85. data/lib/pione/tuple/base-location-tuple.rb +9 -0
  86. data/lib/pione/tuple/basic-tuple.rb +7 -7
  87. data/lib/pione/tuple/data-tuple.rb +5 -2
  88. data/lib/pione/tuple/lift-tuple.rb +14 -0
  89. data/lib/pione/tuple/rule-tuple.rb +1 -1
  90. data/lib/pione/tuple/task-tuple.rb +5 -1
  91. data/lib/pione/version.rb +1 -1
  92. data/pione.gemspec +5 -1
  93. data/test/location/spec_basic-location.rb +35 -0
  94. data/test/location/spec_ftp-location.rb +100 -0
  95. data/test/location/spec_local-location.rb +99 -0
  96. data/test/log/data/sample.log +1003 -0
  97. data/test/log/spec_xes-log.rb +11 -0
  98. data/test/model/spec_data-expr.rb +249 -6
  99. data/test/model/spec_data-expr.yml +45 -0
  100. data/test/parser/spec_expr-parser.yml +4 -0
  101. data/test/spec_data-finder.rb +13 -7
  102. data/test/spec_data-finder.yml +42 -13
  103. data/test/system/spec_file-cache.rb +39 -0
  104. data/test/test-util.rb +226 -1
  105. data/test/transformer/spec_expr-transformer.rb +12 -1
  106. metadata +107 -24
  107. data/bin/pione-search-log +0 -30
  108. data/lib/pione/command-option/basic-option.rb +0 -42
  109. data/lib/pione/command-option/child-process-option.rb +0 -17
  110. data/lib/pione/command-option/daemon-option.rb +0 -12
  111. data/lib/pione/command-option/task-worker-owner-option.rb +0 -17
  112. data/lib/pione/command-option/tuple-space-provider-owner-option.rb +0 -16
  113. data/lib/pione/command-option/tuple-space-receiver-option.rb +0 -12
  114. data/lib/pione/command/tuple-space-provider-owner.rb +0 -6
  115. data/lib/pione/resource/basic-resource.rb +0 -92
  116. data/lib/pione/resource/dropbox-resource.rb +0 -106
  117. data/lib/pione/resource/ftp.rb +0 -84
  118. data/lib/pione/resource/local.rb +0 -113
  119. data/lib/pione/tuple/base-uri-tuple.rb +0 -9
  120. data/lib/pione/tuple/shift-tuple.rb +0 -13
  121. data/lib/pione/util/log.rb +0 -79
  122. data/test/spec_resource.rb +0 -73
@@ -1,20 +1,29 @@
1
1
  module Pione
2
2
  module Command
3
+ # ChildProcess is a superclass for commands that are children of other
4
+ # processes.
3
5
  class ChildProcess < FrontOwnerCommand
4
- use_option_module CommandOption::ChildProcessOption
5
- attr_reader :parent_front
6
+ define_option do
7
+ default :no_parent_front, false
6
8
 
7
- # @api private
8
- def validate_options
9
- if not(@no_parent_mode) and @parent_front.nil?
10
- abort("option error: no caller front address")
9
+ # --parent-front
10
+ option('--parent-front=URI', 'set parent front URI') do |data, uri|
11
+ data[:parent_front] = DRbObject.new_with_uri(uri)
12
+ end
13
+
14
+ # --no-parent
15
+ option('--no-parent', 'turn on no parent mode') do |data|
16
+ data[:no_parent_mode] = true
11
17
  end
12
- end
13
18
 
14
- # @api private
15
- def prepare
16
- super
19
+ validate do |data|
20
+ if not(data[:no_parent_mode]) and data[:parent_front].nil?
21
+ abort("option error: no caller front address")
22
+ end
23
+ end
24
+ end
17
25
 
26
+ prepare do
18
27
  # "ppid == 1" means the parent is dead
19
28
  terminater = Proc.new do
20
29
  if Process.ppid == 1
@@ -28,19 +37,13 @@ module Pione
28
37
  @watchdog = Agent::TrivialRoutineWorker.new(terminater)
29
38
  end
30
39
 
31
- # @api private
32
- def start
40
+ start do
33
41
  @watchdog.start
34
42
  end
35
43
 
36
- # Terminate the child front. Kill watchdog.
37
- #
38
- # @return [void]
39
- def terminate
44
+ terminate do
40
45
  # kill watchdog
41
46
  @watchdog.terminate
42
- # go to other termination processes
43
- super
44
47
  end
45
48
  end
46
49
  end
@@ -1,17 +1,18 @@
1
1
  module Pione
2
2
  module Command
3
+ # DaemonProcess is a class for commands that enable to daemonize.
3
4
  class DaemonProcess < FrontOwnerCommand
4
- use_option_module CommandOption::DaemonOption
5
+ define_option do
6
+ default :daemon, false
5
7
 
6
- def initialize
7
- super
8
- @daemon = false
8
+ # --daemon
9
+ option("--daemon", "turn on daemon mode") do |data|
10
+ data[:daemon] = true
11
+ end
9
12
  end
10
13
 
11
- def prepare
12
- super
13
- puts Global.front.uri
14
- Process.daemon(true, true) if @daemon
14
+ prepare(:post) do
15
+ Process.daemon(true, true) if option[:daemon]
15
16
  end
16
17
  end
17
18
  end
@@ -1,26 +1,14 @@
1
1
  module Pione
2
2
  module Command
3
+ # FrontOwnerCommand is a parent of classes that own front server.
3
4
  class FrontOwnerCommand < BasicCommand
4
- define_option("--my-ip-address=ADDRESS", "set my IP address") do |address|
5
- Global.my_ip_address = address
6
- end
7
-
8
- # Runs the command.
9
- #
10
- # @return [void]
11
- def run
12
- parse_options
13
- validate_options
14
- setup_front
15
- prepare
16
- setup_program_name
17
- start
5
+ define_option do
6
+ option("--my-ip-address=ADDRESS", "set my IP address") do |data, address|
7
+ Global.my_ip_address = address
8
+ end
18
9
  end
19
10
 
20
- # Setup font server.
21
- #
22
- # @return [void]
23
- def setup_front
11
+ prepare do
24
12
  Global.front = create_front
25
13
  end
26
14
 
@@ -32,15 +20,10 @@ module Pione
32
20
  raise NotImplementedError
33
21
  end
34
22
 
35
- # Terminate PIONE front. Stop DRb service.
36
- #
37
- # @return [void]
38
- def terminate
23
+ terminate do
39
24
  Global.monitor.synchronize do
40
25
  # stop DRb service
41
- DRb.stop_service
42
- # go to other termination processes
43
- super
26
+ # DRb.stop_service
44
27
  end
45
28
  end
46
29
  end
@@ -1,45 +1,44 @@
1
1
  module Pione
2
2
  module Command
3
+ # PioneBroker is a command for starting a PIONE broker agent. Brokers
4
+ # provides task processing ability to the system.
3
5
  class PioneBroker < DaemonProcess
4
- set_program_name "pione-broker" do
5
- "--task-worker %s" % @task_worker
6
+ define_info do
7
+ set_name "pione-broker"
8
+ set_tail {|cmd| "{TaskWorker: %s}" % cmd.option[:task_worker]}
9
+ set_banner "Run broker agent to launch task workers."
6
10
  end
7
11
 
8
- set_program_message <<TXT
9
- Runs the broker to launch task workers.
10
- TXT
12
+ define_option do
13
+ use Option::TupleSpaceReceiverOption
14
+ use Option::TaskWorkerOwnerOption
11
15
 
12
- use_option_module CommandOption::TupleSpaceReceiverOption
13
- use_option_module CommandOption::TaskWorkerOwnerOption
16
+ validate do |data|
17
+ unless data[:task_worker] > 0
18
+ abort("error: no task worker resources")
19
+ end
20
+ end
21
+ end
14
22
 
15
23
  attr_reader :broker
16
24
 
17
- def initialize
18
- @task_worker = [Util.core_number - 1, 1].max
19
- @features = nil
20
- end
21
-
22
25
  def create_front
23
26
  Front::BrokerFront.new(self)
24
27
  end
25
28
 
26
- def validate_options
27
- unless @task_worker > 0
28
- abort("error: no task worker resources")
29
- end
30
- end
31
-
32
- def prepare
33
- super
34
- @broker = Pione::Agent[:broker].new(@features, task_worker_resource: @task_worker)
29
+ prepare do
30
+ @broker = Pione::Agent[:broker].new(
31
+ option[:features],
32
+ task_worker_resource: option[:task_worker]
33
+ )
35
34
  @tuple_space_receiver = Pione::TupleSpaceReceiver.instance
36
35
  end
37
36
 
38
- def start
39
- # start broker
37
+ start do
38
+ # start broker agent
40
39
  @broker.start
41
40
 
42
- # start tuple space receiver
41
+ # start tuple space receiver with the broker agent
43
42
  @tuple_space_receiver.register(@broker)
44
43
 
45
44
  # wait
@@ -49,6 +48,10 @@ TXT
49
48
  retry
50
49
  end
51
50
  end
51
+
52
+ terminate do
53
+ @broker.terminate
54
+ end
52
55
  end
53
56
  end
54
57
  end
@@ -1,13 +1,13 @@
1
1
  module Pione
2
2
  module Command
3
+ # PioneClean is a command for clearing temporary files of PIONE system.
3
4
  class PioneClean < BasicCommand
4
- set_program_name("pione-clean")
5
-
6
- set_program_message <<TXT
7
- Cleans working directories and file cache directories.
8
- TXT
5
+ define_info do
6
+ set_name "pione-clean"
7
+ set_banner "Clean working directories and file cache directories."
8
+ end
9
9
 
10
- def start
10
+ start do
11
11
  FileUtils.remove_entry_secure(Global.working_directory_root)
12
12
  FileUtils.remove_entry_secure(Global.file_cache_directory_root)
13
13
  end
@@ -1,142 +1,146 @@
1
1
  module Pione
2
2
  module Command
3
+ # PioneClient is a command to request processing.
3
4
  class PioneClient < FrontOwnerCommand
4
- use_option_module CommandOption::TaskWorkerOwnerOption
5
- use_option_module CommandOption::TupleSpaceProviderOwnerOption
6
-
7
- set_program_name("pione-client") do
8
- [@filename, "-o %s" % @output_uri, @stream ? "--stream" : ""].join(" ")
5
+ define_info do
6
+ set_name "pione-client"
7
+ set_tail {|cmd|
8
+ args = [cmd.option[:filename], cmd.option[:output_uri], cmd.option[:stream]]
9
+ "{Document: %s, OutputURI: %s, Stream: %s}" % args
10
+ }
11
+ set_banner "Requests to process PIONE document."
9
12
  end
10
13
 
11
- set_program_message "Requests to process PIONE document."
14
+ define_option do
15
+ use Option::TaskWorkerOwnerOption
16
+ use Option::TupleSpaceProviderOwnerOption
17
+
18
+ default :output_location, Location["local:./output/"]
19
+ default :stream, false
20
+ default :params, Model::Parameters.empty
21
+ default :dry_run, false
22
+ default :task_worker, [Util.core_number - 1, 1].max
23
+ default :request_task_worker, 1
24
+ default :stand_alone, false
25
+ default :relay, nil
26
+ default :filename, "-"
27
+ default :without_tuple_space_provider, false
28
+ default :features, "^Interactive"
29
+ default :list_params, false
30
+
31
+ # --input
32
+ option('-i LOCATION', '--input=LOCATION', 'set input directory') do |data, uri|
33
+ begin
34
+ data[:input_location] = Location[uri]
35
+ rescue ArgumentError
36
+ abort("opiton error: bad location '%s'" % uri)
37
+ end
38
+ end
12
39
 
13
- # --input-uri
14
- define_option('-i URI', '--input=URI', 'set input directory URI') do |uri|
15
- parsed = URI.parse(uri)
16
- unless parsed.scheme
17
- parsed = URI.parse("local:%s" % Pathname.new(uri).expand_path)
40
+ # --output
41
+ option('-o LOCATION', '--output=LOCATION', 'set output directory') do |data, uri|
42
+ begin
43
+ data[:output_location] = Location[uri]
44
+ rescue ArgumentError
45
+ abort("opiton error: bad location '%s'" % uri)
46
+ end
18
47
  end
19
- @input_uri = parsed.as_directory
20
- end
21
48
 
22
- # --output-uri
23
- define_option('-o URI', '--output=URI', 'set output directory URI') do |uri|
24
- @output_uri = URI.parse(uri)
25
- end
49
+ # --stream
50
+ option('--stream', 'turn on stream mode') do |data|
51
+ data[:stream] = true
52
+ end
26
53
 
27
- # --log
28
- define_option('--log=PATH', 'set log path') do |path|
29
- @log_path = path
30
- end
54
+ # --request-task-worker
55
+ option('--request-task-worker=N', 'set request number of task workers') do |data, n|
56
+ data[:request_task_worker] = n.to_i
57
+ end
31
58
 
32
- # --stream
33
- define_option('--stream', 'turn on stream mode') do
34
- @stream = true
35
- end
59
+ # --params
60
+ option('--params="{Var:1,...}"', "set &main:Main rule's parameters") do |data, str|
61
+ begin
62
+ params = DocumentTransformer.new.apply(
63
+ DocumentParser.new.parameters.parse(str)
64
+ )
65
+ data[:params].merge!(params)
66
+ rescue Parslet::ParseFailed => e
67
+ puts "invalid parameters: " + str
68
+ Util::ErrorReport.print(e)
69
+ abort
70
+ end
71
+ end
36
72
 
37
- # --request-task-worker
38
- define_option('--request-task-worker=N', 'set request number of task workers') do |n|
39
- @request_task_worker = n.to_i
40
- end
73
+ # --stand-alone
74
+ option('--stand-alone', 'turn on stand alone mode') do |data|
75
+ data[:stand_alone] = true
76
+ data[:without_tuple_space_provider] = true
77
+ end
41
78
 
42
- # --params
43
- define_option('--params="{Var:1,...}"', "set &main:Main rule's parameters") do |str|
44
- begin
45
- params = DocumentTransformer.new.apply(
46
- DocumentParser.new.parameters.parse(str)
47
- )
48
- @params.merge!(params)
49
- rescue Parslet::ParseFailed => e
50
- puts "invalid parameters: " + str
51
- Util::ErrorReport.print(e)
52
- abort
79
+ # --dry-run
80
+ option('--dry-run', 'turn on dry run mode') do |data, b|
81
+ data[:dry_run] = true
53
82
  end
54
- end
55
83
 
56
- # --stand-alone
57
- define_option('--stand-alone', 'turn on stand alone mode') do
58
- @stand_alone = true
59
- @without_tuple_space_provider = true
60
- end
84
+ # --relay
85
+ option('--relay=URI', 'turn on relay mode and set relay address') do |data, uri|
86
+ data[:relay] = uri
87
+ end
61
88
 
62
- # --dry-run
63
- define_option('--dry-run', 'turn on dry run mode') do |b|
64
- @dry_run = true
65
- end
89
+ # --name
90
+ option('--name=NAME') do |data, name|
91
+ data[:name] = name
92
+ end
66
93
 
67
- # --relay
68
- define_option('--relay=URI', 'turn on relay mode and set relay address') do |uri|
69
- @relay = uri
70
- end
94
+ # --list-parameters
95
+ option('--list-params', 'show user parameter list in the document') do |data|
96
+ data[:list_params] = true
97
+ end
71
98
 
72
- define_option('--name=NAME') do |name|
73
- @name = name
74
- end
99
+ validate do |data|
100
+ unless data[:task_worker] > 0 or
101
+ (not(data[:stand_alone]) and data[:task_worker] == 0)
102
+ abort("option error: invalid resource size '%s'" % data[:task_worker])
103
+ end
75
104
 
76
- # --list-parameters
77
- define_option('--list-params', 'show user parameter list in the document') do
78
- @list_params = true
105
+ if data[:stream] and data[:input_location].nil?
106
+ abort("option error: no input URI on stream mode")
107
+ end
108
+ end
79
109
  end
80
110
 
111
+ attr_reader :task_worker
112
+ attr_reader :features
81
113
  attr_reader :tuple_space_server
82
114
  attr_reader :name
83
115
 
84
116
  def initialize
85
117
  super()
86
- @input_uri = nil
87
- @output_uri = URI.parse("local:./output/")
88
- @log_path = "log.txt"
89
- @stream = false
90
- @params = Parameters.empty
91
- @dry_run = false
92
- @task_worker = [Util.core_number - 1, 1].max
93
- @request_task_worker = 1
94
118
  @worker_threads = []
95
- @stand_alone = false
96
- @relay = nil
97
- @filename = "-"
98
- @without_tuple_space_provider = false
99
- @features = "^Interactive"
100
- @list_params = false
119
+ @tuple_space_server = nil
101
120
  end
102
121
 
103
122
  private
104
123
 
105
- def validate_options
106
- unless @task_worker > 0 or (not(@stand_alone) and @task_worker == 0)
107
- abort("option error: invalid resource size '%s'" % @task_worker)
108
- end
109
-
110
- if @stream and @input_uri.nil?
111
- abort("option error: no input URI on stream mode")
112
- end
113
-
114
- if not(@input_uri.nil?)
115
- unless @input_uri.pione? and @input_uri.storage?
116
- abort("opiton error: bad URI scheme '%s'" % @input_uri)
117
- end
118
- end
119
- end
120
-
121
124
  def create_front
122
125
  Front::ClientFront.new(self)
123
126
  end
124
127
 
125
- def prepare
126
- super
127
-
128
+ prepare do
128
129
  @filename = ARGF.filename
129
130
 
131
+ # setup log location
132
+ @log_location = option[:output_location] + Time.now.strftime("pione_%Y%m%d%H%M%S.log")
133
+
130
134
  @tuple_space_server = TupleSpaceServer.new(
131
- task_worker_resource: @request_task_worker
135
+ task_worker_resource: option[:request_task_worker]
132
136
  )
133
137
 
134
138
  # setup base uri
135
- case @output_uri.scheme
136
- when "local"
137
- FileUtils.makedirs(@output_uri.path)
138
- @output_uri = @output_uri.absolute
139
- when "dropbox"
139
+ case option[:output_location]
140
+ when Location::LocalLocation
141
+ option[:output_location] = Location[option[:output_location].path.expand_path]
142
+ option[:output_location].path.mkpath
143
+ when Location::DropboxLocation
140
144
  # start session
141
145
  session = nil
142
146
  consumer_key = nil
@@ -145,7 +149,7 @@ module Pione
145
149
  cache = Pathname.new("~/.pione/dropbox_api.cache").expand_path
146
150
  if cache.exist?
147
151
  session = DropboxSession.deserialize(cache.read)
148
- Resource::Dropbox.set_session(session)
152
+ Location::Dropbox.set_session(session)
149
153
  consumer_key = session.instance_variable_get(:@consumer_key)
150
154
  consumer_secret = session.instance_variable_get(:@consumer_secret)
151
155
  else
@@ -153,7 +157,7 @@ module Pione
153
157
  consumer_key = api["key"]
154
158
  consumer_secret = api["secret"]
155
159
  session = DropboxSession.new(consumer_key, consumer_secret)
156
- Resource::Dropbox.set_session(session)
160
+ Location::Dropbox.set_session(session)
157
161
  authorize_url = session.get_authorize_url
158
162
  puts "AUTHORIZING", authorize_url
159
163
  puts "Please visit that web page and hit 'Allow', then hit Enter here."
@@ -170,43 +174,38 @@ module Pione
170
174
  end
171
175
 
172
176
  # share access token in tuple space
173
- Resource::Dropbox.share_access_token(tuple_space_server, consumer_key, consumer_secret)
177
+ Location::Dropbox.share_access_token(tuple_space_server, consumer_key, consumer_secret)
174
178
  end
175
179
 
176
- @output_uri = @output_uri.as_directory.to_s
177
- @tuple_space_server.set_base_uri(@output_uri)
180
+ @tuple_space_server.set_base_location(option[:output_location])
178
181
  end
179
182
 
180
- def start
183
+ start do
181
184
  read_process_document
182
185
 
183
- if @list_params
186
+ if option[:list_params]
184
187
  print_parameter_list
185
- exit
188
+ exit!
186
189
  end
187
190
 
188
191
  write_tuples
189
- connect_relay if @relay
192
+ connect_relay if option[:relay]
190
193
  start_agents
191
194
 
192
195
  # start tuple space provider with thread
193
196
  # the thread is terminated when the client terminated
194
- unless @without_tuple_space_provider
197
+ unless option[:without_tuple_space_provider]
195
198
  @start_tuple_space_provider_thread = Thread.new do
196
199
  start_tuple_space_provider
197
200
  end
198
201
  end
199
202
 
200
203
  start_workers
201
- @agent = Agent[:process_manager].start(@tuple_space_server, @document, @params, @stream)
204
+ @agent = Agent[:process_manager].start(@tuple_space_server, @document, option[:params], option[:stream])
202
205
  @agent.running_thread.join
203
- terminate
204
206
  end
205
207
 
206
- # Terminate pione-client command. Kill tuple space provider.
207
- #
208
- # @return [void]
209
- def terminate
208
+ terminate do
210
209
  Global.monitor.synchronize do
211
210
  # kill the thread for starting tuple space provider
212
211
  if @start_tuple_space_provider_thread
@@ -215,18 +214,20 @@ module Pione
215
214
  end
216
215
  end
217
216
 
217
+ @logger.terminate
218
+
218
219
  # terminate tuple space provider
219
220
  if @tuple_space_provider
220
221
  @tuple_space_provider.terminate
221
222
  end
222
-
223
- # go to other termination processes.
224
- super
225
223
  end
226
224
  end
227
225
 
228
226
  private
229
227
 
228
+ # Read PIONE process document.
229
+ #
230
+ # @return [void]
230
231
  def read_process_document
231
232
  # process definition document is not found.
232
233
  if ARGF.filename == "-"
@@ -246,15 +247,21 @@ module Pione
246
247
  end
247
248
  end
248
249
 
250
+ # Write initial tuples.
251
+ #
252
+ # @return [void]
249
253
  def write_tuples
250
254
  [ Tuple[:process_info].new('standalone', 'Standalone'),
251
- Tuple[:dry_run].new(@dry_run)
255
+ Tuple[:dry_run].new(option[:dry_run])
252
256
  ].each {|tuple| @tuple_space_server.write(tuple) }
253
257
  end
254
258
 
259
+ # Start agent activities.
260
+ #
261
+ # @return [void]
255
262
  def start_agents
256
263
  # logger
257
- Agent[:logger].start(@tuple_space_server, File.open(@log_path, "w+"))
264
+ @logger = Agent[:logger].start(@tuple_space_server, @log_location)
258
265
 
259
266
  # rule provider
260
267
  @rule_loader = Agent[:rule_provider].start(@tuple_space_server)
@@ -262,34 +269,42 @@ module Pione
262
269
  @rule_loader.wait_till(:request_waiting)
263
270
 
264
271
  # input generators
265
- generator_method = @stream ? :start_by_stream : :start_by_dir
272
+ generator_method = option[:stream] ? :start_by_stream : :start_by_dir
266
273
  gen = Agent[:input_generator].send(
267
- generator_method, @tuple_space_server, @input_uri
274
+ generator_method, @tuple_space_server, option[:input_location]
268
275
  )
269
276
 
270
277
  # command listener
271
278
  @command_listener = Agent[:command_listener].start(@tuple_space_server, self)
272
279
  end
273
280
 
274
- # Wakes up tuple space provider process and push my tuple space server to
275
- # it.
281
+ # Wake up tuple space provider process and connect my tuple space server
282
+ # to it.
276
283
  def start_tuple_space_provider
277
284
  @tuple_space_provider = Pione::TupleSpaceProvider.instance
278
285
  @tuple_space_provider.add_tuple_space_server(@tuple_space_server)
279
286
  end
280
287
 
288
+ # Start task workers.
289
+ #
290
+ # @return [void]
281
291
  def start_workers
282
- @task_worker.times do
283
- Thread.new { Agent[:task_worker].spawn(Global.front, Util.generate_uuid, @features) }
292
+ option[:task_worker].times do
293
+ Thread.new {
294
+ Agent[:task_worker].spawn(Global.front, Util.generate_uuid, option[:features])
295
+ }
284
296
  end
285
297
  end
286
298
 
299
+ # Connect relay server.
300
+ #
301
+ # @return [void]
287
302
  def connect_relay
288
303
  Global.relay_tuple_space_server = @tuple_space_server
289
- @relay_ref = DRbObject.new_with_uri(@relay)
304
+ @relay_ref = DRbObject.new_with_uri(option[:relay])
290
305
  @relay_ref.__connect
291
306
  if Global.show_communication
292
- puts "you connected the relay: %s" % @relay
307
+ puts "you connected the relay: %s" % option[:relay]
293
308
  end
294
309
  # watchdog for the relay server
295
310
  Thread.start do