Skip to content

Commit

Permalink
Merge 9c87dde into 88916cb
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Nov 27, 2016
2 parents 88916cb + 9c87dde commit 980ba97
Show file tree
Hide file tree
Showing 70 changed files with 455 additions and 375 deletions.
126 changes: 119 additions & 7 deletions .rubocop.yml
Expand Up @@ -2,21 +2,133 @@ AllCops:
DisplayCopNames: true

#
# Style
# Lint
#

LineLength:
Max: 128
Lint/AssignmentInCondition:
Enabled: false # TODO: enable

Style/StringLiterals:
EnforcedStyle: double_quotes
Lint/EmptyWhen:
Enabled: false

Lint/Loop:
Enabled: false # TODO: enable

Lint/HandleExceptions:
Enabled: false # TODO: enable

Lint/NonLocalExitFromIterator:
Enabled: false # TODO: enable

Lint/RescueException:
Enabled: false # TODO: explicitly mark cases where we want to rescue Exception

Lint/ShadowedException:
Enabled: false # TODO; enable

Lint/UselessAssignment:
Enabled: false # TODO: enable

#
# Metrics
#

Metrics/AbcSize:
Enabled: false # TODO: enable

Metrics/BlockNesting:
Enabled: false # TODO: enable

Metrics/ClassLength:
Max: 200
Max: 250

Metrics/CyclomaticComplexity:
Enabled: false # TODO: enable

Metrics/LineLength:
Max: 200 # TODO: decrease

Metrics/MethodLength:
Max: 50
Max: 100

Metrics/ModuleLength:
Max: 250

Metrics/ParameterLists:
Enabled: false # TODO: enable

Metrics/PerceivedComplexity:
Enabled: false # TODO: enable

#
# Style
#

Style/AccessorMethodName:
Enabled: false # TODO: enable

Style/CaseEquality:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ClassVars:
Enabled: false # TODO: enable

Style/Documentation:
Enabled: false # TODO: enable

Style/DoubleNegation:
Enabled: false # TODO: enable(?)

Style/For:
Enabled: false # TODO: enable

Style/FrozenStringLiteralComment:
Enabled: false # TODO: enable

Style/GlobalVars:
Enabled: false # TODO: enable

Style/GuardClause:
Enabled: false # TODO: enable

Style/IfInsideElse:
Enabled: false # TODO: enable

Style/MethodMissing:
Enabled: false # TODO: enable

Style/ModuleFunction:
Enabled: false

Style/NumericPredicate:
Enabled: false

Style/RegexpLiteral:
Enabled: false # TODO: enable

Style/RescueModifier:
Enabled: false # TODO: enable

Style/SafeNavigation:
Enabled: false

Style/Semicolon:
Enabled: false

Style/SingleLineBlockParams:
Enabled: false

Style/SpecialGlobalVars:
Enabled: false # TODO: enable

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StructInheritance:
Enabled: false # TODO: enable

Style/TernaryParentheses:
Enabled: false
8 changes: 6 additions & 2 deletions Gemfile
Expand Up @@ -6,10 +6,14 @@ group :development do
gem "pry"
end

group :development, :test do
gem "rake", "~> 11", require: false
group :test do
gem "rspec", "~> 3", require: false
gem "rspec-retry", "~> 0.5", require: false
gem "rubocop", "= 0.45.0", require: false
gem "coveralls", ">= 0.8", require: false
gem "benchmark-ips", require: false
end

group :development, :test do
gem "rake"
end
2 changes: 1 addition & 1 deletion Guardfile
Expand Up @@ -6,7 +6,7 @@ guard "rspec", cmd: "bundle exec rspec" do
"actor_examples" => "actor",
"example_actor_class" => "actor",
"mailbox_examples" => %w(mailbox evented_mailbox),
"task_examples" => ["tasks/task_fiber", "tasks/task_thread"],
"task_examples" => ["tasks/task_fiber", "tasks/task_thread"]
}.each do |examples, spec|
watch("spec/support/#{examples}.rb") do
Array(spec).map { |file| "spec/celluloid/#{file}_spec.rb" }
Expand Down
7 changes: 2 additions & 5 deletions Rakefile
Expand Up @@ -2,8 +2,5 @@ require "bundler/gem_tasks"

Dir["tasks/**/*.rake"].each { |task| load task }

default_tasks = ["spec"]
default_tasks << "rubocop" unless ENV["CI"]

task default: default_tasks
task ci: %w(spec benchmark)
task default: %w(spec rubocop)
task ci: %w(default benchmark)
16 changes: 0 additions & 16 deletions benchmarks/parallel_hash.rb

This file was deleted.

1 change: 1 addition & 0 deletions celluloid.gemspec
Expand Up @@ -25,5 +25,6 @@ Gem::Specification.new do |spec|
spec.required_rubygems_version = ">= 2.0.0"

spec.add_runtime_dependency "timers", "~> 4"
spec.add_runtime_dependency "celluloid-pool", "~> 0.20"
spec.add_runtime_dependency "celluloid-supervision", "~> 0.20"
end
2 changes: 1 addition & 1 deletion examples/ring.rb
Expand Up @@ -28,7 +28,7 @@ def initialize(size)

# Go around the ring the given number of times
def run(n)
fail ArgumentError, "I can't go around a negative number of times" if n < 0
raise ArgumentError, "I can't go around a negative number of times" if n < 0

async.around n
wait :done
Expand Down
2 changes: 1 addition & 1 deletion examples/stack.rb
Expand Up @@ -17,7 +17,7 @@ def initialize
def push(x)
@ary.push x
end
alias_method :<<, :push
alias << push

