celluloid 0.17.3 → 0.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +300 -73
- data/CONDUCT.md +13 -0
- data/CONTRIBUTING.md +39 -0
- data/README.md +54 -150
- data/REFACTOR.md +1 -0
- data/architecture.md +120 -0
- data/examples/basic_usage.rb +1 -1
- data/examples/configurations.rb +78 -0
- data/examples/futures.rb +1 -1
- data/examples/ring.rb +5 -4
- data/examples/simple_pmap.rb +1 -1
- data/examples/stack.rb +2 -2
- data/examples/supervisors_and_registry.rb +82 -0
- data/examples/timers.rb +2 -2
- data/lib/celluloid.rb +74 -64
- data/lib/celluloid/actor.rb +27 -17
- data/lib/celluloid/actor/system.rb +13 -29
- data/lib/celluloid/autostart.rb +6 -1
- data/lib/celluloid/call/async.rb +2 -0
- data/lib/celluloid/call/sync.rb +10 -3
- data/lib/celluloid/calls.rb +13 -12
- data/lib/celluloid/cell.rb +5 -9
- data/lib/celluloid/condition.rb +3 -3
- data/lib/celluloid/core_ext.rb +0 -2
- data/lib/celluloid/debug.rb +3 -0
- data/lib/celluloid/exceptions.rb +2 -2
- data/lib/celluloid/future.rb +8 -10
- data/lib/celluloid/group.rb +16 -6
- data/lib/celluloid/group/pool.rb +1 -3
- data/lib/celluloid/group/spawner.rb +2 -6
- data/lib/celluloid/internals/call_chain.rb +15 -0
- data/lib/celluloid/internals/cpu_counter.rb +62 -0
- data/lib/celluloid/internals/handlers.rb +42 -0
- data/lib/celluloid/internals/links.rb +38 -0
- data/lib/celluloid/internals/logger.rb +104 -0
- data/lib/celluloid/internals/method.rb +34 -0
- data/lib/celluloid/internals/properties.rb +32 -0
- data/lib/celluloid/internals/receivers.rb +64 -0
- data/lib/celluloid/internals/registry.rb +102 -0
- data/lib/celluloid/internals/responses.rb +46 -0
- data/lib/celluloid/internals/signals.rb +24 -0
- data/lib/celluloid/internals/stack.rb +74 -0
- data/lib/celluloid/internals/stack/dump.rb +12 -0
- data/lib/celluloid/internals/stack/states.rb +72 -0
- data/lib/celluloid/internals/stack/summary.rb +12 -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 +147 -0
- data/lib/celluloid/logging/incident_reporter.rb +49 -0
- data/lib/celluloid/logging/log_event.rb +20 -0
- data/lib/celluloid/logging/ring_buffer.rb +64 -0
- data/lib/celluloid/mailbox.rb +22 -9
- data/lib/celluloid/mailbox/evented.rb +13 -5
- data/lib/celluloid/notifications.rb +95 -0
- data/lib/celluloid/pool.rb +6 -0
- data/lib/celluloid/probe.rb +81 -0
- data/lib/celluloid/proxy/abstract.rb +9 -9
- data/lib/celluloid/proxy/async.rb +1 -1
- data/lib/celluloid/proxy/block.rb +2 -2
- data/lib/celluloid/proxy/cell.rb +1 -1
- data/lib/celluloid/proxy/future.rb +2 -4
- data/lib/celluloid/proxy/sync.rb +1 -3
- data/lib/celluloid/rspec.rb +22 -33
- data/lib/celluloid/supervision.rb +17 -0
- data/lib/celluloid/supervision/configuration.rb +169 -0
- data/lib/celluloid/supervision/configuration/injections.rb +8 -0
- data/lib/celluloid/supervision/configuration/instance.rb +113 -0
- data/lib/celluloid/supervision/constants.rb +123 -0
- data/lib/celluloid/supervision/container.rb +144 -0
- data/lib/celluloid/supervision/container/behavior.rb +89 -0
- data/lib/celluloid/supervision/container/behavior/pool.rb +71 -0
- data/lib/celluloid/supervision/container/behavior/tree.rb +23 -0
- data/lib/celluloid/supervision/container/injections.rb +8 -0
- data/lib/celluloid/supervision/container/instance.rb +116 -0
- data/lib/celluloid/supervision/container/pool.rb +210 -0
- data/lib/celluloid/supervision/service.rb +27 -0
- data/lib/celluloid/supervision/supervise.rb +34 -0
- data/lib/celluloid/supervision/validation.rb +40 -0
- data/lib/celluloid/supervision/version.rb +5 -0
- data/lib/celluloid/system_events.rb +11 -6
- data/lib/celluloid/task.rb +25 -12
- data/lib/celluloid/task/fibered.rb +6 -2
- data/lib/celluloid/task/threaded.rb +3 -3
- data/lib/celluloid/test.rb +5 -2
- data/lib/celluloid/thread.rb +0 -2
- data/lib/celluloid/version.rb +1 -1
- data/spec/celluloid/block_spec.rb +29 -32
- data/spec/celluloid/calls_spec.rb +5 -15
- data/spec/celluloid/future_spec.rb +7 -1
- data/spec/celluloid/internals/cpu_counter_spec.rb +129 -0
- data/spec/celluloid/internals/links_spec.rb +43 -0
- data/spec/celluloid/internals/properties_spec.rb +40 -0
- data/spec/celluloid/internals/registry_spec.rb +62 -0
- data/spec/celluloid/internals/stack/dump_spec.rb +4 -0
- data/spec/celluloid/internals/stack/summary_spec.rb +4 -0
- data/spec/celluloid/internals/thread_handle_spec.rb +60 -0
- data/spec/celluloid/internals/uuid_spec.rb +9 -0
- data/spec/celluloid/logging/ring_buffer_spec.rb +36 -0
- data/spec/celluloid/mailbox/evented_spec.rb +11 -22
- data/spec/celluloid/misc/leak_spec.rb +3 -4
- data/spec/celluloid/notifications_spec.rb +140 -0
- data/spec/celluloid/probe_spec.rb +102 -0
- data/spec/celluloid/proxy_spec.rb +30 -30
- data/spec/celluloid/supervision/behavior_spec.rb +74 -0
- data/spec/celluloid/supervision/configuration_spec.rb +181 -0
- data/spec/celluloid/supervision/container_spec.rb +72 -0
- data/spec/celluloid/supervision/instance_spec.rb +13 -0
- data/spec/celluloid/supervision/root_spec.rb +28 -0
- data/spec/celluloid/supervision/supervisor_spec.rb +93 -0
- data/spec/celluloid/task/fibered_spec.rb +1 -3
- data/spec/celluloid/task/threaded_spec.rb +1 -3
- data/spec/shared/actor_examples.rb +58 -33
- data/spec/shared/group_examples.rb +2 -2
- data/spec/shared/mailbox_examples.rb +1 -1
- data/spec/shared/stack_examples.rb +87 -0
- data/spec/shared/task_examples.rb +2 -3
- data/spec/spec_helper.rb +2 -4
- data/spec/support/configure_rspec.rb +2 -3
- data/spec/support/coverage.rb +2 -4
- data/spec/support/crash_checking.rb +2 -2
- data/spec/support/examples/actor_class.rb +3 -8
- data/spec/support/examples/call_class.rb +2 -2
- data/spec/support/examples/container_class.rb +35 -0
- data/spec/support/examples/evented_mailbox_class.rb +1 -2
- data/spec/support/examples/stack_classes.rb +58 -0
- data/spec/support/examples/stack_methods.rb +23 -0
- data/spec/support/examples/subordinate_class.rb +19 -0
- data/spec/support/logging.rb +3 -34
- data/spec/support/loose_threads.rb +3 -16
- data/spec/support/reset_class_variables.rb +5 -1
- data/spec/support/stubbing.rb +1 -1
- metadata +91 -290
- data/culture/CONDUCT.md +0 -28
- data/culture/Gemfile +0 -9
- data/culture/LICENSE.txt +0 -22
- data/culture/README.md +0 -22
- data/culture/Rakefile +0 -5
- data/culture/SYNC.md +0 -70
- data/culture/celluloid-culture.gemspec +0 -18
- data/culture/gems/README.md +0 -39
- data/culture/gems/dependencies.yml +0 -85
- data/culture/gems/loader.rb +0 -101
- data/culture/rubocop/README.md +0 -38
- data/culture/rubocop/lint.yml +0 -8
- data/culture/rubocop/metrics.yml +0 -15
- data/culture/rubocop/perf.yml +0 -0
- data/culture/rubocop/rubocop.yml +0 -5
- data/culture/rubocop/style.yml +0 -57
- data/culture/spec/gems_spec.rb +0 -2
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +0 -2
- data/culture/sync.rb +0 -56
- data/culture/tasks/rspec.rake +0 -5
- data/culture/tasks/rubocop.rake +0 -2
- data/lib/celluloid/actor/manager.rb +0 -7
- data/lib/celluloid/backported.rb +0 -2
- data/lib/celluloid/current.rb +0 -2
- data/lib/celluloid/deprecate.rb +0 -21
- data/lib/celluloid/fiber.rb +0 -32
- data/lib/celluloid/managed.rb +0 -3
- data/lib/celluloid/notices.rb +0 -15
- data/spec/deprecate/actor_system_spec.rb +0 -72
- data/spec/deprecate/block_spec.rb +0 -52
- data/spec/deprecate/calls_spec.rb +0 -39
- data/spec/deprecate/evented_mailbox_spec.rb +0 -34
- data/spec/deprecate/future_spec.rb +0 -32
- data/spec/deprecate/internal_pool_spec.rb +0 -4
- data/spec/support/env.rb +0 -21
data/CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Contribution Guidelines
|
2
|
+
|
3
|
+
If you are seeking support, or for discussions about Celluloid, you can use [the mailing list](http://groups.google.com/group/celluloid-ruby) or the IRC channel, #celluloid on freenode.
|
4
|
+
|
5
|
+
If you encounter an issue with Celluloid itself, you should go through the following checklist:
|
6
|
+
|
7
|
+
* Is this a known bug or are you falling into a common trap? Check the [Gotchas wiki page](https://github.com/celluloid/celluloid/wiki/Gotchas).
|
8
|
+
* Is there already an issue filed which looks like your issue? Check the [issue tracker](https://github.com/celluloid/celluloid/issues).
|
9
|
+
* Is the problem present in the latest released version of Celluloid? Upgrade and check!
|
10
|
+
* Is the problem present on the master branch of Celluloid? [Run pre-release](#running-pre-release-celluloid) from source control and check!
|
11
|
+
|
12
|
+
If you don't get anywhere with this checklist, please feel free to [file a bug report](#filing-a-bug-report).
|
13
|
+
|
14
|
+
## Running pre-release Celluloid
|
15
|
+
|
16
|
+
If you encounter a bug, it's entirely possible that it has already been fixed but not yet included in a released version. You can establish this by trying to run your application with a pre-release version of Celluloid direct from source control. You can do this by modifying your application's Gemfile as follows:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'celluloid', github: 'celluloid', submodules: true
|
20
|
+
```
|
21
|
+
|
22
|
+
If it is suggested to you that you try a different branch, add `branch: 'somebranch'`.
|
23
|
+
|
24
|
+
If the problem is resolved, feel free to voice your desire for a new release of Celluloid on IRC (`irc.freenode.net/#celluloid`).
|
25
|
+
|
26
|
+
If it persists, you should consider [filing a bug report](#filing-a-bug-report).
|
27
|
+
|
28
|
+
## Filing a bug report
|
29
|
+
|
30
|
+
* Bug reports should be filed on the [GitHub issue tracker](https://github.com/celluloid/celluloid/issues). Bug reports should contain the following things:
|
31
|
+
* A sensible subject that helps quickly identify the issue.
|
32
|
+
* Full steps to reproduce the issue, including minimal reproduction code. A minimal reproduction means only what is necessary to display the problem and nothing more. This is perhaps the most important thing, don't skip it!
|
33
|
+
* Output from a reproduction.
|
34
|
+
* Full references for version numbers (of Celluloid, dependencies, Ruby, Operating System, etc). One easy way to do this is to post your Gemfile.lock, though you will still need to tell us what version of Ruby is in use.
|
35
|
+
* See: [Triage Process](https://github.com/celluloid/celluloid/wiki/Triage-Process)
|
36
|
+
* Some more guidelines on filing good bug reports:
|
37
|
+
* http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
|
38
|
+
* http://itscommonsensestupid.blogspot.com/2008/07/tips-to-write-good-bug-report.html
|
39
|
+
* http://timheuer.com/blog/archive/2011/10/12/anatomy-of-a-good-bug-report.aspx
|
data/README.md
CHANGED
@@ -1,88 +1,45 @@
|
|
1
|
-
![Celluloid]
|
2
|
-
|
3
|
-
[![Gem Version]
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
*
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
* __Fault-tolerance:__ Celluloid has taken to heart many of Erlang's ideas
|
45
|
-
about fault-tolerance in order to enable self-healing applications.
|
46
|
-
The central idea: have you tried turning it off and on again? Celluloid
|
47
|
-
takes care of rebooting subcomponents of your application when they crash,
|
48
|
-
whether it's a single actor, or large (potentially multi-tiered) groups of
|
49
|
-
actors that are all interdependent. This means rather than worrying about
|
50
|
-
rescuing every last exception, you can just sit back, relax, and let parts
|
51
|
-
of your program crash, knowing Celluloid will automatically reboot them in
|
52
|
-
a clean state. Celluloid provides its own implementation of the core
|
53
|
-
fault-tolerance concepts in Erlang including [linking](https://github.com/celluloid/celluloid/wiki/Linking),
|
54
|
-
[supervisors](https://github.com/celluloid/celluloid/wiki/Supervisors),
|
55
|
-
and [supervision groups](https://github.com/celluloid/celluloid/wiki/Supervision-Groups).
|
56
|
-
|
57
|
-
* __[Futures](https://github.com/celluloid/celluloid/wiki/futures):__
|
58
|
-
Ever wanted to call a method "in the background" and retrieve the
|
59
|
-
value it returns later? Celluloid futures do just that. It's like
|
60
|
-
calling ahead to a restaurant to place an order, so they can work
|
61
|
-
on preparing your food while you're on your way to pick it up.
|
62
|
-
When you ask for a method's return value, it's returned immediately
|
63
|
-
if the method has already completed, or otherwise the current method is
|
64
|
-
suspended until the value becomes available.
|
65
|
-
|
66
|
-
You can also build distributed systems with Celluloid using its
|
67
|
-
[sister project DCell](https://github.com/celluloid/dcell). Evented IO similar
|
68
|
-
to EventMachine (with a synchronous API instead of callback/deferrable soup)
|
69
|
-
is available through the [Celluloid::IO](https://github.com/celluloid/celluloid-io)
|
70
|
-
library.
|
71
|
-
|
72
|
-
Like Celluloid? [Join the mailing list/Google Group](http://groups.google.com/group/celluloid-ruby)
|
73
|
-
or visit us on IRC at #celluloid on freenode
|
74
|
-
|
75
|
-
### Is it any good?
|
76
|
-
|
77
|
-
[Yes](http://news.ycombinator.com/item?id=3067434)
|
78
|
-
|
79
|
-
### Is It "Production Ready™"?
|
80
|
-
|
81
|
-
Yes, many users are now running Celluloid in production by using
|
82
|
-
[Sidekiq](http://sidekiq.org) and [Adhearsion](http://adhearsion.com/)
|
83
|
-
|
84
|
-
Documentation
|
85
|
-
-------------
|
1
|
+
# ![Celluloid][celluloid-logo-image-raw]
|
2
|
+
|
3
|
+
[![Gem Version][gem-image]][gem-link]
|
4
|
+
[![MIT licensed][license-image]][license-link]
|
5
|
+
[![Build Status][build-image]][build-link]
|
6
|
+
[![Maintained: no][maintained-image]][maintained-link]
|
7
|
+
[![Gitter Chat][gitter-image]][gitter-link]
|
8
|
+
|
9
|
+
[celluloid-logo-image-raw]: https://raw.github.com/celluloid/celluloid-logos/master/celluloid/celluloid.png
|
10
|
+
[gem-image]: https://badge.fury.io/rb/celluloid.svg
|
11
|
+
[gem-link]: http://rubygems.org/gems/celluloid
|
12
|
+
[build-image]: https://secure.travis-ci.org/celluloid/celluloid.svg?branch=master
|
13
|
+
[build-link]: http://travis-ci.org/celluloid/celluloid
|
14
|
+
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
|
15
|
+
[license-link]: https://github.com/celluloid/celluloid/blob/master/LICENSE.txt
|
16
|
+
[maintained-image]: https://img.shields.io/maintenance/no/2016.svg
|
17
|
+
[maintained-link]: https://github.com/celluloid/celluloid/issues/779
|
18
|
+
[gitter-image]: https://badges.gitter.im/badge.svg
|
19
|
+
[gitter-link]: https://gitter.im/celluloid/celluloid
|
20
|
+
|
21
|
+
Celluloid is a framework for building asynchronous and multithreaded Ruby
|
22
|
+
programs using object-oriented concepts.
|
23
|
+
|
24
|
+
## Revival Process Underway
|
25
|
+
|
26
|
+
`Celluloid` is in the process of being refactored and released back into the wild during `Google Summer of Code`. The next era will not have one individual active maintainer, but a team of collaborators. Going forward, previously dormant maintainer [Donovan Keme](https://github.com/digitalextremist) is returning to support future primary maintainer [Emese Padányi](https://github.com/emesepadanyi) during `GSoC 2020`. Her plan extends past the Summer program, and aims to revive the community and codebase of `Celluloid` together. Backing this process are [Harsh Deep](https://github.com/harsh183) and `GSoC` alumni [Dilum Navanjana](https://github.com/dilumn). We welcome your collaboration and contributions in this massive work.
|
27
|
+
|
28
|
+
The codebase is being refactored to pursue a stable release with no deprecation warnings, and with this cleaned up:
|
29
|
+
|
30
|
+
# ![Diagram][celluloid-diagram]
|
31
|
+
*Diagram meticulously developed by [Emese Padányi](https://github.com/emesepadanyi)*
|
32
|
+
|
33
|
+
[celluloid-diagram]: https://raw.githubusercontent.com/celluloid/celluloid/master/documentation/ClassDiagram-class_diagram.png
|
34
|
+
|
35
|
+
### Proudly supported by the best cloud infrastructure provider in the world: [`DigitalOcean`](https://digitalocean.com)
|
36
|
+
|
37
|
+
## Discussion
|
38
|
+
|
39
|
+
- [Gitter Chat][gitter-link]
|
40
|
+
- [Google Group](https://groups.google.com/group/celluloid-ruby)
|
41
|
+
|
42
|
+
## Documentation
|
86
43
|
|
87
44
|
[Please see the Celluloid Wiki](https://github.com/celluloid/celluloid/wiki)
|
88
45
|
for more detailed documentation and usage notes.
|
@@ -94,11 +51,9 @@ The following API documentation is also available:
|
|
94
51
|
* [Celluloid class methods](http://rubydoc.info/gems/celluloid/Celluloid/ClassMethods)
|
95
52
|
* [All Celluloid classes](http://rubydoc.info/gems/celluloid/index)
|
96
53
|
|
97
|
-
Related Projects
|
98
|
-
----------------
|
54
|
+
## Related Projects
|
99
55
|
|
100
|
-
|
101
|
-
like Celluloid we definitely recommend you check them out:
|
56
|
+
See also: [Projects Using Celluloid](https://github.com/celluloid/celluloid/wiki/Projects-Using-Celluloid)
|
102
57
|
|
103
58
|
* [Reel][reel]: An "evented" web server based on `Celluloid::IO`
|
104
59
|
* [DCell][dcell]: The Celluloid actor protocol distributed over 0MQ
|
@@ -107,79 +62,28 @@ like Celluloid we definitely recommend you check them out:
|
|
107
62
|
* [Celluloid::ZMQ][celluloid-zmq]: "Evented" 0MQ support for `Celluloid` actors
|
108
63
|
* [Celluloid::DNS][celluloid-dns]: An "evented" DNS server based on `Celluloid::IO`
|
109
64
|
* [Celluloid::SMTP][celluloid-smtp]: An "evented" SMTP server based on `Celluloid::IO`
|
110
|
-
* [Lattice][lattice]: A concurrent realtime web framework based on `Celluloid::IO`
|
111
65
|
* [nio4r][nio4r]: "New IO for Ruby": high performance IO selectors
|
112
66
|
* [Timers][timers]: A generic Ruby timer library for event-based systems
|
113
67
|
|
114
68
|
[reel]: https://github.com/celluloid/reel/
|
115
69
|
[dcell]: https://github.com/celluloid/dcell/
|
116
|
-
[ecell]: https://github.com/
|
70
|
+
[ecell]: https://github.com/abstractive/ecell/
|
117
71
|
[celluloid-io]: https://github.com/celluloid/celluloid-io/
|
118
72
|
[celluloid-zmq]: https://github.com/celluloid/celluloid-zmq/
|
119
73
|
[celluloid-dns]: https://github.com/celluloid/celluloid-dns/
|
120
|
-
[celluloid-smtp]: https://github.com/
|
121
|
-
[lattice]: https://github.com/celluloid/lattice/
|
74
|
+
[celluloid-smtp]: https://github.com/abstractive/celluloid-smtp/
|
122
75
|
[nio4r]: https://github.com/celluloid/nio4r/
|
123
76
|
[timers]: https://github.com/celluloid/timers/
|
124
77
|
|
125
|
-
|
126
|
-
------------
|
127
|
-
|
128
|
-
Add this line to your application's Gemfile:
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
gem 'celluloid'
|
132
|
-
```
|
133
|
-
|
134
|
-
And then execute:
|
135
|
-
|
136
|
-
$ bundle
|
137
|
-
|
138
|
-
Or install it yourself as:
|
139
|
-
|
140
|
-
$ gem install celluloid
|
141
|
-
|
142
|
-
Inside of your Ruby program, require Celluloid with [newest API](https://github.com/celluloid/celluloid/wiki/DEPRECATION-WARNING):
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
require 'celluloid/current'
|
146
|
-
```
|
147
|
-
|
148
|
-
Or to support the old API, use:
|
149
|
-
|
150
|
-
```ruby
|
151
|
-
require 'celluloid/backported'
|
152
|
-
```
|
153
|
-
|
154
|
-
Supported Platforms
|
155
|
-
-------------------
|
156
|
-
|
157
|
-
Celluloid works on Ruby 2.0+, JRuby 1.7+, and Rubinius 2.0.
|
158
|
-
|
159
|
-
JRuby or Rubinius are the preferred platforms as they support true thread-level
|
160
|
-
parallelism when executing Ruby code, whereas MRI/YARV is constrained by a global
|
161
|
-
interpreter lock (GIL) and can only execute one thread at a time.
|
162
|
-
|
163
|
-
Celluloid requires Ruby 1.9 mode on all interpreters.
|
164
|
-
|
165
|
-
Additional Reading
|
166
|
-
------------------
|
167
|
-
|
168
|
-
* [Concurrent Object-Oriented Programming in Python with
|
169
|
-
ATOM](http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=11A3EACE78AAFF6D6D62A64118AFCA7C?doi=10.1.1.47.5074&rep=rep1&type=pdf):
|
170
|
-
a similar system to Celluloid written in Python
|
171
|
-
|
172
|
-
Contributing to Celluloid
|
173
|
-
-------------------------
|
78
|
+
## Contributing to Celluloid
|
174
79
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
* If we've accepted a patch, feel free to ask for commit access
|
80
|
+
- Fork this repository on github
|
81
|
+
- Make your changes and send us a pull request
|
82
|
+
- Pull requests will be reviewed for inclusion in the project
|
179
83
|
|
180
|
-
License
|
181
|
-
-------
|
84
|
+
## License
|
182
85
|
|
183
|
-
Copyright (c) 2011-
|
86
|
+
Copyright (c) 2011-2018 Tony Arcieri, Donovan Keme.
|
184
87
|
|
185
|
-
Distributed under the MIT License. See [LICENSE.txt](https://github.com/celluloid/celluloid/blob/master/LICENSE.txt)
|
88
|
+
Distributed under the MIT License. See [LICENSE.txt](https://github.com/celluloid/celluloid/blob/master/LICENSE.txt)
|
89
|
+
for further details.
|
data/REFACTOR.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
20200703113000: `require "celluloid/current"` is removed. use `require "celluloid"`
|
data/architecture.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# Architecture
|
2
|
+
|
3
|
+
The purpose of this document is to provide an overview of the `Celluloid` project architecture. It is intended as a learning tool for
|
4
|
+
GSoC (Google Summer of Code) and for anyone else interested in peeking under the hood to figure out how Celluloid works.
|
5
|
+
|
6
|
+
This document will evolve since the people writing it are learning the project too. It will likely evolve in the following manner:
|
7
|
+
|
8
|
+
1. Document all major classes by describing the purpose of each one.
|
9
|
+
2. Document the dependencies between classes described in item 1.
|
10
|
+
3. Describe the flow of messages between the classes documented in items 1 and 2.
|
11
|
+
4. Generate a Big Picture overview of the overall Celluloid architecture.
|
12
|
+
5. Create a flew graphics to depict class dependencies and message flows (perhaps as a directed acyclic graph).
|
13
|
+
|
14
|
+
## Document Status
|
15
|
+
|
16
|
+
The document is working on item 1.
|
17
|
+
|
18
|
+
## Required Libraries
|
19
|
+
`logger`
|
20
|
+
`thread`
|
21
|
+
`timeout`
|
22
|
+
`set`
|
23
|
+
|
24
|
+
## Require Lifecycle
|
25
|
+
Document the steps taken from the moment `require "celluloid"` is executed by the runtime.
|
26
|
+
|
27
|
+
The file `celluloid.rb` is read in by the runtime. This file requires some standard libraries like `Thread` and `Set` (see Required Libraries for full list) and initializes the `Celluloid` module namespace. It then sets up a Celluloid singleton class which will contain utility functions that need to be accessed from anywhere. Think of these singleton methods as global methods. These specific methods should be considered private to the library and should not be directly called by user code.
|
28
|
+
|
29
|
+
From here it continues to `extend` and `include` other modules so that any Ruby object that executes `include Celluloid` as part of its class definition automatically gains all of the Celluloid magic.
|
30
|
+
|
31
|
+
Next, it defines regular methods within the Celluloid namespace. These are also global methods but they are essentially the public API to the outside world. These methods (such as `current_actor` and `terminate`) can be called by user code.
|
32
|
+
|
33
|
+
Next we have a list of `require`'d subfiles. This loads the remainder of the library in preparation to start running.
|
34
|
+
|
35
|
+
Next, the code sets up two global default settings for the `task_class` and `group_class`. I don't know what these are yet but by exposing them this way it's clearly intended for these items to be defined in such a way that user code can override them with use-case-specific code. The code here can also read names from the environment variables to set the defaults. This is likely intended for use by the spec/test system.
|
36
|
+
|
37
|
+
Lastly, the code registers some methods for shutdown to terminate all actors `at_exit` and then initializes the system.
|
38
|
+
|
39
|
+
To boot the system, call `require 'celluloid'`.
|
40
|
+
|
41
|
+
## Supervision Lifecycle
|
42
|
+
The final call to `Actor::System.new.start` kicks off the top level supervisor. The supervisor container is an actor and it will keep track of all defined actors as they are added for supervision. A user may create an actor that is not supervised, so the top-level supervisor does not necessarily have a reference to every actor in the system.
|
43
|
+
|
44
|
+
The Registry is also created at this time and lives within the main container. Actors can be added to the registry even if they are not supervised. The two concepts are separate even though the code is somewhat comingled.
|
45
|
+
|
46
|
+
## Classes / Modules
|
47
|
+
|
48
|
+
### Celluloid Module
|
49
|
+
* Sets up class accessors used throughout/globally such as `logger`
|
50
|
+
* When using `include Celluloid` on a class, it performs the following work during `include`:
|
51
|
+
* Extends `ClassMethods` and `Internals::Properties`
|
52
|
+
* Includes `InstanceMethods`
|
53
|
+
* Sets properties on the class object.
|
54
|
+
* Removes `trap_exit` and `exclusive` if they exist on the singleton class so that Celluloid can redefine them for itself.
|
55
|
+
* Defines class methods inside the `Celluloid` namespace such as `actor?` and `mailbox` and `cores`. These are utility functions. They are defined on the Celluloid singleton.
|
56
|
+
* Provides the entry method `boot` to start up the whole system and its opposite `shutdown` to terminate everything.
|
57
|
+
|
58
|
+
#### Depends On Classes
|
59
|
+
* Internals::Logger
|
60
|
+
* Internals::CallChain
|
61
|
+
* Actor::System
|
62
|
+
* Celluloid::Mailbox
|
63
|
+
* Thread (primarily for Thread.current to access fiber locals like `:celluloid_actor`)
|
64
|
+
* Future
|
65
|
+
|
66
|
+
### ClassMethods Module
|
67
|
+
This class contains class-level methods which are added to every user class that contains `include Celluloid`.
|
68
|
+
|
69
|
+
* Overrides `new` for the class object.
|
70
|
+
|
71
|
+
#### Depends On Classes
|
72
|
+
* Cell
|
73
|
+
* Actor
|
74
|
+
* Celluloid
|
75
|
+
|
76
|
+
### InstanceMethods Module
|
77
|
+
This module contains instance-level methods which are added to every user class that contains `include Celluloid`.
|
78
|
+
|
79
|
+
#### Depends on Classes
|
80
|
+
* Actor
|
81
|
+
* Celluloid
|
82
|
+
|
83
|
+
|
84
|
+
### Actor::System class
|
85
|
+
Is created and `start`'ed as part of the entire boot sequence. This class provides essential services utilized by the rest of the library such as the Registry and the top-level Supervisor.
|
86
|
+
|
87
|
+
#### Lifecycle
|
88
|
+
Creates the `Registry` and initializes the `Celluloid.group_class`. Upon `start` it makes sure that it switches the `Thread.current[:celluloid_actor_system]` to itself, then defines and deploys the `Root` services.
|
89
|
+
|
90
|
+
#### Depends On Classes
|
91
|
+
* Supervision::Service::Root which is in gem `celluloid-supervision`
|
92
|
+
* Celluloid::Notifications::Fanout
|
93
|
+
* Celluloid::IncidentReporter
|
94
|
+
* Celluloid::Supervision::Service::Public
|
95
|
+
* Celluloid::Actor::Manager
|
96
|
+
* Celluloid
|
97
|
+
* Internals::Registry
|
98
|
+
* Celluloid.group_class
|
99
|
+
|
100
|
+
## Gem - celluloid-supervision
|
101
|
+
Necessary for the core system to boot.
|
102
|
+
|
103
|
+
Really has only two classes/modules of note. One is Supervision::Container which is an actor that keeps track of all actors under supervision. It also handles restart. Two is Supervision::Configuration. This class manages the several different ways that an actor may be placed under supervision, arguments passed to it, and other data.
|
104
|
+
|
105
|
+
Be careful when reading the code. Each file in the gem relies on open Ruby classes. These files reopen previously defined classes and add more behavior, so to get a complete picture for what the Configuration and Container classes can do you must look through all of the files. While this logical separation of business logic to its own file is neat, it adds to the cognitive load when reading the code since the entire class defintion is spread over multiple files.
|
106
|
+
|
107
|
+
### Supervision::Service::Root
|
108
|
+
|
109
|
+
#### Depends On Classes
|
110
|
+
* Supervision::Container
|
111
|
+
|
112
|
+
|
113
|
+
### Supervision::Container
|
114
|
+
Stores references to Actors on behalf of a Supervisor.
|
115
|
+
|
116
|
+
This is the only class under the `Supervision` namespace that is an Actor. Every other class is a regular Ruby class.
|
117
|
+
|
118
|
+
#### Depends On Classes
|
119
|
+
* Supervision::Configuration
|
120
|
+
*
|
data/examples/basic_usage.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
require "celluloid"
|
2
|
+
|
3
|
+
puts "Use Supervision::Configuration objects!"
|
4
|
+
|
5
|
+
class Hello
|
6
|
+
include Celluloid
|
7
|
+
|
8
|
+
finalizer :ceasing
|
9
|
+
|
10
|
+
def initialize(to)
|
11
|
+
@to = to
|
12
|
+
puts "Created Hello #{@to}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def ceasing
|
16
|
+
puts "Hello #{@to} go buhbye"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class FooBar
|
21
|
+
include Celluloid
|
22
|
+
|
23
|
+
finalizer :ceasing
|
24
|
+
|
25
|
+
def initialize(i = 0)
|
26
|
+
@i = i
|
27
|
+
puts "Created FooBar: #{@i}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def ceasing
|
31
|
+
puts "FooBar FooBar: #{@i} go buhbye"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
puts "\nInstantiated in bulk, using #deploy"
|
36
|
+
|
37
|
+
config = Celluloid::Supervision::Configuration.define([
|
38
|
+
{ type: FooBar, as: :foobar },
|
39
|
+
{ type: Hello, as: :hello, args: ["World"] }
|
40
|
+
])
|
41
|
+
|
42
|
+
config.deploy
|
43
|
+
puts "...shut it down"
|
44
|
+
config.shutdown
|
45
|
+
|
46
|
+
puts "\nInstantiated in bulk, using .deploy"
|
47
|
+
|
48
|
+
config = Celluloid::Supervision::Configuration.deploy([
|
49
|
+
{ type: FooBar, as: :foobar, args: [1] },
|
50
|
+
{ type: Hello, as: :hello, args: ["World"] }
|
51
|
+
])
|
52
|
+
|
53
|
+
puts "...shut it down"
|
54
|
+
config.shutdown
|
55
|
+
|
56
|
+
puts "\nInstantiated two actors individually, using a local configuration object"
|
57
|
+
|
58
|
+
config = Celluloid::Supervision::Configuration.new
|
59
|
+
config.define type: FooBar, as: :foobar11, args: [11]
|
60
|
+
config.define type: FooBar, as: :foobar33, args: [33]
|
61
|
+
config.deploy
|
62
|
+
|
63
|
+
puts "Instantiated another, which starts automatically."
|
64
|
+
puts "... using the local configuration object"
|
65
|
+
puts "... using a lazy loaded argument"
|
66
|
+
config.add type: Hello, as: :hello, args: -> { "Spinning World" }
|
67
|
+
|
68
|
+
config.shutdown
|
69
|
+
|
70
|
+
puts "\nReuse our last configuration!"
|
71
|
+
|
72
|
+
config.deploy
|
73
|
+
puts "...shut it down"
|
74
|
+
config.shutdown
|
75
|
+
|
76
|
+
puts "Thinking for 4 seconds, and 4 seconds only."
|
77
|
+
sleep 4
|
78
|
+
puts "Use Supervision::Configuration objects. Really!"
|