celluloid 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -217,6 +217,7 @@ require 'celluloid/core_ext'
217
217
  require 'celluloid/events'
218
218
  require 'celluloid/fiber'
219
219
  require 'celluloid/links'
220
+ require 'celluloid/logger'
220
221
  require 'celluloid/mailbox'
221
222
  require 'celluloid/receivers'
222
223
  require 'celluloid/registry'
@@ -152,8 +152,7 @@ module Celluloid
152
152
  if fiber
153
153
  fiber.resume message
154
154
  else
155
- warning = "spurious response to call #{message.call_id}"
156
- Celluloid.logger.debug if Celluloid.logger
155
+ Celluloid::Logger.debug("spurious response to call #{message.call_id}")
157
156
  end
158
157
  else
159
158
  @receivers.handle_message(message)
@@ -175,10 +174,10 @@ module Celluloid
175
174
 
176
175
  # Handle any exceptions that occur within a running actor
177
176
  def handle_crash(exception)
178
- log_error(exception)
177
+ Celluloid::Logger.crash("#{@subject.class} crashed!", exception)
179
178
  cleanup ExitEvent.new(@proxy, exception)
180
- rescue Exception => handler_exception
181
- log_error(handler_exception, "ERROR HANDLER CRASHED!")
179
+ rescue Exception => ex
180
+ Celluloid::Logger.crash("#{@subject.class}: ERROR HANDLER CRASHED!", ex)
182
181
  end
183
182
 
184
183
  # Handle cleaning up this actor after it exits
@@ -188,16 +187,9 @@ module Celluloid
188
187
 
189
188
  begin
190
189
  @subject.finalize if @subject.respond_to? :finalize
191
- rescue Exception => finalizer_exception
192
- log_error(finalizer_exception, "#{@subject.class}#finalize crashed!")
190
+ rescue Exception => ex
191
+ Celluloid::Logger.crash("#{@subject.class}#finalize crashed!", ex)
193
192
  end
194
193
  end
195
-
196
- # Log errors when an actor crashes
197
- def log_error(ex, message = "#{@subject.class} crashed!")
198
- message << "\n#{ex.class}: #{ex.to_s}\n"
199
- message << ex.backtrace.join("\n")
200
- Celluloid.logger.error message if Celluloid.logger
201
- end
202
194
  end
203
195
  end
@@ -42,10 +42,7 @@ module Celluloid
42
42
  func.call
43
43
  end
44
44
  rescue Exception => ex
45
- message = "Celluloid::Actor::Pool internal failure:\n"
46
- message << "#{ex.class}: #{ex.to_s}\n"
47
- message << ex.backtrace.join("\n")
48
- Celluloid.logger.error message if Celluloid.logger
45
+ Celluloid::Logger.crash("#{self} internal failure", ex)
49
46
  end
50
47
  end
51
48
  thread[:queue] = queue
@@ -34,8 +34,9 @@ module Celluloid
34
34
  end
35
35
 
36
36
  def inspect
37
- "#<Celluloid::Actor(#{@klass}) dead>" unless alive?
38
37
  Actor.call @mailbox, :inspect
38
+ rescue DeadActorError
39
+ "#<Celluloid::Actor(#{@klass}) dead>"
39
40
  end
40
41
 
41
42
  # Create a Celluloid::Future which calls a given method
@@ -21,7 +21,7 @@ module Celluloid
21
21
  # Take five, toplevel supervisor
22
22
  sleep 5 while supervisor.alive?
23
23
 
24
- Celluloid.logger.error "!!! Celluloid::Application #{self} crashed. Restarting..."
24
+ Celluloid::Logger.error "!!! Celluloid::Application #{self} crashed. Restarting..."
25
25
  end
26
26
  end
27
27
 
@@ -80,20 +80,14 @@ module Celluloid
80
80
  begin
81
81
  check_signature(obj)
82
82
  rescue Exception => ex
83
- log_error ex, "#{obj.class}: async call failed!"
83
+ Celluloid::Logger.crash("#{obj.class}: async call failed!", ex)
84
84
  return
85
85
  end
86
86
 
87
87
  obj.send(@method, *@arguments, &@block)
88
88
  rescue AbortError => ex
89
89
  # Swallow aborted async calls, as they indicate the caller made a mistake