def pop
@ary.pop
Expand Down
61 changes: 35 additions & 26 deletions lib/celluloid.rb
Expand Up @@ -19,7 +19,7 @@ module Celluloid
LINKING_TIMEOUT = 5

# Warning message added to Celluloid objects accessed outside their actors
BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "
BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT ".freeze

class << self
attr_writer :actor_system # Default Actor System
Expand All @@ -31,9 +31,9 @@ class << self

def actor_system
if Thread.current.celluloid?
Thread.current[:celluloid_actor_system] || fail(Error, "actor system not running")
Thread.current[:celluloid_actor_system] || raise(Error, "actor system not running")
else
Thread.current[:celluloid_actor_system] || @actor_system || fail(Error, "Celluloid is not yet started; use Celluloid.boot")
Thread.current[:celluloid_actor_system] || @actor_system || raise(Error, "Celluloid is not yet started; use Celluloid.boot")
end
end

Expand All @@ -59,8 +59,16 @@ def included(klass)
klass.property :exit_handler_name

singleton = class << klass; self; end
singleton.send(:remove_method, :trap_exit) rescue nil
singleton.send(:remove_method, :exclusive) rescue nil
begin
singleton.send(:remove_method, :trap_exit)
rescue
nil
end
begin
singleton.send(:remove_method, :exclusive)
rescue
nil
end

singleton.send(:define_method, :trap_exit) do |*args|
exit_handler_name(*args)
Expand Down Expand Up @@ -94,20 +102,20 @@ def uuid
def cores
Internals::CPUCounter.cores
end
alias_method :cpus, :cores
alias_method :ncpus, :cores
alias cpus cores
alias ncpus cores

# Perform a stack dump of all actors to the given output object
def stack_dump(output = STDERR)
actor_system.stack_dump.print(output)
end
alias_method :dump, :stack_dump
alias dump stack_dump

# Perform a stack summary of all actors to the given output object
def stack_summary(output = STDERR)
actor_system.stack_summary.print(output)
end
alias_method :summarize, :stack_summary
alias summarize stack_summary

def public_registry
actor_system.public_registry
Expand Down Expand Up @@ -157,7 +165,7 @@ def running?
actor_system && actor_system.running?
end

#de TODO Anticipate outside process finalizer that would by-pass this.
# de TODO Anticipate outside process finalizer that would by-pass this.
def register_shutdown
return if defined?(@shutdown_registered) && @shutdown_registered
# Terminate all actors at exit, unless the exit is abnormal.
Expand All @@ -184,18 +192,18 @@ def new(*args, &block)
proxy._send_(:initialize, *args, &block)
proxy
end
alias_method :spawn, :new
alias spawn new

# Create a new actor and link to the current one
def new_link(*args, &block)
fail NotActorError, "can't link outside actor context" unless Celluloid.actor?
raise NotActorError, "can't link outside actor context" unless Celluloid.actor?

proxy = Cell.new(allocate, behavior_options, actor_options).proxy
Actor.link(proxy)
proxy._send_(:initialize, *args, &block)
proxy
end
alias_method :spawn_link, :new_link
alias spawn_link new_link

# Run an actor in the foreground
def run(*args, &block)
Expand All @@ -213,7 +221,7 @@ def actor_options
mailbox_class: mailbox_class,
mailbox_size: mailbox_size,
task_class: task_class,
exclusive: exclusive_actor,
exclusive: exclusive_actor
}
end

Expand All @@ -223,7 +231,7 @@ def behavior_options
exclusive_methods: exclusive_methods,
exit_handler_name: exit_handler_name,
finalizer: finalizer,
receiver_block_executions: execute_block_on_receiver,
receiver_block_executions: execute_block_on_receiver
}
end

Expand Down Expand Up @@ -251,7 +259,7 @@ module InstanceMethods
def bare_object
self
end
alias_method :wrapped_object, :bare_object
alias wrapped_object bare_object

# Are we being invoked in a different thread from our owner?
def leaked?
Expand All @@ -267,18 +275,18 @@ def tap
def registered_name
Actor.registered_name
end
alias_method :name, :registered_name
alias name registered_name

def inspect
return "..." if Celluloid.detect_recursion

str = "#<"

if leaked?
str << Celluloid::BARE_OBJECT_WARNING_MESSAGE
else
str << "Celluloid::Proxy::Cell"
end
str << if leaked?
Celluloid::BARE_OBJECT_WARNING_MESSAGE
else
"Celluloid::Proxy::Cell"
end

str << "(#{self.class}:0x#{object_id.to_s(16)})"
str << " " unless instance_variables.empty?
Expand Down Expand Up @@ -306,9 +314,10 @@ def abort(cause)
cause = case cause
when String then RuntimeError.new(cause)
when Exception then cause
else fail TypeError, "Exception object/String expected, but #{cause.class} received"
end
fail AbortError.new(cause)
else raise TypeError, "Exception object/String expected, but #{cause.class} received"
end

raise AbortError, cause
end

# Terminate this actor
Expand Down Expand Up @@ -446,7 +455,7 @@ def future(meth = nil, *args, &block)
end

if defined?(JRUBY_VERSION) && JRUBY_VERSION == "1.7.3"
fail "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
raise "Celluloid is broken on JRuby 1.7.3. Please upgrade to 1.7.4+"
end

require "celluloid/exceptions"
Expand Down

0 comments on commit 980ba97

Please sign in to comment.