ntl-actor 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/actor/actor.rb +1 -1
  3. data/lib/actor/build.rb +6 -6
  4. data/lib/actor/controls.rb +2 -2
  5. data/lib/actor/messages.rb +3 -3
  6. data/lib/actor/messaging/address/controls.rb +2 -2
  7. data/lib/actor/messaging/address/none.rb +1 -1
  8. data/lib/actor/messaging/address/substitute.rb +1 -1
  9. data/lib/actor/messaging/address.rb +4 -4
  10. data/lib/actor/messaging/message/name.rb +5 -5
  11. data/lib/actor/messaging/message.rb +6 -6
  12. data/lib/actor/messaging/publish/substitute.rb +11 -11
  13. data/lib/actor/messaging/publish.rb +8 -8
  14. data/lib/actor/messaging/queue/substitute.rb +7 -7
  15. data/lib/actor/messaging/queue.rb +2 -2
  16. data/lib/actor/messaging/read/substitute.rb +4 -4
  17. data/lib/actor/messaging/read.rb +11 -11
  18. data/lib/actor/messaging/send/substitute.rb +7 -7
  19. data/lib/actor/messaging/send.rb +5 -5
  20. data/lib/actor/module/dependencies.rb +4 -4
  21. data/lib/actor/module/handler/macro.rb +3 -3
  22. data/lib/actor/module/handler/method_name.rb +2 -2
  23. data/lib/actor/module/handler/send_next_message.rb +1 -1
  24. data/lib/actor/module/handler.rb +5 -5
  25. data/lib/actor/module/run_loop.rb +2 -2
  26. data/lib/actor/module/start.rb +2 -2
  27. data/lib/actor/module/suspend_resume/controls.rb +2 -2
  28. data/lib/actor/module/suspend_resume/handle.rb +2 -2
  29. data/lib/actor/module/suspend_resume/initialize.rb +1 -1
  30. data/lib/actor/module/suspend_resume.rb +3 -3
  31. data/lib/actor/start.rb +9 -9
  32. data/lib/actor/supervisor/address/get.rb +2 -2
  33. data/lib/actor/supervisor/address/put.rb +2 -2
  34. data/lib/actor/supervisor/observer.rb +3 -3
  35. data/lib/actor/supervisor.rb +12 -12
  36. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f13d4d98998e8545edb0339b4c99114f9aca0d329752f32bd8ffff1af8405aff
4
- data.tar.gz: 35a076fe76b028acab5cb7ff50ba33ded3c30da2b28e41db0ac15865daff1425
3
+ metadata.gz: b6d3e788eda858c8899b193ab2bd4f4d188203e4b0e9004aac11a2e5f12366e5
4
+ data.tar.gz: 5fbf401688931eb848408e494a7cf7c00795be9b84585e1db02de70cce7d1e12
5
5
  SHA512:
6
- metadata.gz: d52e098b26cf0970d9a9e004d7eaff65ad026110f09a15aaea0e664332db1e88f60d3fa4c4345ead984ce76e4d110ee7ac22e4a9f5cc1d84c82ff87d4cd08e2b
7
- data.tar.gz: c15455bf367450b34083feea4c380094775016eb871fd3566723351be0bd7dff4478196e9c1b5316b49b3767cb4bb7409a1a2aa302efcb756fbc2dc996ca99a5
6
+ metadata.gz: c62bdfc7c23527f91e237802736ecb5e778443e4583fc557c061e2ccf634422e0bbc1d58de6672855a5c03dbddf19d4388f798eb087c43da42bfdff2632e8486
7
+ data.tar.gz: d861709b6781509f12c8c4ff61aafe703f1c9fc752d0f01c130c55ee23e6c45c2f8841912a22a3d391eb1018a233b6d78831e79c986a469d8956d95b08d0bba0
data/lib/actor/actor.rb CHANGED
@@ -4,7 +4,7 @@ module Actor
4
4
  # order to bring the constants contained in within the Actor namespace to
