tribe 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ module Tribe
10
10
  attr_accessor :active_event
11
11
  attr_accessor :parent
12
12
  attr_accessor :children
13
+ attr_accessor :supervisees
13
14
  attr_accessor :exception
14
15
  end
15
16
  end
@@ -20,7 +20,7 @@ module Tribe
20
20
  end
21
21
 
22
22
  COUNTERS.times do |i|
23
- Tribe.registry["actor_#{rand(ACTOR_COUNT)}"].message!(:do_stuff, MyData.new("data_#{i}"))
23
+ Tribe.registry["actor_#{rand(ACTOR_COUNT)}"].direct_message!(:do_stuff, MyData.new("data_#{i}"))
24
24
  end
25
25
 
26
26
  $lock.synchronize do
@@ -61,12 +61,12 @@ module Tribe
61
61
  private
62
62
  def on_do_stuff(event)
63
63
  if event.data.increment
64
- Tribe.registry["actor_#{rand(ACTOR_COUNT)}"].message!(:do_stuff, event.data)
64
+ Tribe.registry["actor_#{rand(ACTOR_COUNT)}"].direct_message!(:do_stuff, event.data)
65
65
  end
66
66
  end
67
67
 
68
- def exception_handler(e)
69
- puts concat_e("MyActor (#{identifier}) died.", e)
68
+ def on_exception(event)
69
+ puts concat_e("MyActor (#{identifier}) died.", event.data)
70
70
  end
71
71
  end
72
72
  end
@@ -5,6 +5,7 @@ module Tribe
5
5
  class ActorNameError < TribeError; end
6
6
  class ActorChildDied < TribeError; end
7
7
  class ActorParentDied < TribeError; end
8
+ class ActorReservedCommand < TribeError; end
8
9
 
9
10
  class FutureError < TribeError; end
10
11
  class FutureNoResult < TribeError; end
@@ -2,7 +2,7 @@ module Tribe
2
2
  class Future
3
3
  def initialize(actor = nil)
4
4
  @state = :initialized
5
- @mutex = Mutex.new
5
+ @lock = Mutex.new
6
6
  @condition = ConditionVariable.new
7
7
  @result = nil
8
8
  @success_callback = nil
@@ -13,19 +13,19 @@ module Tribe
13
13
  end
14
14
 
15
15
  def finished?
16
- @mutex.synchronize do
16
+ @lock.synchronize do
17
17
  return @state == :finished
18
18
  end
19
19
  end
20
20
 
21
21
  def timeout?
22
- @mutex.synchronnize do
22
+ @lock.synchronnize do
23
23
  return @state == :finished && @result.is_a?(Tribe::FutureTimeout)
24
24
  end
25
25
  end
26
26
 
27
27
  def result=(val)
28
- @mutex.synchronize do
28
+ @lock.synchronize do
29
29
  return unless @state == :initialized
30
30
 
31
31
  @timer.cancel if @timer
@@ -61,7 +61,7 @@ module Tribe
61
61
  end
62
62
 
63
63
  def result
64
- @mutex.synchronize do
64
+ @lock.synchronize do
65
65
  raise Tribe::FutureNoResult.new('Result must be set first.') unless @state == :finished
66
66
 
67
67
  return @result
@@ -69,17 +69,17 @@ module Tribe
69
69
  end
70
70
 
71
71
  def wait
72
- @mutex.synchronize do
72
+ @lock.synchronize do
73
73
  return if @state == :finished
74
74
 
75
- @condition.wait(@mutex)
75
+ @condition.wait(@lock)
76
76
 
77
77
  return nil
78
78
  end
79
79
  end
80
80
 
81
81
  def success?
82
- @mutex.synchronize do
82
+ @lock.synchronize do
83
83
  raise Tribe::FutureNoResult.new('Result must be set first.') unless @state == :finished
84
84
 
85
85
  return !@result.is_a?(Exception)
@@ -91,7 +91,7 @@ module Tribe
91
91
  end
92
92
 
93
93
  def success(&block)
94
- @mutex.synchronize do
94
+ @lock.synchronize do
95
95
  case @state
96
96
  when :initialized
97
97
  @success_callback = block
@@ -114,7 +114,7 @@ module Tribe
114
114
  end
115
115
 
116
116
  def failure(&block)
117
- @mutex.synchronize do
117
+ @lock.synchronize do
118
118
  case @state
119
119
  when :initialized
120
120
  @failure_callback = block
@@ -137,7 +137,8 @@ module Tribe
137
137
  end
138
138
 
139
139
  def timeout
140
- @mutex.synchronize do
140
+ @lock.synchronize do
141
+ @timeout
141
142
  end
142
143
  end
143
144
 
@@ -4,11 +4,11 @@ module Tribe
4
4
  @pool = pool
5
5
  @messages = []
6
6
  @alive = true
7
- @mutex = Mutex.new
7
+ @lock = Mutex.new
8
8
  end
9
9
 
10
10
  def push(event, &block)
11
- @mutex.synchronize do
11
+ @lock.synchronize do
12
12
  return nil unless @alive
13
13
 
14
14
  @messages.push(event)
@@ -19,7 +19,7 @@ module Tribe
19
19
  end
20
20
 
21
21
  def obtain_and_shift
22
- @mutex.synchronize do
22
+ @lock.synchronize do
23
23
  return nil unless @alive
24
24
 
25
25
  if @owner_thread
@@ -36,7 +36,7 @@ module Tribe
36
36
  end
37
37
 
38
38
  def release(&block)
39
- @mutex.synchronize do
39
+ @lock.synchronize do
40
40
  return nil unless @owner_thread == Thread.current
41
41
 
