synapse-core 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/lib/synapse.rb +351 -0
  2. data/lib/synapse/command/command_bus.rb +45 -0
  3. data/lib/synapse/command/command_callback.rb +18 -0
  4. data/lib/synapse/command/command_filter.rb +17 -0
  5. data/lib/synapse/command/command_handler.rb +13 -0
  6. data/lib/synapse/command/dispatch_interceptor.rb +16 -0
  7. data/lib/synapse/command/duplication.rb +43 -0
  8. data/lib/synapse/command/errors.rb +27 -0
  9. data/lib/synapse/command/filters/validation.rb +32 -0
  10. data/lib/synapse/command/gateway.rb +34 -0
  11. data/lib/synapse/command/interceptor_chain.rb +31 -0
  12. data/lib/synapse/command/interceptors/serialization.rb +35 -0
  13. data/lib/synapse/command/message.rb +19 -0
  14. data/lib/synapse/command/rollback_policy.rb +22 -0
  15. data/lib/synapse/command/simple_command_bus.rb +138 -0
  16. data/lib/synapse/command/wiring.rb +47 -0
  17. data/lib/synapse/domain/aggregate_root.rb +121 -0
  18. data/lib/synapse/domain/event_container.rb +127 -0
  19. data/lib/synapse/domain/message.rb +82 -0
  20. data/lib/synapse/domain/message_builder.rb +34 -0
  21. data/lib/synapse/domain/stream.rb +108 -0
  22. data/lib/synapse/duplication.rb +60 -0
  23. data/lib/synapse/errors.rb +13 -0
  24. data/lib/synapse/event_bus/event_bus.rb +40 -0
  25. data/lib/synapse/event_bus/event_listener.rb +16 -0
  26. data/lib/synapse/event_bus/event_listener_proxy.rb +12 -0
  27. data/lib/synapse/event_bus/simple_event_bus.rb +69 -0
  28. data/lib/synapse/event_bus/wiring.rb +23 -0
  29. data/lib/synapse/event_sourcing/aggregate_factory.rb +69 -0
  30. data/lib/synapse/event_sourcing/aggregate_root.rb +104 -0
  31. data/lib/synapse/event_sourcing/conflict_resolver.rb +80 -0
  32. data/lib/synapse/event_sourcing/entity.rb +64 -0
  33. data/lib/synapse/event_sourcing/member.rb +72 -0
  34. data/lib/synapse/event_sourcing/repository.rb +119 -0
  35. data/lib/synapse/event_sourcing/snapshot/count_stream.rb +86 -0
  36. data/lib/synapse/event_sourcing/snapshot/count_trigger.rb +91 -0
  37. data/lib/synapse/event_sourcing/snapshot/taker.rb +73 -0
  38. data/lib/synapse/event_sourcing/storage_listener.rb +34 -0
  39. data/lib/synapse/event_sourcing/stream_decorator.rb +25 -0
  40. data/lib/synapse/event_store/errors.rb +16 -0
  41. data/lib/synapse/event_store/event_store.rb +43 -0
  42. data/lib/synapse/event_store/in_memory.rb +59 -0
  43. data/lib/synapse/event_store/mongo/cursor_event_stream.rb +63 -0
  44. data/lib/synapse/event_store/mongo/event_store.rb +86 -0
  45. data/lib/synapse/event_store/mongo/per_commit_strategy.rb +253 -0
  46. data/lib/synapse/event_store/mongo/per_event_strategy.rb +143 -0
  47. data/lib/synapse/event_store/mongo/storage_strategy.rb +113 -0
  48. data/lib/synapse/event_store/mongo/template.rb +73 -0
  49. data/lib/synapse/identifier.rb +23 -0
  50. data/lib/synapse/message.rb +101 -0
  51. data/lib/synapse/message_builder.rb +38 -0
  52. data/lib/synapse/process_manager/correlation.rb +32 -0
  53. data/lib/synapse/process_manager/correlation_resolver.rb +14 -0
  54. data/lib/synapse/process_manager/correlation_set.rb +58 -0
  55. data/lib/synapse/process_manager/process.rb +71 -0
  56. data/lib/synapse/repository/errors.rb +26 -0
  57. data/lib/synapse/repository/lock_manager.rb +40 -0
  58. data/lib/synapse/repository/locking.rb +97 -0
  59. data/lib/synapse/repository/pessimistic_lock_manager.rb +61 -0
  60. data/lib/synapse/repository/repository.rb +109 -0
  61. data/lib/synapse/serialization/converter.rb +39 -0
  62. data/lib/synapse/serialization/converter/chain.rb +45 -0
  63. data/lib/synapse/serialization/converter/factory.rb +68 -0
  64. data/lib/synapse/serialization/converter/identity.rb +29 -0
  65. data/lib/synapse/serialization/converter/json.rb +31 -0
  66. data/lib/synapse/serialization/converter/ox.rb +31 -0
  67. data/lib/synapse/serialization/errors.rb +12 -0
  68. data/lib/synapse/serialization/lazy_object.rb +61 -0
  69. data/lib/synapse/serialization/message/data.rb +25 -0
  70. data/lib/synapse/serialization/message/metadata.rb +13 -0
  71. data/lib/synapse/serialization/message/serialization_aware.rb +17 -0
  72. data/lib/synapse/serialization/message/serialization_aware_message.rb +66 -0
  73. data/lib/synapse/serialization/message/serialized_message.rb +201 -0
  74. data/lib/synapse/serialization/message/serialized_message_builder.rb +64 -0
  75. data/lib/synapse/serialization/message/serialized_object_cache.rb +50 -0
  76. data/lib/synapse/serialization/message/serializer.rb +47 -0
  77. data/lib/synapse/serialization/revision_resolver.rb +30 -0
  78. data/lib/synapse/serialization/serialized_object.rb +37 -0
  79. data/lib/synapse/serialization/serialized_type.rb +31 -0
  80. data/lib/synapse/serialization/serializer.rb +98 -0
  81. data/lib/synapse/serialization/serializer/marshal.rb +32 -0
  82. data/lib/synapse/serialization/serializer/oj.rb +34 -0
  83. data/lib/synapse/serialization/serializer/ox.rb +31 -0
  84. data/lib/synapse/uow/factory.rb +28 -0
  85. data/lib/synapse/uow/listener.rb +79 -0
  86. data/lib/synapse/uow/listener_collection.rb +93 -0
  87. data/lib/synapse/uow/nesting.rb +262 -0
  88. data/lib/synapse/uow/provider.rb +71 -0
  89. data/lib/synapse/uow/storage_listener.rb +14 -0
  90. data/lib/synapse/uow/transaction_manager.rb +27 -0
  91. data/lib/synapse/uow/uow.rb +178 -0
  92. data/lib/synapse/upcasting/chain.rb +78 -0
  93. data/lib/synapse/upcasting/context.rb +58 -0
  94. data/lib/synapse/upcasting/data.rb +30 -0
  95. data/lib/synapse/upcasting/single_upcaster.rb +57 -0
  96. data/lib/synapse/upcasting/upcaster.rb +55 -0
  97. data/lib/synapse/version.rb +3 -0
  98. data/lib/synapse/wiring/message_wiring.rb +41 -0
  99. data/lib/synapse/wiring/wire.rb +55 -0
  100. data/lib/synapse/wiring/wire_registry.rb +61 -0
  101. data/test/command/duplication_test.rb +54 -0
  102. data/test/command/gateway_test.rb +25 -0
  103. data/test/command/interceptor_chain_test.rb +26 -0
  104. data/test/command/serialization_test.rb +37 -0
  105. data/test/command/simple_command_bus_test.rb +141 -0
  106. data/test/command/validation_test.rb +42 -0
  107. data/test/command/wiring_test.rb +73 -0
  108. data/test/domain/aggregate_root_test.rb +57 -0
  109. data/test/domain/fixtures.rb +31 -0
  110. data/test/domain/message_test.rb +61 -0
  111. data/test/domain/stream_test.rb +35 -0
  112. data/test/duplication_test.rb +40 -0
  113. data/test/event_bus/wiring_test.rb +46 -0
  114. data/test/event_sourcing/aggregate_factory_test.rb +28 -0
  115. data/test/event_sourcing/aggregate_root_test.rb +76 -0
  116. data/test/event_sourcing/entity_test.rb +34 -0
  117. data/test/event_sourcing/fixtures.rb +85 -0
  118. data/test/event_sourcing/repository_test.rb +102 -0
  119. data/test/event_sourcing/snapshot/aggregate_taker_test.rb +39 -0
  120. data/test/event_sourcing/snapshot/deferred_taker_test.rb +19 -0
  121. data/test/event_sourcing/snapshot/integration_test.rb +65 -0
  122. data/test/event_sourcing/storage_listener_test.rb +77 -0
  123. data/test/event_store/in_memory_test.rb +47 -0
  124. data/test/process_manager/correlation_set_test.rb +49 -0
  125. data/test/process_manager/correlation_test.rb +24 -0
  126. data/test/process_manager/process_test.rb +52 -0
  127. data/test/repository/locking_test.rb +101 -0
  128. data/test/serialization/converter/factory_test.rb +33 -0
  129. data/test/serialization/converter/identity_test.rb +17 -0
  130. data/test/serialization/converter/json_test.rb +31 -0
  131. data/test/serialization/converter/ox_test.rb +40 -0
  132. data/test/serialization/fixtures.rb +17 -0
  133. data/test/serialization/lazy_object_test.rb +32 -0
  134. data/test/serialization/message/metadata_test.rb +19 -0
  135. data/test/serialization/message/serialization_aware_message_test.rb +88 -0
  136. data/test/serialization/message/serialized_message_builder_test.rb +41 -0
  137. data/test/serialization/message/serialized_message_test.rb +140 -0
  138. data/test/serialization/message/serializer_test.rb +50 -0
  139. data/test/serialization/revision_resolver_test.rb +12 -0
  140. data/test/serialization/serialized_object_test.rb +36 -0
  141. data/test/serialization/serialized_type_test.rb +27 -0
  142. data/test/serialization/serializer/marshal_test.rb +22 -0
  143. data/test/serialization/serializer/oj_test.rb +24 -0
  144. data/test/serialization/serializer/ox_test.rb +36 -0
  145. data/test/serialization/serializer_test.rb +20 -0
  146. data/test/test_helper.rb +19 -0
  147. data/test/uow/factory_test.rb +23 -0
  148. data/test/uow/outer_commit_listener_test.rb +50 -0
  149. data/test/uow/provider_test.rb +70 -0
  150. data/test/uow/uow_test.rb +337 -0
  151. data/test/upcasting/chain_test.rb +29 -0
  152. data/test/upcasting/fixtures.rb +66 -0
  153. data/test/wiring/wire_registry_test.rb +60 -0
  154. data/test/wiring/wire_test.rb +51 -0
  155. metadata +263 -0
