ntl-actor 1.0.0.pre1 → 1.0.0.pre2

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: 9362612be3698e03771c7fb5098807275df662eb
4
- data.tar.gz: e3052225551eb88b84ac6ed57d3699c588c0c37d
3
+ metadata.gz: 896e0c8cdd1845e3ad71c931366a1930e3a21acc
4
+ data.tar.gz: 38e01ef89b6417ac6c19e536f3a1b0c0101089e3
5
5
  SHA512:
6
- metadata.gz: edb4844e21afd14350a9d872cf7fc4eb219b53c7250647fd121c2e7d4fde80307d273fd5e8c585641ea7ff3338b43de6c9b786bf652ed00a4022aa22ec738ae3
7
- data.tar.gz: 128a2647b95a7f97b83c91c88d22dca296a6544a2a4b0976aa0dcf669b4ba17236df3da55a5647693fa9aa95a67be9b0c18d44ce992635534386630fc34dc8f6
6
+ metadata.gz: 5e97f640579eb0444b6e65621151cfafa669c7656a18757d1ff09e5e521f482e0c2508196e35f6333053100eb5b126ccb0f567f4709a49fb7548ace41f3d1d62
7
+ data.tar.gz: 91a38416a0837219be3791f4162ba3e37aecfa5f1970252045ef89c850bcb939e5e0a5335fed156d2304b0d2f476e20e02587c55479436995b03b9ee6f56c892
data/lib/actor.rb CHANGED
@@ -13,19 +13,19 @@ require 'actor/messaging/address/none'
13
13
  require 'actor/messaging/message'
14
14
  require 'actor/messaging/message/name'
15
15
 
16
- require 'actor/messaging/reader'
17
- require 'actor/messaging/reader/assertions'
18
- require 'actor/messaging/reader/dependency'
19
- require 'actor/messaging/reader/substitute'
20
-
21
- require 'actor/messaging/writer'
22
- require 'actor/messaging/writer/dependency'
23
- require 'actor/messaging/writer/substitute'
24
-
25
- require 'actor/messaging/publisher'
26
- require 'actor/messaging/publisher/assertions'
27
- require 'actor/messaging/publisher/dependency'
28
- require 'actor/messaging/publisher/substitute'
16
+ require 'actor/messaging/read'
17
+ require 'actor/messaging/read/assertions'
18
+ require 'actor/messaging/read/dependency'
19
+ require 'actor/messaging/read/substitute'
20
+
21
+ require 'actor/messaging/write'
22
+ require 'actor/messaging/write/dependency'
23
+ require 'actor/messaging/write/substitute'
24
+
25
+ require 'actor/messaging/publish'
26
+ require 'actor/messaging/publish/assertions'
27
+ require 'actor/messaging/publish/dependency'
28
+ require 'actor/messaging/publish/substitute'
29
29
 
30
30
  require 'actor/messages'
31
31
 
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Controls
3
3
  def next_message= message
4
- reader.add message
4
+ read.add message
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Publisher
4
- include Writer::Dependency
3
+ class Publish
4
+ include Write::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.writer = Writer.new
19
+ instance.write = Write.new
20
20
 
21
21
  instance
22
22
  end
@@ -29,9 +29,9 @@ module Actor
29
29
  addresses.delete address
30
30
  end
31
31
 
32
- def publish message, wait: nil
32
+ def call message, wait: nil
33
33
  addresses.each do |address|
34
- writer.write message, address, wait: wait
34
+ write.(message, address, wait: wait)
35
35
  end
36
36
  end
37
37
  end
@@ -1,9 +1,9 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Publisher
3
+ class Publish
4
4
  module Assertions
5
5
  def registered? address
6
- @addresses.include? address
6
+ addresses.include? address
7
7
  end
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ module Actor
2
+ module Messaging
3
+ class Publish
4
+ module Dependency
5
+ attr_writer :publish
6
+
7
+ def publish
8
+ @publish ||= Substitute.build
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,7 +1,11 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Publisher
3
+ class Publish
4
4
  class Substitute
5
+ attr_reader :records
6
+ attr_reader :registered_addresses
7
+ attr_reader :unregistered_addresses
8
+
5
9
  def initialize