90
- log_error ex, "#{obj.class}: async call aborted!"
91
- end
92
-
93
- def log_error(ex, message)
94
- message << "\n#{ex.class}: #{ex.to_s}\n"
95
- message << ex.backtrace.join("\n")
96
- Celluloid.logger.error message if Celluloid.logger
90
+ Celluloid::Logger.crash("#{obj.class}: async call aborted!", ex)
97
91
  end
98
92
  end
99
93
  end
@@ -54,8 +54,7 @@ module Celluloid
54
54
  if result.is_a? Celluloid::Call
55
55
  actor.register_fiber result, self
56
56
  elsif result
57
- warning = "non-call returned from fiber: #{result.class}"
58
- Celluloid.logger.debug warning if Celluloid.logger
57
+ Celluloid::Logger.debug("non-call returned from fiber: #{result.class}")
59
58
  end
60
59
  nil
61
60
  end
@@ -0,0 +1,27 @@
1
+ module Celluloid
2
+ module Logger
3
+ module_function
4
+
5
+ # Print a debug message
6
+ def debug(string)
7
+ Celluloid.logger.debug(string) if Celluloid.logger
8
+ end
9
+
10
+ # Print a warning message
11
+ def warn(string)
12
+ Celluloid.logger.warn(string) if Celluloid.logger
13
+ end
14
+
15
+ # Print an error message
16
+ def error(string)
17
+ Celluloid.logger.error(string) if Celluloid.logger
18
+ end
19
+
20
+ # Handle a crash
21
+ def crash(string, exception)
22
+ string += "\n#{exception.class}: #{exception.to_s}\n"
23
+ string << exception.backtrace.join("\n")
24
+ error(string)
25
+ end
26
+ end
27
+ end
@@ -5,24 +5,29 @@ module Celluloid
5
5
  module Registry
6
6
  @@registry = {}
7
7
  @@registry_lock = Mutex.new
8
-
8
+
9
9
  # Register an Actor
10
10
  def []=(name, actor)
11
11
  actor_singleton = class << actor; self; end
12
12
  unless actor_singleton.ancestors.include?(Celluloid::ActorProxy)
13
13
  raise ArgumentError, "not an actor"
14
14
  end
15
-
15
+
16
16
  @@registry_lock.synchronize do
17
17
  @@registry[name.to_sym] = actor
18
18
  end
19
19
  end
20
-
20
+
21
21
  # Retrieve an actor by name
22
22
  def [](name)
23
23
  @@registry_lock.synchronize do
24
24
  @@registry[name.to_sym]
25
25
  end
26
26
  end
27
+
28
+ # List all registered actors by name
29
+ def registered
30
+ @@registry_lock.synchronize { @@registry.keys }
31
+ end
27
32
  end
28
- end
33
+ end
@@ -31,11 +31,7 @@ module Celluloid
31
31
  if failures >= start_attempts
32
32
  failures = 0
33
33
 
34
- warning = "#{@klass} is crashing on initialize repeatedly, sleeping for #{sleep_interval} seconds\n"
35
- warning << "#{ex.class}: #{ex}\n "
36
- warning << "#{ex.backtrace.join("\n ")}"
37
-
38
- Celluloid.logger.warn warning if Celluloid.logger
34
+ Celluloid::Logger.crash("#{@klass} is crashing on initialize repeatedly, sleeping for #{sleep_interval} seconds", ex)
39
35
  sleep sleep_interval
40
36
  end
41
37
  retry
@@ -1,4 +1,4 @@
1
1
  module Celluloid
2
- VERSION = '0.6.1'
2
+ VERSION = '0.6.2'
3
3
  def self.version; VERSION; end
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-27 00:00:00.000000000 Z
12
+ date: 2011-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70242345718900 !ruby/object:Gem::Requirement
16
+ requirement: &70122472224600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70242345718900
24
+ version_requirements: *70122472224600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70242345718300 !ruby/object:Gem::Requirement
27
+ requirement: &70122472224020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.7.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70242345718300
35
+ version_requirements: *70122472224020
36
36
  description: Celluloid is a concurrent object framework inspired by the Actor Model
37
37
  email:
38
38
  - tony@medioh.com
@@ -55,6 +55,7 @@ files:
55
55
  - lib/celluloid/io/waker.rb
56
56
  - lib/celluloid/io.rb
57
57
  - lib/celluloid/links.rb
58
+ - lib/celluloid/logger.rb
58
59
  - lib/celluloid/mailbox.rb
59
60
  - lib/celluloid/receivers.rb
60
61
  - lib/celluloid/registry.rb