Skip to content

Commit

Permalink
Merge pull request #737 from celluloid/simplify-dependencies
Browse files Browse the repository at this point in the history
Simplify dependencies: merge 'essentials' and 'culture' repos
  • Loading branch information
tarcieri committed Nov 27, 2016
2 parents ae950fa + 835e7ff commit 88916cb
Show file tree
Hide file tree
Showing 62 changed files with 2,306 additions and 187 deletions.
4 changes: 0 additions & 4 deletions .env-ci

This file was deleted.

4 changes: 0 additions & 4 deletions .env-dev

This file was deleted.

24 changes: 22 additions & 2 deletions .rubocop.yml
@@ -1,2 +1,22 @@
inherit_from:
- culture/rubocop/rubocop.yml
AllCops:
DisplayCopNames: true

#
# Style
#

LineLength:
Max: 128

Style/StringLiterals:
EnforcedStyle: double_quotes

#
# Metrics
#

Metrics/ClassLength:
Max: 200

Metrics/MethodLength:
Max: 50
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
2.3.3
17 changes: 15 additions & 2 deletions Gemfile
@@ -1,2 +1,15 @@
require File.expand_path("../culture/sync", __FILE__)
Celluloid::Sync::Gemfile[self]
source "https://rubygems.org"

gemspec

group :development do
gem "pry"
end

group :development, :test do
gem "rake", "~> 11", require: false
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
end
18 changes: 1 addition & 17 deletions README.md
Expand Up @@ -142,9 +142,7 @@ like Celluloid we definitely recommend you check them out:

Add this line to your application's Gemfile:

```ruby
gem 'celluloid'
```
gem 'celluloid'

And then execute:

Expand All @@ -158,20 +156,6 @@ Require Celluloid with:

require 'celluloid'

### Cloning via GitHub

