engineyard-serverside 1.5.23.ruby19.16 → 1.5.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. data/lib/engineyard-serverside.rb +19 -17
  2. data/lib/engineyard-serverside/cli.rb +38 -30
  3. data/lib/engineyard-serverside/configuration.rb +4 -28
  4. data/lib/engineyard-serverside/deploy.rb +10 -7
  5. data/lib/engineyard-serverside/lockfile_parser.rb +2 -2
  6. data/lib/engineyard-serverside/logged_output.rb +2 -0
  7. data/lib/engineyard-serverside/server.rb +2 -27
  8. data/lib/engineyard-serverside/task.rb +14 -10
  9. data/lib/engineyard-serverside/version.rb +1 -1
  10. data/lib/vendor/dataflow/HISTORY +52 -0
  11. data/lib/vendor/dataflow/LICENSE +19 -0
  12. data/lib/vendor/dataflow/README.textile +290 -0
  13. data/lib/vendor/dataflow/Rakefile +36 -0
  14. data/lib/vendor/dataflow/examples/barrier.rb +9 -0
  15. data/lib/vendor/dataflow/examples/data_driven.rb +17 -0
  16. data/lib/vendor/dataflow/examples/dataflow_http_gets.rb +13 -0
  17. data/lib/vendor/dataflow/examples/flow.rb +20 -0
  18. data/lib/vendor/dataflow/examples/future_http_gets.rb +12 -0
  19. data/lib/vendor/dataflow/examples/future_queue.rb +11 -0
  20. data/lib/vendor/dataflow/examples/instance_variables.rb +15 -0
  21. data/lib/vendor/dataflow/examples/laziness.rb +9 -0
  22. data/lib/vendor/dataflow/examples/local_variables.rb +11 -0
  23. data/lib/vendor/dataflow/examples/messages.rb +26 -0
  24. data/lib/vendor/dataflow/examples/port_http_gets.rb +13 -0
  25. data/lib/vendor/dataflow/examples/port_send.rb +10 -0
  26. data/lib/vendor/dataflow/examples/ring.rb +21 -0
  27. data/lib/vendor/dataflow/spec/actor_spec.rb +28 -0
  28. data/lib/vendor/dataflow/spec/anonymous_variables_spec.rb +21 -0
  29. data/lib/vendor/dataflow/spec/barrier_spec.rb +25 -0
  30. data/lib/vendor/dataflow/spec/by_need_spec.rb +55 -0
  31. data/lib/vendor/dataflow/spec/dataflow_spec.rb +151 -0
  32. data/lib/vendor/dataflow/spec/equality_spec.rb +40 -0
  33. data/lib/vendor/dataflow/spec/flow_spec.rb +25 -0
  34. data/lib/vendor/dataflow/spec/forker_spec.rb +28 -0
  35. data/lib/vendor/dataflow/spec/future_queue_spec.rb +31 -0
  36. data/lib/vendor/dataflow/spec/inspect_spec.rb +19 -0
  37. data/lib/vendor/dataflow/spec/need_later_spec.rb +12 -0
  38. data/lib/vendor/dataflow/spec/port_spec.rb +26 -0
  39. data/lib/vendor/dataflow/spec/spec.opts +1 -0
  40. data/lib/vendor/dataflow/spec/spec_helper.rb +10 -0
  41. data/lib/vendor/escape/Readme +21 -0
  42. data/lib/vendor/escape/doc_include/template/qualitysmith.rb +631 -0
  43. data/lib/vendor/json_pure/CHANGES +166 -0
  44. data/lib/vendor/json_pure/COPYING +58 -0
  45. data/lib/vendor/json_pure/GPL +340 -0
  46. data/lib/vendor/json_pure/README +358 -0
  47. data/lib/vendor/json_pure/Rakefile +292 -0
  48. data/lib/vendor/json_pure/TODO +1 -0
  49. data/lib/vendor/json_pure/VERSION +1 -0
  50. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
  51. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
  52. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
  53. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
  54. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
  55. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
  56. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
  57. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
  58. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
  59. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
  60. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
  61. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
  62. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
  63. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
  64. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
  65. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
  66. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
  67. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
  68. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
  69. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
  70. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
  71. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
  72. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
  73. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
  74. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
  75. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
  76. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
  77. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
  78. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
  79. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
  80. data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
  81. data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
  82. data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +224 -0
  83. data/lib/vendor/json_pure/benchmarks/ohai.json +1216 -0
  84. data/lib/vendor/json_pure/benchmarks/ohai.ruby +1 -0
  85. data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
  86. data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +259 -0
  87. data/lib/vendor/json_pure/bin/edit_json.rb +9 -0
  88. data/lib/vendor/json_pure/bin/prettify_json.rb +75 -0
  89. data/lib/vendor/json_pure/data/example.json +1 -0
  90. data/lib/vendor/json_pure/data/index.html +38 -0
  91. data/lib/vendor/json_pure/data/prototype.js +4184 -0
  92. data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +16 -0
  93. data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +1323 -0
  94. data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
  95. data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +15 -0
  96. data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +1935 -0
  97. data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
  98. data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +792 -0
  99. data/lib/vendor/json_pure/install.rb +26 -0
  100. data/lib/vendor/json_pure/tests/fixtures/fail1.json +1 -0
  101. data/lib/vendor/json_pure/tests/fixtures/fail10.json +1 -0
  102. data/lib/vendor/json_pure/tests/fixtures/fail11.json +1 -0
  103. data/lib/vendor/json_pure/tests/fixtures/fail12.json +1 -0
  104. data/lib/vendor/json_pure/tests/fixtures/fail13.json +1 -0
  105. data/lib/vendor/json_pure/tests/fixtures/fail14.json +1 -0
  106. data/lib/vendor/json_pure/tests/fixtures/fail18.json +1 -0
  107. data/lib/vendor/json_pure/tests/fixtures/fail19.json +1 -0
  108. data/lib/vendor/json_pure/tests/fixtures/fail2.json +1 -0
  109. data/lib/vendor/json_pure/tests/fixtures/fail20.json +1 -0
  110. data/lib/vendor/json_pure/tests/fixtures/fail21.json +1 -0
  111. data/lib/vendor/json_pure/tests/fixtures/fail22.json +1 -0
  112. data/lib/vendor/json_pure/tests/fixtures/fail23.json +1 -0
  113. data/lib/vendor/json_pure/tests/fixtures/fail24.json +1 -0
  114. data/lib/vendor/json_pure/tests/fixtures/fail25.json +1 -0
  115. data/lib/vendor/json_pure/tests/fixtures/fail27.json +2 -0
  116. data/lib/vendor/json_pure/tests/fixtures/fail28.json +2 -0
  117. data/lib/vendor/json_pure/tests/fixtures/fail3.json +1 -0
  118. data/lib/vendor/json_pure/tests/fixtures/fail4.json +1 -0
  119. data/lib/vendor/json_pure/tests/fixtures/fail5.json +1 -0
  120. data/lib/vendor/json_pure/tests/fixtures/fail6.json +1 -0
  121. data/lib/vendor/json_pure/tests/fixtures/fail7.json +1 -0
  122. data/lib/vendor/json_pure/tests/fixtures/fail8.json +1 -0
  123. data/lib/vendor/json_pure/tests/fixtures/fail9.json +1 -0
  124. data/lib/vendor/json_pure/tests/fixtures/pass1.json +56 -0
  125. data/lib/vendor/json_pure/tests/fixtures/pass15.json +1 -0
  126. data/lib/vendor/json_pure/tests/fixtures/pass16.json +1 -0
  127. data/lib/vendor/json_pure/tests/fixtures/pass17.json +1 -0
  128. data/lib/vendor/json_pure/tests/fixtures/pass2.json +1 -0
  129. data/lib/vendor/json_pure/tests/fixtures/pass26.json +1 -0
  130. data/lib/vendor/json_pure/tests/fixtures/pass3.json +6 -0
  131. data/lib/vendor/json_pure/tests/test_json.rb +361 -0
  132. data/lib/vendor/json_pure/tests/test_json_addition.rb +162 -0
  133. data/lib/vendor/json_pure/tests/test_json_encoding.rb +68 -0
  134. data/lib/vendor/json_pure/tests/test_json_fixtures.rb +34 -0
  135. data/lib/vendor/json_pure/tests/test_json_generate.rb +122 -0
  136. data/lib/vendor/json_pure/tests/test_json_rails.rb +144 -0
  137. data/lib/vendor/json_pure/tests/test_json_unicode.rb +76 -0
  138. data/lib/vendor/json_pure/tools/fuzz.rb +139 -0
  139. data/lib/vendor/json_pure/tools/server.rb +61 -0
  140. data/lib/vendor/open4/lib/open4.rb +51 -80
  141. data/lib/vendor/thor/CHANGELOG.rdoc +89 -0
  142. data/lib/vendor/thor/LICENSE +20 -0
  143. data/lib/vendor/thor/README.rdoc +297 -0
  144. data/lib/vendor/thor/Thorfile +69 -0
  145. data/lib/vendor/thor/bin/rake2thor +86 -0
  146. data/lib/vendor/thor/bin/thor +6 -0
  147. data/lib/vendor/thor/thor.gemspec +120 -0
  148. data/spec/basic_deploy_spec.rb +1 -1
  149. data/spec/bundler_deploy_spec.rb +1 -1
  150. data/spec/nodejs_deploy_spec.rb +5 -2
  151. data/spec/rails31_deploy_spec.rb +3 -3
  152. data/spec/services_deploy_spec.rb +1 -1
  153. data/spec/support/integration.rb +1 -2
  154. metadata +165 -44
  155. data/lib/engineyard-serverside/future.rb +0 -29
  156. data/lib/engineyard-serverside/futures/celluloid.rb +0 -25
  157. data/lib/engineyard-serverside/futures/dataflow.rb +0 -31
  158. data/lib/vendor/celluloid/lib/celluloid.rb +0 -261
  159. data/lib/vendor/celluloid/lib/celluloid/actor.rb +0 -242
  160. data/lib/vendor/celluloid/lib/celluloid/actor_pool.rb +0 -54
  161. data/lib/vendor/celluloid/lib/celluloid/actor_proxy.rb +0 -75
  162. data/lib/vendor/celluloid/lib/celluloid/application.rb +0 -78
  163. data/lib/vendor/celluloid/lib/celluloid/calls.rb +0 -94
  164. data/lib/vendor/celluloid/lib/celluloid/core_ext.rb +0 -14
  165. data/lib/vendor/celluloid/lib/celluloid/events.rb +0 -14
  166. data/lib/vendor/celluloid/lib/celluloid/fiber.rb +0 -33
  167. data/lib/vendor/celluloid/lib/celluloid/fsm.rb +0 -141
  168. data/lib/vendor/celluloid/lib/celluloid/future.rb +0 -60
  169. data/lib/vendor/celluloid/lib/celluloid/links.rb +0 -61
  170. data/lib/vendor/celluloid/lib/celluloid/logger.rb +0 -32
  171. data/lib/vendor/celluloid/lib/celluloid/mailbox.rb +0 -124
  172. data/lib/vendor/celluloid/lib/celluloid/receivers.rb +0 -66
  173. data/lib/vendor/celluloid/lib/celluloid/registry.rb +0 -33
  174. data/lib/vendor/celluloid/lib/celluloid/responses.rb +0 -26
  175. data/lib/vendor/celluloid/lib/celluloid/rspec.rb +0 -2
  176. data/lib/vendor/celluloid/lib/celluloid/signals.rb +0 -50
  177. data/lib/vendor/celluloid/lib/celluloid/supervisor.rb +0 -57
  178. data/lib/vendor/celluloid/lib/celluloid/task.rb +0 -73
  179. data/lib/vendor/celluloid/lib/celluloid/tcp_server.rb +0 -33
  180. data/lib/vendor/celluloid/lib/celluloid/timers.rb +0 -109
  181. data/lib/vendor/celluloid/lib/celluloid/version.rb +0 -4
