celluloid 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of celluloid might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGES.md +333 -0
- data/README.md +1 -1
- data/culture/CODE_OF_CONDUCT.md +28 -0
- data/culture/Gemfile +9 -0
- data/culture/README.md +22 -0
- data/culture/Rakefile +5 -0
- data/culture/SYNC.md +70 -0
- data/culture/celluloid-culture.gemspec +18 -0
- data/culture/gems/README.md +39 -0
- data/culture/gems/dependencies.yml +78 -0
- data/culture/gems/loader.rb +101 -0
- data/culture/rubocop/README.md +38 -0
- data/culture/rubocop/lint.yml +8 -0
- data/culture/rubocop/metrics.yml +15 -0
- data/culture/rubocop/rubocop.yml +4 -0
- data/culture/rubocop/style.yml +48 -0
- data/culture/spec/gems_spec.rb +2 -0
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +2 -0
- data/culture/sync.rb +56 -0
- data/culture/tasks/rspec.rake +5 -0
- data/culture/tasks/rubocop.rake +2 -0
- data/examples/basic_usage.rb +49 -0
- data/examples/futures.rb +38 -0
- data/examples/ring.rb +61 -0
- data/examples/simple_pmap.rb +14 -0
- data/examples/timers.rb +72 -0
- data/lib/celluloid.rb +142 -127
- data/lib/celluloid/actor.rb +47 -41
- data/lib/celluloid/actor_system.rb +75 -22
- data/lib/celluloid/autostart.rb +1 -1
- data/lib/celluloid/backported.rb +2 -0
- data/lib/celluloid/call/async.rb +16 -0
- data/lib/celluloid/call/block.rb +22 -0
- data/lib/celluloid/call/sync.rb +70 -0
- data/lib/celluloid/calls.rb +25 -114
- data/lib/celluloid/cell.rb +32 -20
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/current.rb +2 -0
- data/lib/celluloid/deprecate.rb +18 -0
- data/lib/celluloid/exceptions.rb +1 -1
- data/lib/celluloid/fiber.rb +3 -3
- data/lib/celluloid/future.rb +7 -6
- data/lib/celluloid/group.rb +65 -0
- data/lib/celluloid/group/manager.rb +27 -0
- data/lib/celluloid/group/pool.rb +125 -0
- data/lib/celluloid/group/spawner.rb +71 -0
- data/lib/celluloid/logging.rb +5 -5
- data/lib/celluloid/mailbox.rb +14 -13
- data/lib/celluloid/mailbox/evented.rb +76 -0
- data/lib/celluloid/notices.rb +15 -0
- data/lib/celluloid/proxies.rb +12 -0
- data/lib/celluloid/proxy/abstract.rb +24 -0
- data/lib/celluloid/proxy/actor.rb +46 -0
- data/lib/celluloid/proxy/async.rb +36 -0
- data/lib/celluloid/proxy/block.rb +31 -0
- data/lib/celluloid/proxy/cell.rb +76 -0
- data/lib/celluloid/proxy/future.rb +40 -0
- data/lib/celluloid/proxy/sync.rb +44 -0
- data/lib/celluloid/rspec.rb +9 -10
- data/lib/celluloid/system_events.rb +16 -15
- data/lib/celluloid/{tasks.rb → task.rb} +21 -21
- data/lib/celluloid/task/fibered.rb +45 -0
- data/lib/celluloid/task/threaded.rb +59 -0
- data/lib/celluloid/test.rb +1 -1
- data/lib/celluloid/thread.rb +6 -1
- data/lib/celluloid/version.rb +3 -0
- data/spec/celluloid/actor_spec.rb +2 -2
- data/spec/celluloid/actor_system_spec.rb +35 -21
- data/spec/celluloid/block_spec.rb +3 -5
- data/spec/celluloid/calls_spec.rb +33 -11
- data/spec/celluloid/condition_spec.rb +16 -13
- data/spec/celluloid/evented_mailbox_spec.rb +1 -31
- data/spec/celluloid/future_spec.rb +13 -10
- data/spec/celluloid/group/elastic_spec.rb +0 -0
- data/spec/celluloid/group/manager_spec.rb +0 -0
- data/spec/celluloid/group/pool_spec.rb +8 -0
- data/spec/celluloid/group/spawner_spec.rb +8 -0
- data/spec/celluloid/mailbox/evented_spec.rb +27 -0
- data/spec/celluloid/mailbox_spec.rb +1 -3
- data/spec/celluloid/misc/leak_spec.rb +73 -0
- data/spec/celluloid/task/fibered_spec.rb +5 -0
- data/spec/celluloid/task/threaded_spec.rb +5 -0
- data/spec/celluloid/timer_spec.rb +14 -16
- data/spec/deprecate/actor_system_spec.rb +72 -0
- data/spec/deprecate/block_spec.rb +52 -0
- data/spec/deprecate/calls_spec.rb +57 -0
- data/spec/deprecate/evented_mailbox_spec.rb +34 -0
- data/spec/deprecate/future_spec.rb +32 -0
- data/spec/deprecate/internal_pool_spec.rb +4 -0
- data/spec/shared/actor_examples.rb +1237 -0
- data/spec/shared/group_examples.rb +121 -0
- data/{lib/celluloid/rspec → spec/shared}/mailbox_examples.rb +20 -17
- data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
- data/spec/spec_helper.rb +72 -16
- data/spec/support/coverage.rb +4 -0
- data/spec/support/crash_checking.rb +68 -0
- data/spec/support/debugging.rb +31 -0
- data/spec/support/env.rb +16 -0
- data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
- data/spec/support/examples/evented_mailbox_class.rb +27 -0
- data/spec/support/includer.rb +9 -0
- data/spec/support/logging.rb +63 -0
- data/spec/support/loose_threads.rb +65 -0
- data/spec/support/reset_class_variables.rb +27 -0
- data/spec/support/sleep_and_wait.rb +14 -0
- data/spec/support/split_logs.rb +1 -0
- data/spec/support/stubbing.rb +14 -0
- metadata +255 -95
- data/lib/celluloid/call_chain.rb +0 -13
- data/lib/celluloid/cpu_counter.rb +0 -34
- data/lib/celluloid/evented_mailbox.rb +0 -73
- data/lib/celluloid/fsm.rb +0 -186
- data/lib/celluloid/handlers.rb +0 -41
- data/lib/celluloid/internal_pool.rb +0 -159
- data/lib/celluloid/legacy.rb +0 -9
- data/lib/celluloid/links.rb +0 -36
- data/lib/celluloid/logger.rb +0 -93
- data/lib/celluloid/logging/incident.rb +0 -21
- data/lib/celluloid/logging/incident_logger.rb +0 -129
- data/lib/celluloid/logging/incident_reporter.rb +0 -48
- data/lib/celluloid/logging/log_event.rb +0 -20
- data/lib/celluloid/logging/ring_buffer.rb +0 -65
- data/lib/celluloid/method.rb +0 -32
- data/lib/celluloid/notifications.rb +0 -83
- data/lib/celluloid/pool_manager.rb +0 -146
- data/lib/celluloid/probe.rb +0 -73
- data/lib/celluloid/properties.rb +0 -24
- data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
- data/lib/celluloid/proxies/actor_proxy.rb +0 -38
- data/lib/celluloid/proxies/async_proxy.rb +0 -31
- data/lib/celluloid/proxies/block_proxy.rb +0 -29
- data/lib/celluloid/proxies/cell_proxy.rb +0 -68
- data/lib/celluloid/proxies/future_proxy.rb +0 -35
- data/lib/celluloid/proxies/sync_proxy.rb +0 -36
- data/lib/celluloid/receivers.rb +0 -63
- data/lib/celluloid/registry.rb +0 -57
- data/lib/celluloid/responses.rb +0 -44
- data/lib/celluloid/rspec/actor_examples.rb +0 -1054
- data/lib/celluloid/signals.rb +0 -23
- data/lib/celluloid/stack_dump.rb +0 -133
- data/lib/celluloid/supervision_group.rb +0 -169
- data/lib/celluloid/supervisor.rb +0 -22
- data/lib/celluloid/task_set.rb +0 -49
- data/lib/celluloid/tasks/task_fiber.rb +0 -43
- data/lib/celluloid/tasks/task_thread.rb +0 -53
- data/lib/celluloid/thread_handle.rb +0 -50
- data/lib/celluloid/uuid.rb +0 -38
- data/spec/celluloid/cpu_counter_spec.rb +0 -82
- data/spec/celluloid/fsm_spec.rb +0 -107
- data/spec/celluloid/internal_pool_spec.rb +0 -52
- data/spec/celluloid/links_spec.rb +0 -45
- data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
- data/spec/celluloid/notifications_spec.rb +0 -120
- data/spec/celluloid/pool_spec.rb +0 -92
- data/spec/celluloid/probe_spec.rb +0 -121
- data/spec/celluloid/properties_spec.rb +0 -42
- data/spec/celluloid/registry_spec.rb +0 -64
- data/spec/celluloid/stack_dump_spec.rb +0 -64
- data/spec/celluloid/supervision_group_spec.rb +0 -65
- data/spec/celluloid/supervisor_spec.rb +0 -103
- data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
- data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
- data/spec/celluloid/thread_handle_spec.rb +0 -26
- data/spec/celluloid/uuid_spec.rb +0 -11
data/lib/celluloid/legacy.rb
DELETED
data/lib/celluloid/links.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
# Linked actors send each other system events
|
3
|
-
class Links
|
4
|
-
include Enumerable
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@links = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
# Add an actor to the current links
|
11
|
-
def <<(actor)
|
12
|
-
@links[actor.mailbox.address] = actor
|
13
|
-
end
|
14
|
-
|
15
|
-
# Do links include the given actor?
|
16
|
-
def include?(actor)
|
17
|
-
@links.has_key? actor.mailbox.address
|
18
|
-
end
|
19
|
-
|
20
|
-
# Remove an actor from the links
|
21
|
-
def delete(actor)
|
22
|
-
@links.delete actor.mailbox.address
|
23
|
-
end
|
24
|
-
|
25
|
-
# Iterate through all links
|
26
|
-
def each
|
27
|
-
@links.each { |_, actor| yield(actor) }
|
28
|
-
end
|
29
|
-
|
30
|
-
# Generate a string representation
|
31
|
-
def inspect
|
32
|
-
links = self.map(&:inspect).join(',')
|
33
|
-
"#<#{self.class}[#{links}]>"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/celluloid/logger.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
module Logger
|
3
|
-
class WithBacktrace
|
4
|
-
def initialize(backtrace)
|
5
|
-
@backtrace = backtrace
|
6
|
-
end
|
7
|
-
|
8
|
-
def debug(string)
|
9
|
-
Celluloid.logger.debug(decorate(string))
|
10
|
-
end
|
11
|
-
|
12
|
-
def info(string)
|
13
|
-
Celluloid.logger.info(decorate(string))
|
14
|
-
end
|
15
|
-
|
16
|
-
def warn(string)
|
17
|
-
Celluloid.logger.warn(decorate(string))
|
18
|
-
end
|
19
|
-
|
20
|
-
def error(string)
|
21
|
-
Celluloid.logger.error(decorate(string))
|
22
|
-
end
|
23
|
-
|
24
|
-
def decorate(string)
|
25
|
-
[string, @backtrace].join("\n\t")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
@exception_handlers = []
|
30
|
-
module_function
|
31
|
-
|
32
|
-
def with_backtrace(backtrace)
|
33
|
-
yield WithBacktrace.new(backtrace) if Celluloid.logger
|
34
|
-
end
|
35
|
-
|
36
|
-
# Send a debug message
|
37
|
-
def debug(string)
|
38
|
-
Celluloid.logger.debug(string) if Celluloid.logger
|
39
|
-
end
|
40
|
-
|
41
|
-
# Send a info message
|
42
|
-
def info(string)
|
43
|
-
Celluloid.logger.info(string) if Celluloid.logger
|
44
|
-
end
|
45
|
-
|
46
|
-
# Send a warning message
|
47
|
-
def warn(string)
|
48
|
-
Celluloid.logger.warn(string) if Celluloid.logger
|
49
|
-
end
|
50
|
-
|
51
|
-
# Send an error message
|
52
|
-
def error(string)
|
53
|
-
Celluloid.logger.error(string) if Celluloid.logger
|
54
|
-
end
|
55
|
-
|
56
|
-
# Handle a crash
|
57
|
-
def crash(string, exception)
|
58
|
-
string << "\n" << format_exception(exception)
|
59
|
-
error string
|
60
|
-
|
61
|
-
@exception_handlers.each do |handler|
|
62
|
-
begin
|
63
|
-
handler.call(exception)
|
64
|
-
rescue => ex
|
65
|
-
error "EXCEPTION HANDLER CRASHED:\n" << format_exception(ex)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Note a deprecation
|
71
|
-
def deprecate(message)
|
72
|
-
trace = caller.join("\n\t")
|
73
|
-
warn "DEPRECATION WARNING: #{message}\n\t#{trace}"
|
74
|
-
end
|
75
|
-
|
76
|
-
# Define an exception handler
|
77
|
-
# NOTE: These should be defined at application start time
|
78
|
-
def exception_handler(&block)
|
79
|
-
@exception_handlers << block
|
80
|
-
nil
|
81
|
-
end
|
82
|
-
|
83
|
-
# Format an exception message
|
84
|
-
def format_exception(exception)
|
85
|
-
str = "#{exception.class}: #{exception.to_s}\n\t"
|
86
|
-
if exception.backtrace
|
87
|
-
str << exception.backtrace.join("\n\t")
|
88
|
-
else
|
89
|
-
str << "EMPTY BACKTRACE\n\t"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
# Wraps all events and context for a single incident.
|
3
|
-
class Incident
|
4
|
-
attr_accessor :pid
|
5
|
-
attr_accessor :events, :triggering_event
|
6
|
-
|
7
|
-
def initialize(events, triggering_event=nil)
|
8
|
-
@events = events
|
9
|
-
@triggering_event = triggering_event
|
10
|
-
@pid = $$
|
11
|
-
end
|
12
|
-
|
13
|
-
# Merge two incidents together. This may be useful if two incidents occur at the same time.
|
14
|
-
def merge(*other_incidents)
|
15
|
-
merged_events = other_incidents.flatten.inject(events) do |events, incident|
|
16
|
-
events += incident.events
|
17
|
-
end
|
18
|
-
Incident.new(merged_events.sort, triggering_event)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
module Celluloid
|
3
|
-
# A logger that holds all messages in circular buffers, then flushes the buffers
|
4
|
-
# when an event occurs at a configurable severity threshold.
|
5
|
-
#
|
6
|
-
# Unlike ruby's Logger, this class only supports a single progname.
|
7
|
-
class IncidentLogger
|
8
|
-
module Severity
|
9
|
-
include ::Logger::Severity
|
10
|
-
|
11
|
-
TRACE = -1
|
12
|
-
|
13
|
-
def severity_to_string(severity)
|
14
|
-
case severity
|
15
|
-
when TRACE then 'TRACE'
|
16
|
-
when DEBUG then 'DEBUG'
|
17
|
-
when INFO then 'INFO'
|
18
|
-
when WARN then 'WARN'
|
19
|
-
when ERROR then 'ERROR'
|
20
|
-
when FATAL then 'FATAL'
|
21
|
-
when UNKNOWN then 'UNKNOWN'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
include Severity
|
27
|
-
|
28
|
-
# The progname (facility) for this instance.
|
29
|
-
attr_accessor :progname
|
30
|
-
|
31
|
-
# The logging level. Messages below this severity will not be logged at all.
|
32
|
-
attr_accessor :level
|
33
|
-
|
34
|
-
# The incident threshold. Messages at or above this severity will generate an
|
35
|
-
# incident and be published to incident reporters.
|
36
|
-
attr_accessor :threshold
|
37
|
-
|
38
|
-
# The buffer size limit. Each log level will retain this number of messages
|
39
|
-
# at maximum.
|
40
|
-
attr_accessor :sizelimit
|
41
|
-
|
42
|
-
attr_accessor :buffers
|
43
|
-
|
44
|
-
# Create a new IncidentLogger.
|
45
|
-
def initialize(progname=nil, options={})
|
46
|
-
@progname = progname || "default"
|
47
|
-
@level = options[:level] || DEBUG
|
48
|
-
@threshold = options[:threshold] || ERROR
|
49
|
-
@sizelimit = options[:sizelimit] || 100
|
50
|
-
|
51
|
-
@buffer_mutex = Mutex.new
|
52
|
-
@buffers = Hash.new do |progname_hash, _progname|
|
53
|
-
@buffer_mutex.synchronize do
|
54
|
-
progname_hash[_progname] = Hash.new do |severity_hash, severity|
|
55
|
-
severity_hash[severity] = RingBuffer.new(@sizelimit)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# When the IncidentLogger itself encounters an error, it falls back to logging to stderr
|
61
|
-
@fallback_logger = ::Logger.new(STDERR)
|
62
|
-
@fallback_logger.progname = "FALLBACK"
|
63
|
-
end
|
64
|
-
|
65
|
-
# add an event.
|
66
|
-
def add(severity, message=nil, progname=nil, &block)
|
67
|
-
progname ||= @progname
|
68
|
-
severity ||= UNKNOWN
|
69
|
-
|
70
|
-
if severity < @level
|
71
|
-
return event.id
|
72
|
-
end
|
73
|
-
|
74
|
-
if message.nil? && !block_given?
|
75
|
-
message = progname
|
76
|
-
progname = @progname
|
77
|
-
end
|
78
|
-
|
79
|
-
event = LogEvent.new(severity, message, progname, &block)
|
80
|
-
|
81
|
-
@buffers[progname][severity] << event
|
82
|
-
|
83
|
-
if severity >= @threshold
|
84
|
-
begin
|
85
|
-
Celluloid::Notifications.notifier.async.publish(incident_topic, create_incident(event))
|
86
|
-
rescue => ex
|
87
|
-
@fallback_logger.error(ex)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
event.id
|
91
|
-
end
|
92
|
-
alias :log :add
|
93
|
-
|
94
|
-
# See docs for Logger#info
|
95
|
-
def trace (progname=nil, &block); add(TRACE, nil, progname, &block); end
|
96
|
-
def debug (progname=nil, &block); add(DEBUG, nil, progname, &block); end
|
97
|
-
def info (progname=nil, &block); add(INFO, nil, progname, &block); end
|
98
|
-
def warn (progname=nil, &block); add(WARN, nil, progname, &block); end
|
99
|
-
def error (progname=nil, &block); add(ERROR, nil, progname, &block); end
|
100
|
-
def fatal (progname=nil, &block); add(FATAL, nil, progname, &block); end
|
101
|
-
def unknown (progname=nil, &block); add(UNKNOWN, nil, progname, &block); end
|
102
|
-
|
103
|
-
def flush
|
104
|
-
messages = []
|
105
|
-
@buffer_mutex.synchronize do
|
106
|
-
@buffers.each do |progname, severities|
|
107
|
-
severities.each do |severity, buffer|
|
108
|
-
messages += buffer.flush
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
messages.sort
|
113
|
-
end
|
114
|
-
|
115
|
-
def clear
|
116
|
-
@buffer_mutex.synchronize do
|
117
|
-
@buffers.each { |buffer| buffer.clear }
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def create_incident(event=nil)
|
122
|
-
Incident.new(flush, event)
|
123
|
-
end
|
124
|
-
|
125
|
-
def incident_topic
|
126
|
-
"log.incident.#{@progname}"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
module Celluloid
|
3
|
-
# Subscribes to log incident topics to report on them.
|
4
|
-
class IncidentReporter
|
5
|
-
include Celluloid
|
6
|
-
include Celluloid::Notifications
|
7
|
-
|
8
|
-
# get the time from the event
|
9
|
-
class Formatter < ::Logger::Formatter
|
10
|
-
def call(severity, time, progname, msg)
|
11
|
-
super(severity, msg.time, progname, msg.message)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(*args)
|
16
|
-
subscribe(/log\.incident/, :report)
|
17
|
-
@logger = ::Logger.new(*args)
|
18
|
-
@logger.formatter = Formatter.new
|
19
|
-
@silenced = false
|
20
|
-
end
|
21
|
-
|
22
|
-
def report(topic, incident)
|
23
|
-
return if @silenced
|
24
|
-
|
25
|
-
header = "INCIDENT"
|
26
|
-
header << " AT #{incident.triggering_event.time}" if incident.triggering_event
|
27
|
-
@logger << header
|
28
|
-
@logger << "\n"
|
29
|
-
@logger << "====================\n"
|
30
|
-
incident.events.each do |event|
|
31
|
-
@logger.add(event.severity, event, event.progname)
|
32
|
-
end
|
33
|
-
@logger << "====================\n"
|
34
|
-
end
|
35
|
-
|
36
|
-
def silence
|
37
|
-
@silenced = true
|
38
|
-
end
|
39
|
-
|
40
|
-
def unsilence
|
41
|
-
@silenced = false
|
42
|
-
end
|
43
|
-
|
44
|
-
def silenced?
|
45
|
-
@silenced
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
# Wraps a single log event.
|
3
|
-
class LogEvent
|
4
|
-
attr_accessor :id, :severity, :message, :progname, :time
|
5
|
-
|
6
|
-
def initialize(severity, message, progname, time=Time.now, &block)
|
7
|
-
# This id should be ordered. For now relies on Celluloid::UUID to be ordered.
|
8
|
-
# May want to use a generation/counter strategy for independence of uuid.
|
9
|
-
@id = Celluloid::UUID.generate
|
10
|
-
@severity = severity
|
11
|
-
@message = block_given? ? yield : message
|
12
|
-
@progname = progname
|
13
|
-
@time = time
|
14
|
-
end
|
15
|
-
|
16
|
-
def <=>(other)
|
17
|
-
@id <=> other.id
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
class RingBuffer
|
3
|
-
def initialize(size)
|
4
|
-
@size = size
|
5
|
-
@start = 0
|
6
|
-
@count = 0
|
7
|
-
@buffer = Array.new(size)
|
8
|
-
@mutex = Mutex.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def full?
|
12
|
-
@count == @size
|
13
|
-
end
|
14
|
-
|
15
|
-
def empty?
|
16
|
-
@count == 0
|
17
|
-
end
|
18
|
-
|
19
|
-
def push(value)
|
20
|
-
@mutex.synchronize do
|
21
|
-
stop = (@start + @count) % @size
|
22
|
-
@buffer[stop] = value
|
23
|
-
if full?
|
24
|
-
@start = (@start + 1) % @size
|
25
|
-
else
|
26
|
-
@count += 1
|
27
|
-
end
|
28
|
-
value
|
29
|
-
end
|
30
|
-
end
|
31
|
-
alias :<< :push
|
32
|
-
|
33
|
-
def shift
|
34
|
-
@mutex.synchronize do
|
35
|
-
remove_element
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def flush
|
40
|
-
values = []
|
41
|
-
@mutex.synchronize do
|
42
|
-
while !empty?
|
43
|
-
values << remove_element
|
44
|
-
end
|
45
|
-
end
|
46
|
-
values
|
47
|
-
end
|
48
|
-
|
49
|
-
def clear
|
50
|
-
@buffer = Array.new(@size)
|
51
|
-
@start = 0
|
52
|
-
@count = 0
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def remove_element
|
58
|
-
return nil if empty?
|
59
|
-
value, @buffer[@start] = @buffer[@start], nil
|
60
|
-
@start = (@start + 1) % @size
|
61
|
-
@count -= 1
|
62
|
-
value
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
data/lib/celluloid/method.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Celluloid
|
2
|
-
# Method handles that route through an actor proxy
|
3
|
-
class Method
|
4
|
-
|
5
|
-
def initialize(proxy, name)
|
6
|
-
raise NameError, "undefined method `#{name}'" unless proxy.respond_to? name
|
7
|
-
|
8
|
-
@proxy, @name = proxy, name
|
9
|
-
@klass = @proxy.class
|
10
|
-
end
|
11
|
-
|
12
|
-
def arity
|
13
|
-
@proxy.method_missing(:method, @name).arity
|
14
|
-
end
|
15
|
-
|
16
|
-
def name
|
17
|
-
@proxy.method_missing(:method, @name).name
|
18
|
-
end
|
19
|
-
|
20
|
-
def parameters
|
21
|
-
@proxy.method_missing(:method, @name).parameters
|
22
|
-
end
|
23
|
-
|
24
|
-
def call(*args, &block)
|
25
|
-
@proxy.__send__(@name, *args, &block)
|
26
|
-
end
|
27
|
-
|
28
|
-
def inspect
|
29
|
-
"#<Celluloid::Method #{@klass}##{@name}>"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|