5
5
  # the top level. When we do so, it is necessary to prevent the actual mixin
6
6
  # from altering the main object.
7
- return if cls.eql? Object
7
+ return if cls.eql?(Object)
8
8
 
9
9
  cls.class_exec do
10
10
  extend Module::Start
data/lib/actor/build.rb CHANGED
@@ -5,23 +5,23 @@ module Actor
5
5
  attr_reader :block
6
6
  attr_reader :cls
7
7
 
8
- def initialize cls, arguments, keyword_arguments, &block
8
+ def initialize(cls, arguments, keyword_arguments, &block)
9
9
  @arguments = arguments
10
10
  @keyword_arguments = keyword_arguments
11
11
  @block = block
12
12
  @cls = cls
13
13
  end
14
14
 
15
- def self.call cls, *arguments, **keyword_arguments, &block
16
- instance = new cls, arguments, keyword_arguments, &block
15
+ def self.call(cls, *arguments, **keyword_arguments, &block)
16
+ instance = new(cls, arguments, keyword_arguments, &block)
17
17
  instance.()
18
18
  end
19
19
 
20
20
  def call
21
- if cls.respond_to? :build
22
- method = cls.method :build
21
+ if cls.respond_to?(:build)
22
+ method = cls.method(:build)
23
23
  else
24
- method = cls.method :new
24
+ method = cls.method(:new)
25
25
  end
26
26
 
27
27
  if block
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Controls
3
- def next_message= message
4
- read.add message
3
+ def next_message=(message)
4
+ read.add(message)
5
5
  end
6
6
  end
7
7
  end
@@ -4,15 +4,15 @@ module Actor
4
4
  extend Messaging::Message
5
5
  end
6
6
 
7
- ActorStarted = Struct.new :address, :actor do
7
+ ActorStarted = Struct.new(:address, :actor) do
8
8
  include Messaging::Message
9
9
  end
10
10
 
11
- ActorStopped = Struct.new :address, :actor do
11
+ ActorStopped = Struct.new(:address, :actor) do
12
12
  include Messaging::Message
13
13
  end
14
14
 
15
- ActorCrashed = Struct.new :error, :actor do
15
+ ActorCrashed = Struct.new(:error, :actor) do
16
16
  include Messaging::Message
17
17
  end
18
18
 
@@ -2,8 +2,8 @@ module Actor
2
2
  module Messaging
3
3
  class Address
4
4
  module Controls
5
- def send message
6
- queue.enq message
5
+ def send(message)
6
+ queue.enq(message)
7
7
  end
8
8
  end
9
9
  end
@@ -6,7 +6,7 @@ module Actor
6
6
  id = ID.get
7
7
  queue = Queue::Substitute.build
8
8
 
9
- new id, queue
9
+ new(id, queue)
10
10
  end
11
11
 
12
12
  def self.instance
@@ -4,7 +4,7 @@ module Actor
4
4
  class Substitute < None
5
5
  def self.build
6
6
  instance = super
7
- instance.extend Controls
7
+ instance.extend(Controls)
8
8
  instance
9
9
  end
10
10
 
@@ -1,13 +1,13 @@
1
1
  module Actor
2
2
  module Messaging
3
- Address = Struct.new :id, :queue
3
+ Address = Struct.new(:id, :queue)
4
4
 
5
5
  class Address
6
- def self.build max_queue_size: nil
6
+ def self.build(max_queue_size: nil)
7
7
  id = SecureRandom.uuid
8
- queue = Queue.get max_size: max_queue_size
8
+ queue = Queue.get(max_size: max_queue_size)
9
9
 
10
- new id, queue
10
+ new(id, queue)
11
11
  end
12
12
 
13
13
  def actors_waiting
@@ -4,18 +4,18 @@ module Actor
4
4
  module Name