6
10
  @registered_addresses = Set.new
7
11
  @unregistered_addresses = Set.new
@@ -9,19 +13,19 @@ module Actor
9
13
  end
10
14
 
11
15
  def register address
12
- @registered_addresses << address
16
+ registered_addresses << address
13
17
  end
14
18
 
15
19
  def unregister address
16
- @unregistered_addresses << address
20
+ unregistered_addresses << address
17
21
  end
18
22
 
19
- def publish message, wait: nil
23
+ def call message, wait: nil
20
24
  wait = true if wait.nil?
21
25
 
22
26
  record = Record.new message, wait
23
27
 
24
- @records << record
28
+ records << record
25
29
  end
26
30
 
27
31
  Record = Struct.new :message, :wait
@@ -29,22 +33,22 @@ module Actor
29
33
  module Assertions
30
34
  def registered? address=nil
31
35
  if address.nil?
32
- @registered_addresses.any?
36
+ registered_addresses.any?
33
37
  else
34
- @registered_addresses.include? address
38
+ registered_addresses.include? address
35
39
  end
36
40
  end
37
41
 
38
42
  def unregistered? address=nil
39
43
  if address.nil?
40
- @unregistered_addresses.any?
44
+ unregistered_addresses.any?
41
45
  else
42
- @unregistered_addresses.include? address
46
+ unregistered_addresses.include? address
43
47
  end
44
48
  end
45
49
 
46
50
  def published? message=nil, wait: nil
47
- @records.each do |record|
51
+ records.each do |record|
48
52
  next unless message.nil? or record.message == message
49
53
  next unless wait.nil? or record.wait == wait
50
54
 
@@ -1,6 +1,6 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Reader
3
+ class Read
4
4
  attr_reader :queue
5
5
 
6
6
  def initialize queue
@@ -16,10 +16,10 @@ module Actor
16
16
  def self.call address, wait: nil
17
17
  instance = build address
18
18
 
19
- instance.read wait: wait
19
+ instance.(wait: wait)
20
20
  end
21
21
 
22
- def read wait: nil
22
+ def call wait: nil
23
23
  non_block = wait == false
24
24
 
25
25
  queue.deq non_block
@@ -1,6 +1,6 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Reader
3
+ class Read
4
4
  module Assertions
5
5
  def address? address
6
6
  queue? address.queue
@@ -17,7 +17,7 @@ module Actor
17
17
  end
18
18
 
19
19
  def queue? queue
20
- @queue == queue
20
+ self.queue == queue
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,13 @@
1
+ module Actor
2
+ module Messaging
3
+ class Read
4
+ module Dependency
5
+ attr_writer :read
6
+
7
+ def read
8
+ @read ||= Substitute.build
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,8 +1,8 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Reader
4
- class Substitute < Reader
5
- attr_writer :next_message
3
+ class Read
4
+ class Substitute < Read
5
+ attr_accessor :next_message
6
6
 
7
7
  def self.build
8
8
  queue = Queue::Substitute.new
@@ -12,17 +12,17 @@ module Actor
12
12
  instance
13
13
  end
14
14
 
15
- def read wait: nil
16
- if @next_message.nil?
15
+ def call wait: nil
16
+ if next_message.nil?
17
17
  super
18
18
  else
19
- @next_message
19
+ next_message
20
20
  end
21
21
  end
22
22
 
23
23
  module Controls
24
24
  def add message
25
- @next_message = message
25
+ self.next_message = message
26
26
  end
27
27
  end
28
28
  end
@@ -1,7 +1,7 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Writer
4
- def write message, address, wait: nil
3
+ class Write
4
+ def call message, address, wait: nil
5
5
  non_block = wait == false
6
6
 
7
7
  queue = address.queue
@@ -21,7 +21,7 @@ module Actor
21
21
 
22
22
  def self.call *arguments
23
23
  instance = new
24
- instance.write *arguments
24
+ instance.(*arguments)
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,13 @@
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
@@ -1,17 +1,19 @@
1
1
  module Actor
2
2
  module Messaging
3
- class Writer
3
+ class Write
4
4
  class Substitute