Right now `Celluloid` has a [submodule](https://github.com/celluloid/culture). To install the framework via GitHub, you need to clone the submodules as well.

__Clone from scratch:__

$ git clone --recursive https://github.com/celluloid/celluloid

__If you already cloned `Celluloid` without submodules:__

Run the following command in the directory containing `Celluloid`:

git submodule update --init --recursive

## Supported Platforms

This library aims to support and is [tested against][travis] the following Ruby
Expand Down
46 changes: 20 additions & 26 deletions celluloid.gemspec
@@ -1,35 +1,29 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

require File.expand_path("../culture/sync", __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "celluloid/version"

Gem::Specification.new do |gem|
gem.name = "celluloid"
gem.version = Celluloid::VERSION
gem.platform = Gem::Platform::RUBY
gem.licenses = ["MIT"]
gem.authors = ["Tony Arcieri", "Donovan Keme"]
gem.email = ["bascule@gmail.com", "code@extremist.digital"]
gem.homepage = "https://github.com/celluloid/celluloid"
gem.summary = "Actor-based concurrent object framework for Ruby"
gem.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
Gem::Specification.new do |spec|
spec.name = "celluloid"
spec.version = Celluloid::VERSION
spec.platform = Gem::Platform::RUBY
spec.licenses = ["MIT"]
spec.authors = ["Tony Arcieri", "Donovan Keme"]
spec.email = ["bascule@gmail.com", "code@extremist.digital"]
spec.homepage = "https://github.com/celluloid/celluloid"
spec.summary = "Actor-based concurrent object framework for Ruby"
spec.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
Celluloid enables people to build concurrent programs out of concurrent objects just as easily
as they build sequential programs out of sequential objects
DESCRIPTION

gem.required_ruby_version = ">= 2.2.6"
gem.required_rubygems_version = ">= 2.0.0"
spec.require_path = "lib"
spec.files = Dir["*.md", "*.txt", "lib/**/*", "spec/**/*", "examples/*"]
spec.required_ruby_version = ">= 2.2.6"
spec.required_rubygems_version = ">= 2.0.0"

gem.files = Dir[
"README.md",
"CHANGES.md",
"LICENSE.txt",
"culture/**/*",
"lib/**/*",
"spec/**/*",
"examples/*"
]

gem.require_path = "lib"

Celluloid::Sync::Gemspec[gem]
spec.add_runtime_dependency "timers", "~> 4"
spec.add_runtime_dependency "celluloid-supervision", "~> 0.20"
end
1 change: 0 additions & 1 deletion culture
Submodule culture deleted from 0a8899
29 changes: 23 additions & 6 deletions lib/celluloid.rb
Expand Up @@ -4,12 +4,13 @@
require "set"

$CELLULOID_DEBUG = false

require "celluloid/version"
$CELLULOID_MONITORING = false

# TODO: gut this
$CELLULOID_BACKPORTED = false

require "celluloid/version"

module Celluloid
# Expose all instance methods as singleton methods
extend self
Expand Down Expand Up @@ -470,8 +471,6 @@ def future(meth = nil, *args, &block)
require "celluloid/mailbox"
require "celluloid/mailbox/evented"

require "celluloid/essentials"

require "celluloid/group"
require "celluloid/group/spawner"
require "celluloid/group/pool" # TODO: Find way to only load this if being used.
Expand All @@ -484,10 +483,28 @@ def future(meth = nil, *args, &block)
require "celluloid/cell"
require "celluloid/future"

require "celluloid/internals/call_chain"
require "celluloid/internals/cpu_counter"
require "celluloid/internals/handlers"
require "celluloid/internals/links"
require "celluloid/internals/logger"
require "celluloid/internals/method"
require "celluloid/internals/properties"
require "celluloid/internals/receivers"
require "celluloid/internals/registry"
require "celluloid/internals/responses"
require "celluloid/internals/signals"
require "celluloid/internals/stack"
require "celluloid/internals/task_set"
require "celluloid/internals/thread_handle"
require "celluloid/internals/uuid"

require "celluloid/notifications"
require "celluloid/supervision"

require "celluloid/logging"
require "celluloid/actor/system"

$CELLULOID_MONITORING = false

# Configure default systemwide settings

Celluloid.task_class =
Expand Down
33 changes: 12 additions & 21 deletions lib/celluloid/actor/system.rb
Expand Up @@ -7,26 +7,18 @@ class System
extend Forwardable
def_delegators :@registry, :[], :get, :[]=, :set, :delete

ROOT_SERVICES = begin
root_services = [
{
as: :notifications_fanout,
type: Celluloid::Notifications::Fanout,
},
{
as: :incident_reporter,
type: Celluloid::IncidentReporter,
args: [STDERR],
},
{
as: :public_services,
type: Celluloid::Supervision::Service::Public,
accessors: [:services],
supervise: [],
},
]
root_services
end
ROOT_SERVICES = [
{
as: :notifications_fanout,
type: Celluloid::Notifications::Fanout,
},
{
as: :public_services,
type: Celluloid::Supervision::Service::Public,
accessors: [:services],
supervise: [],
},
]

attr_reader :registry, :group

Expand All @@ -52,7 +44,6 @@ def start
within do
@root = Supervision::Service::Root.define
@tree = root_configuration.deploy
# de root_services[:group_manager].manage! @group
end
true
end
Expand Down
8 changes: 2 additions & 6 deletions lib/celluloid/autostart.rb
@@ -1,8 +1,4 @@
require "celluloid"

Celluloid.start

unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
Celluloid.register_shutdown
Celluloid.init
end
Celluloid.boot
Celluloid.register_shutdown unless defined?($CELLULOID_TEST) && $CELLULOID_TEST
9 changes: 1 addition & 8 deletions lib/celluloid/calls.rb
Expand Up @@ -24,14 +24,7 @@ def execute_block_on_receiver

def dispatch(obj)
check(obj)
_b = @block && @block.to_proc
obj.public_send(@method, *@arguments, &_b)
# rescue Celluloid::TaskTimeout => ex
# raise ex unless ( @retry += 1 ) <= RETRY_CALL_LIMIT
# puts "retrying"
# Internals::Logger.warn("TaskTimeout at Call dispatch. Retrying in #{RETRY_CALL_WAIT} seconds. ( Attempt #{@retry} of #{RETRY_CALL_LIMIT} )")
# sleep RETRY_CALL_WAIT
# retry
obj.public_send(@method, *@arguments, &(@block && @block.to_proc))
end

def check(obj)
Expand Down
15 changes: 15 additions & 0 deletions lib/celluloid/internals/call_chain.rb
@@ -0,0 +1,15 @@
module Celluloid
module Internals
class CallChain
def self.current_id=(value)
Thread.current[:celluloid_chain_id] = value
task = Thread.current[:celluloid_task]
task.chain_id = value if task
end

def self.current_id
Thread.current[:celluloid_chain_id]
end
end
end
end
64 changes: 64 additions & 0 deletions lib/celluloid/internals/cpu_counter.rb
@@ -0,0 +1,64 @@
module Celluloid
module Internals
module CPUCounter
class << self
def cores
@cores ||= count_cores
end

private unless $CELLULOID_TEST

def count_cores
from_result(from_env || from_sysdev || from_java || from_proc || from_win32ole || from_sysctl) || 1
end

def from_env
result = ENV["NUMBER_OF_PROCESSORS"]
result if result && !result.empty?
rescue
end

def from_sysdev
::IO.read("/sys/devices/system/cpu/present").split("-").last.to_i + 1
rescue Errno::ENOENT
begin
result = Dir["/sys/devices/system/cpu/cpu*"].count { |n| n =~ /cpu\d+/ }
result unless result.zero?
rescue
end
rescue
end

def from_java
Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java
rescue
end

def from_proc
File.read("/proc/cpuinfo").scan(/^processor\s*:/).size if File.exist?("/proc/cpuinfo")
rescue
end

def from_win32ole
require "win32ole"
WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
rescue
end

def from_sysctl
Integer `sysctl -n hw.ncpu 2>/dev/null`
rescue
end

def from_result(result)
if result
i = Integer(result.to_s[/\d+/], 10)
return i if i > 0
end
rescue
end
end
end
end
end
42 changes: 42 additions & 0 deletions lib/celluloid/internals/handlers.rb
@@ -0,0 +1,42 @@
require "set"

module Celluloid
module Internals
class Handlers
def initialize
@handlers = Set.new
end

def handle(*patterns, &block)
patterns.each do |pattern|
handler = Handler.new pattern, block
@handlers << handler
end
end

# Handle incoming messages
def handle_message(message)
handler = @handlers.find { |h| h.match(message) }
handler.call message if handler
handler
end
end

# Methods blocking on a call to receive
class Handler
def initialize(pattern, block)
@pattern = pattern
@block = block
end

# Match a message with this receiver's block
def match(message)
@pattern === message
end

def call(message)
@block.call message
end
end
end
end

0 comments on commit 88916cb

Please sign in to comment.