@@ -1,29 +0,0 @@
1
- module EY
2
- module Serverside
3
- class Future
4
- def self.success?(futures)
5
- futures.empty? || futures.all? {|f| f.success?}
6
- end
7
-
8
- def initialize(server, *args, &block)
9
- @server = server
10
- @args = args
11
- @block = block
12
- end
13
-
14
- def success?
15
- @value == true
16
- end
17
-
18
- def error?
19
- !success?
20
- end
21
- end
22
-
23
- if defined?(Fiber)
24
- require 'engineyard-serverside/futures/celluloid'
25
- else
26
- require 'engineyard-serverside/futures/dataflow'
27
- end
28
- end
29
- end
@@ -1,25 +0,0 @@
1
- module EY
2
- module Serverside
3
- $LOAD_PATH.unshift File.expand_path('../../vendor/celluloid/lib', File.dirname(__FILE__))
4
- require 'celluloid'
5
- class Future
6
- def self.call(servers, *args, &block)
7
- futures = servers.map do |server|
8
- new(server, *args, &block)
9
- end
10
-
11
- futures.each {|f| f.call}
12
- futures
13
- end
14
-
15
- def future
16
- Celluloid::Future.new(@server, *@args, &@block)
17
- end
18
-
19
- def call
20
- # Celluloid needs to call the block explicitely
21
- @value ||= future.call
22
- end
23
- end
24
- end
25
- end
@@ -1,31 +0,0 @@
1
- module EY
2
- module Serverside
3
- $LOAD_PATH.unshift File.expand_path('../../vendor/dataflow', File.dirname(__FILE__))
4
- require 'dataflow'
5
-
6
- class Future
7
- extend Dataflow
8
-
9
- def self.call(servers, *args, &block)
10
- futures = []
11
- # Dataflow needs to call `barrier` and `need_later` in the same object
12
- barrier(*servers.map do |server|
13
- future = new(server, *args, &block)
14
- futures << future
15
-
16
- need_later { future.call }
17
- end)
18
-
19
- futures
20
- end
21
-
22
- def future
23
- @block.call(@server, *@args)
24
- end
25
-
26
- def call
27
- @value ||= future
28
- end
29
- end
30
- end
31
- end
@@ -1,261 +0,0 @@
1
- require 'logger'
2
- require 'thread'
3
-
4
- module Celluloid
5
- @logger = Logger.new STDERR
6
-
7
- class << self
8
- attr_accessor :logger # Thread-safe logger class
9
-
10
- def included(klass)
11
- klass.send :extend, ClassMethods
12
- end
13
-
14
- # Are we currently inside of an actor?
15
- def actor?
16
- !!Thread.current[:actor]
17
- end
18
-
19
- # Obtain the currently running actor (if one exists)
20
- def current_actor
21
- actor = Thread.current[:actor]
22
- raise NotActorError, "not in actor scope" unless actor
23
- actor.proxy
24
- end
25
- alias_method :current, :current_actor
26
-
27
- # Receive an asynchronous message
28
- def receive(timeout = nil, &block)
29
- actor = Thread.current[:actor]
30
- if actor
31
- actor.receive(timeout, &block)
32
- else
33
- Thread.mailbox.receive(timeout, &block)
34
- end
35
- end
36
-
37
- # Sleep letting the actor continue processing messages
38
- def sleep(interval)
39
- actor = Thread.current[:actor]
40
- if actor
41
- actor.sleep(interval)
42
- else
43
- Kernel.sleep interval
44
- end
45
- end
46
-
47
- # Obtain a hash of active tasks to their current activities
48
- def tasks
49
- actor = Thread.current[:actor]
50
- raise NotActorError, "not in actor scope" unless actor
51
- actor.tasks
52
- end
53
- end
54
-
55
- # Class methods added to classes which include Celluloid
56
- module ClassMethods
57
- # Create a new actor
58
- def new(*args, &block)
59
- proxy = Actor.new(allocate).proxy
60
- proxy.send(:initialize, *args, &block)
61
- proxy
62
- end
63
- alias_method :spawn, :new
64
-
65
- # Create a new actor and link to the current one
66
- def new_link(*args, &block)
67
- current_actor = Celluloid.current_actor
68
- raise NotActorError, "can't link outside actor context" unless current_actor
69
-
70
- proxy = Actor.new(allocate).proxy
71
- current_actor.link proxy
72
- proxy.send(:initialize, *args, &block)
73
- proxy
74
- end
75
- alias_method :spawn_link, :new_link
76
-
77
- # Create a supervisor which ensures an instance of an actor will restart
78
- # an actor if it fails
79
- def supervise(*args, &block)
80
- Supervisor.supervise(self, *args, &block)
81
- end
82
-
83
- # Create a supervisor which ensures an instance of an actor will restart
84
- # an actor if it fails, and keep the actor registered under a given name
85
- def supervise_as(name, *args, &block)
86
- Supervisor.supervise_as(name, self, *args, &block)
87
- end
88
-
89
- # Trap errors from actors we're linked to when they exit
90
- def trap_exit(callback)
91
- @exit_handler = callback.to_sym
92
- end
93
-
94
- # Obtain the exit handler for this actor
95
- attr_reader :exit_handler
96
-
97
- # Configure a custom mailbox factory
98
- def use_mailbox(klass = nil, &block)
99
- if block
100
- define_method(:mailbox_factory, &block)
101
- else
102
- define_method(:mailbox_factory) { klass.new }
103
- end
104
- end
105
- end
106
-
107
- #
108
- # Instance methods
109
- #
110
-
111
- # Is this actor alive?
112
- def alive?
113
- Thread.current[:actor].alive?
114
- end
115
-
116
- # Raise an exception in caller context, but stay running
117
- def abort(cause)
118
- raise AbortError.new(cause)
119
- end
120
-
121
- # Terminate this actor
122
- def terminate
123
- Thread.current[:actor].terminate
124
- end
125
-
126
- def inspect
127
- str = "#<Celluloid::Actor(#{self.class}:0x#{object_id.to_s(16)})"
128
- ivars = instance_variables.map do |ivar|
129
- "#{ivar}=#{instance_variable_get(ivar).inspect}"
130
- end
131
-
132
- str << " " << ivars.join(' ') unless ivars.empty?
133
- str << ">"
134
- end
135
-
136
- # Send a signal with the given name to all waiting methods
137
- def signal(name, value = nil)
138
- Thread.current[:actor].signal name, value
139
- end
140
-
141
- # Wait for the given signal
142
- def wait(name)
143
- Thread.current[:actor].wait name
144
- end
145
-
146
- # Obtain the current_actor
147
- def current_actor
148
- Celluloid.current_actor
149
- end
150
-
151
- # Obtain the running tasks for this actor
152
- def tasks
153
- Celluloid.tasks
154
- end
155
-
156
- # Obtain the Ruby object the actor is wrapping. This should ONLY be used
157
- # for a limited set of use cases like runtime metaprogramming. Interacting
158
- # directly with the wrapped object foregoes any kind of thread safety that
159
- # Celluloid would ordinarily provide you, and the object is guaranteed to
160
- # be shared with at least the actor thread. Tread carefully.
161
- def wrapped_object; self; end
162
-
163
- # Obtain the Celluloid::Links for this actor
164
- def links
165
- Thread.current[:actor].links
166
- end
167
-
168
- # Link this actor to another, allowing it to crash or react to errors
169
- def link(actor)
170
- actor.notify_link current_actor
171
- notify_link actor
172
- end
173
-
174
- # Remove links to another actor
175
- def unlink(actor)
176
- actor.notify_unlink current_actor
177
- notify_unlink actor
178
- end
179
-
180
- def notify_link(actor)
181
- links << actor
182
- end
183
-
184
- def notify_unlink(actor)
185
- links.delete actor
186
- end
187
-
188
- # Is this actor linked to another?
189
- def linked_to?(actor)
190
- Thread.current[:actor].links.include? actor
191
- end
192
-
193
- # Receive an asynchronous message via the actor protocol
194
- def receive(timeout = nil, &block)
195
- Celluloid.receive(timeout, &block)
196
- end
197
-
198
- # Sleep while letting the actor continue to receive messages
199
- def sleep(interval)
200
- Celluloid.sleep(interval)
201
- end
202
-
203
- # Call a block after a given interval
204
- def after(interval, &block)
205
- Thread.current[:actor].after(interval, &block)
206
- end
207
-
208
- # Perform a blocking or computationally intensive action inside an
209
- # asynchronous thread pool, allowing the caller to continue processing other
210
- # messages in its mailbox in the meantime
211
- def async(&block)
212
- # This implementation relies on the present implementation of
213
- # Celluloid::Future, which uses an Actor to run the block
214
- Future.new(&block).value
215
- end
216
-
217
- # Process async calls via method_missing
218
- def method_missing(meth, *args, &block)
219
- # bang methods are async calls
220
- if meth.to_s.match(/!$/)
221
- unbanged_meth = meth.to_s.sub(/!$/, '')
222
- call = AsyncCall.new(@mailbox, unbanged_meth, args, block)
223
-
224
- begin
225
- Thread.current[:actor].mailbox << call
226
- rescue MailboxError
227
- # Silently swallow asynchronous calls to dead actors. There's no way
228
- # to reliably generate DeadActorErrors for async calls, so users of
229
- # async calls should find other ways to deal with actors dying
230
- # during an async call (i.e. linking/supervisors)
231
- end
232
-
233
- return # casts are async and return immediately
234
- end
235
-
236
- super
237
- end
238
- end
239
-
240
- require 'celluloid/version'
241
- require 'celluloid/actor_proxy'
242
- require 'celluloid/calls'
243
- require 'celluloid/core_ext'
244
- require 'celluloid/events'
245
- require 'celluloid/fiber'
246
- require 'celluloid/fsm'
247
- require 'celluloid/links'
248
- require 'celluloid/logger'
249
- require 'celluloid/mailbox'
250
- require 'celluloid/receivers'
251
- require 'celluloid/registry'
252
- require 'celluloid/responses'
253
- require 'celluloid/signals'
254
- require 'celluloid/task'
255
- require 'celluloid/timers'
256
-
257
- require 'celluloid/actor'
258
- require 'celluloid/actor_pool'
259
- require 'celluloid/supervisor'
260
- require 'celluloid/future'
261
- require 'celluloid/application'
@@ -1,242 +0,0 @@
1
- module Celluloid
2
- # Don't do Actor-like things outside Actor scope
3
- class NotActorError < StandardError; end
4
-
5
- # Trying to do something to a dead actor
6
- class DeadActorError < StandardError; end
7
-
8
- # The caller made an error, not the current actor
9
- class AbortError < StandardError
10
- attr_reader :cause
11
-
12
- def initialize(cause)
13
- @cause = cause
14
- super "caused by #{cause.inspect}: #{cause.to_s}"
15
- end
16
- end
17
-
18
- # Actors are Celluloid's concurrency primitive. They're implemented as
19
- # normal Ruby objects wrapped in threads which communicate with asynchronous
20
- # messages.
21
- class Actor
22
- extend Registry
23
-
24
- attr_reader :proxy
25
- attr_reader :links
26
- attr_reader :mailbox
27
-
28
- # Invoke a method on the given actor via its mailbox
29
- def self.call(mailbox, meth, *args, &block)
30
- call = SyncCall.new(Thread.mailbox, meth, args, block)
31
-
32
- begin
33
- mailbox << call
34
- rescue MailboxError
35
- raise DeadActorError, "attempted to call a dead actor"
36
- end
37
-
38
- if Celluloid.actor?
39
- response = Thread.current[:actor].wait [:call, call.id]
40
- else
41
- # Otherwise we're inside a normal thread, so block
42
- response = Thread.mailbox.receive do |msg|
43
- msg.respond_to?(:call_id) and msg.call_id == call.id
44
- end
45
- end
46
-
47
- response.value
48
- end
49
-
50
- # Invoke a method asynchronously on an actor via its mailbox
51
- def self.async(mailbox, meth, *args, &block)
52
- begin
53
- mailbox << AsyncCall.new(Thread.mailbox, meth, args, block)
54
- rescue MailboxError
55
- # Silently swallow asynchronous calls to dead actors. There's no way
56
- # to reliably generate DeadActorErrors for async calls, so users of
57
- # async calls should find other ways to deal with actors dying
58
- # during an async call (i.e. linking/supervisors)
59
- end
60
- end
61
-
62
- # Wrap the given subject with an Actor
63
- def initialize(subject)
64
- @subject = subject
65
-
66
- if subject.respond_to? :mailbox_factory
67
- @mailbox = subject.mailbox_factory
68
- else
69
- @mailbox = Mailbox.new
70
- end
71
-
72
- @links = Links.new
73
- @signals = Signals.new
74
- @receivers = Receivers.new
75
- @timers = Timers.new
76
- @proxy = ActorProxy.new(@mailbox, self.class.to_s)
77
- @running = true
78
-
79
- @thread = Pool.get do
80
- Thread.current[:actor] = self
81
- Thread.current[:mailbox] = @mailbox
82
-
83
- run
84
- end
85
- end
86
-
87
- # Is this actor alive?
88
- def alive?
89
- @running
90
- end
91
-
92
- # Terminate this actor
93
- def terminate
94
- @running = false
95
- nil
96
- end
97
-
98
- # Send a signal with the given name to all waiting methods
99
- def signal(name, value = nil)
100
- @signals.send name, value
101
- end
102
-
103
- # Wait for the given signal
104
- def wait(name)
105
- @signals.wait name
106
- end
107
-
108
- # Receive an asynchronous message
109
- def receive(timeout = nil, &block)
110
- @receivers.receive(timeout, &block)
111
- end
112
-
113
- # Run the actor loop
114
- def run
115
- while @running
116
- begin
117
- message = @mailbox.receive(timeout)
118
- rescue ExitEvent => exit_event
119
- Task.new(:exit_handler) { handle_exit_event exit_event }.resume
120
- retry
121
- end
122
-
123
- if message
124
- handle_message message
125
- else
126
- # No message indicates a timeout
127
- @timers.fire
128
- @receivers.fire_timers
129
- end
130
- end
131
-
132
- cleanup ExitEvent.new(@proxy)
133
- rescue MailboxShutdown
134
- # If the mailbox detects shutdown, exit the actor
135
- @running = false
136
- rescue Exception => ex
137
- @running = false
138
- handle_crash(ex)
139
- ensure
140
- Pool.put @thread
141
- end
142
-
143
- # How long to wait until the next timer fires
144
- def timeout
145
- i1 = @timers.wait_interval
146
- i2 = @receivers.wait_interval
147
-
148
- if i1 and i2
149
- i1 < i2 ? i1 : i2
150
- elsif i1
151
- i1
152
- else
153
- i2
154
- end
155
- end
156
-
157
- # Obtain a hash of tasks that are currently waiting
158
- def tasks
159
- # A hash of tasks to what they're waiting on is more meaningful to the
160
- # end-user, and lets us make a copy of the tasks table, rather than
161
- # handing them the one we're using internally across threads, a definite
162
- # thread safety shared state no-no
163
- tasks = {}
164
- current_task = Task.current rescue nil
165
- tasks[current_task] = :running if current_task
166
-
167
- @signals.waiting.each do |waitable, waiters|
168
- if waiters.is_a? Enumerable
169
- waiters.each { |waiter| tasks[waiter] = waitable }
170
- else
171
- tasks[waiters] = waitable
172
- end
173
- end
174
-
175
- tasks
176
- end
177
-
178
- # Schedule a block to run at the given time
179
- def after(interval)
180
- @timers.add(interval) do
181
- Task.new(:timer) { yield }.resume
182
- end
183
- end
184
-
185
- # Sleep for the given amount of time
186
- def sleep(interval)
187
- task = Task.current
188
- @timers.add(interval) { task.resume }
189
- Task.suspend
190
- end
191
-
192
- # Handle an incoming message
193
- def handle_message(message)
194
- case message
195
- when Call
196
- Task.new(:message_handler) { message.dispatch(@subject) }.resume
197
- when Response
198
- handled_successfully = signal [:call, message.call_id], message
199
-
200
- unless handled_successfully
201
- Logger.debug("anomalous message! spurious response to call #{message.call_id}")
202
- end
203
- else
204
- @receivers.handle_message(message)
205
- end
206
- message
207
- end
208
-
209
- # Handle exit events received by this actor
210
- def handle_exit_event(exit_event)
211
- exit_handler = @subject.class.exit_handler
212
- if exit_handler
213
- return @subject.send(exit_handler, exit_event.actor, exit_event.reason)
214
- end
215
-
216
- # Reraise exceptions from linked actors
217
- # If no reason is given, actor terminated cleanly
218
- raise exit_event.reason if exit_event.reason
219
- end
220
-
221
- # Handle any exceptions that occur within a running actor
222
- def handle_crash(exception)
223
- Logger.crash("#{@subject.class} crashed!", exception)
224
- cleanup ExitEvent.new(@proxy, exception)
225
- rescue Exception => ex
226
- Logger.crash("#{@subject.class}: ERROR HANDLER CRASHED!", ex)
227
- end
228
-
229
- # Handle cleaning up this actor after it exits
230
- def cleanup(exit_event)
231
- @mailbox.shutdown
232
- @links.send_event exit_event
233
- tasks.each { |task, _| task.terminate }
234
-
235
- begin
236
- @subject.finalize if @subject.respond_to? :finalize
237
- rescue Exception => ex
238
- Logger.crash("#{@subject.class}#finalize crashed!", ex)
239
- end
240
- end
241
- end
242
- end