Interface Channel<T>
-
- Type Parameters:
T- the type of messages send over thisChannel
- All Superinterfaces:
AutoCloseable,NoErrorAutoClosable
public interface Channel<T> extends NoErrorAutoClosable
Channelis the concept used for transporting messages from sender to an consumingActionat the end of theChannel.Each
Channelhas a defaultAction, which, if not changed by aFilter, is executed for every message at the end of the transport. DifferentActionexists, that allow to addSubscriber, execute specific logic or move the message to differentChannels. During the transportFiltercan be added, that alter the message, its flow or theAction.Channelscan be synchronous or asynchronous. SynchronousChannelexecute the transport on the Thread callingsend. AsynchronousChannelsprovide their own Threads and mechanism to queue messages, for which no Threads is available right away. Messages collect statistics over messages, that can be queried anytime. During creation exception handler can be set, that control theChannel'sbehavior, when an exception is thrown.The
Channelimplements theAutoCloseableinterface, so that it can be used in try-with-resource statements.- See Also:
- EventMaid Documentation,
ChannelBuilder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddPostFilter(Filter<ProcessingContext<T>> filter)Adds theFilterto the list of postFilter.voidaddPostFilter(Filter<ProcessingContext<T>> filter, int position)Adds theFilterat the given position to the list of postFilter.voidaddPreFilter(Filter<ProcessingContext<T>> filter)Adds theFilterto the list of preFilter.voidaddPreFilter(Filter<ProcessingContext<T>> filter, int position)Adds theFilterat the given position to the list of preFilter.voidaddProcessFilter(Filter<ProcessingContext<T>> filter)Adds theFilterto the list of processFilter.voidaddProcessFilter(Filter<ProcessingContext<T>> filter, int position)Adds theFilterat the given position to the list of processFilter.booleanawaitTermination(int timeout, TimeUnit timeUnit)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 theChannelso that it shutdowns.Action<T>getDefaultAction()Returns the defaultActionof thisChannel.List<Filter<ProcessingContext<T>>>getPostFilter()Returns a list of allFilterregistered in the post list.List<Filter<ProcessingContext<T>>>getPreFilter()Returns a list of allFilterregistered in the pre list.List<Filter<ProcessingContext<T>>>getProcessFilter()Returns a list of allFilterregistered in the process list.ChannelStatusInformationgetStatusInformation()Returns aChannelStatusInformationobject, which can be used to query theChannel'sstatistics.booleanisClosed()Returnstrueifclosehas been called on thisChannel.voidremovePostFilter(Filter<ProcessingContext<T>> filter)Removes theFilterfrom the post list.voidremovePreFilter(Filter<ProcessingContext<T>> filter)Removes theFilterfrom the pre list.voidremoveProcessFilter(Filter<ProcessingContext<T>> filter)Removes theFilterfrom the process list.MessageIdsend(ProcessingContext<T> processingContext)Send the given processingContext object over thisChannel.MessageIdsend(T message)Send the given message over thisChannel.MessageIdsend(T message, CorrelationId correlationId)Send the given message over thisChannelwith the givenCorrelationId.-
Methods inherited from interface de.quantummaid.eventmaid.internal.autoclosable.NoErrorAutoClosable
close
-
-
-
-
Method Detail
-
send
MessageId send(T message)
Send the given message over thisChannel.- Parameters:
message- the message to be sent- Returns:
- the
MessageIdof the send message - Throws:
AlreadyClosedException- if theChannelis already closed
-
send
MessageId send(T message, CorrelationId correlationId)
Send the given message over thisChannelwith the givenCorrelationId.- Parameters:
message- the message to be sentcorrelationId- theCorrelationIdof the message- Returns:
- the
MessageIdof the send message - Throws:
AlreadyClosedException- if theChannelis already closed
-
send
MessageId send(ProcessingContext<T> processingContext)
Send the given processingContext object over thisChannel.ChannelsuseProcessingContextobjects internally to store and share processing relevant information. Examples are a shared key-value map or the history of pastChannels. In case severalChannelsare logical connected and the information and history should be kept,Channelscan accept theProcessingContextobject of the previousChanneldirectly.- Parameters:
processingContext- theProcessingContextto be sent- Returns:
- the
ProcessingContext'sMessageId - Throws:
AlreadyClosedException- if theChannelis already closed
-
addPreFilter
void addPreFilter(Filter<ProcessingContext<T>> filter)
Adds theFilterto the list of preFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be added
-
addPreFilter
void addPreFilter(Filter<ProcessingContext<T>> filter, int position)
Adds theFilterat the given position to the list of preFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be addedposition- the position of theFilter- Throws:
ArrayIndexOutOfBoundsException- if the position is higher than the number ofFilteror negative
-
getPreFilter
List<Filter<ProcessingContext<T>>> getPreFilter()
Returns a list of allFilterregistered in the pre list.- Returns:
- list of
Filterin the pre position
-
removePreFilter
void removePreFilter(Filter<ProcessingContext<T>> filter)
Removes theFilterfrom the pre list.- Parameters:
filter- theFilterto be removed
-
addProcessFilter
void addProcessFilter(Filter<ProcessingContext<T>> filter)
Adds theFilterto the list of processFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be added
-
addProcessFilter
void addProcessFilter(Filter<ProcessingContext<T>> filter, int position)
Adds theFilterat the given position to the list of processFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be addedposition- the position of theFilter- Throws:
ArrayIndexOutOfBoundsException- if the position is higher than the number ofFilteror negative
-
getProcessFilter
List<Filter<ProcessingContext<T>>> getProcessFilter()
Returns a list of allFilterregistered in the process list.- Returns:
- list of
Filterin the process position
-
removeProcessFilter
void removeProcessFilter(Filter<ProcessingContext<T>> filter)
Removes theFilterfrom the process list.- Parameters:
filter- theFilterto be removed
-
addPostFilter
void addPostFilter(Filter<ProcessingContext<T>> filter)
Adds theFilterto the list of postFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be added
-
addPostFilter
void addPostFilter(Filter<ProcessingContext<T>> filter, int position)
Adds theFilterat the given position to the list of postFilter.Each
Channelhas three points, whereFiltercan be added: pre, process and post. All preFilterwill always be executed before the first processFilter. The same goes for process and postFilter.- Parameters:
filter- theFilterto be addedposition- the position of theFilter- Throws:
ArrayIndexOutOfBoundsException- if the position is higher than the number ofFilteror negative
-
getPostFilter
List<Filter<ProcessingContext<T>>> getPostFilter()
Returns a list of allFilterregistered in the post list.- Returns:
- list of
Filterin the post position
-
removePostFilter
void removePostFilter(Filter<ProcessingContext<T>> filter)
Removes theFilterfrom the post list.- Parameters:
filter- theFilterto be removed
-
getDefaultAction
Action<T> getDefaultAction()
Returns the defaultActionof thisChannel.- Returns:
- the default
Actionof thisChannel
-
getStatusInformation
ChannelStatusInformation getStatusInformation()
Returns aChannelStatusInformationobject, which can be used to query theChannel'sstatistics.- Returns:
- a
ChannelStatusInformationobject
-
close
void close(boolean finishRemainingTasks)
Closes theChannelso that it shutdowns.When setting the parameter to true, the
Channeltries to finish remaining tasks, that are still pending. Setting the parameter to false instructs theChannelto shutdown immediately. It is not defined how unfinished tasks should be handled. Independent of the parameter, theChannelwill be closed. All tries to send messages will result in exceptions.- Parameters:
finishRemainingTasks- boolean flag indicating, whether theChannelshould try to finish pending tasks
-
isClosed
boolean isClosed()
Returnstrueifclosehas been called on thisChannel.- Returns:
- true, if a
closewas already called, or false otherwise
-
awaitTermination
boolean awaitTermination(int timeout, TimeUnit timeUnit) 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 waittimeUnit- the time unit of the timeout- Returns:
trueif thisChannelterminated,falseif the timeout elapsed before termination orfalseifclosewas not yet called- Throws:
InterruptedException- if interrupted while waiting
-
-