5
5
  PATTERN = %r{(?:\A|[a-z0-9])[A-Z]}
6
6
 
7
- def self.get value
7
+ def self.get(value)
8
8
  case value
9
9
  when Symbol
10
10
  value
11
11
 
12
12
  when ::Module, Class
13
- get value.name
13
+ get(value.name)
14
14
 
15
15
  when String
16
- *, inner_namespace = value.split '::'
16
+ *, inner_namespace = value.split('::')
17
17
 
18
- inner_namespace.gsub! PATTERN do |str|
18
+ inner_namespace.gsub!(PATTERN) do |str|
19
19
  str.downcase!
20
20
  str.insert 1, '_' if str.length == 2
21
21
  str
@@ -24,7 +24,7 @@ module Actor
24
24
  inner_namespace.to_sym
25
25
 
26
26
  else
27
- get value.class
27
+ get(value.class)
28
28
  end
29
29
  end
30
30
  end
@@ -17,7 +17,7 @@ module Actor
17
17
  end
18
18
 
19
19
  def self.=== object
20
- if object.is_a? Symbol
20
+ if object.is_a?(Symbol)
21
21
  true
22
22
  else
23
23
  super
@@ -26,14 +26,14 @@ module Actor
26
26
 
27
27
  module Matcher
28
28
  def === other
29
- other_message_name = Name.get other
29
+ other_message_name = Name.get(other)
30
30
 
31
31
  message_name == other_message_name
32
32
  end
33
33
  end
34
34
 
35
35
  module MessageName
36
- def self.included cls
36
+ def self.included(cls)
37
37
  cls.class_exec do
38
38
  extend ClassMethod
39
39
 
@@ -41,8 +41,8 @@ module Actor
41
41
  end
42
42
  end
43
43
 
44
- def self.extended receiver
45
- receiver.extend ClassMethod
44
+ def self.extended(receiver)
45
+ receiver.extend(ClassMethod)
46
46
  end
47
47
 
48
48
  module InstanceMethod
@@ -53,7 +53,7 @@ module Actor
53
53
 
54
54
  module ClassMethod
55
55
  def message_name
56
- Name.get name
56
+ Name.get(name)
57
57
  end
58
58
  end
59
59
  end
@@ -12,39 +12,39 @@ module Actor
12
12
  @records = []
13
13
  end
14
14
 
15
- def register address
15
+ def register(address)
16
16
  registered_addresses << address
17
17
  end
18
18
 
19
- def unregister address
19
+ def unregister(address)
20
20
  unregistered_addresses << address
21
21
  end
22
22
 
23
- def call message, wait: nil
23
+ def call(message, wait: nil)
24
24
  wait = false if wait.nil?
25
25
 
26
- record = Record.new message, wait
26
+ record = Record.new(message, wait)
27
27
 
28
28
  records << record
29
29
  end
30
30
 
31
- def registered? address=nil
31
+ def registered?(address=nil)
32
32
  if address.nil?
33
33
  registered_addresses.any?
34
34
  else
35
- registered_addresses.include? address
35
+ registered_addresses.include?(address)
36
36
  end
37
37
  end
38
38
 
39
- def unregistered? address=nil
39
+ def unregistered?(address=nil)
40
40
  if address.nil?
41
41
  unregistered_addresses.any?
42
42
  else
43
- unregistered_addresses.include? address
43
+ unregistered_addresses.include?(address)
44
44
  end
45
45
  end
46
46
 
47
- def published? message=nil, wait: nil
47
+ def published?(message=nil, wait: nil)
48
48
  records.each do |record|
49
49
  next unless message.nil? or record.message == message
50
50
  next unless wait.nil? or record.wait == wait
@@ -55,9 +55,9 @@ module Actor
55
55
  false
56
56
  end
57
57
 
58
- Record = Struct.new :message, :wait
58
+ Record = Struct.new(:message, :wait)
59
59
 