5
+ attr_reader :records
6
+
5
7
  def initialize
6
8
  @records = []
7
9
  end
8
10
 
9
- def write message, address, wait: nil
11
+ def call message, address, wait: nil
10
12
  wait = true if wait.nil?
11
13
 
12
14
  record = Record.new message, address, wait
13
15
 
14
- @records << record
16
+ records << record
15
17
  end
16
18
 
17
19
  Record = Struct.new :message, :address, :wait do
@@ -26,7 +28,7 @@ module Actor
26
28
 
27
29
  module Assertions
28
30
  def written? message=nil, address: nil, wait: nil
29
- @records.each do |record|
31
+ records.each do |record|
30
32
  next unless message.nil? or record.message? message
31
33
  next unless address.nil? or record.address == address
32
34
  next unless wait.nil? or record.wait == wait
@@ -4,8 +4,8 @@ module Actor
4
4
  def self.included receiver
5
5
  receiver.class_exec do
6
6
  include Messaging::Address::Dependency
7
- include Messaging::Reader::Dependency
8
- include Messaging::Writer::Dependency
7
+ include Messaging::Read::Dependency
8
+ include Messaging::Write::Dependency
9
9
 
10
10
  prepend Configure
11
11
 
@@ -19,8 +19,8 @@ module Actor
19
19
  module Configure
20
20
  def configure
21
21
  self.address = Messaging::Address.build
22
- self.reader = Messaging::Reader.build address
23
- self.writer = Messaging::Writer.new
22
+ self.read = Messaging::Read.build address
23
+ self.write = Messaging::Write.new
24
24
 
25
25
  super
26
26
  end
@@ -11,11 +11,11 @@ module Actor
11
11
  end
12
12
 
13
13
  def reader_configured?
14
- reader.instance_of? Messaging::Reader
14
+ read.instance_of? Messaging::Read
15
15
  end
16
16
 
17
17
  def writer_configured?
18
- writer.instance_of? Messaging::Writer
18
+ write.instance_of? Messaging::Write
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
- writer.write return_value, address
24
+ write.(return_value, address)
25
25
  end
26
26
 
27
27
  return_value
@@ -3,7 +3,7 @@ module Actor
3
3
  module RunLoop
4
4
  def run_loop &supplemental_action
5
5
  loop do
6
- message = reader.read
6
+ message = read.()
7
7
 
8
8
  handle message
9
9
 
@@ -24,7 +24,7 @@ module Actor
24
24
  until suspend_queue.empty?
25
25
  deferred_message = suspend_queue.deq
26
26
 
