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.
- data/lib/synapse/command/async_command_bus.rb +41 -0
- data/lib/synapse/command/command_callback.rb +49 -2
- data/lib/synapse/command/command_handler.rb +2 -0
- data/lib/synapse/command/filters/validation.rb +2 -2
- data/lib/synapse/command/gateway/interval_retry_scheduler.rb +75 -0
- data/lib/synapse/command/gateway/retry_scheduler.rb +26 -0
- data/lib/synapse/command/gateway/retrying_callback.rb +46 -0
- data/lib/synapse/command/gateway.rb +56 -11
- data/lib/synapse/command/interceptor_chain.rb +2 -2
- data/lib/synapse/command/interceptors/serialization.rb +2 -2
- data/lib/synapse/command/message.rb +16 -0
- data/lib/synapse/command/simple_command_bus.rb +6 -2
- data/lib/synapse/command/wiring.rb +3 -3
- data/lib/synapse/command.rb +7 -1
- data/lib/synapse/common/concurrency/identifier_lock.rb +2 -17
- data/lib/synapse/common/concurrency/public_lock.rb +8 -9
- data/lib/synapse/common/errors.rb +1 -1
- data/lib/synapse/common/message.rb +2 -6
- data/lib/synapse/common.rb +9 -0
- data/lib/synapse/configuration/component/command_bus/async_command_bus.rb +41 -0
- data/lib/synapse/configuration/component/command_bus/gateway.rb +38 -0
- data/lib/synapse/configuration/component/command_bus/simple_command_bus.rb +81 -0
- data/lib/synapse/configuration/component/command_bus.rb +35 -0
- data/lib/synapse/configuration/component/event_bus/simple_event_bus.rb +41 -0
- data/lib/synapse/configuration/component/event_bus.rb +15 -0
- data/lib/synapse/configuration/component/event_sourcing/repository.rb +62 -0
- data/lib/synapse/configuration/component/event_sourcing.rb +15 -0
- data/lib/synapse/configuration/component/repository/locking_repository.rb +85 -0
- data/lib/synapse/configuration/component/repository/simple_repository.rb +31 -0
- data/lib/synapse/configuration/component/repository.rb +15 -0
- data/lib/synapse/configuration/component/serialization/converter_factory.rb +50 -0
- data/lib/synapse/configuration/component/serialization/serializer.rb +90 -0
- data/lib/synapse/configuration/component/serialization.rb +25 -0
- data/lib/synapse/configuration/component/uow/unit_factory.rb +51 -0
- data/lib/synapse/configuration/component/uow.rb +22 -0
- data/lib/synapse/configuration/component/upcasting/upcaster_chain.rb +61 -0
- data/lib/synapse/configuration/component/upcasting.rb +15 -0
- data/lib/synapse/configuration/container.rb +80 -0
- data/lib/synapse/configuration/container_builder.rb +108 -0
- data/lib/synapse/configuration/definition.rb +31 -0
- data/lib/synapse/configuration/definition_builder.rb +138 -0
- data/lib/synapse/configuration/dependent.rb +31 -0
- data/lib/synapse/configuration/ext.rb +35 -0
- data/lib/synapse/configuration.rb +32 -0
- data/lib/synapse/domain/aggregate_root.rb +25 -26
- data/lib/synapse/domain/event_container.rb +5 -5
- data/lib/synapse/domain/message.rb +16 -0
- data/lib/synapse/event_bus/event_listener.rb +2 -0
- data/lib/synapse/event_bus/event_publisher.rb +19 -0
- data/lib/synapse/event_bus/simple_event_bus.rb +21 -30
- data/lib/synapse/event_bus/wiring.rb +5 -4
- data/lib/synapse/event_bus.rb +1 -1
- data/lib/synapse/event_sourcing/aggregate_root.rb +6 -4
- data/lib/synapse/process_manager/container_resource_injector.rb +18 -0
- data/lib/synapse/process_manager/pessimistic_lock_manager.rb +1 -1
- data/lib/synapse/process_manager/process.rb +4 -0
- data/lib/synapse/process_manager/process_factory.rb +3 -3
- data/lib/synapse/process_manager/repository/in_memory.rb +1 -1
- data/lib/synapse/process_manager/wiring/process.rb +6 -6
- data/lib/synapse/process_manager/wiring/process_manager.rb +8 -8
- data/lib/synapse/process_manager.rb +2 -0
- data/lib/synapse/repository/locking.rb +5 -3
- data/lib/synapse/repository/optimistic_lock_manager.rb +2 -7
- data/lib/synapse/repository/pessimistic_lock_manager.rb +3 -3
- data/lib/synapse/repository/repository.rb +2 -2
- data/lib/synapse/repository/simple_repository.rb +69 -0
- data/lib/synapse/repository.rb +1 -0
- data/lib/synapse/serialization/converter/chain.rb +2 -2
- data/lib/synapse/serialization/converter_factory.rb +2 -2
- data/lib/synapse/serialization/lazy_object.rb +2 -2
- data/lib/synapse/serialization/message/serialization_aware_message.rb +3 -3
- data/lib/synapse/serialization/message/serialized_message.rb +6 -10
- data/lib/synapse/serialization/message/serialized_message_builder.rb +4 -4
- data/lib/synapse/serialization/message/serialized_object_cache.rb +2 -2
- data/lib/synapse/serialization/message/serializer.rb +2 -2
- data/lib/synapse/serialization/revision_resolver.rb +3 -3
- data/lib/synapse/serialization/serialized_object.rb +2 -2
- data/lib/synapse/serialization/serialized_type.rb +2 -2
- data/lib/synapse/serialization/serializer/attribute.rb +2 -2
- data/lib/synapse/serialization/serializer/marshal.rb +2 -2
- data/lib/synapse/serialization/serializer/oj.rb +2 -2
- data/lib/synapse/serialization/serializer/ox.rb +2 -2
- data/lib/synapse/serialization/serializer.rb +2 -2
- data/lib/synapse/uow/factory.rb +2 -2
- data/lib/synapse/uow/listener_collection.rb +2 -2
- data/lib/synapse/uow/nesting.rb +9 -2
- data/lib/synapse/uow/provider.rb +2 -2
- data/lib/synapse/uow/uow.rb +8 -2
- data/lib/synapse/upcasting/{chain.rb → upcaster_chain.rb} +0 -0
- data/lib/synapse/upcasting.rb +1 -1
- data/lib/synapse/version.rb +1 -1
- data/lib/synapse/wiring/message_wiring.rb +31 -0
- data/lib/synapse.rb +2 -14
- data/test/auditing/data_provider_test.rb +2 -2
- data/test/auditing/dispatch_interceptor_test.rb +1 -1
- data/test/auditing/unit_listener_test.rb +3 -3
- data/test/command/async_command_bus_test.rb +49 -0
- data/test/command/duplication_test.rb +2 -2
- data/test/command/gateway/interval_retry_scheduler_test.rb +42 -0
- data/test/command/gateway/retrying_callback_test.rb +57 -0
- data/test/command/gateway_test.rb +41 -7
- data/test/command/interceptor_chain_test.rb +1 -1
- data/test/command/message_test.rb +17 -0
- data/test/command/serialization_test.rb +2 -2
- data/test/command/simple_command_bus_test.rb +7 -7
- data/test/command/validation_test.rb +3 -3
- data/test/command/wiring_test.rb +3 -3
- data/test/common/concurrency/identifier_lock_test.rb +2 -13
- data/test/common/concurrency/public_lock_test.rb +6 -6
- data/test/{duplication_test.rb → common/duplication_test.rb} +3 -3
- data/test/configuration/component/command_bus/async_command_bus_test.rb +36 -0
- data/test/configuration/component/command_bus/simple_command_bus_test.rb +57 -0
- data/test/configuration/component/event_bus/simple_event_bus_test.rb +58 -0
- data/test/configuration/component/serialization/converter_factory_test.rb +48 -0
- data/test/configuration/component/serialization/serializer_test.rb +78 -0
- data/test/configuration/component/uow/unit_factory_test.rb +46 -0
- data/test/configuration/container_builder_test.rb +47 -0
- data/test/configuration/container_test.rb +88 -0
- data/test/configuration/definition_builder_test.rb +126 -0
- data/test/configuration/definition_test.rb +41 -0
- data/test/configuration/dependent_test.rb +30 -0
- data/test/configuration/ext_test.rb +19 -0
- data/test/configuration/fixtures/dependent.rb +10 -0
- data/test/domain/aggregate_root_test.rb +5 -5
- data/test/domain/message_test.rb +15 -3
- data/test/domain/stream_test.rb +2 -2
- data/test/event_bus/publisher_test.rb +29 -0
- data/test/event_bus/wiring_test.rb +1 -1
- data/test/event_sourcing/aggregate_factory_test.rb +12 -6
- data/test/event_sourcing/aggregate_root_test.rb +4 -4
- data/test/event_sourcing/entity_test.rb +10 -9
- data/test/event_sourcing/repository_test.rb +6 -6
- data/test/event_sourcing/storage_listener_test.rb +8 -4
- data/test/event_store/in_memory_test.rb +3 -3
- data/test/process_manager/container_resource_injector_test.rb +19 -0
- data/test/process_manager/correlation_set_test.rb +2 -2
- data/test/process_manager/correlation_test.rb +2 -2
- data/test/process_manager/in_memory_test.rb +3 -3
- data/test/process_manager/process_factory_test.rb +2 -2
- data/test/process_manager/process_test.rb +3 -3
- data/test/process_manager/simple_process_manager_test.rb +5 -5
- data/test/process_manager/wiring/process_manager_test.rb +4 -4
- data/test/process_manager/wiring/process_test.rb +2 -2
- data/test/repository/locking_test.rb +4 -4
- data/test/repository/optimistic_test.rb +2 -2
- data/test/repository/pessimistic_test.rb +1 -1
- data/test/repository/simple_repository_test.rb +79 -0
- data/test/support/countdown_latch.rb +18 -0
- data/test/test_helper.rb +6 -3
- data/test/upcasting/data_test.rb +31 -0
- metadata +84 -25
- data/lib/synapse/event_bus/event_listener_proxy.rb +0 -12
- data/lib/synapse/partitioning/memory_queue_reader.rb +0 -31
- data/lib/synapse/partitioning/memory_queue_writer.rb +0 -19
- data/lib/synapse/partitioning/message_receipt.rb +0 -25
- data/lib/synapse/partitioning/packing/json_packer.rb +0 -93
- data/lib/synapse/partitioning/packing/json_unpacker.rb +0 -83
- data/lib/synapse/partitioning/packing.rb +0 -27
- data/lib/synapse/partitioning/queue_reader.rb +0 -32
- data/lib/synapse/partitioning/queue_writer.rb +0 -17
- data/lib/synapse/partitioning.rb +0 -18
- data/test/partitioning/memory_test.rb +0 -34
- 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
|