60
- singleton_class.send :alias_method, :build, :new # subst-attr compat
60
+ singleton_class.send(:alias_method, :build, :new) # subst-attr compat
61
61
  end
62
62
  end
63
63
  end
@@ -9,11 +9,11 @@ module Actor
9
9
  @addresses = Set.new
10
10
  end
11
11
 
12
- def self.build *addresses
12
+ def self.build(*addresses)
13
13
  instance = new
14
14
 
15
15
  addresses.each do |address|
16
- instance.register address
16
+ instance.register(address)
17
17
  end
18
18
 
19
19
  instance.send = Send.new
@@ -21,22 +21,22 @@ module Actor
21
21
  instance
22
22
  end
23
23
 
24
- def register address
24
+ def register(address)
25
25
  addresses << address
26
26
  end
27
27
 
28
- def unregister address
29
- addresses.delete address
28
+ def unregister(address)
29
+ addresses.delete(address)
30
30
  end
31
31
 
32
- def call message, wait: nil
32
+ def call(message, wait: nil)
33
33
  addresses.each do |address|
34
34
  send.(message, address, wait: wait)
35
35
  end
36
36
  end
37
37
 
38
- def registered? address
39
- addresses.include? address
38
+ def registered?(address)
39
+ addresses.include?(address)
40
40
  end
41
41
  end
42
42
  end
@@ -11,7 +11,7 @@ module Actor
11
11
  instance
12
12
  end
13
13
 
14
- def deq non_block=nil
14
+ def deq(non_block=nil)
15
15
  if non_block
16
16
  raise ThreadError
17
17
  else
@@ -23,15 +23,15 @@ module Actor
23
23
  true
24
24
  end
25
25
 
26
- def enq message, non_block=nil
26
+ def enq(message, non_block=nil)
27
27
  non_block = false if non_block.nil?
28
28
 
29
- record = Record.new message, non_block
29
+ record = Record.new(message, non_block)
30
30
  @enqueued_records << record
31
31
  record
32
32
  end
33
33
 
34
- def enqueued? message=nil, wait: nil
34
+ def enqueued?(message=nil, wait: nil)
35
35
  @enqueued_records.any? do |record|
36
36
  next unless message.nil? or record.message == message
37
37
  next unless wait.nil? or record.non_block == !wait
@@ -48,10 +48,10 @@ module Actor
48
48
  0
49
49
  end
50
50
 
51
- WouldBlockError = Class.new StandardError
51
+ WouldBlockError = Class.new(StandardError)
52
52
 
53
- Record = Struct.new :message, :non_block
54
- singleton_class.send :alias_method, :build, :new # subst-attr compat
53
+ Record = Struct.new(:message, :non_block)
54
+ singleton_class.send(:alias_method, :build, :new) # subst-attr compat
55
55
  end
56
56
  end
57
57
  end
@@ -1,10 +1,10 @@
1
1
  module Actor
2
2
  module Messaging
3
3
  module Queue
4
- def self.get max_size: nil
4
+ def self.get(max_size: nil)
5
5
  max_size ||= Defaults.maximum_size
6
6
 
7
- SizedQueue.new max_size
7
+ SizedQueue.new(max_size)
8
8
  end
9
9
 
10
10
  module Defaults
@@ -7,12 +7,12 @@ module Actor
7
7
  def self.build
8
8
  queue = Queue::Substitute.new
9
9
 
10
- instance = new queue
11
- instance.extend Controls
10
+ instance = new(queue)
11
+ instance.extend(Controls)
12
12
  instance
13
13
  end
14
14
 
15
- def call wait: nil
15
+ def call(wait: nil)
16
16
  if next_message.nil?
17
17
  super
18
18
  else
@@ -21,7 +21,7 @@ module Actor
21
21
  end
22
22
 
23
23
  module Controls
24
- def add message
24
+ def add(message)
25
25
  self.next_message = message
26
26
  end
27
27
  end