@@ -0,0 +1,351 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'eventmachine'
4
+ require 'logging'
5
+ require 'set'
6
+
7
+ require 'synapse/version'
8
+
9
+ module Synapse
10
+ extend ActiveSupport::Autoload
11
+
12
+ eager_autoload do
13
+ autoload_at 'synapse/errors' do
14
+ autoload :SynapseError
15
+ autoload :ConfigurationError
16
+ autoload :NonTransientError
17
+ autoload :TransientError
18
+ end
19
+
20
+ autoload_at 'synapse/identifier' do
21
+ autoload :IdentifierFactory
22
+ autoload :GuidIdentifierFactory
23
+ end
24
+
25
+ autoload :Message
26
+ autoload :MessageBuilder
27
+
28
+ autoload_at 'synapse/duplication' do
29
+ autoload :DuplicationError
30
+ autoload :DuplicationRecorder
31
+ end
32
+ end
33
+
34
+ module Command
35
+ extend ActiveSupport::Autoload
36
+
37
+ eager_autoload do
38
+ autoload :CommandBus
39
+ autoload :SimpleCommandBus
40
+
41
+ autoload :CommandCallback
42
+ autoload :CommandFilter
43
+ autoload :CommandHandler
44
+
45
+ autoload_at 'synapse/command/message' do
46
+ autoload :CommandMessage
47
+ autoload :CommandMessageBuilder
48
+ end
49
+
50
+ autoload :CommandGateway, 'synapse/command/gateway'
51
+
52
+ autoload :DispatchInterceptor
53
+ autoload :InterceptorChain
54
+
55
+ autoload_at 'synapse/command/duplication' do
56
+ autoload :DuplicationFilter
57
+ autoload :DuplicationCleanupInterceptor
58
+ end
59
+
60
+ autoload_at 'synapse/command/errors' do
61
+ autoload :CommandExecutionError
62
+ autoload :CommandValidationError
63
+ autoload :NoHandlerError
64
+ end
65
+
66
+ autoload_at 'synapse/command/filters/validation' do
67
+ autoload :ActiveModelValidationFilter
68
+ autoload :ActiveModelValidationError
69
+ end
70
+
71
+ autoload_at 'synapse/command/interceptors/serialization' do
72
+ autoload :SerializationOptimizingInterceptor
73
+ autoload :SerializationOptimizingListener
74
+ end
75
+
76
+ autoload_at 'synapse/command/rollback_policy' do
77
+ autoload :RollbackPolicy
78
+ autoload :RollbackOnAnyExceptionPolicy
79
+ end
80
+
81
+ autoload :WiringCommandHandler, 'synapse/command/wiring'
82
+ end
83
+ end
84
+
85
+ module Domain
86
+ extend ActiveSupport::Autoload
87
+
88
+ eager_autoload do
89
+ autoload_at 'synapse/domain/aggregate_root' do
90
+ autoload :AggregateRoot
91
+ autoload :AggregateIdentifierNotInitializedError
92
+ end
93
+
94
+ autoload :EventContainer
95
+
96
+ autoload_at 'synapse/domain/message' do
97
+ autoload :EventMessage
98
+ autoload :DomainEventMessage
99
+ end
100
+
101
+ autoload_at 'synapse/domain/message_builder' do
102
+ autoload :EventMessageBuilder
103
+ autoload :DomainEventMessageBuilder
104
+ end
105
+
106
+ autoload_at 'synapse/domain/stream' do
107
+ autoload :DomainEventStream
108
+ autoload :EndOfStreamError
109
+ autoload :SimpleDomainEventStream
110
+ end
111
+ end
112
+ end
113
+
114
+ module EventBus
115
+ extend ActiveSupport::Autoload
116
+
117
+ eager_autoload do
118
+ autoload_at 'synapse/event_bus/event_bus' do
119
+ autoload :EventBus
120
+ autoload :SubscriptionFailedError
121
+ end
122
+
123
+ autoload :EventListener
124
+ autoload :EventListenerProxy
125
+ autoload :SimpleEventBus
126
+ autoload :WiringEventListener, 'synapse/event_bus/wiring'
127
+ end
128
+ end
129
+
130
+ module EventSourcing
131
+ extend ActiveSupport::Autoload
132
+
133
+ eager_autoload do
134
+ autoload_at 'synapse/event_sourcing/aggregate_factory' do
135
+ autoload :AggregateFactory
136
+ autoload :GenericAggregateFactory
137
+ end
138
+
139
+ autoload :AggregateRoot
140
+ autoload :Entity
141
+ autoload :Member
142
+
143
+ autoload :EventSourcingRepository, 'synapse/event_sourcing/repository'
144
+ autoload :EventSourcedStorageListener, 'synapse/event_sourcing/storage_listener'
145
+ autoload :EventStreamDecorator, 'synapse/event_sourcing/stream_decorator'
146
+
147
+ autoload_at 'synapse/event_sourcing/conflict_resolver' do
148
+ autoload :ConflictResolver
149
+ autoload :ConflictResolvingUnitOfWorkListener
150
+ autoload :CapturingEventStream
151
+ end
152
+
153
+ autoload_at 'synapse/event_sourcing/snapshot/taker' do
154
+ autoload :AggregateSnapshotTaker
155
+ autoload :DeferredSnapshotTaker
156
+ autoload :SnapshotTaker
157
+ end
158
+
159
+ autoload_at 'synapse/event_sourcing/snapshot/count_stream' do
160
+ autoload :CountingEventStream
161
+ autoload :TriggeringEventStream
162
+ autoload :SnapshotUnitOfWorkListener
163
+ end
164
+
165
+ autoload :EventCountSnapshotTrigger, 'synapse/event_sourcing/snapshot/count_trigger'
166
+ end
167
+ end
168
+
169
+ module EventStore
170
+ extend ActiveSupport::Autoload
171
+
172
+ eager_autoload do
173
+ autoload_at 'synapse/event_store/errors' do
174
+ autoload :EventStoreError
175
+ autoload :StreamNotFoundError
176
+ end
177
+
178
+ autoload_at 'synapse/event_store/event_store' do
179
+ autoload :EventStore
180
+ autoload :SnapshotEventStore
181
+ end
182
+ end
183
+
184
+ autoload :InMemoryEventStore, 'synapse/event_store/in_memory'
185
+
186
+ module Mongo
187
+ extend ActiveSupport::Autoload
188
+
189
+ autoload :CursorDomainEventStream, 'synapse/event_store/mongo/cursor_event_stream'
190
+ autoload :MongoEventStore, 'synapse/event_store/mongo/event_store'
191
+ autoload :DocumentPerEventStrategy, 'synapse/event_store/mongo/per_event_strategy'
192
+ autoload :DocumentPerCommitStrategy, 'synapse/event_store/mongo/per_commit_strategy'
193
+ autoload :StorageStrategy, 'synapse/event_store/mongo/storage_strategy'
194
+
195
+ autoload_at 'synapse/event_store/mongo/template' do
196
+ autoload :MongoTemplate
197
+ autoload :DefaultMongoTemplate
198
+ end
199
+ end
200
+ end
201
+
202
+ module ProcessManager
203
+ extend ActiveSupport::Autoload
204
+
205
+ autoload :Correlation
206
+ autoload :CorrelationResolver
207
+ autoload :CorrelationSet
208
+
209
+ autoload :Process
210
+ end
211
+
212
+ module Repository
213
+ extend ActiveSupport::Autoload
214
+
215
+ eager_autoload do
216
+ autoload_at 'synapse/repository/errors' do
217
+ autoload :AggregateNotFoundError
218
+ autoload :ConcurrencyError
219
+ autoload :ConflictingAggregateVersionError
220
+ autoload :ConflictingModificationError
221
+ end
222
+
223
+ autoload :LockManager
224
+ autoload :PessimisticLockManager
225
+
226
+ autoload_at 'synapse/repository/locking' do
227
+ autoload :LockingRepository
228
+ autoload :LockCleaningUnitOfWorkListener
229
+ end
230
+
231
+ autoload :Repository
232
+ end
233
+ end
234
+
235
+ module Serialization
236
+ extend ActiveSupport::Autoload
237
+
238
+ eager_autoload do
239
+ autoload :Converter
240
+ autoload :ConverterFactory, 'synapse/serialization/converter/factory'
241
+ autoload :IdentityConverter, 'synapse/serialization/converter/identity'
242
+
243
+ autoload_at 'synapse/serialization/errors' do
244
+ autoload :ConversionError
245
+ autoload :SerializationError
246
+ autoload :UnknownSerializedTypeError
247
+ end
248
+
249
+ autoload_at 'synapse/serialization/lazy_object' do
250
+ autoload :DeserializedObject
251
+ autoload :LazyObject
252
+ end
253
+
254
+ autoload_at 'synapse/serialization/revision_resolver' do
255
+ autoload :RevisionResolver
256
+ autoload :FixedRevisionResolver
257
+ end
258
+
259
+ autoload :SerializedDomainEventData, 'synapse/serialization/message/data'
260
+ autoload :MessageSerializer, 'synapse/serialization/message/serializer'
261
+ autoload :SerializedMetadata, 'synapse/serialization/message/metadata'
262
+ autoload :SerializationAware, 'synapse/serialization/message/serialization_aware'
263
+ autoload :SerializedObjectCache, 'synapse/serialization/message/serialized_object_cache'
264
+
265
+ autoload_at 'synapse/serialization/message/serialization_aware_message' do
266
+ autoload :SerializationAwareEventMessage
267
+ autoload :SerializationAwareDomainEventMessage
268
+ end
269
+
270
+ autoload_at 'synapse/serialization/message/serialized_message' do
271
+ autoload :SerializedMessage
272
+ autoload :SerializedEventMessage
273
+ autoload :SerializedDomainEventMessage
274
+ end
275
+
276
+ autoload_at 'synapse/serialization/message/serialized_message_builder' do
277
+ autoload :SerializedMessageBuilder
278
+ autoload :SerializedEventMessageBuilder
279
+ autoload :SerializedDomainEventMessageBuilder
280
+ end
281
+
282
+ autoload :Serializer
283
+ autoload :SerializedObject
284
+ autoload :SerializedType
285
+ end
286
+
287
+ autoload_at 'synapse/serialization/converter/json' do
288
+ autoload :JsonToObjectConverter
289
+ autoload :ObjectToJsonConverter
290
+ end
291
+
292
+ autoload_at 'synapse/serialization/converter/ox' do
293
+ autoload :XmlToOxDocumentConverter
294
+ autoload :OxDocumentToXmlConverter
295
+ end
296
+
297
+ autoload :OjSerializer, 'synapse/serialization/serializer/oj'
298
+ autoload :OxSerializer, 'synapse/serialization/serializer/ox'
299
+ autoload :MarshalSerializer, 'synapse/serialization/serializer/marshal'
300
+ end
301
+
302
+ module UnitOfWork
303
+ extend ActiveSupport::Autoload
304
+
305
+ eager_autoload do
306
+ autoload_at 'synapse/uow/nesting' do
307
+ autoload :NestableUnitOfWork
308
+ autoload :OuterCommitUnitOfWorkListener
309
+ end
310
+
311
+ autoload :StorageListener, 'synapse/uow/storage_listener'
312
+ autoload :TransactionManager, 'synapse/uow/transaction_manager'
313
+ autoload :UnitOfWork, 'synapse/uow/uow'
314
+ autoload :UnitOfWorkFactory, 'synapse/uow/factory'
315
+ autoload :UnitOfWorkListener, 'synapse/uow/listener'
316
+ autoload :UnitOfWorkListenerCollection, 'synapse/uow/listener_collection'
317
+ autoload :UnitOfWorkProvider, 'synapse/uow/provider'
318
+ end
319
+ end
320
+
321
+ module Upcasting
322
+ extend ActiveSupport::Autoload
323
+
324
+ autoload :SingleUpcaster
325
+ autoload :Upcaster
326
+ autoload :UpcasterChain, 'synapse/upcasting/chain'
327
+
328
+ autoload_at 'synapse/upcasting/context' do
329
+ autoload :UpcastingContext
330
+ autoload :SerializedDomainEventUpcastingContext
331
+ end
332
+
333
+ autoload :UpcastSerializedDomainEventData, 'synapse/upcasting/data'
334
+ end
335
+
336
+ module Wiring
337
+ extend ActiveSupport::Autoload
338
+
339
+ autoload :MessageWiring
340
+ autoload :Wire
341
+ autoload :WireRegistry
342
+ end
343
+
344
+ # TODO this is more of an application call
345
+ ActiveSupport::Autoload.eager_autoload!
346
+
347
+ # Setup the default identifier factory
348
+ ActiveSupport.on_load :identifier_factory do
349
+ IdentifierFactory.instance = GuidIdentifierFactory.new
350
+ end
351
+ end
@@ -0,0 +1,45 @@
1
+ module Synapse
2
+ module Command
3
+ # Represents a mechanism for dispatching commands to their appropriate handlers
4
+ #
5
+ # Command handlers can subscribe and unsubscribe to different command types. Only a single
6
+ # handler can be subscribed for a command type at one time.
7
+ #
8
+ # Implementations can choose to dispatch commands in the calling thread or in another thread.
9
+ #
10
+ # @abstract
11
+ class CommandBus
12
+ # Dispatches the given command to the handler subscribed to its type
13
+ #
14
+ # @abstract
15
+ # @param [CommandMessage] command
16
+ # @return [undefined]
17
+ def dispatch(command); end
18
+
19
+ # Dispatches the given command to the handler subscribed to its type and notifies the
20
+ # given callback of the outcome of the dispatch
21
+ #
22
+ # @abstract
23
+ # @param [CommandMessage] command
24
+ # @param [CommandCallback] callback
25
+ # @return [undefined]
26
+ def dispatch_with_callback(command, callback); end
27
+
28
+ # Subscribes the given handler to the given command type, replacing the currently subscribed
29
+ # handler, if any.
30
+ #
31
+ # @param [Class] command_type
32
+ # @param [CommandHandler] handler
33
+ # @return [undefined]
34
+ def subscribe(command_type, handler); end
35
+
36
+ # Unsubscribes the given handler from the given command type, if it is currently subscribed
37
+ # to the given command type.
38
+ #
39
+ # @param [Class] command_type
40
+ # @param [CommandHandler] handler
41
+ # @return [undefined]
42
+ def unsubscribe(command_type, handler); end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ module Synapse
2
+ module Command
3
+ # Callback that is notified of the outcome of the dispatch of a command
4
+ class CommandCallback
5
+ # Called when a dispatch is successful
6
+ #
7
+ # @param [Object] result The result from the command handler
8
+ # @return [undefined]
9
+ def on_success(result); end
10
+
11
+ # Called when a dispatch fails due to an exception
12
+ #
13
+ # @param [Exception] exception The cause of the failure
14
+ # @return [undefined]
15
+ def on_failure(exception); end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Synapse
2
+ module Command
3
+ # Represents a mechanism for validating or modifying commands before they are dispatched on
4
+ # the command bus. This filtering is done very early in the dispatch process, before a unit of
5
+ # work is created for the dispatch.
6
+ #
7
+ # @abstract
8
+ class CommandFilter
9
+ # Called when a command is preparing to be dispatched on the command bus
10
+ #
11
+ # @abstract
12
+ # @param [CommandMessage] command
13
+ # @return [CommandMessage] The command to dispatch on the bus
14
+ def filter(command); end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module Synapse
2
+ module Command
3
+ # Mixin for an object capable of handling commands
4
+ module CommandHandler
5
+ # Handles the given command
6
+ #
7
+ # @param [CommandMessage] command
8
+ # @param [UnitOfWork] current_unit Current unit of work
9
+ # @return [Object] The result of handling the given command
10
+ def handle(command, current_unit); end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ module Synapse
2
+ module Command
3
+ # Interceptor wrapping a command dispatch that can add custom behavior before or after a
4
+ # command is dispatched to a command handler
5
+ #
6
+ # @abstract
7
+ class DispatchInterceptor
8
+ # @abstract
9
+ # @param [CommandMessage] command
10
+ # @param [UnitOfWork] unit The current unit of work for this command dispatch
11
+ # @param [InterceptorChain] chain
12
+ # @return [Object] The result of the execution of the command
13
+ def intercept(command, unit, chain); end
14
+ end
15
+ end
16
+ end