agent 0.1.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +2 -0
  2. data/.rspec +0 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +12 -12
  5. data/README.md +51 -36
  6. data/Rakefile +5 -0
  7. data/agent.gemspec +1 -0
  8. data/autotest/discover.rb +9 -1
  9. data/benchmark/multi_ruby_bench.sh +87 -0
  10. data/benchmark/sieve.rb +238 -0
  11. data/examples/agent-workers.rb +51 -0
  12. data/examples/producer-consumer.rb +15 -0
  13. data/lib/agent.rb +1 -15
  14. data/lib/agent/all.rb +22 -0
  15. data/lib/agent/blocking_once.rb +26 -0
  16. data/lib/agent/channel.rb +88 -41
  17. data/lib/agent/error.rb +15 -0
  18. data/lib/agent/errors.rb +14 -0
  19. data/lib/agent/go.rb +9 -0
  20. data/lib/agent/kernel/channel.rb +7 -0
  21. data/lib/agent/kernel/go.rb +7 -0
  22. data/lib/agent/kernel/select.rb +7 -0
  23. data/lib/agent/notifier.rb +34 -0
  24. data/lib/agent/once.rb +32 -0
  25. data/lib/agent/pop.rb +70 -0
  26. data/lib/agent/push.rb +70 -0
  27. data/lib/agent/queue.rb +133 -0
  28. data/lib/agent/queue/buffered.rb +68 -0
  29. data/lib/agent/queue/unbuffered.rb +88 -0
  30. data/lib/agent/queues.rb +50 -0
  31. data/lib/agent/selector.rb +119 -0
  32. data/lib/agent/uuid.rb +36 -0
  33. data/lib/agent/version.rb +1 -1
  34. data/lib/agent/wait_group.rb +43 -0
  35. data/spec/blocking_once_spec.rb +122 -0
  36. data/spec/channel_spec.rb +153 -82
  37. data/spec/error_spec.rb +15 -0
  38. data/spec/examples/channel_of_channels_spec.rb +17 -14
  39. data/spec/examples/producer_consumer_spec.rb +26 -16
  40. data/spec/examples/sieve_spec.rb +43 -37
  41. data/spec/go_spec.rb +17 -0
  42. data/spec/notifier_spec.rb +42 -0
  43. data/spec/once_spec.rb +91 -0
  44. data/spec/pop_spec.rb +97 -0
  45. data/spec/push_spec.rb +95 -0
  46. data/spec/queue_spec.rb +335 -37
  47. data/spec/queues_spec.rb +28 -0
  48. data/spec/selector_spec.rb +398 -0
  49. data/spec/spec_helper.rb +19 -0
  50. data/spec/uuid_spec.rb +13 -0
  51. data/spec/wait_group_spec.rb +45 -0
  52. metadata +94 -54
  53. data/lib/agent/transport/queue.rb +0 -82
  54. data/spec/helper.rb +0 -5
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+
3
+ describe Agent::WaitGroup do
4
+
5
+ before do
6
+ @wait_group = Agent::WaitGroup.new
7
+ end
8
+
9
+ it "should allow adding" do
10
+ @wait_group.add(1)
11
+ end
12
+
13
+ it "should allow adding negative numbers" do
14
+ @wait_group.add(2)
15
+ @wait_group.add(-1)
16
+ end
17
+
18
+ it "should decrement the cound when WaitGroup#done is called" do
19
+ @wait_group.add(1)
20
+ @wait_group.count.should == 1
21
+ @wait_group.done
22
+ @wait_group.count.should == 0
23
+ end
24
+
25
+ it "should error when the count becomes negative via WaitGroup#add" do
26
+ lambda{ @wait_group.add(-1) }.should raise_error(Agent::Errors::NegativeWaitGroupCount)
27
+ end
28
+
29
+ it "should error when the count becomes negative via WaitGroup#done" do
30
+ lambda{ @wait_group.done }.should raise_error(Agent::Errors::NegativeWaitGroupCount)
31
+ end
32
+
33
+ it "should allow waiting on a wait_group and should signal when it is done" do
34
+ @wait_group.add(1)
35
+
36
+ go!{ sleep 0.2; @wait_group.done }
37
+
38
+ t = Time.now
39
+
40
+ @wait_group.wait
41
+
42
+ (Time.now - t).should be_within(0.01).of(0.2)
43
+ end
44
+
45
+ end
metadata CHANGED
@@ -1,102 +1,142 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: agent
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Ilya Grigorik
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-10 00:00:00 -06:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rspec
12
+ date: 2012-03-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2153154840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
22
23
  prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153154840
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2153154240 !ruby/object:Gem::Requirement
24
28
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
31
33
  type: :development
32
- version_requirements: *id001
33
- description: Agent is a diverse family of related approaches for modelling concurrent systems, in Ruby
34
- email:
34
+ prerelease: false
35
+ version_requirements: *2153154240
36
+ description: Agent is a diverse family of related approaches for modelling concurrent
37
+ systems, in Ruby
38
+ email:
35
39
  - ilya@igvita.com
36
40
  executables: []
37
-
38
41
  extensions: []
39
-
40
42
  extra_rdoc_files: []
41
-
42
- files:
43
+ files:
43
44
  - .gitignore
45
+ - .rspec
44
46
  - Gemfile
45
47
  - Gemfile.lock
46
48
  - README.md
47
49
  - Rakefile
48
50
  - agent.gemspec
49
51
  - autotest/discover.rb
52
+ - benchmark/multi_ruby_bench.sh
53
+ - benchmark/sieve.rb
54
+ - examples/agent-workers.rb
55
+ - examples/producer-consumer.rb
50
56
  - lib/agent.rb
57
+ - lib/agent/all.rb
58
+ - lib/agent/blocking_once.rb
51
59
  - lib/agent/channel.rb
52
- - lib/agent/transport/queue.rb
60
+ - lib/agent/error.rb
61
+ - lib/agent/errors.rb
62
+ - lib/agent/go.rb
63
+ - lib/agent/kernel/channel.rb
64
+ - lib/agent/kernel/go.rb
65
+ - lib/agent/kernel/select.rb
66
+ - lib/agent/notifier.rb
67
+ - lib/agent/once.rb
68
+ - lib/agent/pop.rb
69
+ - lib/agent/push.rb
70
+ - lib/agent/queue.rb
71
+ - lib/agent/queue/buffered.rb
72
+ - lib/agent/queue/unbuffered.rb
73
+ - lib/agent/queues.rb
74
+ - lib/agent/selector.rb
75
+ - lib/agent/uuid.rb
53
76
  - lib/agent/version.rb
77
+ - lib/agent/wait_group.rb
78
+ - spec/blocking_once_spec.rb
54
79
  - spec/channel_spec.rb
80
+ - spec/error_spec.rb
55
81
  - spec/examples/channel_of_channels_spec.rb
56
82
  - spec/examples/go/producer_consumer.go
57
83
  - spec/examples/go/sieve.go
58
84
  - spec/examples/producer_consumer_spec.rb
59
85
  - spec/examples/sieve_spec.rb
60
- - spec/helper.rb
86
+ - spec/go_spec.rb
87
+ - spec/notifier_spec.rb
88
+ - spec/once_spec.rb
89
+ - spec/pop_spec.rb
90
+ - spec/push_spec.rb
61
91
  - spec/queue_spec.rb
62
- has_rdoc: true
92
+ - spec/queues_spec.rb
93
+ - spec/selector_spec.rb
94
+ - spec/spec_helper.rb
95
+ - spec/uuid_spec.rb
96
+ - spec/wait_group_spec.rb
63
97
  homepage: https://github.com/igrigorik/agent
64
98
  licenses: []
65
-
66
99
  post_install_message:
67
100
  rdoc_options: []
68
-
69
- require_paths:
101
+ require_paths:
70
102
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
103
+ required_ruby_version: !ruby/object:Gem::Requirement
72
104
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
110
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- segments:
85
- - 0
86
- version: "0"
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
87
115
  requirements: []
88
-
89
116
  rubyforge_project: agent
90
- rubygems_version: 1.3.7
117
+ rubygems_version: 1.8.10
91
118
  signing_key:
92
119
  specification_version: 3
93
- summary: Agent is a diverse family of related approaches for modelling concurrent systems, in Ruby
94
- test_files:
120
+ summary: Agent is a diverse family of related approaches for modelling concurrent
121
+ systems, in Ruby
122
+ test_files:
123
+ - spec/blocking_once_spec.rb
95
124
  - spec/channel_spec.rb
125
+ - spec/error_spec.rb
96
126
  - spec/examples/channel_of_channels_spec.rb
97
127
  - spec/examples/go/producer_consumer.go
98
128
  - spec/examples/go/sieve.go
99
129
  - spec/examples/producer_consumer_spec.rb
100
130
  - spec/examples/sieve_spec.rb
101
- - spec/helper.rb
131
+ - spec/go_spec.rb
132
+ - spec/notifier_spec.rb
133
+ - spec/once_spec.rb
134
+ - spec/pop_spec.rb
135
+ - spec/push_spec.rb
102
136
  - spec/queue_spec.rb
137
+ - spec/queues_spec.rb
138
+ - spec/selector_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/uuid_spec.rb
141
+ - spec/wait_group_spec.rb
142
+ has_rdoc:
@@ -1,82 +0,0 @@
1
- module Agent
2
- module Transport
3
-
4
- class Queue
5
-
6
- @@registry = {}
7
-
8
- def initialize(name, max = 1)
9
- raise ArgumentError, "queue size must be positive" unless max > 0
10
-
11
- @name = name
12
- @max = max
13
-
14
- if !@@registry[@name]
15
- @@registry[@name] = {
16
- :que => [],
17
- :wait => [],
18
- :mutex => Mutex.new,
19
- :cvar => ConditionVariable.new
20
- }
21
- end
22
- end
23
-
24
- def data; @@registry[@name]; end
25
- def que; data[:que]; end
26
- def wait; data[:wait]; end
27
- def mutex; data[:mutex]; end
28
- def cvar; data[:cvar]; end
29
-
30
- def max; @max; end
31
- def size; que.size; end
32
- def length; que.size; end
33
-
34
- def push(obj)
35
- mutex.synchronize {
36
- while true
37
- break if que.length < @max
38
- cvar.wait(mutex)
39
- end
40
-
41
- que.push obj
42
- cvar.signal
43
- }
44
- end
45
- alias << push
46
- alias enq push
47
-
48
- def pop(*args)
49
- mutex.synchronize {
50
- while true
51
- break if !que.empty?
52
- cvar.wait(mutex)
53
- end
54
-
55
- retval = que.shift
56
- cvar.signal
57
-
58
- retval
59
- }
60
- end
61
- alias shift pop
62
- alias deq pop
63
-
64
- def async?; @max > 1; end
65
-
66
- def send(msg, nonblock = false)
67
- raise ThreadError, "buffer full" if nonblock && que.length >= @max
68
- push(msg)
69
- end
70
-
71
- def receive(nonblock = false)
72
- raise ThreadError, "buffer empty" if nonblock && que.empty?
73
- pop
74
- end
75
-
76
- def close
77
- @@registry.delete @name
78
- end
79
-
80
- end
81
- end
82
- end
@@ -1,5 +0,0 @@
1
- require 'timeout'
2
- require 'rspec'
3
- require 'yaml'
4
-
5
- require 'lib/agent'