ntl-actor 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5dc4bd77cfa0aabbe7527ff0d9f678723c70d2e
4
- data.tar.gz: 9f4c7dce521cc7f59c16665187a81c1431debbbe
3
+ metadata.gz: 34237e060f184d1c210821d69dd254831d659e8a
4
+ data.tar.gz: 4c7b69ea47f9697489b6532dbbc1685a08d5696e
5
5
  SHA512:
6
- metadata.gz: 85dba9dea45d42334b259829b5e220738f694de83b90f50c5260f11e0a225eaae3d174e7e0e5b1c9b26b3a956ed7c52fe0b1a16036e8eba9109939e8f181d878
7
- data.tar.gz: 1b42fd98088fba0838ed9fa60c8c948e8aa5de4573a6f2ec5bbc1114b2a4939809a38f72a39aa33aaf2e05392920262d1f0d99602c22f5d13f4125120089a083
6
+ metadata.gz: 894647ffcc52aa656d4f91054ef2bfe175fafd45d9e9ffa54504624c1f87f51e3fa84131efb2e689a573e4364a031d224332b62b76c275bc5f57625da3e64043
7
+ data.tar.gz: 804cbe31ba1d237e699a90cb6291281daebaca721c1395ba8389aafdb85e721fa6f8652e1e7ae55bdac0582d491babf335cd09b38098a698d4c346118a22929f
data/lib/actor.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'observer'
1
2
  require 'securerandom'
2
3
  require 'set'
3
4
 
@@ -19,9 +20,9 @@ require 'actor/messaging/read/assertions'
19
20
  require 'actor/messaging/read/dependency'
20
21
  require 'actor/messaging/read/substitute'
21
22
 
22
- require 'actor/messaging/write'
23
- require 'actor/messaging/write/dependency'
24
- require 'actor/messaging/write/substitute'
23
+ require 'actor/messaging/send'
24
+ require 'actor/messaging/send/dependency'
25
+ require 'actor/messaging/send/substitute'
25
26
 
26
27
  require 'actor/messaging/publish'
27
28
  require 'actor/messaging/publish/assertions'
@@ -54,5 +55,6 @@ require 'actor/supervisor/address/get'
54
55
  require 'actor/supervisor/address/put'
55
56
  require 'actor/supervisor/address/registry'
56
57
  require 'actor/supervisor/assertions'
58
+ require 'actor/supervisor/observer'
57
59
 
58
60
  require 'actor/actor'
@@ -2,7 +2,7 @@ module Actor
2
2
  module Messaging
3
3
  class Address
4
4
  module Controls
5
- def write message
5
+ def send message
6
6
  queue.enq message
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Messaging
3
3
  class Publish
4
- include Write::Dependency
4
+ include Send::Dependency
5
5
 
6
6
  attr_reader :addresses
7
7
 
@@ -16,7 +16,7 @@ module Actor
16
16
  instance.register address
17
17
  end
18
18
 
19
- instance.write = Write.new
19
+ instance.send = Send.new
20
20
 
21
21
  instance
22
22
  end
@@ -31,7 +31,7 @@ module Actor
31
31
 
32
32
  def call message, wait: nil
33
33
  addresses.each do |address|
34
- write.(message, address, wait: wait)
34
+ send.(message, address, wait: wait)
35
35
  end
36
36
  end
37
37
  end
@@ -1,6 +1,6 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Write
3
+ class Send
4
4
  def call message, address, wait: nil
5
5
  non_block = wait == false
6
6
 
@@ -0,0 +1,13 @@
1
+ module Actor
2
+ module Messaging
3
+ class Send
4
+ module Dependency
5
+ attr_writer :send
6
+
7
+ def send
8
+ @send ||= Substitute.build
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,6 +1,6 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Write
3
+ class Send
4
4
  class Substitute
5
5
  attr_reader :records
6
6
 
@@ -27,7 +27,7 @@ module Actor
27
27
  end
28
28
 
29
29
  module Assertions
30
- def written? message=nil, address: nil, wait: nil
30
+ def sent? message=nil, address: nil, wait: nil
31
31
  records.each do |record|
32
32
  next unless message.nil? or record.message? message
33
33
  next unless address.nil? or record.address == address
@@ -5,7 +5,7 @@ module Actor
5
5
  receiver.class_exec do
6
6
  include Messaging::Address::Dependency
7
7
  include Messaging::Read::Dependency
8
- include Messaging::Write::Dependency
8
+ include Messaging::Send::Dependency
9
9
 
10
10
  prepend Configure
11
11
 
@@ -20,7 +20,7 @@ module Actor
20
20
  def configure
21
21
  self.address = Messaging::Address.build
22
22
  self.read = Messaging::Read.build address
23
- self.write = Messaging::Write.new
23
+ self.send = Messaging::Send.new
24
24
 
25
25
  super
26
26
  end
@@ -3,7 +3,7 @@ module Actor
3
3
  module Dependencies
4
4
  module Assertions
5
5
  def dependencies_configured?
6
- address_configured? and reader_configured? and writer_configured?
6
+ address_configured? and reader_configured? and send_configured?
7
7
  end
