Class AbstractCommandBus
- java.lang.Object
-
- dk.cloudcreate.essentials.reactive.command.AbstractCommandBus
-
- All Implemented Interfaces:
CommandBus
- Direct Known Subclasses:
LocalCommandBus
public abstract class AbstractCommandBus extends Object implements CommandBus
Base implementation of theCommandBus- provides default implementation for all operations except forCommandBus.sendAndDontWait(Object)/CommandBus.sendAndDontWait(Object, Duration)
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<CommandHandler>commandHandlersprotected ConcurrentMap<Class<?>,CommandHandler>commandTypeToCommandHandlerCacheKey: Concrete Command type
Value:CommandHandlerthat can handle the command typeprotected List<CommandBusInterceptor>interceptorsprotected SendAndDontWaitErrorHandlersendAndDontWaitErrorHandler
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCommandBus(SendAndDontWaitErrorHandler sendAndDontWaitErrorHandler, List<CommandBusInterceptor> interceptors)protectedAbstractCommandBus(List<CommandBusInterceptor> interceptors)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandBusaddCommandHandler(CommandHandler commandHandler)Add a new command handler.CommandBusaddInterceptor(CommandBusInterceptor interceptor)Add a new interceptorCommandHandlerfindCommandHandlerCapableOfHandling(Object command)Find aCommandHandlercapable of handling the given commandList<CommandBusInterceptor>getInterceptors()Returns 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 interceptorCommandBusremoveCommandHandler(CommandHandler commandHandler)Remove a command handler.CommandBusremoveInterceptor(CommandBusInterceptor interceptor)Remove an interceptor<R,C>
Rsend(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()threadStringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface dk.cloudcreate.essentials.reactive.command.CommandBus
sendAndDontWait, sendAndDontWait
-
-
-
-
Field Detail
-
interceptors
protected final List<CommandBusInterceptor> interceptors
-
commandHandlers
protected final Set<CommandHandler> commandHandlers
-
sendAndDontWaitErrorHandler
protected final SendAndDontWaitErrorHandler sendAndDontWaitErrorHandler
-
commandTypeToCommandHandlerCache
protected final ConcurrentMap<Class<?>,CommandHandler> commandTypeToCommandHandlerCache
Key: Concrete Command type
Value:CommandHandlerthat can handle the command type
-
-
Constructor Detail
-
AbstractCommandBus
protected AbstractCommandBus(List<CommandBusInterceptor> interceptors)
-
AbstractCommandBus
protected AbstractCommandBus(SendAndDontWaitErrorHandler sendAndDontWaitErrorHandler, List<CommandBusInterceptor> interceptors)
-
-
Method Detail
-
getInterceptors
public List<CommandBusInterceptor> getInterceptors()
Description copied from interface:CommandBusReturns an immutable list of interceptors- Specified by:
getInterceptorsin interfaceCommandBus- Returns:
- Returns an immutable list of interceptors
-
addInterceptor
public CommandBus addInterceptor(CommandBusInterceptor interceptor)
Description copied from interface:CommandBusAdd a new interceptor- Specified by:
addInterceptorin interfaceCommandBus- Parameters:
interceptor- the interceptor to add- Returns:
- this bus instance
-
hasInterceptor
public boolean hasInterceptor(CommandBusInterceptor interceptor)
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
public CommandBus removeInterceptor(CommandBusInterceptor interceptor)
Description copied from interface:CommandBusRemove an interceptor- Specified by:
removeInterceptorin interfaceCommandBus- Parameters:
interceptor- the interceptor to remove- Returns:
- this bus instance
-
addCommandHandler
public CommandBus addCommandHandler(CommandHandler commandHandler)
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
public CommandBus removeCommandHandler(CommandHandler commandHandler)
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
public CommandHandler findCommandHandlerCapableOfHandling(Object command)
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
public boolean hasCommandHandler(CommandHandler commandHandler)
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
-
-