synapse-core 0.4.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/lib/synapse/command/async_command_bus.rb +41 -0
  2. data/lib/synapse/command/command_callback.rb +49 -2
  3. data/lib/synapse/command/command_handler.rb +2 -0
  4. data/lib/synapse/command/filters/validation.rb +2 -2
  5. data/lib/synapse/command/gateway/interval_retry_scheduler.rb +75 -0
  6. data/lib/synapse/command/gateway/retry_scheduler.rb +26 -0
  7. data/lib/synapse/command/gateway/retrying_callback.rb +46 -0
  8. data/lib/synapse/command/gateway.rb +56 -11
  9. data/lib/synapse/command/interceptor_chain.rb +2 -2
  10. data/lib/synapse/command/interceptors/serialization.rb +2 -2
  11. data/lib/synapse/command/message.rb +16 -0
  12. data/lib/synapse/command/simple_command_bus.rb +6 -2
  13. data/lib/synapse/command/wiring.rb +3 -3
  14. data/lib/synapse/command.rb +7 -1
  15. data/lib/synapse/common/concurrency/identifier_lock.rb +2 -17
  16. data/lib/synapse/common/concurrency/public_lock.rb +8 -9
  17. data/lib/synapse/common/errors.rb +1 -1
  18. data/lib/synapse/common/message.rb +2 -6
  19. data/lib/synapse/common.rb +9 -0
  20. data/lib/synapse/configuration/component/command_bus/async_command_bus.rb +41 -0
  21. data/lib/synapse/configuration/component/command_bus/gateway.rb +38 -0
  22. data/lib/synapse/configuration/component/command_bus/simple_command_bus.rb +81 -0
  23. data/lib/synapse/configuration/component/command_bus.rb +35 -0
  24. data/lib/synapse/configuration/component/event_bus/simple_event_bus.rb +41 -0
  25. data/lib/synapse/configuration/component/event_bus.rb +15 -0
  26. data/lib/synapse/configuration/component/event_sourcing/repository.rb +62 -0
  27. data/lib/synapse/configuration/component/event_sourcing.rb +15 -0
  28. data/lib/synapse/configuration/component/repository/locking_repository.rb +85 -0
  29. data/lib/synapse/configuration/component/repository/simple_repository.rb +31 -0
  30. data/lib/synapse/configuration/component/repository.rb +15 -0
  31. data/lib/synapse/configuration/component/serialization/converter_factory.rb +50 -0
  32. data/lib/synapse/configuration/component/serialization/serializer.rb +90 -0
  33. data/lib/synapse/configuration/component/serialization.rb +25 -0
  34. data/lib/synapse/configuration/component/uow/unit_factory.rb +51 -0
  35. data/lib/synapse/configuration/component/uow.rb +22 -0
  36. data/lib/synapse/configuration/component/upcasting/upcaster_chain.rb +61 -0
  37. data/lib/synapse/configuration/component/upcasting.rb +15 -0
  38. data/lib/synapse/configuration/container.rb +80 -0
  39. data/lib/synapse/configuration/container_builder.rb +108 -0
  40. data/lib/synapse/configuration/definition.rb +31 -0
  41. data/lib/synapse/configuration/definition_builder.rb +138 -0
  42. data/lib/synapse/configuration/dependent.rb +31 -0
  43. data/lib/synapse/configuration/ext.rb +35 -0
  44. data/lib/synapse/configuration.rb +32 -0
  45. data/lib/synapse/domain/aggregate_root.rb +25 -26
  46. data/lib/synapse/domain/event_container.rb +5 -5
  47. data/lib/synapse/domain/message.rb +16 -0
  48. data/lib/synapse/event_bus/event_listener.rb +2 -0
  49. data/lib/synapse/event_bus/event_publisher.rb +19 -0
  50. data/lib/synapse/event_bus/simple_event_bus.rb +21 -30
  51. data/lib/synapse/event_bus/wiring.rb +5 -4
  52. data/lib/synapse/event_bus.rb +1 -1
  53. data/lib/synapse/event_sourcing/aggregate_root.rb +6 -4
  54. data/lib/synapse/process_manager/container_resource_injector.rb +18 -0
  55. data/lib/synapse/process_manager/pessimistic_lock_manager.rb +1 -1
  56. data/lib/synapse/process_manager/process.rb +4 -0
  57. data/lib/synapse/process_manager/process_factory.rb +3 -3
  58. data/lib/synapse/process_manager/repository/in_memory.rb +1 -1
  59. data/lib/synapse/process_manager/wiring/process.rb +6 -6
  60. data/lib/synapse/process_manager/wiring/process_manager.rb +8 -8
  61. data/lib/synapse/process_manager.rb +2 -0
  62. data/lib/synapse/repository/locking.rb +5 -3
  63. data/lib/synapse/repository/optimistic_lock_manager.rb +2 -7
  64. data/lib/synapse/repository/pessimistic_lock_manager.rb +3 -3
  65. data/lib/synapse/repository/repository.rb +2 -2
  66. data/lib/synapse/repository/simple_repository.rb +69 -0
  67. data/lib/synapse/repository.rb +1 -0
  68. data/lib/synapse/serialization/converter/chain.rb +2 -2
  69. data/lib/synapse/serialization/converter_factory.rb +2 -2
  70. data/lib/synapse/serialization/lazy_object.rb +2 -2
  71. data/lib/synapse/serialization/message/serialization_aware_message.rb +3 -3
  72. data/lib/synapse/serialization/message/serialized_message.rb +6 -10
  73. data/lib/synapse/serialization/message/serialized_message_builder.rb +4 -4
  74. data/lib/synapse/serialization/message/serialized_object_cache.rb +2 -2
  75. data/lib/synapse/serialization/message/serializer.rb +2 -2
  76. data/lib/synapse/serialization/revision_resolver.rb +3 -3
  77. data/lib/synapse/serialization/serialized_object.rb +2 -2
  78. data/lib/synapse/serialization/serialized_type.rb +2 -2
  79. data/lib/synapse/serialization/serializer/attribute.rb +2 -2
  80. data/lib/synapse/serialization/serializer/marshal.rb +2 -2
  81. data/lib/synapse/serialization/serializer/oj.rb +2 -2
  82. data/lib/synapse/serialization/serializer/ox.rb +2 -2
  83. data/lib/synapse/serialization/serializer.rb +2 -2
  84. data/lib/synapse/uow/factory.rb +2 -2
  85. data/lib/synapse/uow/listener_collection.rb +2 -2
  86. data/lib/synapse/uow/nesting.rb +9 -2
  87. data/lib/synapse/uow/provider.rb +2 -2
  88. data/lib/synapse/uow/uow.rb +8 -2
  89. data/lib/synapse/upcasting/{chain.rb → upcaster_chain.rb} +0 -0
  90. data/lib/synapse/upcasting.rb +1 -1
  91. data/lib/synapse/version.rb +1 -1
  92. data/lib/synapse/wiring/message_wiring.rb +31 -0
  93. data/lib/synapse.rb +2 -14
  94. data/test/auditing/data_provider_test.rb +2 -2
  95. data/test/auditing/dispatch_interceptor_test.rb +1 -1
  96. data/test/auditing/unit_listener_test.rb +3 -3
  97. data/test/command/async_command_bus_test.rb +49 -0
  98. data/test/command/duplication_test.rb +2 -2
  99. data/test/command/gateway/interval_retry_scheduler_test.rb +42 -0
  100. data/test/command/gateway/retrying_callback_test.rb +57 -0
  101. data/test/command/gateway_test.rb +41 -7
  102. data/test/command/interceptor_chain_test.rb +1 -1
  103. data/test/command/message_test.rb +17 -0
  104. data/test/command/serialization_test.rb +2 -2
  105. data/test/command/simple_command_bus_test.rb +7 -7
  106. data/test/command/validation_test.rb +3 -3
  107. data/test/command/wiring_test.rb +3 -3
  108. data/test/common/concurrency/identifier_lock_test.rb +2 -13
  109. data/test/common/concurrency/public_lock_test.rb +6 -6
  110. data/test/{duplication_test.rb → common/duplication_test.rb} +3 -3
  111. data/test/configuration/component/command_bus/async_command_bus_test.rb +36 -0
  112. data/test/configuration/component/command_bus/simple_command_bus_test.rb +57 -0
  113. data/test/configuration/component/event_bus/simple_event_bus_test.rb +58 -0
  114. data/test/configuration/component/serialization/converter_factory_test.rb +48 -0
  115. data/test/configuration/component/serialization/serializer_test.rb +78 -0
  116. data/test/configuration/component/uow/unit_factory_test.rb +46 -0
  117. data/test/configuration/container_builder_test.rb +47 -0
  118. data/test/configuration/container_test.rb +88 -0
  119. data/test/configuration/definition_builder_test.rb +126 -0
  120. data/test/configuration/definition_test.rb +41 -0
  121. data/test/configuration/dependent_test.rb +30 -0
  122. data/test/configuration/ext_test.rb +19 -0
  123. data/test/configuration/fixtures/dependent.rb +10 -0
  124. data/test/domain/aggregate_root_test.rb +5 -5
  125. data/test/domain/message_test.rb +15 -3
  126. data/test/domain/stream_test.rb +2 -2
  127. data/test/event_bus/publisher_test.rb +29 -0
  128. data/test/event_bus/wiring_test.rb +1 -1
  129. data/test/event_sourcing/aggregate_factory_test.rb +12 -6
  130. data/test/event_sourcing/aggregate_root_test.rb +4 -4
  131. data/test/event_sourcing/entity_test.rb +10 -9
  132. data/test/event_sourcing/repository_test.rb +6 -6
  133. data/test/event_sourcing/storage_listener_test.rb +8 -4
  134. data/test/event_store/in_memory_test.rb +3 -3
  135. data/test/process_manager/container_resource_injector_test.rb +19 -0
  136. data/test/process_manager/correlation_set_test.rb +2 -2
  137. data/test/process_manager/correlation_test.rb +2 -2
  138. data/test/process_manager/in_memory_test.rb +3 -3
  139. data/test/process_manager/process_factory_test.rb +2 -2
  140. data/test/process_manager/process_test.rb +3 -3
  141. data/test/process_manager/simple_process_manager_test.rb +5 -5
  142. data/test/process_manager/wiring/process_manager_test.rb +4 -4
  143. data/test/process_manager/wiring/process_test.rb +2 -2
  144. data/test/repository/locking_test.rb +4 -4
  145. data/test/repository/optimistic_test.rb +2 -2
  146. data/test/repository/pessimistic_test.rb +1 -1
  147. data/test/repository/simple_repository_test.rb +79 -0
  148. data/test/support/countdown_latch.rb +18 -0
  149. data/test/test_helper.rb +6 -3
  150. data/test/upcasting/data_test.rb +31 -0
  151. metadata +84 -25
  152. data/lib/synapse/event_bus/event_listener_proxy.rb +0 -12
  153. data/lib/synapse/partitioning/memory_queue_reader.rb +0 -31
  154. data/lib/synapse/partitioning/memory_queue_writer.rb +0 -19
  155. data/lib/synapse/partitioning/message_receipt.rb +0 -25
  156. data/lib/synapse/partitioning/packing/json_packer.rb +0 -93
  157. data/lib/synapse/partitioning/packing/json_unpacker.rb +0 -83
  158. data/lib/synapse/partitioning/packing.rb +0 -27
  159. data/lib/synapse/partitioning/queue_reader.rb +0 -32
  160. data/lib/synapse/partitioning/queue_writer.rb +0 -17
  161. data/lib/synapse/partitioning.rb +0 -18
  162. data/test/partitioning/memory_test.rb +0 -34
  163. data/test/partitioning/packing/json_test.rb +0 -62
