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.
- data/lib/engineyard-serverside.rb +19 -17
- data/lib/engineyard-serverside/cli.rb +38 -30
- data/lib/engineyard-serverside/configuration.rb +4 -28
- data/lib/engineyard-serverside/deploy.rb +10 -7
- data/lib/engineyard-serverside/lockfile_parser.rb +2 -2
- data/lib/engineyard-serverside/logged_output.rb +2 -0
- data/lib/engineyard-serverside/server.rb +2 -27
- data/lib/engineyard-serverside/task.rb +14 -10
- data/lib/engineyard-serverside/version.rb +1 -1
- data/lib/vendor/dataflow/HISTORY +52 -0
- data/lib/vendor/dataflow/LICENSE +19 -0
- data/lib/vendor/dataflow/README.textile +290 -0
- data/lib/vendor/dataflow/Rakefile +36 -0
- data/lib/vendor/dataflow/examples/barrier.rb +9 -0
- data/lib/vendor/dataflow/examples/data_driven.rb +17 -0
- data/lib/vendor/dataflow/examples/dataflow_http_gets.rb +13 -0
- data/lib/vendor/dataflow/examples/flow.rb +20 -0
- data/lib/vendor/dataflow/examples/future_http_gets.rb +12 -0
- data/lib/vendor/dataflow/examples/future_queue.rb +11 -0
- data/lib/vendor/dataflow/examples/instance_variables.rb +15 -0
- data/lib/vendor/dataflow/examples/laziness.rb +9 -0
- data/lib/vendor/dataflow/examples/local_variables.rb +11 -0
- data/lib/vendor/dataflow/examples/messages.rb +26 -0
- data/lib/vendor/dataflow/examples/port_http_gets.rb +13 -0
- data/lib/vendor/dataflow/examples/port_send.rb +10 -0
- data/lib/vendor/dataflow/examples/ring.rb +21 -0
- data/lib/vendor/dataflow/spec/actor_spec.rb +28 -0
- data/lib/vendor/dataflow/spec/anonymous_variables_spec.rb +21 -0
- data/lib/vendor/dataflow/spec/barrier_spec.rb +25 -0
- data/lib/vendor/dataflow/spec/by_need_spec.rb +55 -0
- data/lib/vendor/dataflow/spec/dataflow_spec.rb +151 -0
- data/lib/vendor/dataflow/spec/equality_spec.rb +40 -0
- data/lib/vendor/dataflow/spec/flow_spec.rb +25 -0
- data/lib/vendor/dataflow/spec/forker_spec.rb +28 -0
- data/lib/vendor/dataflow/spec/future_queue_spec.rb +31 -0
- data/lib/vendor/dataflow/spec/inspect_spec.rb +19 -0
- data/lib/vendor/dataflow/spec/need_later_spec.rb +12 -0
- data/lib/vendor/dataflow/spec/port_spec.rb +26 -0
- data/lib/vendor/dataflow/spec/spec.opts +1 -0
- data/lib/vendor/dataflow/spec/spec_helper.rb +10 -0
- data/lib/vendor/escape/Readme +21 -0
- data/lib/vendor/escape/doc_include/template/qualitysmith.rb +631 -0
- data/lib/vendor/json_pure/CHANGES +166 -0
- data/lib/vendor/json_pure/COPYING +58 -0
- data/lib/vendor/json_pure/GPL +340 -0
- data/lib/vendor/json_pure/README +358 -0
- data/lib/vendor/json_pure/Rakefile +292 -0
- data/lib/vendor/json_pure/TODO +1 -0
- data/lib/vendor/json_pure/VERSION +1 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log +52 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat +900 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat +901 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log +261 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log +262 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log +82 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log +34 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat +900 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat +901 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log +81 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log +82 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log +82 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat +1000 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat +1001 -0
- data/lib/vendor/json_pure/benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log +82 -0
- data/lib/vendor/json_pure/benchmarks/generator2_benchmark.rb +222 -0
- data/lib/vendor/json_pure/benchmarks/generator_benchmark.rb +224 -0
- data/lib/vendor/json_pure/benchmarks/ohai.json +1216 -0
- data/lib/vendor/json_pure/benchmarks/ohai.ruby +1 -0
- data/lib/vendor/json_pure/benchmarks/parser2_benchmark.rb +251 -0
- data/lib/vendor/json_pure/benchmarks/parser_benchmark.rb +259 -0
- data/lib/vendor/json_pure/bin/edit_json.rb +9 -0
- data/lib/vendor/json_pure/bin/prettify_json.rb +75 -0
- data/lib/vendor/json_pure/data/example.json +1 -0
- data/lib/vendor/json_pure/data/index.html +38 -0
- data/lib/vendor/json_pure/data/prototype.js +4184 -0
- data/lib/vendor/json_pure/ext/json/ext/generator/extconf.rb +16 -0
- data/lib/vendor/json_pure/ext/json/ext/generator/generator.c +1323 -0
- data/lib/vendor/json_pure/ext/json/ext/generator/generator.h +170 -0
- data/lib/vendor/json_pure/ext/json/ext/parser/extconf.rb +15 -0
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.c +1935 -0
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.h +71 -0
- data/lib/vendor/json_pure/ext/json/ext/parser/parser.rl +792 -0
- data/lib/vendor/json_pure/install.rb +26 -0
- data/lib/vendor/json_pure/tests/fixtures/fail1.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail10.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail11.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail12.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail13.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail14.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail18.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail19.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail2.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail20.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail21.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail22.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail23.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail24.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail25.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail27.json +2 -0
- data/lib/vendor/json_pure/tests/fixtures/fail28.json +2 -0
- data/lib/vendor/json_pure/tests/fixtures/fail3.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail4.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail5.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail6.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail7.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail8.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/fail9.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass1.json +56 -0
- data/lib/vendor/json_pure/tests/fixtures/pass15.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass16.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass17.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass2.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass26.json +1 -0
- data/lib/vendor/json_pure/tests/fixtures/pass3.json +6 -0
- data/lib/vendor/json_pure/tests/test_json.rb +361 -0
- data/lib/vendor/json_pure/tests/test_json_addition.rb +162 -0
- data/lib/vendor/json_pure/tests/test_json_encoding.rb +68 -0
- data/lib/vendor/json_pure/tests/test_json_fixtures.rb +34 -0
- data/lib/vendor/json_pure/tests/test_json_generate.rb +122 -0
- data/lib/vendor/json_pure/tests/test_json_rails.rb +144 -0
- data/lib/vendor/json_pure/tests/test_json_unicode.rb +76 -0
- data/lib/vendor/json_pure/tools/fuzz.rb +139 -0
- data/lib/vendor/json_pure/tools/server.rb +61 -0
- data/lib/vendor/open4/lib/open4.rb +51 -80
- data/lib/vendor/thor/CHANGELOG.rdoc +89 -0
- data/lib/vendor/thor/LICENSE +20 -0
- data/lib/vendor/thor/README.rdoc +297 -0
- data/lib/vendor/thor/Thorfile +69 -0
- data/lib/vendor/thor/bin/rake2thor +86 -0
- data/lib/vendor/thor/bin/thor +6 -0
- data/lib/vendor/thor/thor.gemspec +120 -0
- data/spec/basic_deploy_spec.rb +1 -1
- data/spec/bundler_deploy_spec.rb +1 -1
- data/spec/nodejs_deploy_spec.rb +5 -2
- data/spec/rails31_deploy_spec.rb +3 -3
- data/spec/services_deploy_spec.rb +1 -1
- data/spec/support/integration.rb +1 -2
- metadata +165 -44
- data/lib/engineyard-serverside/future.rb +0 -29
- data/lib/engineyard-serverside/futures/celluloid.rb +0 -25
- data/lib/engineyard-serverside/futures/dataflow.rb +0 -31
- data/lib/vendor/celluloid/lib/celluloid.rb +0 -261
- data/lib/vendor/celluloid/lib/celluloid/actor.rb +0 -242
- data/lib/vendor/celluloid/lib/celluloid/actor_pool.rb +0 -54
- data/lib/vendor/celluloid/lib/celluloid/actor_proxy.rb +0 -75
- data/lib/vendor/celluloid/lib/celluloid/application.rb +0 -78
- data/lib/vendor/celluloid/lib/celluloid/calls.rb +0 -94
- data/lib/vendor/celluloid/lib/celluloid/core_ext.rb +0 -14
- data/lib/vendor/celluloid/lib/celluloid/events.rb +0 -14
- data/lib/vendor/celluloid/lib/celluloid/fiber.rb +0 -33
- data/lib/vendor/celluloid/lib/celluloid/fsm.rb +0 -141
- data/lib/vendor/celluloid/lib/celluloid/future.rb +0 -60
- data/lib/vendor/celluloid/lib/celluloid/links.rb +0 -61
- data/lib/vendor/celluloid/lib/celluloid/logger.rb +0 -32
- data/lib/vendor/celluloid/lib/celluloid/mailbox.rb +0 -124
- data/lib/vendor/celluloid/lib/celluloid/receivers.rb +0 -66
- data/lib/vendor/celluloid/lib/celluloid/registry.rb +0 -33
- data/lib/vendor/celluloid/lib/celluloid/responses.rb +0 -26
- data/lib/vendor/celluloid/lib/celluloid/rspec.rb +0 -2
- data/lib/vendor/celluloid/lib/celluloid/signals.rb +0 -50
- data/lib/vendor/celluloid/lib/celluloid/supervisor.rb +0 -57
- data/lib/vendor/celluloid/lib/celluloid/task.rb +0 -73
- data/lib/vendor/celluloid/lib/celluloid/tcp_server.rb +0 -33
- data/lib/vendor/celluloid/lib/celluloid/timers.rb +0 -109
- data/lib/vendor/celluloid/lib/celluloid/version.rb +0 -4
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
require 'thread'
|
|
2
|
-
|
|
3
|
-
module Celluloid
|
|
4
|
-
class Actor
|
|
5
|
-
# Maintain a thread pool of actors FOR SPEED!!
|
|
6
|
-
class Pool
|
|
7
|
-
@pool = []
|
|
8
|
-
@lock = Mutex.new
|
|
9
|
-
@max_idle = 16
|
|
10
|
-
|
|
11
|
-
class << self
|
|
12
|
-
attr_accessor :max_idle
|
|
13
|
-
|
|
14
|
-
def get(&block)
|
|
15
|
-
@lock.synchronize do
|
|
16
|
-
if @pool.empty?
|
|
17
|
-
thread = create
|
|
18
|
-
else
|
|
19
|
-
thread = @pool.shift
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
thread[:queue] << block
|
|
23
|
-
thread
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def put(thread)
|
|
28
|
-
@lock.synchronize do
|
|
29
|
-
if @pool.size >= @max_idle
|
|
30
|
-
thread[:queue] << nil
|
|
31
|
-
else
|
|
32
|
-
@pool << thread
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def create
|
|
38
|
-
queue = Queue.new
|
|
39
|
-
thread = Thread.new do
|
|
40
|
-
begin
|
|
41
|
-
while func = queue.pop
|
|
42
|
-
func.call
|
|
43
|
-
end
|
|
44
|
-
rescue Exception => ex
|
|
45
|
-
Logger.crash("#{self} internal failure", ex)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
thread[:queue] = queue
|
|
49
|
-
thread
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
module Celluloid
|
|
2
|
-
# A proxy object returned from Celluloid::Actor.spawn/spawn_link which
|
|
3
|
-
# dispatches calls and casts to normal Ruby objects which are running inside
|
|
4
|
-
# of their own threads.
|
|
5
|
-
class ActorProxy
|
|
6
|
-
attr_reader :mailbox
|
|
7
|
-
|
|
8
|
-
def initialize(mailbox, klass = "Object")
|
|
9
|
-
@mailbox, @klass = mailbox, klass
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def send(meth, *args, &block)
|
|
13
|
-
Actor.call @mailbox, :send, meth, *args, &block
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def class
|
|
17
|
-
Actor.call @mailbox, :send, :class
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def respond_to?(meth)
|
|
21
|
-
Actor.call @mailbox, :respond_to?, meth
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def methods(include_ancestors = true)
|
|
25
|
-
Actor.call @mailbox, :methods, include_ancestors
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def alive?
|
|
29
|
-
@mailbox.alive?
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def to_s
|
|
33
|
-
Actor.call @mailbox, :to_s
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def inspect
|
|
37
|
-
Actor.call @mailbox, :inspect
|
|
38
|
-
rescue DeadActorError
|
|
39
|
-
"#<Celluloid::Actor(#{@klass}) dead>"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Create a Celluloid::Future which calls a given method
|
|
43
|
-
def future(method_name, *args, &block)
|
|
44
|
-
Future.new { Actor.call @mailbox, method_name, *args, &block }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Terminate the associated actor
|
|
48
|
-
def terminate
|
|
49
|
-
raise DeadActorError, "actor already terminated" unless alive?
|
|
50
|
-
|
|
51
|
-
begin
|
|
52
|
-
send :terminate
|
|
53
|
-
rescue DeadActorError
|
|
54
|
-
# In certain cases this is thrown during termination. This is likely
|
|
55
|
-
# a bug in Celluloid's internals, but it shouldn't affect the caller.
|
|
56
|
-
# FIXME: track this down and fix it, or at the very least log it
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# Always return nil until a dependable exit value can be obtained
|
|
60
|
-
nil
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# method_missing black magic to call bang predicate methods asynchronously
|
|
64
|
-
def method_missing(meth, *args, &block)
|
|
65
|
-
# bang methods are async calls
|
|
66
|
-
if meth.to_s.match(/!$/)
|
|
67
|
-
unbanged_meth = meth.to_s.sub(/!$/, '')
|
|
68
|
-
Actor.async @mailbox, unbanged_meth, *args, &block
|
|
69
|
-
return
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
Actor.call @mailbox, meth, *args, &block
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
module Celluloid
|
|
2
|
-
# Applications describe and manage networks of Celluloid actors
|
|
3
|
-
class Application
|
|
4
|
-
include Celluloid
|
|
5
|
-
trap_exit :restart_supervisor
|
|
6
|
-
|
|
7
|
-
class << self
|
|
8
|
-
# Actors or sub-applications to be supervised
|
|
9
|
-
def supervisables
|
|
10
|
-
@supervisables ||= []
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Start this application (and watch it with a supervisor)
|
|
14
|
-
alias_method :run!, :supervise
|
|
15
|
-
|
|
16
|
-
# Run the application in the foreground with a simple watchdog
|
|
17
|
-
def run
|
|
18
|
-
loop do
|
|
19
|
-
supervisor = run!
|
|
20
|
-
|
|
21
|
-
# Take five, toplevel supervisor
|
|
22
|
-
sleep 5 while supervisor.alive?
|
|
23
|
-
|
|
24
|
-
Logger.error "!!! Celluloid::Application #{self} crashed. Restarting..."
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Register an actor class or a sub-application class to be launched and
|
|
29
|
-
# supervised while this application is running. Available options are:
|
|
30
|
-
#
|
|
31
|
-
# * as: register this application in the Celluloid::Actor[] directory
|
|
32
|
-
# * args: start the actor with the given arguments
|
|
33
|
-
def supervise(klass, options = {})
|
|
34
|
-
supervisables << Supervisable.new(klass, options)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Start the application
|
|
39
|
-
def initialize
|
|
40
|
-
@supervisors = {}
|
|
41
|
-
|
|
42
|
-
# This is some serious lolcode, but like... start the supervisors for
|
|
43
|
-
# this application
|
|
44
|
-
self.class.supervisables.each do |supervisable|
|
|
45
|
-
supervisor = supervisable.supervise
|
|
46
|
-
@supervisors[supervisor] = supervisable
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Restart a crashed supervisor
|
|
51
|
-
def restart_supervisor(supervisor, reason)
|
|
52
|
-
supervisable = @supervisors.delete supervisor
|
|
53
|
-
raise "a supervisable went missing. This shouldn't be!" unless supervisable
|
|
54
|
-
|
|
55
|
-
supervisor = supervisable.supervise
|
|
56
|
-
@supervisors[supervisor] = supervisable
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
# A subcomponent of an application to be supervised
|
|
60
|
-
class Supervisable
|
|
61
|
-
attr_reader :klass, :as, :args
|
|
62
|
-
|
|
63
|
-
def initialize(klass, options = {})
|
|
64
|
-
@klass = klass
|
|
65
|
-
|
|
66
|
-
# Stringify keys :/
|
|
67
|
-
options = options.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
|
|
68
|
-
|
|
69
|
-
@as = options['as']
|
|
70
|
-
@args = options['args'] || []
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def supervise
|
|
74
|
-
Supervisor.new_link(@as, @klass, *@args)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
module Celluloid
|
|
2
|
-
# Calls represent requests to an actor
|
|
3
|
-
class Call
|
|
4
|
-
attr_reader :id, :caller, :method, :arguments, :block
|
|
5
|
-
|
|
6
|
-
def initialize(caller, method, arguments, block)
|
|
7
|
-
@id = object_id # memoize object ID for serialization
|
|
8
|
-
@caller, @method, @arguments, @block = caller, method, arguments, block
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def check_signature(obj)
|
|
12
|
-
unless obj.respond_to? @method
|
|
13
|
-
raise NoMethodError, "undefined method `#{@method}' for #{obj.inspect}"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
arity = obj.method(@method).arity
|
|
17
|
-
if arity >= 0
|
|
18
|
-
if arguments.size != arity
|
|
19
|
-
raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{arity})"
|
|
20
|
-
end
|
|
21
|
-
elsif arity < -1
|
|
22
|
-
mandatory_args = -arity - 1
|
|
23
|
-
if arguments.size < mandatory_args
|
|
24
|
-
raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{mandatory_args})"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Synchronous calls wait for a response
|
|
31
|
-
class SyncCall < Call
|
|
32
|
-
def dispatch(obj)
|
|
33
|
-
begin
|
|
34
|
-
check_signature(obj)
|
|
35
|
-
rescue Exception => ex
|
|
36
|
-
respond ErrorResponse.new(@id, AbortError.new(ex))
|
|
37
|
-
return
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
begin
|
|
41
|
-
result = obj.send @method, *@arguments, &@block
|
|
42
|
-
rescue Exception => exception
|
|
43
|
-
# Exceptions that occur during synchronous calls are reraised in the
|
|
44
|
-
# context of the caller
|
|
45
|
-
respond ErrorResponse.new(@id, exception)
|
|
46
|
-
|
|
47
|
-
if exception.is_a? AbortError
|
|
48
|
-
# Aborting indicates a protocol error on the part of the caller
|
|
49
|
-
# It should crash the caller, but the exception isn't reraised
|
|
50
|
-
return
|
|
51
|
-
else
|
|
52
|
-
# Otherwise, it's a bug in this actor and should be reraised
|
|
53
|
-
raise exception
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
respond SuccessResponse.new(@id, result)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def cleanup
|
|
61
|
-
exception = DeadActorError.new("attempted to call a dead actor")
|
|
62
|
-
respond ErrorResponse.new(@id, exception)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
#######
|
|
66
|
-
private
|
|
67
|
-
#######
|
|
68
|
-
|
|
69
|
-
def respond(message)
|
|
70
|
-
@caller << message
|
|
71
|
-
rescue MailboxError
|
|
72
|
-
# It's possible the caller exited or crashed before we could send a
|
|
73
|
-
# response to them.
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# Asynchronous calls don't wait for a response
|
|
78
|
-
class AsyncCall < Call
|
|
79
|
-
def dispatch(obj)
|
|
80
|
-
begin
|
|
81
|
-
check_signature(obj)
|
|
82
|
-
rescue Exception => ex
|
|
83
|
-
Logger.crash("#{obj.class}: async call failed!", ex)
|
|
84
|
-
return
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
obj.send(@method, *@arguments, &@block)
|
|
88
|
-
rescue AbortError => ex
|
|
89
|
-
# Swallow aborted async calls, as they indicate the caller made a mistake
|
|
90
|
-
Logger.crash("#{obj.class}: async call aborted!", ex)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require 'celluloid/fiber'
|
|
2
|
-
|
|
3
|
-
# Monkeypatch Thread to allow lazy access to its Celluloid::Mailbox
|
|
4
|
-
class Thread
|
|
5
|
-
# Retrieve the mailbox for the current thread or lazily initialize it
|
|
6
|
-
def self.mailbox
|
|
7
|
-
current[:mailbox] ||= Celluloid::Mailbox.new
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class Fiber
|
|
12
|
-
# Celluloid::Task associated with this Fiber
|
|
13
|
-
attr_accessor :task
|
|
14
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module Celluloid
|
|
2
|
-
# Exceptional system events which need to be processed out of band
|
|
3
|
-
class SystemEvent < Exception; end
|
|
4
|
-
|
|
5
|
-
# An actor has exited for the given reason
|
|
6
|
-
class ExitEvent < SystemEvent
|
|
7
|
-
attr_reader :actor, :reason
|
|
8
|
-
|
|
9
|
-
def initialize(actor, reason = nil)
|
|
10
|
-
@actor, @reason = actor, reason
|
|
11
|
-
super reason.to_s
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Fibers are hard... let's go shopping!
|
|
2
|
-
begin
|
|
3
|
-
require 'fiber'
|
|
4
|
-
rescue LoadError => ex
|
|
5
|
-
if defined? JRUBY_VERSION
|
|
6
|
-
if RUBY_VERSION < "1.9.2"
|
|
7
|
-
raise LoadError, "Celluloid requires JRuby 1.9 mode. Please pass the --1.9 flag or set JRUBY_OPTS=--1.9"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# Fibers are broken on JRuby 1.6.5. This works around the issue
|
|
11
|
-
if JRUBY_VERSION == "1.6.5"
|
|
12
|
-
require 'jruby'
|
|
13
|
-
org.jruby.ext.fiber.FiberExtLibrary.new.load(JRuby.runtime, false)
|
|
14
|
-
class org::jruby::ext::fiber::ThreadFiber
|
|
15
|
-
field_accessor :state
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class Fiber
|
|
19
|
-
def alive?
|
|
20
|
-
JRuby.reference(self).state != org.jruby.ext.fiber.ThreadFiberState::FINISHED
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
else
|
|
24
|
-
# Just in case subsequent JRuby releases have broken fibers :/
|
|
25
|
-
raise ex
|
|
26
|
-
end
|
|
27
|
-
elsif defined? Rubinius
|
|
28
|
-
# If we're on Rubinius, we can still work in 1.8 mode
|
|
29
|
-
Fiber = Rubinius::Fiber
|
|
30
|
-
else
|
|
31
|
-
raise ex
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
module Celluloid
|
|
2
|
-
# Turn concurrent objects into finite state machines
|
|
3
|
-
# Inspired by Erlang's gen_fsm. See http://www.erlang.org/doc/man/gen_fsm.html
|
|
4
|
-
module FSM
|
|
5
|
-
DEFAULT_STATE = :default # Default state name unless one is explicitly set
|
|
6
|
-
|
|
7
|
-
# Included hook to extend class methods
|
|
8
|
-
def self.included(klass)
|
|
9
|
-
klass.send :include, Celluloid
|
|
10
|
-
klass.send :extend, ClassMethods
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
module ClassMethods
|
|
14
|
-
# Ensure FSMs transition into the default state after they're initialized
|
|
15
|
-
def new(*args, &block)
|
|
16
|
-
fsm = super
|
|
17
|
-
fsm.transition default_state
|
|
18
|
-
fsm
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
# Ensure FSMs transition into the default state after they're initialized
|
|
22
|
-
def new_link(*args, &block)
|
|
23
|
-
fsm = super
|
|
24
|
-
fsm.transition default_state
|
|
25
|
-
fsm
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Obtain or set the default state
|
|
29
|
-
# Passing a state name sets the default state
|
|
30
|
-
def default_state(new_default = nil)
|
|
31
|
-
if new_default
|
|
32
|
-
@default_state = new_default.to_sym
|
|
33
|
-
else
|
|
34
|
-
defined?(@default_state) ? @default_state : DEFAULT_STATE
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Obtain the valid states for this FSM
|
|
39
|
-
def states
|
|
40
|
-
@states ||= {}
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Declare an FSM state and optionally provide a callback block to fire
|
|
44
|
-
# Options:
|
|
45
|
-
# * to: a state or array of states this state can transition to
|
|
46
|
-
def state(*args, &block)
|
|
47
|
-
if args.last.is_a? Hash
|
|
48
|
-
options = args.pop.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
|
|
49
|
-
else
|
|
50
|
-
options = {}
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
args.each do |name|
|
|
54
|
-
name = name.to_sym
|
|
55
|
-
states[name] = State.new(name, options['to'], &block)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# Obtain the current state of the FSM
|
|
61
|
-
def current_state
|
|
62
|
-
defined?(@state) ? @state : @state = self.class.default_state
|
|
63
|
-
end
|
|
64
|
-
alias_method :state, :current_state
|
|
65
|
-
|
|
66
|
-
# Transition to another state
|
|
67
|
-
# Options:
|
|
68
|
-
# * delay: don't transition immediately, wait the given number of seconds.
|
|
69
|
-
# This will return a Celluloid::Timer object you can use to
|
|
70
|
-
# cancel the pending state transition.
|
|
71
|
-
#
|
|
72
|
-
# Note: making additional state transitions will cancel delayed transitions
|
|
73
|
-
def transition(state_name, options = {})
|
|
74
|
-
state_name = state_name.to_sym
|
|
75
|
-
current_state = self.class.states[@state]
|
|
76
|
-
|
|
77
|
-
return if current_state && current_state.name == state_name
|
|
78
|
-
|
|
79
|
-
if current_state and not current_state.valid_transition? state_name
|
|
80
|
-
valid = current_state.transitions.map(&:to_s).join(", ")
|
|
81
|
-
raise ArgumentError, "#{self.class} can't change state from '#{@state}' to '#{state_name}', only to: #{valid}"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
new_state = self.class.states[state_name]
|
|
85
|
-
|
|
86
|
-
if !new_state and state_name == self.class.default_state
|
|
87
|
-
# FIXME This probably isn't thread safe... or wise
|
|
88
|
-
new_state = self.class.states[state_name] = State.new(state_name)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
if new_state
|
|
92
|
-
if options[:delay]
|
|
93
|
-
@delayed_transition.cancel if @delayed_transition
|
|
94
|
-
|
|
95
|
-
@delayed_transition = after(options[:delay]) do
|
|
96
|
-
transition! new_state.name
|
|
97
|
-
new_state.call(self)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
return @delayed_transition
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
if defined?(@delayed_transition) and @delayed_transition
|
|
104
|
-
@delayed_transition.cancel
|
|
105
|
-
@delayed_transition = nil
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
transition! new_state.name
|
|
109
|
-
new_state.call(self)
|
|
110
|
-
else
|
|
111
|
-
raise ArgumentError, "invalid state for #{self.class}: #{state_name}"
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
# Immediate state transition with no sanity checks. "Dangerous!"
|
|
116
|
-
def transition!(state_name)
|
|
117
|
-
@state = state_name
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
# FSM states as declared by Celluloid::FSM.state
|
|
121
|
-
class State
|
|
122
|
-
attr_reader :name, :transitions
|
|
123
|
-
|
|
124
|
-
def initialize(name, transitions = nil, &block)
|
|
125
|
-
@name, @block = name, block
|
|
126
|
-
@transitions = Array(transitions).map { |t| t.to_sym } if transitions
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def call(obj)
|
|
130
|
-
obj.instance_eval(&@block) if @block
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def valid_transition?(new_state)
|
|
134
|
-
# All transitions are allowed unless expressly
|
|
135
|
-
return true unless @transitions
|
|
136
|
-
|
|
137
|
-
@transitions.include? new_state.to_sym
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|