@@ -3,38 +3,38 @@ module Actor
3
3
  class Read
4
4
  attr_reader :queue
5
5
 
6
- def initialize queue
6
+ def initialize(queue)
7
7
  @queue = queue
8
8
  end
9
9
 
10
- def self.build address
10
+ def self.build(address)
11
11
  queue = address.queue
12
12
 
13
13
  new queue
14
14
  end
15
15
 
16
- def self.call address, wait: nil
17
- instance = build address
16
+ def self.call(address, wait: nil)
17
+ instance = build(address)
18
18
 
19
19
  instance.(wait: wait)
20
20
  end
21
21
 
22
- def call wait: nil
22
+ def call(wait: nil)
23
23
  non_block = wait == false
24
24
 
25
- queue.deq non_block
25
+ queue.deq(non_block)
26
26
 
27
27
  rescue ThreadError
28
28
  return nil
29
29
  end
30
30
 
31
- def address? address
32
- queue? address.queue
31
+ def address?(address)
32
+ queue?(address.queue)
33
33
  end
34
34
 
35
- def next_message? message
35
+ def next_message?(message)
36
36
  begin
37
- next_message = @queue.deq true
37
+ next_message = @queue.deq(true)
38
38
  rescue ThreadError
39
39
  return false
40
40
  end
@@ -42,7 +42,7 @@ module Actor
42
42
  next_message == message
43
43
  end
44
44
 
45
- def queue? queue
45
+ def queue?(queue)
46
46
  self.queue == queue
47
47
  end
48
48
  end
@@ -8,17 +8,17 @@ module Actor
8
8
  @records = []
9
9
  end
10
10
 
11
- def call message, address, wait: nil
11
+ def call(message, address, wait: nil)
12
12
  wait = false if wait.nil?
13
13
 
14
- record = Record.new message, address, wait
14
+ record = Record.new(message, address, wait)
15
15
 
16
16
  records << record
17
17
  end
18
18
 
19
- def sent? message=nil, address: nil, wait: nil
19
+ def sent?(message=nil, address: nil, wait: nil)
20
20
  records.each do |record|
21
- next unless message.nil? or record.message? message
21
+ next unless message.nil? or record.message?(message)
22
22
  next unless address.nil? or record.address == address
23
23
  next unless wait.nil? or record.wait == wait
24
24
 
@@ -28,17 +28,17 @@ module Actor
28
28
  false
29
29
  end
30
30
 
31
- Record = Struct.new :message, :address, :wait do
31
+ Record = Struct.new(:message, :address, :wait) do
32
32
  def message? pattern
33
33
  return true if message == pattern
34
34
 
35
- if pattern.is_a? Symbol and message.is_a? Message
35
+ if pattern.is_a?(Symbol) and message.is_a?(Message)
36
36
  message.message_name == pattern
37
37
  end
38
38
  end
39
39
  end
40
40
 
41
- singleton_class.send :alias_method, :build, :new # subst-attr compat
41
+ singleton_class.send(:alias_method, :build, :new) # subst-attr compat
42
42
  end
43
43
  end
44
44
  end
@@ -1,25 +1,25 @@
1
1
  module Actor
2
2
  module Messaging
3
3
  class Send
4
- def call message, address, wait: nil
4
+ def call(message, address, wait: nil)
5
5
  non_block = !wait
6
6
 
7
7
  queue = address.queue
8
8
 
9
- if message.instance_of? ::Module
9
+ if message.instance_of?(::Module)
10
10
  message = message.message_name
11
11
  end
12
12
 
13
13
  begin
14
- queue.enq message, non_block
14
+ queue.enq(message, non_block)
15
15
  rescue ThreadError
16
16
  raise QueueFullError
17
17
  end
18
18
  end
19
19
 
20
- QueueFullError = Class.new StandardError
20
+ QueueFullError = Class.new(StandardError)
21
21
 