8
8
 
9
9
  def address_configured?
@@ -14,8 +14,8 @@ module Actor
14
14
  read.instance_of? Messaging::Read
15
15
  end
16
16
 
17
- def writer_configured?
18
- write.instance_of? Messaging::Write
17
+ def send_configured?
18
+ send.instance_of? Messaging::Send
19
19
  end
20
20
  end
21
21
  end
@@ -21,7 +21,7 @@ module Actor
21
21
  end
22
22
 
23
23
  if Messaging::Message === return_value
24
- write.(return_value, address)
24
+ send.(return_value, address)
25
25
  end
26
26
 
27
27
  return_value
@@ -24,7 +24,7 @@ module Actor
24
24
  until suspend_queue.empty?
25
25
  deferred_message = suspend_queue.deq
26
26
 
27
- write.(deferred_message, address)
27
+ send.(deferred_message, address)
28
28
  end
29
29
  end
30
30
 
data/lib/actor/start.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Actor
2
2
  class Start
3
- include Messaging::Write::Dependency
3
+ include Messaging::Send::Dependency
4
4
 
5
5
  attr_reader :actor
6
6
  attr_accessor :supervisor_address
@@ -13,13 +13,13 @@ module Actor
13
13
  actor = Build.(actor_class, *arguments, &block)
14
14
 
15
15
  instance = new actor
16
- instance.write = Messaging::Write.new
16
+ instance.send = Messaging::Send.new
17
17
  instance.supervisor_address = Supervisor::Address::Get.()
18
18
  instance.()
19
19
  end
20
20
 
21
21
  def call
22
- write.(Messages::Start, address)
22
+ send.(Messages::Start, address)
23
23
 
24
24
  thread = Thread.new do
25
25
  actor_started
@@ -37,17 +37,17 @@ module Actor
37
37
 
38
38
  def actor_crashed error
39
39
  actor_crashed = Messages::ActorCrashed.new error
40
- write.(actor_crashed, supervisor_address)
40
+ send.(actor_crashed, supervisor_address)
41
41
  end
42
42
 
43
43
  def actor_started
44
44
  actor_started = Messages::ActorStarted.new address
45
- write.(actor_started, supervisor_address)
45
+ send.(actor_started, supervisor_address)
46
46
  end
47
47
 
48
48
  def actor_stopped
49
49
  actor_stopped = Messages::ActorStopped.new address
50
- write.(actor_stopped, supervisor_address)
50
+ send.(actor_stopped, supervisor_address)
51
51
  end
52
52
 
53
53
  def address
@@ -1,5 +1,7 @@
1
1
  module Actor
2
2
  class Supervisor
3
+ include Observable
4
+
3
5
  include Module::Dependencies
4
6
  include Module::Handler
5
7
  include Module::RunLoop
@@ -49,6 +51,15 @@ module Actor
49
51
  self.publish = Messaging::Publish.build
50
52
  end
51
53
 
54
+ def handle message
55
+ result = super
56
+
57
+ changed
58
+ notify_observers message
59
+
60
+ result
61
+ end
62
+
52
63
  handle Messages::ActorStarted do |message|
53
64
  publish.register message.address
54
65
 
@@ -0,0 +1,15 @@
1
+ module Actor
2
+ class Supervisor
3
+ module Observer
4
+ def self.included cls
5
+ cls.class_exec do
6
+ include Module::Handler
7
+ end
8
+ end
9
+
10
+ def update message
11
+ handle message
12
+ end
13
+ end
14
+ end
15
+ 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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-25 00:00:00.000000000 Z
11
+ date: 2016-12-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Implementation of actor pattern for ruby
14
14
  email: nathanladd+github@gmail.com
@@ -38,9 +38,9 @@ files:
38
38
  - lib/actor/messaging/read/assertions.rb
39
39
  - lib/actor/messaging/read/dependency.rb
40
40
  - lib/actor/messaging/read/substitute.rb
41
- - lib/actor/messaging/write.rb
42
- - lib/actor/messaging/write/dependency.rb
43
- - lib/actor/messaging/write/substitute.rb
41
+ - lib/actor/messaging/send.rb
42
+ - lib/actor/messaging/send/dependency.rb
43
+ - lib/actor/messaging/send/substitute.rb
44
44
  - lib/actor/module/dependencies.rb
45
45
  - lib/actor/module/dependencies/assertions.rb
46
46
  - lib/actor/module/handler.rb
@@ -61,6 +61,7 @@ files:
61
61
  - lib/actor/supervisor/address/put.rb
62
62
  - lib/actor/supervisor/address/registry.rb
63
63
  - lib/actor/supervisor/assertions.rb
64
+ - lib/actor/supervisor/observer.rb
64
65
  homepage: https://github.com/ntl/actor
65
66
  licenses:
66
67
  - MIT
@@ -1,13 +0,0 @@
1
- module Actor
2
- module Messaging
3
- class Write
4
- module Dependency
5
- attr_writer :write
6
-
7
- def write
8
- @write ||= Substitute.build
9
- end
10
- end
11
- end
12
- end
13
- end