Class ChannelBuilder<T>
- java.lang.Object
-
- de.quantummaid.eventmaid.channel.ChannelBuilder<T>
-
- Type Parameters:
T- the type of messages, that will be send over the createdChannel
public class ChannelBuilder<T> extends Object
TheChannelBuilderclass provides a fluent interface to create and configure aChannel.Most of the configurable properties have default values set by the builder. Only the default
Actionhas to be set manually. Per default a synchronousChannelis created with an exception handler, that throws exception once they occur.- See Also:
- EventMaid Documentation
-
-
Constructor Summary
Constructors Constructor Description ChannelBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ChannelBuilder<T>aChannel()Creates a newChannelBuilderstatic <T> ChannelBuilder<T>aChannel(Class<T> channelTypeClass)Creates a newChannelBuilderfor the given classstatic <T> Channel<T>aChannelWithDefaultAction(Action<T> defaultAction)Returns a synchronous Channel with the defaultActionChannel<T>build()Creates the configuredChannel.ChannelBuilder<T>forType(ChannelType type)Sets the type for theChannel.ChannelBuilder<T>withActionHandlerSet(ActionHandlerSet<T> actionHandlerSet)Overwrites the defaultActionHandlerSet, that can handle all built-inActions.ChannelBuilder<T>withAsynchronousConfiguration(AsynchronousConfiguration configuration)Adds anAsynchronousConfigurationto theChannel.ChannelBuilder<T>withChannelExceptionHandler(ChannelExceptionHandler<T> channelExceptionHandler)Sets a different exception handler for theChannel.ChannelBuilder<T>withDefaultAction(Action<T> action)Sets the defaultActionfor theChannel.
-
-
-
Method Detail
-
aChannelWithDefaultAction
public static <T> Channel<T> aChannelWithDefaultAction(Action<T> defaultAction)
Returns a synchronous Channel with the defaultActionThis is a short, more convenient form for
aChannel().withDefaultAction(action).build();- Type Parameters:
T- type of messages of the createdChannel- Parameters:
defaultAction- theChannel'sdefaultAction- Returns:
- the created
Channel
-
aChannel
public static <T> ChannelBuilder<T> aChannel()
Creates a newChannelBuilder- Type Parameters:
T- type of messages of the createdChannel- Returns:
- a new
ChannelBuilder
-
aChannel
public static <T> ChannelBuilder<T> aChannel(Class<T> channelTypeClass)
Creates a newChannelBuilderfor the given class- Type Parameters:
T- type of messages of the createdChannel- Parameters:
channelTypeClass- class of messages of the createdChannel- Returns:
- a new
ChannelBuilder
-
forType
public ChannelBuilder<T> forType(ChannelType type)
Sets the type for theChannel. Can beChannelType.SYNCHRONOUSorChannelType.ASYNCHRONOUS.Per default the type is set to synchronous and no further configuration is needed. If an asynchronous
Channelis to be created, an additionalAsynchronousConfigurationhas to be given. Also setting a differentChannelExceptionHandleris advised, as the default exception handler throws all exception on the executing Thread.- Parameters:
type- the type of theChannel. Can beChannelType.SYNCHRONOUSorChannelType.ASYNCHRONOUS.- Returns:
- the same
ChannelBuilderinstance the method was called one
-
withAsynchronousConfiguration
public ChannelBuilder<T> withAsynchronousConfiguration(AsynchronousConfiguration configuration)
Adds anAsynchronousConfigurationto theChannel.The asynchronous configuration is only used if the type of the
Channelis asynchronous.- Parameters:
configuration- the configuration for the asynchronousChannel- Returns:
- the same
ChannelBuilderinstance the method was called one
-
withDefaultAction
public ChannelBuilder<T> withDefaultAction(Action<T> action)
Sets the defaultActionfor theChannel.If the
Actionis a custom one, make sure that a matching handler is contained in the ActionHandlerSet.- Parameters:
action- the defaultActionof theChannel- Returns:
- the same
ChannelBuilderinstance the method was called one
-
withChannelExceptionHandler
public ChannelBuilder<T> withChannelExceptionHandler(ChannelExceptionHandler<T> channelExceptionHandler)
Sets a different exception handler for theChannel.Per default an exception handler is set, that rethrows all exceptions. This is not suitable for an asynchronous setting. So any asynchronous
Channelshould have a custom exception handler set.- Parameters:
channelExceptionHandler- the exception handler for theChannel- Returns:
- the same
ChannelBuilderinstance the method was called one
-
withActionHandlerSet
public ChannelBuilder<T> withActionHandlerSet(ActionHandlerSet<T> actionHandlerSet)
Overwrites the defaultActionHandlerSet, that can handle all built-inActions.Actions only contain relevant data. All logic about handling
Actionsat the end of theChannelis done by theActionHandler. For eachActiona matchingActionHandlershould be contained theActionHandlerSet. When using custom definedActions, theActionHandlerSetalways have to be modified, as an exception is raised, when anActionis encountered, for that no handler is known.- Parameters:
actionHandlerSet- the newActionHandlerSet- Returns:
- the same
ChannelBuilderinstance the method was called one
-
-