22
- def self.call *arguments
22
+ def self.call(*arguments)
23
23
  instance = new
24
24
  instance.(*arguments)
25
25
  end
@@ -19,21 +19,21 @@ module Actor
19
19
  end
20
20
 
21
21
  def address_configured?
22
- address.instance_of? Messaging::Address
22
+ address.instance_of?(Messaging::Address)
23
23
  end
24
24
 
25
25
  def reader_configured?
26
- read.instance_of? Messaging::Read
26
+ read.instance_of?(Messaging::Read)
27
27
  end
28
28
 
29
29
  def send_configured?
30
- send.instance_of? Messaging::Send
30
+ send.instance_of?(Messaging::Send)
31
31
  end
32
32
 
33
33
  module Configure
34
34
  def configure
35
35
  self.address = Messaging::Address.build
36
- self.read = Messaging::Read.build address
36
+ self.read = Messaging::Read.build(address)
37
37
  self.send = Messaging::Send.new
38
38
 
39
39
  super
@@ -2,10 +2,10 @@ module Actor
2
2
  module Module
3
3
  module Handler
4
4
  module Macro
5
- def handle message_pattern, &handler
6
- method_name = MethodName.get message_pattern
5
+ def handle(message_pattern, &handler)
6
+ method_name = MethodName.get(message_pattern)
7
7
 
8
- define_method method_name, &handler
8
+ define_method(method_name, &handler)
9
9
  end
10
10
  end
11
11
  end
@@ -2,8 +2,8 @@ module Actor
2
2
  module Module
3
3
  module Handler
4
4
  module MethodName
5
- def self.get message_pattern
6
- message_name = Messaging::Message::Name.get message_pattern
5
+ def self.get(message_pattern)
6
+ message_name = Messaging::Message::Name.get(message_pattern)
7
7
 
8
8
  :"handle_#{message_name}"
9
9
  end
@@ -2,7 +2,7 @@ module Actor
2
2
  module Module
3
3
  module Handler
4
4
  module SendNextMessage
5
- def handle message
5
+ def handle(message)
6
6
  return_value = super
7
7
 
8
8
  if Messaging::Message === return_value
@@ -1,18 +1,18 @@
1
1
  module Actor
2
2
  module Module
3
3
  module Handler
4
- def self.included cls
4
+ def self.included(cls)
5
5
  cls.class_exec do
6
6
  extend Macro
7
7
  end
8
8
  end
9
9
 
10
- def handle message
11
- handler_method_name = MethodName.get message
10
+ def handle(message)
11
+ handler_method_name = MethodName.get(message)
12
12
 
13
- return unless handler_method_name and respond_to? handler_method_name
13
+ return unless handler_method_name and respond_to?(handler_method_name)
14
14
 
15
- handler_method = method handler_method_name
15
+ handler_method = method(handler_method_name)
16
16
 
17
17
  if handler_method.arity == 0
18
18
  handler_method.()
@@ -1,11 +1,11 @@
1
1
  module Actor
2
2
  module Module
3
3
  module RunLoop
4
- def run_loop &supplemental_action
4
+ def run_loop(&supplemental_action)
5
5
  loop do
6
6
  message = read.()
7
7
 
8
- handle message
8
+ handle(message)
9
9
 
10
10
  supplemental_action.() if supplemental_action
11
11
  end
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Module
3
3
  module Start
4
- def start *arguments, include: nil, **keyword_arguments, &block
4
+ def start(*arguments, include: nil, **keyword_arguments, &block)
5
5
  actor, thread = Actor::Start.(self, *arguments, **keyword_arguments, &block)
6
6
 
7
7
  address = actor.address
@@ -10,7 +10,7 @@ module Actor
10
10
  return_values = [address]
11
11
 
12
12
  Array(include).each do |label|
13
- argument = { :thread => thread, :actor => actor }.fetch label
13
+ argument = { :thread => thread, :actor => actor }.fetch(label)
14
14
 
