Skip to content

Commit

Permalink
Merge pull request #643 from celluloid/0.17.5-release
Browse files Browse the repository at this point in the history
Update GSoC branch.
  • Loading branch information
//de committed Jul 4, 2015
2 parents c1d245d + e63d4a7 commit e504a20
Show file tree
Hide file tree
Showing 26 changed files with 359 additions and 354 deletions.
13 changes: 7 additions & 6 deletions .travis.yml
@@ -1,18 +1,15 @@
script: rake ci
language: ruby
rvm:
- 2.0.0
- 2.1.4
- 2.2.0
- 2.2.2
- jruby
- ruby-head
- jruby-head
- rbx-2

# TODO: Put these back:
# * CELLULOID_TASK_CLASS=Fibered
# * CELLULOID_TASK_CLASS=Threaded
# For right now the imporant thing is to test BACKPORTED mode:

matrix:
fast_finish: true
allow_failures:
Expand All @@ -21,14 +18,18 @@ matrix:
- rvm: jruby-head
- env: CELLULOID_BACKPORTED=true
- env: CELLULOID_BACKPORTED=false CELLULOID_LEAKTEST=1
- env: CELLULOID_BACKPORTED=false CELLULOID_TASK_CLASS=Threaded
- env: CELLULOID_BACKPORTED=true CELLULOID_TASK_CLASS=Threaded

env:
global:
- NUMBER_OF_PROCESSORS=2 CELLULOID_CONFIG_FILE=.env-ci
- NUMBER_OF_PROCESSORS=4 CELLULOID_CONFIG_FILE=.env-ci
matrix:
- CELLULOID_BACKPORTED=true
- CELLULOID_BACKPORTED=false
- CELLULOID_BACKPORTED=false CELLULOID_LEAKTEST=1
- CELLULOID_BACKPORTED=false CELLULOID_TASK_CLASS=Threaded
- CELLULOID_BACKPORTED=true CELLULOID_TASK_CLASS=Threaded