42
42
  @owner_thread = nil
@@ -47,7 +47,7 @@ module Tribe
47
47
  end
48
48
 
49
49
  def kill
50
- @mutex.synchronize do
50
+ @lock.synchronize do
51
51
  @alive = false
52
52
  @messages.clear
53
53
  end
@@ -56,7 +56,7 @@ module Tribe
56
56
  end
57
57
 
58
58
  def alive?
59
- @mutex.synchronize do
59
+ @lock.synchronize do
60
60
  return @alive
61
61
  end
62
62
  end
@@ -1,5 +1,5 @@
1
1
  module Tribe
2
- class Root < Tribe::Actor
2
+ class Root < Tribe::DedicatedActor
3
3
  private
4
4
 
5
5
  def initialize(options = {})
@@ -14,6 +14,10 @@ module Tribe
14
14
 
15
15
  def child_died_handler(child, exception)
16
16
  # Let the children die silently since the root actor should live forever.
17
+ begin
18
+ super
19
+ rescue Tribe::ActorChildDied => e
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -13,28 +13,46 @@ module Tribe
13
13
 
14
14
  def add(item)
15
15
  @mutex.synchronize do
16
- @set.add(item)
16
+ return @set.add(item)
17
17
  end
18
-
19
- return self
20
18
  end
21
19
 
22
20
  def delete(item)
23
21
  @mutex.synchronize do
24
- @set.delete(item)
22
+ return @set.delete(item)
25
23
  end
24
+ end
26
25
 
27
- return self
26
+ def delete?(item)
27
+ @mutex.synchronize do
28
+ return @set.delete?(item)
29
+ end
28
30
  end
29
31
 
30
32
  def each(&block)
31
33
  @mutex.synchronize do
32
- @set.each do |item|
34
+ return @set.each do |item|
33
35
  yield(item)
34
36
  end
35
37
  end
38
+ end
36
39
 
37
- return self
40
+ def clear
41
+ @mutex.synchronize do
42
+ return @set.clear
43
+ end
44
+ end
45
+
46
+ def size
47
+ @mutex.synchronize do
48
+ return @set.size
49
+ end
50
+ end
51
+
52
+ def to_a
53
+ @mutex.synchronize do
54
+ return @set.to_a
55
+ end
38
56
  end
39
57
  end
40
58
  end
@@ -1,3 +1,3 @@
1
1
  module Tribe
2
- VERSION = '0.4.0'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -1,19 +1,26 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/tribe/version', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tribe/version'
3
5
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Chad Remesch"]
6
- gem.email = ["chad@remesch.com"]
7
- gem.description = %q{Tribe is a Ruby gem that implements event-driven actors.}
8
- gem.summary = %q{Actors are lightweight concurrent objects that use asynchronous message passing for communication. Tribe focuses on high performance, low latency, an easy to use API, and flexibility.}
9
- gem.homepage = "https://github.com/chadrem/tribe"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tribe"
8
+ spec.version = Tribe::VERSION
9
+ spec.authors = ["Chad Remesch"]
10
+ spec.email = ["chad@remesch.com"]
10
11
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "tribe"
15
- gem.require_paths = ["lib"]
16
- gem.version = Tribe::VERSION
12
+ spec.summary = %q{Actors based concurrency library for Ruby.}
13
+ spec.homepage = "https://github.com/chadrem/tribe"
14
+ spec.license = "MIT"
17
15
 
18
- gem.add_dependency('workers', '0.2.2')
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "workers", "~> 0.4"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
19
26
  end
metadata CHANGED
@@ -1,42 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tribe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Remesch
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2013-06-15 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workers
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.2
19
+ version: '0.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.2
27
- description: Tribe is a Ruby gem that implements event-driven actors.
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
28
70
  email:
29
71
  - chad@remesch.com
30
72
  executables: []
31
73
  extensions: []
32
74
  extra_rdoc_files: []
33
75
  files:
34
- - .gitignore
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - ".travis.yml"
35
79
  - Gemfile
36
80
  - Gemfile.lock
37
81
  - LICENSE
38
82
  - README.md
39
83
  - Rakefile
84
+ - bin/console
85
+ - bin/setup
40
86
  - lib/tribe.rb
41
87
  - lib/tribe/actable.rb
42
88
  - lib/tribe/actor.rb
@@ -54,7 +100,8 @@ files:
54
100
  - lib/tribe/version.rb
55
101
  - tribe.gemspec
56
102
  homepage: https://github.com/chadrem/tribe
57
- licenses: []
103
+ licenses:
104
+ - MIT
58
105
  metadata: {}
59
106
  post_install_message:
60
107
  rdoc_options: []
@@ -62,20 +109,18 @@ require_paths:
62
109
  - lib
63
110
  required_ruby_version: !ruby/object:Gem::Requirement
64
111
  requirements:
65
- - - '>='
112
+ - - ">="
66
113
  - !ruby/object:Gem::Version
67
114
  version: '0'
68
115
  required_rubygems_version: !ruby/object:Gem::Requirement
69
116
  requirements:
70
- - - '>='
117
+ - - ">="
71
118
  - !ruby/object:Gem::Version
72
119
  version: '0'
73
120
  requirements: []
74
121
  rubyforge_project:
75
- rubygems_version: 2.0.3
122
+ rubygems_version: 2.4.5
76
123
  signing_key:
77
124
  specification_version: 4
78
- summary: Actors are lightweight concurrent objects that use asynchronous message passing
79
- for communication. Tribe focuses on high performance, low latency, an easy to use
80
- API, and flexibility.
125
+ summary: Actors based concurrency library for Ruby.
81
126
  test_files: []