27
- writer.write deferred_message, address
27
+ write.(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::Writer::Dependency
3
+ include Messaging::Write::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.writer = Messaging::Writer.new
16
+ instance.write = Messaging::Write.new
17
17
  instance.supervisor_address = Supervisor::Address::Get.()
18
18
  instance.()
19
19
  end
20
20
 
21
21
  def call
22
- writer.write Messages::Start, address
22
+ write.(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
- writer.write actor_crashed, supervisor_address
40
+ write.(actor_crashed, supervisor_address)
41
41
  end
42
42
 
43
43
  def actor_started
44
44
  actor_started = Messages::ActorStarted.new address
45
- writer.write actor_started, supervisor_address
45
+ write.(actor_started, supervisor_address)
46
46
  end
47
47
 
48
48
  def actor_stopped
49
49
  actor_stopped = Messages::ActorStopped.new address
50
- writer.write actor_stopped, supervisor_address
50
+ write.(actor_stopped, supervisor_address)
51
51
  end
52
52
 
53
53
  def address
@@ -4,7 +4,7 @@ module Actor
4
4
  include Module::Handler
5
5
  include Module::RunLoop
6
6
 
7
- include Messaging::Publisher::Dependency
7
+ include Messaging::Publish::Dependency
8
8
 
9
9
  attr_accessor :actor_count
10
10
  attr_writer :assembly_block
@@ -49,17 +49,17 @@ module Actor
49
49
 
50
50
  assembly_block.(self)
51
51
 
52
- self.publisher = Messaging::Publisher.build
52
+ self.publish = Messaging::Publish.build
53
53
  end
54
54
 
55
55
  handle Messages::ActorStarted do |message|
56
- publisher.register message.address
56
+ publish.register message.address
57
57
 
58
58
  self.actor_count += 1
59
59
  end
60
60
 
61
61
  handle Messages::ActorStopped do |message|
62
- publisher.unregister message.address
62
+ publish.unregister message.address
63
63
 
64
64
  self.actor_count -= 1
65
65
 
@@ -77,15 +77,15 @@ module Actor
77
77
  end
78
78
 
79
79
  handle Messages::Shutdown do
80
- publisher.publish Messages::Stop
80
+ publish.(Messages::Stop)
81
81
  end
82
82
 
83
83
  handle Messages::Suspend do |message|
84
- publisher.publish message
84
+ publish.(message)
85
85
  end
86
86
 
87
87
  handle Messages::Resume do |message|
88
- publisher.publish message
88
+ publish.(message)
89
89
  end
90
90
 
91
91
  handle Messages::Stop do |stop|
@@ -3,17 +3,17 @@ module Actor
3
3
  module Assertions
4
4
  def self.extended supervisor
5
5
  supervisor.instance_exec do
6
- assertions_module = publisher.class::Assertions
7
- publisher.extend assertions_module
6
+ assertions_module = publish.class::Assertions
7
+ publish.extend assertions_module
8
8
  end
9
9
  end
10
10
 
11
11
  def registered_actor? actor
12
- publisher.registered? actor.address
12
+ publish.registered? actor.address
13
13
  end
14
14
 
15
15
  def unregistered_actor? actor
16
- publisher.unregistered? actor.address
16
+ publish.unregistered? actor.address
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ntl-actor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre1
4
+ version: 1.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
@@ -27,19 +27,19 @@ files:
27
27
  - lib/actor/messaging/address/none.rb
28
28
  - lib/actor/messaging/message.rb
29
29
  - lib/actor/messaging/message/name.rb
30
- - lib/actor/messaging/publisher.rb
31
- - lib/actor/messaging/publisher/assertions.rb
32
- - lib/actor/messaging/publisher/dependency.rb
33
- - lib/actor/messaging/publisher/substitute.rb
30
+ - lib/actor/messaging/publish.rb
31
+ - lib/actor/messaging/publish/assertions.rb
32
+ - lib/actor/messaging/publish/dependency.rb
33
+ - lib/actor/messaging/publish/substitute.rb
34
34
  - lib/actor/messaging/queue.rb
35
35
  - lib/actor/messaging/queue/substitute.rb
36
- - lib/actor/messaging/reader.rb
37
- - lib/actor/messaging/reader/assertions.rb
38
- - lib/actor/messaging/reader/dependency.rb
39
- - lib/actor/messaging/reader/substitute.rb
40
- - lib/actor/messaging/writer.rb
41
- - lib/actor/messaging/writer/dependency.rb
42
- - lib/actor/messaging/writer/substitute.rb
36
+ - lib/actor/messaging/read.rb
37
+ - lib/actor/messaging/read/assertions.rb
38
+ - lib/actor/messaging/read/dependency.rb
39
+ - lib/actor/messaging/read/substitute.rb
40
+ - lib/actor/messaging/write.rb
41
+ - lib/actor/messaging/write/dependency.rb
42
+ - lib/actor/messaging/write/substitute.rb
43
43
  - lib/actor/module/dependencies.rb
44
44
  - lib/actor/module/dependencies/assertions.rb
45
45
  - lib/actor/module/handler.rb
@@ -1,13 +0,0 @@
1
- module Actor
2
- module Messaging
3
- class Publisher
4
- module Dependency
5
- attr_writer :publisher
6
-
7
- def publisher
8
- @publisher ||= Substitute.build
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Actor
2
- module Messaging
3
- class Reader
4
- module Dependency
5
- attr_writer :reader
6
-
7
- def reader
8
- @reader ||= Substitute.build
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Actor
2
- module Messaging
3
- class Writer
4
- module Dependency
5
- attr_writer :writer
6
-
7
- def writer
8
- @writer ||= Substitute.build
9
- end
10
- end
11
- end
12
- end
13
- end