Class AbstractCommandBus
java.lang.Object
dk.cloudcreate.essentials.reactive.command.AbstractCommandBus
- All Implemented Interfaces:
CommandBus
- Direct Known Subclasses:
LocalCommandBus
Base implementation of the
CommandBus - provides default implementation for all
operations except for CommandBus.sendAndDontWait(Object)/CommandBus.sendAndDontWait(Object, Duration)-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Set<CommandHandler>protected final ConcurrentMap<Class<?>,CommandHandler> Key: Concrete Command type
Value:CommandHandlerthat can handle the command typeprotected final List<CommandBusInterceptor>protected final SendAndDontWaitErrorHandler -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCommandBus(SendAndDontWaitErrorHandler sendAndDontWaitErrorHandler, List<CommandBusInterceptor> interceptors) protectedAbstractCommandBus(List<CommandBusInterceptor> interceptors) -
Method Summary
Modifier and TypeMethodDescriptionaddCommandHandler(CommandHandler commandHandler) Add a new command handler.addInterceptor(CommandBusInterceptor interceptor) Add a new interceptorFind aCommandHandlercapable of handling the given commandReturns an immutable list of interceptorsbooleanhasCommandHandler(CommandHandler commandHandler) Guard method to test if theCommandBusalready contains the commandHandlerbooleanhasInterceptor(CommandBusInterceptor interceptor) Guard method to test if theCommandBusalready contains the interceptorremoveCommandHandler(CommandHandler commandHandler) Remove a command handler.removeInterceptor(CommandBusInterceptor interceptor) Remove an interceptor<R,C> R send(C command) The send command synchronously and process the command on the sending thread<R,C> reactor.core.publisher.Mono<R> sendAsync(C command) The send command asynchronously and process the command on aSchedulers.boundedElastic()threadtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dk.cloudcreate.essentials.reactive.command.CommandBus
addInterceptors, sendAndDontWait, sendAndDontWait
-
Field Details
-
interceptors
-
commandHandlers
-
sendAndDontWaitErrorHandler
-
commandTypeToCommandHandlerCache
Key: Concrete Command type
Value:CommandHandlerthat can handle the command type
-
-
Constructor Details
-
AbstractCommandBus
-
AbstractCommandBus
protected AbstractCommandBus(SendAndDontWaitErrorHandler sendAndDontWaitErrorHandler, List<CommandBusInterceptor> interceptors)
-
-
Method Details
-
getInterceptors
Description copied from interface:CommandBusReturns an immutable list of interceptors- Specified by:
getInterceptorsin interfaceCommandBus- Returns:
- Returns an immutable list of interceptors
-
addInterceptor
Description copied from interface:CommandBusAdd a new interceptor- Specified by:
addInterceptorin interfaceCommandBus- Parameters:
interceptor- the interceptor to add- Returns:
- this bus instance
-
hasInterceptor
Description copied from interface:CommandBusGuard method to test if theCommandBusalready contains the interceptor- Specified by:
hasInterceptorin interfaceCommandBus- Parameters:
interceptor- the interceptor to check- Returns:
- true if the
CommandBusalready contains the interceptor, otherwise false
-
removeInterceptor
Description copied from interface:CommandBusRemove an interceptor- Specified by:
removeInterceptorin interfaceCommandBus- Parameters:
interceptor- the interceptor to remove- Returns:
- this bus instance
-
addCommandHandler
Description copied from interface:CommandBusAdd a new command handler.- Specified by:
addCommandHandlerin interfaceCommandBus- Parameters:
commandHandler- the command handler to add- Returns:
- this bus instance
-
removeCommandHandler
Description copied from interface:CommandBusRemove a command handler.- Specified by:
removeCommandHandlerin interfaceCommandBus- Parameters:
commandHandler- the command handler to remove- Returns:
- this bus instance
-
send
public <R,C> R send(C command) Description copied from interface:CommandBusThe send command synchronously and process the command on the sending thread- Specified by:
sendin interfaceCommandBus- Type Parameters:
R- the return typeC- the command type- Parameters:
command- the command to send- Returns:
- the result of the command processing (if any)
-
sendAsync
public <R,C> reactor.core.publisher.Mono<R> sendAsync(C command) Description copied from interface:CommandBusThe send command asynchronously and process the command on aSchedulers.boundedElastic()thread- Specified by:
sendAsyncin interfaceCommandBus- Type Parameters:
R- the return typeC- the command type- Parameters:
command- the command to send- Returns:
- a
Monothat will contain the result of the command processing (if any)
-
findCommandHandlerCapableOfHandling
Description copied from interface:CommandBusFind aCommandHandlercapable of handling the given command- Specified by:
findCommandHandlerCapableOfHandlingin interfaceCommandBus- Parameters:
command- the command to handle- Returns:
- the single
CommandHandlerthat's capable of handling the given command
-
hasCommandHandler
Description copied from interface:CommandBusGuard method to test if theCommandBusalready contains the commandHandler- Specified by:
hasCommandHandlerin interfaceCommandBus- Parameters:
commandHandler- the commandHandler to check- Returns:
- true if the
CommandBusalready contains the commandHandler, otherwise false
-
toString
-