Interface MessageBus
-
- All Superinterfaces:
AutoCloseable,NoErrorAutoClosable
public interface MessageBus extends NoErrorAutoClosable
Messages of different types can be sent over aMessageBus.Subscribersinterested in specific messages can subscribe on these selected messages. AMessageBusallows addingFiltersto alter the message flow.- See Also:
- EventMaid Documentation
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(Filter<Object> filter)voidadd(Filter<Object> filter, int position)voidaddRaw(Filter<ProcessingContext<Object>> filter)voidaddRaw(Filter<ProcessingContext<Object>> filter, int position)booleanawaitTermination(long timeout, TimeUnit unit)Blocks the caller until all remaining tasks have completed execution after aclosehas been called, the timeout occurs or the current thread is interrupted.voidclose(boolean finishRemainingTasks)Closes theMessageBus.List<Filter<Object>>getFilter()Returns all currently addedFilters.MessageBusStatusInformationgetStatusInformation()Removes theMessageBusStatusInformationinterface, that allows querying statistics andSubscribers.booleanisClosed()Returnstrueifclosehas been called on thisMessageBus.SubscriptionIdonException(CorrelationId correlationId, MessageBusExceptionListener exceptionListener)Adds a dynamicMessageBusExceptionListenerfor the messages matching theCorrelationId.SubscriptionIdonException(EventType eventType, MessageBusExceptionListener exceptionListener)Adds a dynamicMessageBusExceptionListenerfor the messages with theEventTypevoidremove(Filter<Object> filter)Removes the givenFilter.MessageIdsend(EventType eventType, Object object)Sends the message with the givenEventType.MessageIdsend(EventType eventType, Object object, CorrelationId correlationId)Sends the message with the givenEventType.MessageIdsend(ProcessingContext<Object> processingContext)Sends theProcessingContexton theMessageBus.SubscriptionIdsubscribe(CorrelationId correlationId, Subscriber<ProcessingContext<Object>> subscriber)Adds the givenSubscriberfor all messages with a matchingCorrelationId.SubscriptionIdsubscribe(CorrelationId correlationId, Consumer<ProcessingContext<Object>> consumer)Adds the givenConsumerwrapped in aSubscriberobject for all messages with a matchingCorrelationId.SubscriptionIdsubscribe(EventType eventType, Subscriber<Object> subscriber)Adds the givenSubscriberfor all messages with a matchingEventType.SubscriptionIdsubscribe(EventType eventType, Consumer<Object> consumer)SubscriptionIdsubscribeRaw(EventType eventType, Subscriber<ProcessingContext<Object>> subscriber)Adds theSubscriberobject for all messages with a matchingEventType.SubscriptionIdsubscribeRaw(EventType eventType, Consumer<ProcessingContext<Object>> consumer)voidunregisterExceptionListener(SubscriptionId subscriptionId)Removes all exceptionListener with the givenSubscriptionId.voidunsubcribe(SubscriptionId subscriptionId)Removes allSubscriberswith the givenSubscriptionId-
Methods inherited from interface de.quantummaid.eventmaid.internal.autoclosable.NoErrorAutoClosable
close
-
-
-
-
Method Detail
-
send
MessageId send(EventType eventType, Object object)
Sends the message with the givenEventType.- Parameters:
eventType- theEventTypeto identify the messageobject- the message- Returns:
- the
MessageIdof the send message - Throws:
AlreadyClosedException- ifMessageBusalready closed
-
send
MessageId send(EventType eventType, Object object, CorrelationId correlationId)
Sends the message with the givenEventType.- Parameters:
eventType- theEventTypeto identify the messageobject- the messagecorrelationId- theCorrelationIdof the message- Returns:
- the
MessageIdof the send message - Throws:
AlreadyClosedException- ifMessageBusalready closed
-
send
MessageId send(ProcessingContext<Object> processingContext)
Sends theProcessingContexton theMessageBus.- Parameters:
processingContext- theProcessingContextto send- Returns:
- the
MessageIdof the send message - Throws:
AlreadyClosedException- ifMessageBusalready closed
-
subscribe
SubscriptionId subscribe(EventType eventType, Consumer<Object> consumer)
- Parameters:
eventType- theEventTypeof interestconsumer- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
subscribe
SubscriptionId subscribe(EventType eventType, Subscriber<Object> subscriber)
Adds the givenSubscriberfor all messages with a matchingEventType.- Parameters:
eventType- theEventTypeof interestsubscriber- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
subscribe
SubscriptionId subscribe(CorrelationId correlationId, Consumer<ProcessingContext<Object>> consumer)
Adds the givenConsumerwrapped in aSubscriberobject for all messages with a matchingCorrelationId.- Parameters:
correlationId- theCorrelationIdof interestconsumer- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
subscribe
SubscriptionId subscribe(CorrelationId correlationId, Subscriber<ProcessingContext<Object>> subscriber)
Adds the givenSubscriberfor all messages with a matchingCorrelationId.- Parameters:
correlationId- theCorrelationIdof interestsubscriber- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
subscribeRaw
SubscriptionId subscribeRaw(EventType eventType, Consumer<ProcessingContext<Object>> consumer)
Adds the givenConsumerwrapped in aSubscriberobject for all messages with a matchingEventType. TheSubscribergets access to the underlyingProcessingContext.- Parameters:
eventType- theEventTypeof interestconsumer- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
subscribeRaw
SubscriptionId subscribeRaw(EventType eventType, Subscriber<ProcessingContext<Object>> subscriber)
Adds theSubscriberobject for all messages with a matchingEventType. TheSubscribergets access to the underlyingProcessingContext.- Parameters:
eventType- theEventTypeof interestsubscriber- theSubscriberto add- Returns:
- the
SubscriptionIdof theSubscriber
-
unsubcribe
void unsubcribe(SubscriptionId subscriptionId)
Removes allSubscriberswith the givenSubscriptionId- Parameters:
subscriptionId- theSubscriptionIdto removeSubscribers
-
add
void add(Filter<Object> filter, int position)
- Parameters:
filter- theFilterto be addedposition- the position of theFilter- Throws:
ArrayIndexOutOfBoundsException- if the position is higher than the number ofFilteror negative
-
addRaw
void addRaw(Filter<ProcessingContext<Object>> filter)
- Parameters:
filter- theFilterto be added
-
addRaw
void addRaw(Filter<ProcessingContext<Object>> filter, int position)
- Parameters:
filter- theFilterto be addedposition- the position of theFilter
-
getFilter
List<Filter<Object>> getFilter()
Returns all currently addedFilters.- Returns:
- all
Filters
-
remove
void remove(Filter<Object> filter)
Removes the givenFilter.- Parameters:
filter- theFilterto remove
-
onException
SubscriptionId onException(EventType eventType, MessageBusExceptionListener exceptionListener)
Adds a dynamicMessageBusExceptionListenerfor the messages with theEventType- Parameters:
eventType- theEventTypeto matchexceptionListener- theMessageBusExceptionListenerto add- Returns:
- a
SubscriptionIdidentifying exception listener
-
onException
SubscriptionId onException(CorrelationId correlationId, MessageBusExceptionListener exceptionListener)
Adds a dynamicMessageBusExceptionListenerfor the messages matching theCorrelationId.- Parameters:
correlationId- theCorrelationIdto matchexceptionListener- theMessageBusExceptionListenerto add- Returns:
- a
SubscriptionIdidentifying exception listener
-
unregisterExceptionListener
void unregisterExceptionListener(SubscriptionId subscriptionId)
Removes all exceptionListener with the givenSubscriptionId.- Parameters:
subscriptionId- theSubscriptionIdto remove exception listener for
-
getStatusInformation
MessageBusStatusInformation getStatusInformation()
Removes theMessageBusStatusInformationinterface, that allows querying statistics andSubscribers.- Returns:
- the
MessageBusStatusInformationinterface
-
close
void close(boolean finishRemainingTasks)
Closes theMessageBus.- Parameters:
finishRemainingTasks- whentrue, theMessageBustries to deliver queued messages, otherwise they are discarded
-
awaitTermination
boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedExceptionBlocks the caller until all remaining tasks have completed execution after aclosehas been called, the timeout occurs or the current thread is interrupted.- Parameters:
timeout- the duration to waitunit- the time unit of the timeout- Returns:
trueif thisMessageBusterminated,falseif the timeout elapsed before termination orfalseifclosewas not yet called- Throws:
InterruptedException- if interrupted while waiting
-
isClosed
boolean isClosed()
Returnstrueifclosehas been called on thisMessageBus.- Returns:
- true, if a
closewas already called, or false otherwise
-
-