@@ -0,0 +1,38 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create a command gateway
4
+ #
5
+ # @example The minimum possible effort to build a command gateway
6
+ # gateway
7
+ #
8
+ # @example Create a command gateway using an alternate command bus
9
+ # gateway :alt_gateway do
10
+ # use_command_bus :alt_command_bus
11
+ # end
12
+ #
13
+ # @todo Support for command filters and retry scheduler
14
+ class CommandGatewayDefinitionBuilder < DefinitionBuilder
15
+ # Changes the command bus that commands are sent from the gateway
16
+ #
17
+ # @param [Symbol] command_bus
18
+ # @return [undefined]
19
+ def use_command_bus(command_bus)
20
+ @command_bus = command_bus
21
+ end
22
+
23
+ protected
24
+
25
+ # @return [undefined]
26
+ def populate_defaults
27
+ identified_by :gateway
28
+
29
+ use_command_bus :command_bus
30
+
31
+ use_factory do
32
+ command_bus = resolve @command_bus
33
+ Command::CommandGateway.new command_bus
34
+ end
35
+ end
36
+ end # CommandGatewayDefinitionBuilder
37
+ end # Configuration
38
+ end
@@ -0,0 +1,81 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create a simple command bus
4
+ #
5
+ # @example The minimum possible effort to build a command bus
6
+ # simple_command_bus
7
+ #
8
+ # @example Create a command bus with an alternate identifier and handler tag
9
+ # simple_command_bus :alt_command_bus do
10
+ # use_handler_tag :alt_command_handler
11
+ # end
12
+ #
13
+ # @todo Support for interceptors and filters
14
+ class SimpleCommandBusDefinitionBuilder < DefinitionBuilder
15
+ # Changes the tag to use to automatically subscribe command handlers
16
+ #
17
+ # Note that command handlers that are tagged must support self-subscription to the
18
+ # command bus. An example of a handler capable of doing so is the wiring command handler.
19
+ #
20
+ # @param [Symbol] handler_tag
21
+ # @return [undefined]
22
+ def use_handler_tag(handler_tag)
23
+ @handler_tag = handler_tag
24
+ end
25
+
26
+ # Changes the rollback policy to use for the command bus
27
+ #
28
+ # By default, the command bus will always rollback on an exception
29
+ #
30
+ # @param [Symbol] rollback_policy
31
+ # @return [undefined]
32
+ def use_rollback_policy(rollback_policy)
33
+ @rollback_policy = rollback_policy
34
+ end
35
+
36
+ # Changes the unit of work factory to use with this command bus
37
+ #
38
+ # @param [Symbol] unit_factory
39
+ # @return [undefined]
40
+ def use_unit_factory(unit_factory)
41
+ @unit_factory = unit_factory
42
+ end
43
+
44
+ protected
45
+
46
+ # @return [undefined]
47
+ def populate_defaults
48
+ identified_by :command_bus
49
+
50
+ use_handler_tag :command_handler
51
+ use_unit_factory :unit_factory
52
+
53
+ use_factory do
54
+ unit_factory = resolve @unit_factory
55
+
56
+ command_bus = create_command_bus unit_factory
57
+
58
+ if @rollback_policy
59
+ command_bus.rollback_policy = resolve @rollback_policy
60
+ end
61
+
62
+ with_tagged @handler_tag do |handler|
63
+ handler.subscribe command_bus
64
+ end
65
+
66
+ command_bus
67
+ end
68
+ end
69
+
70
+ # Creates an instance of SimpleCommandBus with the given unit of work factory
71
+ #
72
+ # This can be overriden to serve up special subclasses of SimpleCommandBus
73
+ #
74
+ # @param [UnitOfWorkFactory] unit_factory
75
+ # @return [SimpleCommandBus]
76
+ def create_command_bus(unit_factory)
77
+ Command::SimpleCommandBus.new unit_factory
78
+ end
79
+ end # SimpleCommandBusDefinitionBuilder
80
+ end # Configuration
81
+ end
@@ -0,0 +1,35 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ # Creates and configures an asynchronous command bus
5
+ #
6
+ # @see AsynchronousCommandBusDefinitionBuilder
7
+ # @param [Symbol] identifier
8
+ # @param [Proc] block
9
+ # @return [undefined]
10
+ def async_command_bus(identifier = nil, &block)
11
+ with_definition_builder AsynchronousCommandBusDefinitionBuilder, identifier, &block
12
+ end
13
+
14
+ # Creates and configures a simple command bus
15
+ #
16
+ # @see SimpleCommandBusDefinitionBuilder
17
+ # @param [Symbol] identifier
18
+ # @param [Proc] block
19
+ # @return [undefined]
20
+ def simple_command_bus(identifier = nil, &block)
21
+ with_definition_builder SimpleCommandBusDefinitionBuilder, identifier, &block
22
+ end
23
+
24
+ # Creates and configures a command gateway
25
+ #
26
+ # @see CommandGatewayBusDefinitionBuilder
27
+ # @param [Symbol] identifier
28
+ # @param [Proc] block
29
+ # @return [undefined]
30
+ def gateway(identifier = nil, &block)
31
+ with_definition_builder CommandGatewayBusDefinitionBuilder, identifier, &block
32
+ end
33
+ end # ContainerBuilder
34
+ end # Configuration
35
+ end
@@ -0,0 +1,41 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create a simple event bus
4
+ #
5
+ # @example The minimum possible effort to build an event bus
6
+ # simple_event_bus
7
+ #
8
+ # @example Create an event bus with an alternate identifier and listener tag
9
+ # simple_event_bus :alt_event_bus do
10
+ # use_listener_tag :alt_event_listener
11
+ # end
12
+ class SimpleEventBusDefinitionBuilder < DefinitionBuilder
13
+ # Changes the tag to use to automatically subscribe event listeners
14
+ #
15
+ # @param [Symbol] listener_tag
16
+ # @return [undefined]
17
+ def use_listener_tag(listener_tag)
18
+ @listener_tag = listener_tag
19
+ end
20
+
21
+ protected
22
+
23
+ # @return [undefined]
24
+ def populate_defaults
25
+ identified_by :event_bus
26
+
27
+ use_listener_tag :event_listener
28
+
29
+ use_factory do
30
+ event_bus = EventBus::SimpleEventBus.new
31
+
32
+ with_tagged @listener_tag do |listener|
33
+ event_bus.subscribe listener
34
+ end
35
+
36
+ event_bus
37
+ end
38
+ end
39
+ end # SimpleEventBusDefinitionBuilder
40
+ end # Configuration
41
+ end
@@ -0,0 +1,15 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ # Creates and configures a simple event bus
5
+ #
6
+ # @see SimpleEventBusDefinitionBuilder
7
+ # @param [Symbol] identifier
8
+ # @param [Proc] block
9
+ # @return [undefined]
10
+ def simple_event_bus(identifier = nil, &block)
11
+ with_definition_builder SimpleEventBusDefinitionBuilder, identifier, &block
12
+ end
13
+ end # ContainerBuilder
14
+ end # Configuration
15
+ end
@@ -0,0 +1,62 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create event sourced aggregate repositories
4
+ #
5
+ # @example The minimum possible effort to build a event sourcing repository
6
+ # es_repository :orderbook_repository do
7
+ # use_aggregate_type TradeEngine::OrderBook
8
+ # end
9
+ class EventSourcingRepositoryDefinitionBuilder < LockingRepositoryDefinitionBuilder
10
+ # Convenience method that defines an aggregate factory capable of creating aggregates
11
+ # of the given type
12
+ #
13
+ # @param [Class] aggregate_type
14
+ # @return [undefined]
15
+ def use_aggregate_type(aggregate_type)
16
+ @aggregate_factory = build_composite do
17
+ anonymous
18
+ tag :aggregate_factory
19
+ use_factory do
20
+ EventSourcing::GenericAggregateFactory.new aggregate_type
21
+ end
22
+ end
23
+ end
24
+
25
+ # @param [Symbol] aggregate_factory
26
+ # @return [undefined]
27
+ def use_aggregate_factory(aggregate_factory)
28
+ @aggregate_factory = aggregate_factory
29
+ end
30
+
31
+ # @param [Symbol] conflict_resolver
32
+ # @return [undefined]
33
+ def use_conflict_resolver(conflict_resolver)
34
+ @conflict_resolver = conflict_resolver
35
+ end
36
+
37
+ # @param [Symbol] event_store
38
+ # @return [undefined]
39
+ def use_event_store(event_store)
40
+ @event_store = event_store
41
+ end
42
+
43
+ protected
44
+
45
+ # @return [undefined]
46
+ def populate_defaults
47
+ super
48
+
49
+ use_event_store :event_store
50
+
51
+ use_factory do
52
+ aggregate_factory = resolve @aggregate_factory
53
+ event_store = resolve @event_store
54
+ lock_manager = build_lock_manager
55
+
56
+ repository = EventSourcing::EventSourcingRepository.new aggregate_factory, event_store, lock_manager
57
+ inject_base_dependencies repository
58
+ end
59
+ end
60
+ end # EventSourcingRepositoryDefinitionBuilder
61
+ end # Configuration
62
+ end
@@ -0,0 +1,15 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ # Creates and configures an event sourcing repository
5
+ #
6
+ # @see EventSourcingRepositoryDefinitionBuilder
7
+ # @param [Symbol] identifier
8
+ # @param [Proc] block
9
+ # @return [undefined]
10
+ def es_repository(identifier = nil, &block)
11
+ with_definition_builder EventSourcingRepositoryDefinitionBuilder, identifier, &block
12
+ end
13
+ end # ContainerBuilder
14
+ end # Configuration
15
+ end
@@ -0,0 +1,85 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder that serves a base for building specific implementations of a
4
+ # locking repository
5
+ #
6
+ # @abstract
7
+ # @see EventSourcingRepositoryDefinitionBuilder
8
+ # @see SimpleRepositoryDefinitionBuilder
9
+ class LockingRepositoryDefinitionBuilder < DefinitionBuilder
10
+ # Changes the event bus used to publish aggregate events to
11
+ #
12
+ # @param [Symbol] event_bus
13
+ # @return [undefined]
14
+ def use_event_bus(event_bus)
15
+ @event_bus = event_bus
16
+ end
17
+
18
+ # Uses the lock manager with no locking
19
+ # @return [undefined]
20
+ def use_no_locking
21
+ @lock_manager_type = Repository::NullLockManager
22
+ end
23
+
24
+ # Uses the lock manager with pessimistic locking
25
+ # @return [undefined]
26
+ def use_pessimistic_locking
27
+ @lock_manager_type = Repository::PessimisticLockManager
28
+ end
29
+
30
+ # Uses the lock manager with optimistic locking
31
+ # @return [undefined]
32
+ def use_optimistic_locking
33
+ @lock_manager_type = Repository::OptimisticLockManager
34
+ end
35
+
36
+ # Changes the lock manager used to prevent concurrent aggregate modification
37
+ #
38
+ # @param [Symbol] lock_manager
39
+ # @return [undefined]
40
+ def use_lock_manager(lock_manager)
41
+ @lock_manager = lock_manager
42
+ end
43
+
44
+ # Changes the provider used to get the current unit of work
45
+ #
46
+ # @param [Symbol] unit_provider
47
+ # @return [undefined]
48
+ def use_unit_provider(unit_provider)
49
+ @unit_provider = unit_provider
50
+ end
51
+
52
+ protected
53
+
54
+ # @return [undefined]
55
+ def populate_defaults
56
+ use_event_bus :event_bus
57
+ use_pessimistic_locking
58
+ use_unit_provider :unit_provider
59
+ end
60
+
61
+ # @raise [RuntimeError] If no locking manager was configured
62
+ # @return [LockManager]
63
+ def build_lock_manager
64
+ if @lock_manager
65
+ resolve @lock_manager
66
+ elsif @lock_manager_type
67
+ @lock_manager_type.new
68
+ else
69
+ raise 'No lock manager was configured for this repository'
70
+ end
71
+ end
72
+
73
+ # Injects the dependencies required by the base repository class
74
+ #
75
+ # @param [Repository] repository
76
+ # @return [Repository]
77
+ def inject_base_dependencies(repository)
78
+ repository.event_bus = resolve @event_bus
79
+ repository.unit_provider = resolve @unit_provider
80
+
81
+ repository
82
+ end
83
+ end # LockingRepositoryDefinitionBuilder
84
+ end # Configuration
85
+ end
@@ -0,0 +1,31 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create simple aggregate repositories
4
+ #
5
+ # @example The minimum possible effort to build a simple repository
6
+ # simple_repository :user_repository do
7
+ # use_aggregate_type User
8
+ # end
9
+ class SimpleRepositoryDefinitionBuilder < LockingRepositoryDefinitionBuilder
10
+ # @param [Class] aggregate_type
11
+ # @return [undefined]
12
+ def use_aggregate_type(aggregate_type)
13
+ @aggregate_type = aggregate_type
14
+ end
15
+
16
+ protected
17
+
18
+ # @return [undefined]
19
+ def populate_defaults
20
+ super
21
+
22
+ use_factory do
23
+ lock_manager = build_lock_manager
24
+
25
+ repository = Repository::SimpleRepository.new lock_manager, @aggregate_type
26
+ inject_base_dependencies repository
27
+ end
28
+ end
29
+ end # SimpleRepositoryDefinitionBuilder
30
+ end # Configuration
31
+ end
@@ -0,0 +1,15 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ # Creates and configures a simple repository
5
+ #
6
+ # @see SimpleRepositoryDefinitionBuilder
7
+ # @param [Symbol] identifier
8
+ # @param [Proc] block
9
+ # @return [undefined]
10
+ def simple_repository(identifier = nil, &block)
11
+ with_definition_builder SimpleRepositoryDefinitionBuilder, identifier, &block
12
+ end
13
+ end # ContainerBuilder
14
+ end # Configuration
15
+ end
@@ -0,0 +1,50 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create a converter factory
4
+ #
5
+ # @example The minimum possible effort to build a converter factory
6
+ # converter_factory
7
+ #
8
+ # @example Create a converter factory using a different identifier and different converter tag
9
+ # converter_factory :alt_converter_factory do
10
+ # use_converter_tag :alt_converter
11
+ # end
12
+ #
13
+ # @example Register several converters that will be picked up by a converter factory
14
+ # factory :xml2ox_converter, :tag => :converter do
15
+ # Serialization::XmlToOxDocumentConverter.new
16
+ # end
17
+ #
18
+ # factory :ox2xml_converter, :tag => :converter do
19
+ # Serialization::OxDocumentToXmlConverter.new
20
+ # end
21
+ class ConverterFactoryDefinitionBuilder < DefinitionBuilder
22
+ # Changes the tag to use to automatically register converters
23
+ #
24
+ # @param [Symbol] converter_tag
25
+ # @return [undefined]
26
+ def use_converter_tag(converter_tag)
27
+ @converter_tag = converter_tag
28
+ end
29
+
30
+ protected
31
+
32
+ # @return [undefined]
33
+ def populate_defaults
34
+ identified_by :converter_factory
35
+
36
+ use_converter_tag :converter
37
+
38
+ use_factory do
39
+ converter_factory = Serialization::ConverterFactory.new
40
+
41
+ with_tagged @converter_tag do |converter|
42
+ converter_factory.register converter
43
+ end
44
+
45
+ converter_factory
46
+ end
47
+ end
48
+ end # ConverterFactoryDefinitionBuilder
49
+ end # Configuration
50
+ end
@@ -0,0 +1,90 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create and configure serializers
4
+ #
5
+ # @example The minimum possible to create a serializer (defaults to marshal)
6
+ # serializer
7
+ #
8
+ # @example Use a specific serializer and converter_factory
9
+ # serializer :alt_serializer do
10
+ # use_ox
11
+ # use_converter_factory :alt_converter_factory
12
+ # end
13
+ class SerializerDefinitionBuilder < DefinitionBuilder
14
+ # Selects a serializer that uses attributes (ActiveModel, Virtus, etc.)
15
+ # @return [undefined]
16
+ def use_attribute
17
+ @serializer_type = Serialization::AttributeSerializer
18
+ end
19
+
20
+ # Selects a serializer that uses the Ruby marshaling library
21
+ # @return [undefined]
22
+ def use_marshal
23
+ @serializer_type = Serialization::MarshalSerializer
24
+ end
25
+
26
+ # Selects a serializer that uses the Optimized JSON (Oj) serialization library
27
+ # @return [undefined]
28
+ def use_oj
29
+ @serializer_type = Serialization::OjSerializer
30
+ end
31
+
32
+ # Selects a serializer that uses the Optimized XML (Ox) serialization library
33
+ # @return [undefined]
34
+ def use_ox
35
+ @serializer_type = Serialization::OxSerializer
36
+ end
37
+
38
+ # Changes the converter factory
39
+ #
40
+ # @param [Symbol] converter_factory
41
+ # @return [undefined]
42
+ def use_converter_factory(converter_factory)
43
+ @converter_factory = converter_factory
44
+ end
45
+
46
+ # Changes the options to use during serialization; note that these are serializer-specific
47
+ # and that not all serializers support options.
48
+ #
49
+ # @param [Hash] serialize_options
50
+ # @return [undefined]
51
+ def use_serialize_options(serialize_options)
52
+ @serialize_options = serialize_options
53
+ end
54
+
55
+ # Changes the options to use during deserialization; note that these are serializer-specific
56
+ # and that not all serializers support options.
57
+ #
58
+ # @param [Hash] deserialize_options
59
+ # @return [undefined]
60
+ def use_deserialize_options(deserialize_options)
61
+ @deserialize_options = deserialize_options
62
+ end
63
+
64
+ protected
65
+
66
+ # @return [undefined]
67
+ def populate_defaults
68
+ identified_by :serializer
69
+
70
+ use_marshal
71
+ use_converter_factory :converter_factory
72
+
73
+ use_factory do
74
+ converter_factory = resolve @converter_factory
75
+ serializer = @serializer_type.new converter_factory
76
+
77
+ if @serialize_options
78
+ serializer.serialize_options = @serialize_options
79
+ end
80
+
81
+ if @deserialize_options
82
+ serializer.deserialize_options = @deserialize_options
83
+ end
84
+
85
+ serializer
86
+ end
87
+ end
88
+ end # SerializerDefinitionBuilder
89
+ end # Configuration
90
+ end
@@ -0,0 +1,25 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ # Creates and configures a converter factory for serialization
5
+ #
6
+ # @see ConverterFactoryDefinitionBuilder
7
+ # @param [Symbol] identifier
8
+ # @param [Proc] block
9
+ # @return [undefined]
10
+ def converter_factory(identifier = nil, &block)
11
+ with_definition_builder ConverterFactoryDefinitionBuilder, identifier, &block
12
+ end
13
+
14
+ # Creates and configures a serializer for partitioning, event storage, etc.
15
+ #
16
+ # @see SerializerDefinitionBuilder
17
+ # @param [Symbol] identifier
18
+ # @param [Proc] block
19
+ # @return [undefined]
20
+ def serializer(identifier = nil, &block)
21
+ with_definition_builder SerializerDefinitionBuilder, identifier, &block
22
+ end
23
+ end # ContainerBuilder
24
+ end # Configuration
25
+ end
@@ -0,0 +1,51 @@
1
+ module Synapse
2
+ module Configuration
3
+ # Definition builder used to create a unit of work factory
4
+ #
5
+ # @example The minimum possible effort to build a unit of work factory
6
+ # unit_factory
7
+ #
8
+ # @example Create a factory with a specific unit provider and tx manager
9
+ # unit_factory :alt_unit_factory do
10
+ # use_transaction_manager :sequel_tx_manager
11
+ # use_unit_provider :alt_unit_provider
12
+ # end
13
+ class UnitOfWorkFactoryDefinitionBuilder < DefinitionBuilder
14
+ # Changes the transaction manager to use when creating units of work
15
+ #
16
+ # @param [Symbol] tx_manager
17
+ # @return [undefined]
18
+ def use_transaction_manager(tx_manager)
19
+ @tx_manager = tx_manager
20
+ end
21
+
22
+ # Changes the unit of work provider to use when creating units of work
23
+ #
24
+ # @param [Symbol] unit_provider
25
+ # @return [undefined]
26
+ def use_unit_provider(unit_provider)
27
+ @unit_provider = unit_provider
28
+ end
29
+
30
+ protected
31
+
32
+ # @return [undefined]
33
+ def populate_defaults
34
+ identified_by :unit_factory
35
+
36
+ use_transaction_manager :transaction_manager
37
+ use_unit_provider :unit_provider
38
+
39
+ use_factory do
40
+ tx_manager = resolve @tx_manager, true
41
+ unit_provider = resolve @unit_provider
42
+
43
+ unit_factory = UnitOfWork::UnitOfWorkFactory.new unit_provider
44
+ unit_factory.transaction_manager = tx_manager
45
+
46
+ unit_factory
47
+ end
48
+ end
49
+ end # UnitOfWorkFactoryDefinitionBuilder
50
+ end # Configuration
51
+ end
@@ -0,0 +1,22 @@
1
+ module Synapse
2
+ module Configuration
3
+ class ContainerBuilder
4
+ initializer do
5
+ # Configures the default unit of work provider implementation
6
+ factory :unit_provider do
7
+ UnitOfWork::UnitOfWorkProvider.new
8
+ end
9
+ end
10
+
11
+ # Creates and configures a unit of work factory
12
+ #
13
+ # @see UnitOfWorkFactoryDefinitionBuilder
14
+ # @param [Symbol] identifier
15
+ # @param [Proc] block
16
+ # @return [undefined]
17
+ def unit_factory(identifier = nil, &block)
18
+ with_definition_builder UnitOfWorkFactoryDefinitionBuilder, identifier, &block
19
+ end
20
+ end # ContainerBuilder
21
+ end # Configuration
22
+ end