15
15
  return_values << argument
16
16
  end
@@ -6,9 +6,9 @@ module Actor
6
6
  self.suspended = true
7
7
  end
8
8
 
9
- def defer_message *messages
9
+ def defer_message(*messages)
10
10
  messages.each do |message|
11
- suspend_queue.enq message
11
+ suspend_queue.enq(message)
12
12
  end
13
13
  end
14
14
  end
@@ -2,11 +2,11 @@ module Actor
2
2
  module Module
3
3
  module SuspendResume
4
4
  module Handle
5
- def handle message
5
+ def handle(message)
6
6
  self.suspended = false if Messages::Resume === message
7
7
 
8
8
  if suspended
9
- suspend_queue.enq message, true
9
+ suspend_queue.enq(message, true)
10
10
  else
11
11
  super
12
12
  end
@@ -2,7 +2,7 @@ module Actor
2
2
  module Module
3
3
  module SuspendResume
4
4
  module Initialize
5
- def initialize ...
5
+ def initialize(...)
6
6
  @suspended = false
7
7
 
8
8
  super
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Module
3
3
  module SuspendResume
4
- def self.included cls
4
+ def self.included(cls)
5
5
  cls.class_exec do
6
6
  prepend Configure
7
7
  prepend Handle
@@ -26,11 +26,11 @@ module Actor
26
26
  end
27
27
  end
28
28
 
29
- def message_deferred? message=nil, wait: nil
29
+ def message_deferred?(message=nil, wait: nil)
30
30
  non_block = wait == false
31
31
 
32
32
  begin
33
- msg = suspend_queue.deq true
33
+ msg = suspend_queue.deq(true)
34
34
  rescue ThreadError
35
35
  end
36
36
 
data/lib/actor/start.rb CHANGED
@@ -5,18 +5,18 @@ module Actor
5
5
  attr_reader :actor
6
6
  attr_accessor :supervisor_address
7
7
 
8
- def initialize actor
8
+ def initialize(actor)
9
9
  @actor = actor
10
10
  end
11
11
 
12
- def self.call actor_or_actor_class, *arguments, **keyword_arguments, &block
13
- if actor_or_actor_class.is_a? Actor and not actor_or_actor_class.is_a? Class
12
+ def self.call(actor_or_actor_class, *arguments, **keyword_arguments, &block)
13
+ if actor_or_actor_class.is_a?(Actor) and not actor_or_actor_class.is_a?(Class)
14
14
  actor = actor_or_actor_class
15
15
  else
16
16
  actor = Build.(actor_or_actor_class, *arguments, **keyword_arguments, &block)
17
17
  end
18
18
 
19
- instance = new actor
19
+ instance = new(actor)
20
20
  instance.send = Messaging::Send.new
21
21
  instance.supervisor_address = Supervisor::Address::Get.()
22
22
  instance.()
@@ -32,25 +32,25 @@ module Actor
32
32
  actor.run_loop
33
33
  actor_stopped
34
34
  rescue => error
35
- actor_crashed error
35
+ actor_crashed(error)
36
36
  end
37
37
  end
38
38
 
39
39
  return actor, thread
40
40
  end
41
41
 
42
- def actor_crashed error
43
- actor_crashed = Messages::ActorCrashed.new error, actor
42
+ def actor_crashed(error)
43
+ actor_crashed = Messages::ActorCrashed.new(error, actor)
44
44
  send.(actor_crashed, supervisor_address)
45
45
  end
46
46
 
47
47
  def actor_started
48
- actor_started = Messages::ActorStarted.new address, actor
48
+ actor_started = Messages::ActorStarted.new(address, actor)
49
49
  send.(actor_started, supervisor_address)
50
50
  end
51
51
 
52
52
  def actor_stopped
53
- actor_stopped = Messages::ActorStopped.new address, actor
53
+ actor_stopped = Messages::ActorStopped.new(address, actor)
54
54
  send.(actor_stopped, supervisor_address)