notifications:
irc: "irc.freenode.org#celluloid"
Expand Down
2 changes: 1 addition & 1 deletion CHANGES.md
@@ -1,4 +1,4 @@
0.17.0 (2015)
0.17.0 (2015-07-04)
----
* Fix $CELLULOID_TEST warnings
* Massive overhaul of test suite, end-to-end.
Expand Down
18 changes: 12 additions & 6 deletions README.md
@@ -1,9 +1,9 @@
![Celluloid](https://raw.github.com/celluloid/celluloid-logos/master/celluloid/celluloid.png)
=========
[![Gem Version](https://badge.fury.io/rb/celluloid.png)](http://rubygems.org/gems/celluloid)
[![Build Status](https://secure.travis-ci.org/celluloid/celluloid.png?branch=master)](http://travis-ci.org/celluloid/celluloid)
[![Code Climate](https://codeclimate.com/github/celluloid/celluloid.png)](https://codeclimate.com/github/celluloid/celluloid)
[![Coverage Status](https://coveralls.io/repos/celluloid/celluloid/badge.png?branch=master)](https://coveralls.io/r/celluloid/celluloid)
[![Gem Version](https://badge.fury.io/rb/celluloid.svg)](http://rubygems.org/gems/celluloid)
[![Build Status](https://secure.travis-ci.org/celluloid/celluloid.svg?branch=master)](http://travis-ci.org/celluloid/celluloid)
[![Code Climate](https://codeclimate.com/github/celluloid/celluloid.svg)](https://codeclimate.com/github/celluloid/celluloid)
[![Coverage Status](https://coveralls.io/repos/celluloid/celluloid/badge.svg?branch=master)](https://coveralls.io/r/celluloid/celluloid)

> "I thought of objects being like biological cells and/or individual
> computers on a network, only able to communicate with messages"
Expand Down Expand Up @@ -133,10 +133,16 @@ Or install it yourself as:

$ gem install celluloid

Inside of your Ruby program, require Celluloid with:
Inside of your Ruby program, require Celluloid with [newest API](/celluloid/celluloid/wiki/DEPRECATION-WARNING):

```ruby
require 'celluloid/autostart'
require 'celluloid/current'
```

Or to support the old API, use:

```ruby
require 'celluloid/backported'
```

Supported Platforms
Expand Down
4 changes: 2 additions & 2 deletions celluloid.gemspec
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |gem|
gem.description = "Celluloid enables people to build concurrent programs out of concurrent objects just as easily as they build sequential programs out of sequential objects"
gem.licenses = ["MIT"]

gem.authors = ["Tony Arcieri"]
gem.email = ["tony.arcieri@gmail.com"]
gem.authors = ["Tony Arcieri", "digitalextremist//"]
gem.email = ["tony.arcieri@gmail.com", "code@extremist.digital"]
gem.homepage = "https://github.com/celluloid/celluloid"

gem.required_ruby_version = ">= 1.9.2"
Expand Down
47 changes: 47 additions & 0 deletions examples/stack.rb
@@ -0,0 +1,47 @@
#!/usr/bin/env ruby

$:.push File.expand_path('../../lib', __FILE__)
require 'celluloid/autostart'

# This example builds on basic_usage.rb to show two things about #async: the
# (new) fluent API and the preservation of causality order.
class Stack
include Celluloid

attr_reader :ary

def initialize
@ary = []
end

def push x
@ary.push x
end
alias << push

def pop
@ary.pop
end

def show
p @ary
end
end

st = Stack.new

# Schedule three calls to #push some integers on the stack. They will execute
# in order because the calls originated as a sequence of method calls in a
# single thread.
st.async << 1 << 2 << 3

# Schedule a call to show the stack after the three push calls execute.
st.async.show

# Schedule three calls to #pop from the stack.
st.async.pop.pop.pop

# The next (non-async) call is guaranteed to execute after methods previously
# scheduled in this thread. The causal order of calls (order as requested) is
# preserved in the execution order.
st.show
11 changes: 3 additions & 8 deletions lib/celluloid.rb
Expand Up @@ -8,14 +8,9 @@
require "celluloid/version"
require "celluloid/notices"

if ENV["CELLULOID_BACKPORTED"] == "silently" || (defined?($CELLULOID_BACKPORTED) && $CELLULOID_BACKPORTED == :silently)
$CELLULOID_BACKPORTED = true
Celluloid::Notices.backported_mini
else
$CELLULOID_BACKPORTED = false if defined?(CELLULOID_FUTURE) && CELLULOID_FUTURE
$CELLULOID_BACKPORTED = (ENV["CELLULOID_BACKPORTED"] != "false") unless defined?($CELLULOID_BACKPORTED)
Celluloid::Notices.backported if $CELLULOID_BACKPORTED
end
$CELLULOID_BACKPORTED = false if defined?(CELLULOID_FUTURE) && CELLULOID_FUTURE
$CELLULOID_BACKPORTED = (ENV["CELLULOID_BACKPORTED"] != "false") unless defined?($CELLULOID_BACKPORTED)
Celluloid::Notices.backported if $CELLULOID_BACKPORTED

module Celluloid
# Expose all instance methods as singleton methods
Expand Down
2 changes: 1 addition & 1 deletion lib/celluloid/actor.rb
Expand Up @@ -132,7 +132,7 @@ def start
run
end

@proxy = Proxy::Actor.new(@thread, @mailbox)
@proxy = Proxy::Actor.new(@mailbox, @thread)
Celluloid::Probe.actor_created(self) if $CELLULOID_MONITORING
end

Expand Down
2 changes: 1 addition & 1 deletion lib/celluloid/backported.rb
@@ -1,2 +1,2 @@
$CELLULOID_BACKPORTED = :silently
$CELLULOID_BACKPORTED = true
require "celluloid/autostart"
2 changes: 1 addition & 1 deletion lib/celluloid/calls.rb
Expand Up @@ -12,7 +12,7 @@ def initialize(method, arguments = [], block = nil)
# FIXME: nicer exception
fail "Cannot execute blocks on sender in exclusive mode"
end
@block = Proxy::Block.new(self, Celluloid.mailbox, block)
@block = Proxy::Block.new(Celluloid.mailbox, self, block)
else
@block = nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/celluloid/cell.rb
Expand Up @@ -41,7 +41,7 @@ def initialize(subject, options, actor_options)
end

@actor.start
@proxy = (options[:proxy_class] || Proxy::Cell).new(@actor.proxy, @actor.mailbox, @subject.class.to_s)
@proxy = (options[:proxy_class] || Proxy::Cell).new(@actor.mailbox, @actor.proxy, @subject.class.to_s)
end
attr_reader :proxy, :subject

Expand Down
35 changes: 34 additions & 1 deletion lib/celluloid/future.rb
Expand Up @@ -21,12 +21,36 @@ def self.new(*args, &block)

attr_reader :address

def initialize
def initialize(&block)
@address = Celluloid.uuid
@mutex = Mutex.new
@ready = false
@result = nil
@forwards = nil
@cancelled = false

if block
@call = SyncCall.new(self, :call, args)
Celluloid.internal_pool.get do
begin
@call.dispatch(block)
rescue
# Exceptions in blocks will get raised when the value is retrieved
end
end
else
@call = nil
end
end

# Execute the given method in future context
def execute(receiver, method, args, block)
@mutex.synchronize do
raise "already calling" if @call
@call = SyncCall.new(self, method, args, block)
end

receiver << @call
end

# Check if this future has a value yet
Expand Down Expand Up @@ -74,6 +98,7 @@ def value(timeout = nil)

# Signal this future with the given result value
def signal(value)
return if @cancelled
result = Result.new(value, self)

@mutex.synchronize do
Expand All @@ -89,6 +114,14 @@ def signal(value)
end
alias_method :<<, :signal

def cancel(error)
response = ErrorResponse.new(@call, error)
signal response
@mutex.synchronize do
@cancelled = true
end
end

# Inspect this Celluloid::Future
alias_method :inspect, :to_s

Expand Down
19 changes: 1 addition & 18 deletions lib/celluloid/notices.rb
Expand Up @@ -3,25 +3,8 @@ module Notices
class << self
@@notices = []

def backported_mini
@@notices << [:warn, "Celluloid is running in BACKPORTED mode. [ http://git.io/vJf3J ]"]
end

def version
@@notices << [:info, "+--------------------------------------------------+"]
@@notices << [:info, "| Celluloid version running now: #{'%-13s' % Celluloid::VERSION} +"]
end

def backported
version
@@notices << [:warn, "+--------------------------------------------------+"]
@@notices << [:warn, "| Celluloid is running in BACKPORTED mode. |"]
@@notices << [:warn, "| Time to update deprecated code, before v1.0! |"]
@@notices << [:warn, "+--------------------------------------------------+"]
@@notices << [:warn, "| Prepare! As of v0.17.5 you can begin updating. |"]
@@notices << [:warn, "+--------------------------------------------------+"]
@@notices << [:warn, "| Want to read about it? http://git.io/vJf3J |"]
@@notices << [:warn, "+--------------------------------------------------+"]
@@notices << [:debug, "Celluloid #{Celluloid::VERSION} is running in BACKPORTED mode. [ http://git.io/vJf3J ]"]
end

def output
Expand Down
37 changes: 16 additions & 21 deletions lib/celluloid/proxy/abstract.rb
@@ -1,24 +1,19 @@
module Celluloid
module Proxy
# Base class of all Celluloid proxies
class Abstract < BasicObject
# Used for reflecting on proxy objects themselves
def __class__
Proxy::Abstract
end

# Needed for storing proxies in data structures
needed = [:object_id, :__id__, :hash, :private_methods] - instance_methods
if needed.any?
include ::Kernel.dup.module_eval {
undef_method(*(instance_methods - needed))
self
}
# Base class of Celluloid proxies
class Celluloid::Proxy::Abstract < BasicObject
# Used for reflecting on proxy objects themselves
def __class__
::Celluloid::Proxy::Abstract
end

# rubinius bug? These methods disappear when we include hacked kernel
define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==)
alias_method(:equal?, :==) unless instance_methods.include?(:equal?)
end
end
# Needed for storing proxies in data structures
needed = [:object_id, :__id__, :hash, :private_methods] - instance_methods
if needed.any?
include ::Kernel.dup.module_eval {
undef_method(*(instance_methods - needed))
self
}
# rubinius bug? These methods disappear when we include hacked kernel
define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==)
alias_method(:equal?, :==) unless instance_methods.include?(:equal?)
end
end
69 changes: 32 additions & 37 deletions lib/celluloid/proxy/actor.rb
@@ -1,46 +1,41 @@
module Celluloid
module Proxy
# A proxy which controls the Actor lifecycle
class Actor < Abstract
attr_reader :thread, :mailbox
# A proxy which controls the Actor lifecycle
class Celluloid::Proxy::Actor < Celluloid::Proxy::Abstract
attr_reader :thread, :mailbox

# Used for reflecting on proxy objects themselves
def __class__
Proxy::Actor
end
# Used for reflecting on proxy objects themselves
def __class__
::Celluloid::Proxy::Actor
end

def initialize(thread, mailbox)
@thread = thread
@mailbox = mailbox
end
def initialize(mailbox, thread)
@mailbox, @thread = mailbox, thread
end

def inspect
# TODO: use a system event to fetch actor state: tasks?
"#<Celluloid::Proxy::Actor(#{@mailbox.address}) alive>"
rescue DeadActorError
"#<Celluloid::Proxy::Actor(#{@mailbox.address}) dead>"
end
def inspect
# TODO: use a system event to fetch actor state: tasks?
"#<::Celluloid::Proxy::Actor(#{@mailbox.address}) alive>"
rescue DeadActorError
"#<::Celluloid::Proxy::Actor(#{@mailbox.address}) dead>"
end

def alive?
@mailbox.alive?
end
def alive?
@mailbox.alive?
end

def dead?
!alive?
end
def dead?
!alive?
end

# Terminate the associated actor
def terminate
terminate!
::Celluloid::Actor.join(self)
nil
end
# Terminate the associated actor
def terminate
terminate!
::Celluloid::Actor.join(self)
nil
end

# Terminate the associated actor asynchronously
def terminate!
::Kernel.raise DeadActorError, "actor already terminated" unless alive?
@mailbox << TerminationRequest.new
end
end
# Terminate the associated actor asynchronously
def terminate!
::Kernel.raise ::Celluloid::DeadActorError, "actor already terminated" unless alive?
@mailbox << ::Celluloid::TerminationRequest.new
end
end

0 comments on commit e504a20

Please sign in to comment.