celluloid-essentials 0.20.0.pre12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env-ci +4 -0
- data/.env-dev +4 -0
- data/.gitignore +10 -0
- data/.gitmodules +3 -0
- data/.rspec +5 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +29 -0
- data/CHANGES.md +0 -0
- data/Gemfile +29 -0
- data/LICENSE.txt +22 -0
- data/README.md +3 -0
- data/Rakefile +9 -0
- data/celluloid-essentials.gemspec +24 -0
- data/lib/celluloid/essentials.rb +33 -0
- data/lib/celluloid/internals/call_chain.rb +15 -0
- data/lib/celluloid/internals/cpu_counter.rb +36 -0
- data/lib/celluloid/internals/handlers.rb +42 -0
- data/lib/celluloid/internals/links.rb +38 -0
- data/lib/celluloid/internals/logger.rb +98 -0
- data/lib/celluloid/internals/method.rb +33 -0
- data/lib/celluloid/internals/properties.rb +28 -0
- data/lib/celluloid/internals/receivers.rb +64 -0
- data/lib/celluloid/internals/registry.rb +104 -0
- data/lib/celluloid/internals/responses.rb +45 -0
- data/lib/celluloid/internals/signals.rb +24 -0
- data/lib/celluloid/internals/stack.rb +76 -0
- data/lib/celluloid/internals/stack/dump.rb +14 -0
- data/lib/celluloid/internals/stack/states.rb +74 -0
- data/lib/celluloid/internals/stack/summary.rb +14 -0
- data/lib/celluloid/internals/task_set.rb +51 -0
- data/lib/celluloid/internals/thread_handle.rb +52 -0
- data/lib/celluloid/internals/uuid.rb +40 -0
- data/lib/celluloid/logging/incident.rb +21 -0
- data/lib/celluloid/logging/incident_logger.rb +128 -0
- data/lib/celluloid/logging/incident_reporter.rb +48 -0
- data/lib/celluloid/logging/log_event.rb +20 -0
- data/lib/celluloid/logging/ring_buffer.rb +65 -0
- data/lib/celluloid/notifications.rb +95 -0
- data/lib/celluloid/probe.rb +75 -0
- data/tasks/benchmarks.rake +16 -0
- data/tasks/rspec.rake +7 -0
- data/tasks/rubocop.rake +4 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 465c17603445ec94193ded92aa14e4c03a9f458e
|
4
|
+
data.tar.gz: b47f9cc8d04bb273aef64b60cc5ee756e559e0ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9dff6fac7b6ba39e3a72bcf10f83e2d12fd62830456d584f119e404f5bf864b5010eaf776ce9fdc48ed4c0ac7ba06b9e63d2c60589975cda9d2b544de70fda12
|
7
|
+
data.tar.gz: bdbf67635bc5d8df9b61120fd657018daeb159c6d7a808b4fd1362d1e23e11bbd2f2c7904ad4e2d0fb0a14f921f037fb42133ddb1e87ed8947cddf0de5fdf567
|
data/.env-ci
ADDED
data/.env-dev
ADDED
data/.gitignore
ADDED
data/.gitmodules
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
script: rake ci
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 2.2.0
|
5
|
+
- jruby
|
6
|
+
- ruby-head
|
7
|
+
- jruby-head
|
8
|
+
- rbx-2
|
9
|
+
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: rbx-2
|
13
|
+
- rvm: ruby-head
|
14
|
+
- rvm: jruby-head
|
15
|
+
- env: CELLULOID_TASK_CLASS=Threaded
|
16
|
+
|
17
|
+
env:
|
18
|
+
matrix:
|
19
|
+
- CELLULOID_TASK_CLASS=Fibered
|
20
|
+
- CELLULOID_TASK_CLASS=Threaded
|
21
|
+
- CELLULOID_BACKPORTED=false
|
22
|
+
global:
|
23
|
+
- NUMBER_OF_PROCESSORS=2 CELLULOID_CONFIG_FILE=.env-ci
|
24
|
+
|
25
|
+
notifications:
|
26
|
+
irc: "irc.freenode.org#celluloid"
|
27
|
+
|
28
|
+
sudo: false
|
29
|
+
install: bundle install --retry=3 --without=development
|
data/CHANGES.md
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'bundler'
|
4
|
+
gem 'coveralls', require: false
|
5
|
+
|
6
|
+
gemspec development_group: :gem_build_tools
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'pry'
|
10
|
+
#de gem 'guard'
|
11
|
+
#de gem 'rb-fsevent', '~> 0.9.1' if RUBY_PLATFORM =~ /darwin/
|
12
|
+
#de gem 'guard-rspec'
|
13
|
+
gem 'rubocop'
|
14
|
+
end
|
15
|
+
|
16
|
+
group :test do
|
17
|
+
gem 'dotenv', '~> 2.0'
|
18
|
+
gem 'nenv'
|
19
|
+
gem 'benchmark_suite'
|
20
|
+
gem 'rspec', '~> 3.2'
|
21
|
+
gem 'rspec-retry'
|
22
|
+
gem 'rspec-log_split', github: 'abstractive/rspec-log_split', branch: 'master'
|
23
|
+
end
|
24
|
+
|
25
|
+
group :gem_build_tools do
|
26
|
+
gem 'rake'
|
27
|
+
end
|
28
|
+
|
29
|
+
gem 'celluloid-gems', github: 'celluloid/celluloid-gems', branch: 'master'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Celluloid
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'celluloid-essentials'
|
5
|
+
gem.version = '0.20.0.pre12'
|
6
|
+
gem.platform = Gem::Platform::RUBY
|
7
|
+
gem.summary = 'Internally used tools, and superstructural dependencies of Celluloid'
|
8
|
+
gem.description = 'Notifications, Internals, Logging, Probe, and essential Celluloid pieces demanding Supervision'
|
9
|
+
gem.licenses = ['MIT']
|
10
|
+
|
11
|
+
gem.authors = ["Tony Arcieri", "digitalextremist //"]
|
12
|
+
gem.email = ['tony.arcieri@gmail.com', 'code@extremist.digital']
|
13
|
+
gem.homepage = 'https://github.com/celluloid/celluloid-essentials'
|
14
|
+
|
15
|
+
gem.required_ruby_version = '>= 1.9.2'
|
16
|
+
gem.required_rubygems_version = '>= 1.3.6'
|
17
|
+
|
18
|
+
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|examples|spec|features)/}) }
|
19
|
+
gem.require_path = 'lib'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'bundler'
|
22
|
+
|
23
|
+
gem.add_dependency 'celluloid-gems'
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Celluloid::Internals; end
|
2
|
+
|
3
|
+
require 'celluloid/internals/call_chain'
|
4
|
+
require 'celluloid/internals/cpu_counter'
|
5
|
+
require 'celluloid/internals/links'
|
6
|
+
require 'celluloid/internals/logger'
|
7
|
+
require 'celluloid/internals/method'
|
8
|
+
require 'celluloid/internals/properties'
|
9
|
+
require 'celluloid/internals/handlers'
|
10
|
+
require 'celluloid/internals/receivers'
|
11
|
+
require 'celluloid/internals/registry'
|
12
|
+
require 'celluloid/internals/responses'
|
13
|
+
require 'celluloid/internals/signals'
|
14
|
+
require 'celluloid/internals/task_set'
|
15
|
+
require 'celluloid/internals/thread_handle'
|
16
|
+
require 'celluloid/internals/uuid'
|
17
|
+
|
18
|
+
require 'celluloid/internals/stack'
|
19
|
+
|
20
|
+
require 'celluloid/notifications'
|
21
|
+
require 'celluloid/logging'
|
22
|
+
|
23
|
+
if $CELLULOID_DEPRECATE
|
24
|
+
puts "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}"
|
25
|
+
Celluloid::Registry = Celluloid::Internals::Registry
|
26
|
+
Celluloid::Logger = Celluloid::Internals::Logger
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'celluloid/supervision'
|
30
|
+
|
31
|
+
# TODO: Remove unneeded gem requirements once the gems are well known.
|
32
|
+
require 'celluloid/pool'
|
33
|
+
require 'celluloid/fsm'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Celluloid
|
2
|
+
module Internals
|
3
|
+
class CallChain
|
4
|
+
def self.current_id=(value)
|
5
|
+
Thread.current[:celluloid_chain_id] = value
|
6
|
+
task = Thread.current[:celluloid_task]
|
7
|
+
task.chain_id = value if task
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.current_id
|
11
|
+
Thread.current[:celluloid_chain_id]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Celluloid
|
2
|
+
module Internals
|
3
|
+
module CPUCounter
|
4
|
+
class << self
|
5
|
+
def cores
|
6
|
+
@cores ||= count_cores
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def count_cores
|
12
|
+
result = from_env || from_sysdev || from_sysctl
|
13
|
+
Integer(result.to_s[/\d+/], 10) if result
|
14
|
+
end
|
15
|
+
|
16
|
+
def from_env
|
17
|
+
result = ENV['NUMBER_OF_PROCESSORS']
|
18
|
+
result if result
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_sysdev
|
22
|
+
::IO.read('/sys/devices/system/cpu/present').split('-').last.to_i + 1
|
23
|
+
rescue Errno::ENOENT
|
24
|
+
result = Dir['/sys/devices/system/cpu/cpu*'].count { |n| n =~ /cpu\d+/ }
|
25
|
+
result unless result.zero?
|
26
|
+
end
|
27
|
+
|
28
|
+
def from_sysctl
|
29
|
+
result = `sysctl -n hw.ncpu`
|
30
|
+
result if $?.success?
|
31
|
+
rescue Errno::ENOENT
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module Celluloid
|
4
|
+
module Internals
|
5
|
+
class Handlers
|
6
|
+
def initialize
|
7
|
+
@handlers = Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def handle(*patterns, &block)
|
11
|
+
patterns.each do |pattern|
|
12
|
+
handler = Handler.new pattern, block
|
13
|
+
@handlers << handler
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Handle incoming messages
|
18
|
+
def handle_message(message)
|
19
|
+
handler = @handlers.find { |h| h.match(message) }
|
20
|
+
handler.call message if handler
|
21
|
+
handler
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Methods blocking on a call to receive
|
26
|
+
class Handler
|
27
|
+
def initialize(pattern, block)
|
28
|
+
@pattern = pattern
|
29
|
+
@block = block
|
30
|
+
end
|
31
|
+
|
32
|
+
# Match a message with this receiver's block
|
33
|
+
def match(message)
|
34
|
+
@pattern === message
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(message)
|
38
|
+
@block.call message
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Celluloid
|
2
|
+
module Internals
|
3
|
+
# Linked actors send each other system events
|
4
|
+
class Links
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@links = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Add an actor to the current links
|
12
|
+
def <<(actor)
|
13
|
+
@links[actor.mailbox.address] = actor
|
14
|
+
end
|
15
|
+
|
16
|
+
# Do links include the given actor?
|
17
|
+
def include?(actor)
|
18
|
+
@links.has_key? actor.mailbox.address
|
19
|
+
end
|
20
|
+
|
21
|
+
# Remove an actor from the links
|
22
|
+
def delete(actor)
|
23
|
+
@links.delete actor.mailbox.address
|
24
|
+
end
|
25
|
+
|
26
|
+
# Iterate through all links
|
27
|
+
def each
|
28
|
+
@links.each { |_, actor| yield(actor) }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Generate a string representation
|
32
|
+
def inspect
|
33
|
+
links = self.map(&:inspect).join(',')
|
34
|
+
"#<#{self.class}[#{links}]>"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Celluloid
|
2
|
+
module Internals
|
3
|
+
module Logger
|
4
|
+
class WithBacktrace
|
5
|
+
def initialize(backtrace)
|
6
|
+
@backtrace = backtrace
|
7
|
+
end
|
8
|
+
|
9
|
+
def debug(string)
|
10
|
+
Celluloid.logger.debug(decorate(string))
|
11
|
+
end
|
12
|
+
|
13
|
+
def info(string)
|
14
|
+
Celluloid.logger.info(decorate(string))
|
15
|
+
end
|
16
|
+
|
17
|
+
def warn(string)
|
18
|
+
Celluloid.logger.warn(decorate(string))
|
19
|
+
end
|
20
|
+
|
21
|
+
def error(string)
|
22
|
+
Celluloid.logger.error(decorate(string))
|
23
|
+
end
|
24
|
+
|
25
|
+
def decorate(string)
|
26
|
+
[string, @backtrace].join("\n\t")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
@exception_handlers = []
|
31
|
+
|
32
|
+
module_function
|
33
|
+
|
34
|
+
def with_backtrace(backtrace)
|
35
|
+
yield WithBacktrace.new(backtrace) if Celluloid.logger
|
36
|
+
end
|
37
|
+
|
38
|
+
# Send a debug message
|
39
|
+
def debug(string)
|
40
|
+
Celluloid.logger.debug(string) if Celluloid.logger
|
41
|
+
end
|
42
|
+
|
43
|
+
# Send a info message
|
44
|
+
def info(string)
|
45
|
+
Celluloid.logger.info(string) if Celluloid.logger
|
46
|
+
end
|
47
|
+
|
48
|
+
# Send a warning message
|
49
|
+
def warn(string)
|
50
|
+
Celluloid.logger.warn(string) if Celluloid.logger
|
51
|
+
end
|
52
|
+
|
53
|
+
# Send an error message
|
54
|
+
def error(string)
|
55
|
+
Celluloid.logger.error(string) if Celluloid.logger
|
56
|
+
end
|
57
|
+
|
58
|
+
# Handle a crash
|
59
|
+
def crash(string, exception)
|
60
|
+
if Celluloid.log_actor_crashes
|
61
|
+
string << "\n" << format_exception(exception)
|
62
|
+
error string
|
63
|
+
end
|
64
|
+
|
65
|
+
@exception_handlers.each do |handler|
|
66
|
+
begin
|
67
|
+
handler.call(exception)
|
68
|
+
rescue => ex
|
69
|
+
error "EXCEPTION HANDLER CRASHED:\n" << format_exception(ex)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Note a deprecation
|
75
|
+
def deprecate(message)
|
76
|
+
trace = caller.join("\n\t")
|
77
|
+
warn "DEPRECATION WARNING: #{message}\n\t#{trace}"
|
78
|
+
end
|
79
|
+
|
80
|
+
# Define an exception handler
|
81
|
+
# NOTE: These should be defined at application start time
|
82
|
+
def exception_handler(&block)
|
83
|
+
@exception_handlers << block
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
# Format an exception message
|
88
|
+
def format_exception(exception)
|
89
|
+
str = "#{exception.class}: #{exception.to_s}\n\t"
|
90
|
+
if exception.backtrace
|
91
|
+
str << exception.backtrace.join("\n\t")
|
92
|
+
else
|
93
|
+
str << "EMPTY BACKTRACE\n\t"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|