55
55
  end
56
56
 
@@ -2,10 +2,10 @@ module Actor
2
2
  class Supervisor
3
3
  module Address
4
4
  module Get
5
- def self.call thread_group=nil
5
+ def self.call(thread_group=nil)
6
6
  thread_group ||= Thread.current.group
7
7
 
8
- Registry.fetch thread_group do
8
+ Registry.fetch(thread_group) do
9
9
  Messaging::Address::None.instance
10
10
  end
11
11
  end
@@ -2,11 +2,11 @@ module Actor
2
2
  class Supervisor
3
3
  module Address
4
4
  module Put
5
- def self.call address=nil
5
+ def self.call(address=nil)
6
6
  thread_group = Thread.current.group
7
7
 
8
8
  if address.nil?
9
- Registry.delete thread_group
9
+ Registry.delete(thread_group)
10
10
  else
11
11
  Registry[thread_group] = address
12
12
  end
@@ -1,14 +1,14 @@
1
1
  module Actor
2
2
  class Supervisor
3
3
  module Observer
4
- def self.included cls
4
+ def self.included(cls)
5
5
  cls.class_exec do
6
6
  include Module::Handler
7
7
  end
8
8
  end
9
9
 
10
- def update message
11
- handle message
10
+ def update(message)
11
+ handle(message)
12
12
  end
13
13
  end
14
14
  end
@@ -17,13 +17,13 @@ module Actor
17
17
  @actor_count = 0
18
18
  end
19
19
 
20
- def self.build &assembly_block
20
+ def self.build(&assembly_block)
21
21
  instance = new
22
22
  instance.assembly_block = assembly_block
23
23
  instance
24
24
  end
25
25
 
26
- def self.start &assembly_block
26
+ def self.start(&assembly_block)
27
27
  Thread.report_on_exception = false
28
28
 
29
29
  thread = Thread.new do
@@ -34,7 +34,7 @@ module Actor
34
34
  loop do
35
35
  ten_seconds = 10
36
36
 
37
- result = thread.join ten_seconds
37
+ result = thread.join(ten_seconds)
38
38
 
39
39
  break unless result.nil?
40
40
  end
@@ -50,11 +50,11 @@ module Actor
50
50
  self.publish = Messaging::Publish.build
51
51
  end
52
52
 
53
- def handle message
53
+ def handle(message)
54
54
  result = super
55
55
 
56
56
  changed
57
- notify_observers message
57
+ notify_observers(message)
58
58
 
59
59
  result
60
60
  end
@@ -67,13 +67,13 @@ module Actor
67
67
  return
68
68
  end
69
69
 
70
- publish.register actor_address
70
+ publish.register(actor_address)
71
71
 
72
72
  self.actor_count += 1
73
73
  end
74
74
 
75
75
  handle Messages::ActorStopped do |message|
76
- publish.unregister message.address
76
+ publish.unregister(message.address)
77
77
 
78
78
  self.actor_count -= 1
79
79
 
@@ -112,12 +112,12 @@ module Actor
112
112
  super stop
113
113
  end
114
114
 
115
- def registered_actor? actor
116
- publish.registered? actor.address
115
+ def registered_actor?(actor)
116
+ publish.registered?(actor.address)
117
117
  end
118
118
 
119
- def unregistered_actor? actor
120
- publish.unregistered? actor.address
119
+ def unregistered_actor?(actor)
120
+ publish.unregistered?(actor.address)
121
121
  end
122
122
 
123
123
  def assembly_block
@@ -128,6 +128,6 @@ module Actor
128
128
  @thread_group ||= ThreadGroup::Default
129
129
  end
130
130
 
131
- NoActorsStarted = Class.new StandardError
131
+ NoActorsStarted = Class.new(StandardError)
132
132
  end
133
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntl-actor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2022-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench