synapse-core 0.5.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/lib/synapse-core.rb +31 -1
  3. data/lib/synapse/command.rb +1 -0
  4. data/lib/synapse/command/callbacks/future.rb +3 -3
  5. data/lib/synapse/command/callbacks/void.rb +14 -0
  6. data/lib/synapse/command/command_bus.rb +2 -2
  7. data/lib/synapse/command/command_callback.rb +9 -2
  8. data/lib/synapse/command/gateway.rb +1 -1
  9. data/lib/synapse/command/gateway/interval_retry_scheduler.rb +6 -6
  10. data/lib/synapse/command/gateway/retry_scheduler.rb +7 -4
  11. data/lib/synapse/command/interceptor_chain.rb +1 -1
  12. data/lib/synapse/command/interceptors/serialization.rb +2 -1
  13. data/lib/synapse/command/simple_command_bus.rb +23 -34
  14. data/lib/synapse/common.rb +2 -2
  15. data/lib/synapse/common/concurrency/disposable_lock.rb +157 -0
  16. data/lib/synapse/common/concurrency/identifier_lock_manager.rb +164 -0
  17. data/lib/synapse/common/duplication.rb +4 -4
  18. data/lib/synapse/common/errors.rb +5 -0
  19. data/lib/synapse/configuration/container.rb +1 -1
  20. data/lib/synapse/configuration/container_builder.rb +1 -1
  21. data/lib/synapse/configuration/definition.rb +1 -1
  22. data/lib/synapse/domain/aggregate_root.rb +1 -1
  23. data/lib/synapse/domain/simple_stream.rb +3 -5
  24. data/lib/synapse/domain/stream.rb +2 -2
  25. data/lib/synapse/event_bus/event_bus.rb +2 -2
  26. data/lib/synapse/event_bus/simple_event_bus.rb +5 -6
  27. data/lib/synapse/event_sourcing/caching.rb +1 -1
  28. data/lib/synapse/event_sourcing/entity.rb +4 -2
  29. data/lib/synapse/event_sourcing/repository.rb +9 -13
  30. data/lib/synapse/event_sourcing/snapshot/taker.rb +1 -1
  31. data/lib/synapse/mapping/mapping.rb +1 -1
  32. data/lib/synapse/process_manager/correlation.rb +3 -29
  33. data/lib/synapse/process_manager/pessimistic_lock_manager.rb +3 -3
  34. data/lib/synapse/process_manager/process.rb +2 -6
  35. data/lib/synapse/process_manager/process_manager.rb +1 -1
  36. data/lib/synapse/process_manager/process_repository.rb +1 -1
  37. data/lib/synapse/process_manager/repository/in_memory.rb +5 -4
  38. data/lib/synapse/process_manager/simple_process_manager.rb +2 -2
  39. data/lib/synapse/repository/errors.rb +2 -2
  40. data/lib/synapse/repository/locking.rb +48 -0
  41. data/lib/synapse/repository/optimistic_lock_manager.rb +10 -9
  42. data/lib/synapse/repository/pessimistic_lock_manager.rb +5 -4
  43. data/lib/synapse/repository/repository.rb +1 -1
  44. data/lib/synapse/repository/simple_repository.rb +8 -7
  45. data/lib/synapse/serialization/converter.rb +3 -0
  46. data/lib/synapse/serialization/converter_factory.rb +6 -5
  47. data/lib/synapse/serialization/serialized_object.rb +4 -4
  48. data/lib/synapse/serialization/serialized_type.rb +4 -4
  49. data/lib/synapse/uow/listener_collection.rb +12 -9
  50. data/lib/synapse/uow/provider.rb +1 -1
  51. data/lib/synapse/uow/uow.rb +1 -1
  52. data/lib/synapse/upcasting/upcaster_chain.rb +1 -1
  53. data/lib/synapse/version.rb +1 -1
  54. data/test/command/serialization_test.rb +5 -2
  55. data/test/command/simple_command_bus_test.rb +9 -16
  56. data/test/command/validation_test.rb +1 -1
  57. data/test/common/concurrency/identifier_lock_manager_test.rb +137 -0
  58. data/test/configuration/component/serialization/converter_factory_test.rb +2 -2
  59. data/test/event_sourcing/repository_test.rb +18 -0
  60. data/test/repository/simple_repository_test.rb +42 -10
  61. data/test/test_helper.rb +3 -4
  62. metadata +25 -29
  63. data/lib/synapse.rb +0 -34
  64. data/lib/synapse/common/concurrency/identifier_lock.rb +0 -56
  65. data/lib/synapse/common/concurrency/public_lock.rb +0 -95
  66. data/lib/synapse/event_bus/clustering/cluster.rb +0 -10
  67. data/lib/synapse/event_bus/clustering/event_bus.rb +0 -55
  68. data/lib/synapse/event_bus/clustering/selector.rb +0 -14
  69. data/lib/synapse/rails/injection_helper.rb +0 -23
  70. data/lib/synapse/railtie.rb +0 -17
  71. data/test/common/concurrency/identifier_lock_test.rb +0 -25
  72. data/test/common/concurrency/public_lock_test.rb +0 -83
  73. data/test/process_manager/correlation_test.rb +0 -24
  74. data/test/rails/injection_helper_test.rb +0 -27
data/test/test_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'bundler/setup'
2
+
1
3
  if ENV['TRAVIS']
2
4
  require 'coveralls'
3
5
  Coveralls.wear!
@@ -8,10 +10,7 @@ else
8
10
  end
9
11
  end
10
12
 
11
- # Need this for Contender, since we get it from GitHub for now
12
- require 'bundler/setup'
13
-
14
- require 'synapse'
13
+ require 'synapse-core'
15
14
 
16
15
  require 'pp'
17
16
  require 'test/unit'
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synapse-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ian Unruh
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-18 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: atomic
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: logging
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: contender
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,11 +62,24 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ref
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
78
83
  description: A versatile CQRS and event sourcing framework
79
84
  email: ianunruh@gmail.com
80
85
  executables: []
@@ -90,6 +95,7 @@ files:
90
95
  - lib/synapse/auditing.rb
91
96
  - lib/synapse/command/async_command_bus.rb
92
97
  - lib/synapse/command/callbacks/future.rb
98
+ - lib/synapse/command/callbacks/void.rb
93
99
  - lib/synapse/command/command_bus.rb
94
100
  - lib/synapse/command/command_callback.rb
95
101
  - lib/synapse/command/command_filter.rb
@@ -109,8 +115,8 @@ files:
109
115
  - lib/synapse/command/rollback_policy.rb
110
116
  - lib/synapse/command/simple_command_bus.rb
111
117
  - lib/synapse/command.rb
112
- - lib/synapse/common/concurrency/identifier_lock.rb
113
- - lib/synapse/common/concurrency/public_lock.rb
118
+ - lib/synapse/common/concurrency/disposable_lock.rb
119
+ - lib/synapse/common/concurrency/identifier_lock_manager.rb
114
120
  - lib/synapse/common/duplication.rb
115
121
  - lib/synapse/common/errors.rb
116
122
  - lib/synapse/common/identifier.rb
@@ -157,9 +163,6 @@ files:
157
163
  - lib/synapse/domain/simple_stream.rb
158
164
  - lib/synapse/domain/stream.rb
159
165
  - lib/synapse/domain.rb
160
- - lib/synapse/event_bus/clustering/cluster.rb
161
- - lib/synapse/event_bus/clustering/event_bus.rb
162
- - lib/synapse/event_bus/clustering/selector.rb
163
166
  - lib/synapse/event_bus/event_bus.rb
164
167
  - lib/synapse/event_bus/event_listener.rb
165
168
  - lib/synapse/event_bus/event_publisher.rb
@@ -202,8 +205,6 @@ files:
202
205
  - lib/synapse/process_manager/resource_injector.rb
203
206
  - lib/synapse/process_manager/simple_process_manager.rb
204
207
  - lib/synapse/process_manager.rb
205
- - lib/synapse/rails/injection_helper.rb
206
- - lib/synapse/railtie.rb
207
208
  - lib/synapse/repository/errors.rb
208
209
  - lib/synapse/repository/lock_manager.rb
209
210
  - lib/synapse/repository/locking.rb
@@ -253,7 +254,6 @@ files:
253
254
  - lib/synapse/upcasting.rb
254
255
  - lib/synapse/version.rb
255
256
  - lib/synapse-core.rb
256
- - lib/synapse.rb
257
257
  - test/auditing/data_provider_test.rb
258
258
  - test/auditing/dispatch_interceptor_test.rb
259
259
  - test/auditing/unit_listener_test.rb
@@ -268,8 +268,7 @@ files:
268
268
  - test/command/serialization_test.rb
269
269
  - test/command/simple_command_bus_test.rb
270
270
  - test/command/validation_test.rb
271
- - test/common/concurrency/identifier_lock_test.rb
272
- - test/common/concurrency/public_lock_test.rb
271
+ - test/common/concurrency/identifier_lock_manager_test.rb
273
272
  - test/common/duplication_test.rb
274
273
  - test/configuration/component/command_bus/async_command_bus_test.rb
275
274
  - test/configuration/component/command_bus/simple_command_bus_test.rb
@@ -306,7 +305,6 @@ files:
306
305
  - test/event_store/in_memory_test.rb
307
306
  - test/process_manager/container_resource_injector_test.rb
308
307
  - test/process_manager/correlation_set_test.rb
309
- - test/process_manager/correlation_test.rb
310
308
  - test/process_manager/in_memory_test.rb
311
309
  - test/process_manager/mapping/fixtures.rb
312
310
  - test/process_manager/mapping/process_manager_test.rb
@@ -314,7 +312,6 @@ files:
314
312
  - test/process_manager/process_factory_test.rb
315
313
  - test/process_manager/process_test.rb
316
314
  - test/process_manager/simple_process_manager_test.rb
317
- - test/rails/injection_helper_test.rb
318
315
  - test/repository/locking_test.rb
319
316
  - test/repository/optimistic_test.rb
320
317
  - test/repository/pessimistic_test.rb
@@ -351,27 +348,26 @@ files:
351
348
  homepage: https://github.com/ianunruh/synapse
352
349
  licenses:
353
350
  - Apache 2.0
351
+ metadata: {}
354
352
  post_install_message:
355
353
  rdoc_options: []
356
354
  require_paths:
357
355
  - lib
358
356
  required_ruby_version: !ruby/object:Gem::Requirement
359
- none: false
360
357
  requirements:
361
- - - ! '>='
358
+ - - '>='
362
359
  - !ruby/object:Gem::Version
363
360
  version: '0'
364
361
  required_rubygems_version: !ruby/object:Gem::Requirement
365
- none: false
366
362
  requirements:
367
- - - ! '>='
363
+ - - '>='
368
364
  - !ruby/object:Gem::Version
369
365
  version: '0'
370
366
  requirements: []
371
367
  rubyforge_project:
372
- rubygems_version: 1.8.25
368
+ rubygems_version: 2.0.3
373
369
  signing_key:
374
- specification_version: 3
370
+ specification_version: 4
375
371
  summary: A versatile CQRS and event sourcing framework
376
372
  test_files: []
377
373
  has_rdoc:
data/lib/synapse.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
3
- require 'contender'
4
- require 'forwardable'
5
- require 'logging'
6
- require 'set'
7
-
8
- require 'synapse/common'
9
- require 'synapse/version'
10
-
11
- module Synapse
12
- extend ActiveSupport::Autoload
13
-
14
- eager_autoload do
15
- # Common components
16
- autoload :Command
17
- autoload :Domain
18
- autoload :EventBus
19
- autoload :Mapping
20
- autoload :Repository
21
- autoload :Serialization
22
- autoload :UnitOfWork, 'synapse/uow'
23
- end
24
-
25
- # Optional components
26
- autoload :Auditing
27
- autoload :Configuration
28
- autoload :EventSourcing
29
- autoload :EventStore
30
- autoload :ProcessManager
31
- autoload :Upcasting
32
- end
33
-
34
- require 'synapse/railtie' if defined? Rails
@@ -1,56 +0,0 @@
1
- module Synapse
2
- # Generic implementation of a lock that can be used to lock an identifier for use
3
- # @todo Deadlock detection
4
- class IdentifierLock
5
- # @return [undefined]
6
- def initialize
7
- @identifiers = Hash.new
8
- @lock = Mutex.new
9
- end
10
-
11
- # Returns true if the calling thread holds the lock for the given identifier
12
- #
13
- # @param [Object] identifier
14
- # @return [Boolean]
15
- def owned?(identifier)
16
- lock_available?(identifier) and lock_for(identifier).owned?
17
- end
18
-
19
- # Obtains a lock for the given identifier, blocking until the lock is obtained
20
- #
21
- # @param [Object] identifier
22
- # @return [undefined]
23
- def obtain_lock(identifier)
24
- lock_for(identifier).lock
25
- end
26
-
27
- # Releases a lock for the given identifier
28
- #
29
- # @raise [ThreadError] If no lock was ever obtained for the identifier
30
- # @param [Object] identifier
31
- # @return [undefined]
32
- def release_lock(identifier)
33
- unless lock_available? identifier
34
- raise ThreadError, 'No lock for this identifier was ever obtained'
35
- end
36
-
37
- lock_for(identifier).unlock
38
- end
39
-
40
- private
41
-
42
- def lock_for(identifier)
43
- @lock.synchronize do
44
- if @identifiers.has_key? identifier
45
- @identifiers[identifier]
46
- else
47
- @identifiers[identifier] = PublicLock.new
48
- end
49
- end
50
- end
51
-
52
- def lock_available?(identifier)
53
- @identifiers.has_key? identifier
54
- end
55
- end # IdentifierLock
56
- end
@@ -1,95 +0,0 @@
1
- module Synapse
2
- # Lock that tracks the thread owning the lock and any waiting threads
3
- class PublicLock
4
- # @return [Thread] The current owner of the thread, if any
5
- attr_reader :owner
6
-
7
- # @return [Array] The list of threads waiting for this lock
8
- attr_reader :waiting
9
-
10
- # @return [undefined]
11
- def initialize
12
- @mutex = Mutex.new
13
- @waiting = Array.new
14
- end
15
-
16
- # Returns true if the calling thread owns this lock
17
- #
18
- # @see Mutex#owned?
19
- # @return [Boolean]
20
- def owned?
21
- @owner == Thread.current
22
- end
23
-
24
- # Returns true if the given thread owns this lock
25
- # @return [Boolean]
26
- def owned_by?(thread)
27
- @owner == thread
28
- end
29
-
30
- # @see Mutex#synchronize
31
- # @return [undefined]
32
- def synchronize
33
- lock
34
-
35
- begin
36
- yield
37
- ensure
38
- unlock rescue nil
39
- end
40
- end
41
-
42
- # @see Mutex#lock
43
- # @return [undefined]
44
- def lock
45
- @mutex.synchronize do
46
- if @owner == Thread.current
47
- raise ThreadError, 'Lock is already owned by the current thread'
48
- end
49
-
50
- while @owner
51
- @waiting.push Thread.current
52
-
53
- begin
54
- @mutex.sleep
55
- ensure
56
- @waiting.delete Thread.current
57
- end
58
- end
59
-
60
- @owner = Thread.current
61
- end
62
- end
63
-
64
- # @see Mutex#unlock
65
- # @return [undefined]
66
- def unlock
67
- @mutex.synchronize do
68
- if @owner == Thread.current
69
- @owner = nil
70
-
71
- first_waiter = @waiting.first
72
- first_waiter.wakeup if first_waiter
73
- else
74
- raise ThreadError, 'Lock is not owned by the current thread'
75
- end
76
- end
77
- end
78
-
79
- # @see Mutex#try_lock
80
- # @return [Boolean]]
81
- def try_lock
82
- @mutex.synchronize do
83
- if @owner == Thread.current
84
- raise ThreadError, 'Lock is already owned by the current thread'
85
- end
86
-
87
- return false if @owner
88
-
89
- @owner = Thread.current
90
- end
91
-
92
- true
93
- end
94
- end
95
- end
@@ -1,10 +0,0 @@
1
- module Synapse
2
- module EventBus
3
- # Represents a group of event listeners
4
- #
5
- # Clusters allow attributes and behaviors to be applied across an entire group of listeners,
6
- # such as asynchronous processing, event replay, transaction management and distribution.
7
- class Cluster
8
- end # Cluster
9
- end # EventBus
10
- end
@@ -1,55 +0,0 @@
1
- module Synapse
2
- module EventBus
3
- class ClusteringEventBus
4
- # @param [ClusterSelector] cluster_selector
5
- # @return [undefined]
6
- def initialize(cluster_selector)
7
- @cluster_selector = cluster_selector
8
- @clusters = Set.new
9
- end
10
-
11
- # @api public
12
- # @param [EventMessage...] events
13
- # @return [undefined]
14
- def publish(*events)
15
- events.flatten!
16
-
17
- @clusters.each do |cluster|
18
- cluster.publish events
19
- end
20
- end
21
-
22
- # @api public
23
- # @raise [SubscriptionFailedError] If subscription of an event listener failed
24
- # @param [EventListener] listener
25
- # @return [undefined]
26
- def subscribe(listener)
27
- select_cluster(listener).subscribe(listener)
28
- end
29
-
30
- # @api public
31
- # @param [EventListener] listener
32
- # @return [undefined]
33
- def unsubscribe(listener)
34
- select_cluster(listener).unsubscribe(listener)
35
- end
36
-
37
- private
38
-
39
- # @raise [SubscriptionFailedError] If no suitable cluster for listener
40
- # @param [EventListener] listener
41
- # @return [Cluster]
42
- def select_cluster(listener)
43
- cluster = @cluster_selector.select_cluster listener
44
-
45
- unless cluster
46
- raise SubscriptionFailedError, 'Unable to find suitable cluster for [%s]' % listener.class
47
- end
48
-
49
- @clusters.add cluster
50
-
51
- cluster
52
- end
53
- end # ClusteringEventBus
54
- end # EventBus
55
- end