Class ChannelBuilder<T>

  • Type Parameters:
    T - the type of messages, that will be send over the created Channel

    public class ChannelBuilder<T>
    extends Object
    The ChannelBuilder class provides a fluent interface to create and configure a Channel.

    Most of the configurable properties have default values set by the builder. Only the default Action has to be set manually. Per default a synchronous Channel is created with an exception handler, that throws exception once they occur.

    See Also:
    EventMaid Documentation
    • Constructor Detail

      • ChannelBuilder

        public ChannelBuilder()
    • Method Detail

      • aChannelWithDefaultAction

        public static <T> Channel<T> aChannelWithDefaultAction​(Action<T> defaultAction)
        Returns a synchronous Channel with the default Action

        This is a short, more convenient form for

        
              aChannel().withDefaultAction(action).build();
         
        Type Parameters:
        T - type of messages of the created Channel
        Parameters:
        defaultAction - the Channel's default Action
        Returns:
        the created Channel
      • aChannel

        public static <T> ChannelBuilder<T> aChannel()
        Creates a new ChannelBuilder
        Type Parameters:
        T - type of messages of the created Channel
        Returns:
        a new ChannelBuilder
      • aChannel

        public static <T> ChannelBuilder<T> aChannel​(Class<T> channelTypeClass)
        Creates a new ChannelBuilder for the given class
        Type Parameters:
        T - type of messages of the created Channel
        Parameters:
        channelTypeClass - class of messages of the created Channel
        Returns:
        a new ChannelBuilder
      • forType

        public ChannelBuilder<T> forType​(ChannelType type)
        Sets the type for the Channel. Can be ChannelType.SYNCHRONOUS or ChannelType.ASYNCHRONOUS.

        Per default the type is set to synchronous and no further configuration is needed. If an asynchronous Channel is to be created, an additional AsynchronousConfiguration has to be given. Also setting a different ChannelExceptionHandler is advised, as the default exception handler throws all exception on the executing Thread.

        Parameters:
        type - the type of the Channel. Can be ChannelType.SYNCHRONOUS or ChannelType.ASYNCHRONOUS.
        Returns:
        the same ChannelBuilder instance the method was called one
      • withAsynchronousConfiguration

        public ChannelBuilder<T> withAsynchronousConfiguration​(AsynchronousConfiguration configuration)
        Adds an AsynchronousConfiguration to the Channel.

        The asynchronous configuration is only used if the type of the Channel is asynchronous.

        Parameters:
        configuration - the configuration for the asynchronous Channel
        Returns:
        the same ChannelBuilder instance the method was called one
      • withDefaultAction

        public ChannelBuilder<T> withDefaultAction​(Action<T> action)
        Sets the default Action for the Channel.

        If the Action is a custom one, make sure that a matching handler is contained in the ActionHandlerSet.

        Parameters:
        action - the default Action of the Channel
        Returns:
        the same ChannelBuilder instance the method was called one
      • withChannelExceptionHandler

        public ChannelBuilder<T> withChannelExceptionHandler​(ChannelExceptionHandler<T> channelExceptionHandler)
        Sets a different exception handler for the Channel.

        Per default an exception handler is set, that rethrows all exceptions. This is not suitable for an asynchronous setting. So any asynchronous Channel should have a custom exception handler set.

        Parameters:
        channelExceptionHandler - the exception handler for the Channel
        Returns:
        the same ChannelBuilder instance the method was called one
      • withActionHandlerSet

        public ChannelBuilder<T> withActionHandlerSet​(ActionHandlerSet<T> actionHandlerSet)
        Overwrites the default ActionHandlerSet, that can handle all built-in Actions.

        Actions only contain relevant data. All logic about handling Actions at the end of the Channel is done by the ActionHandler. For each Action a matching ActionHandler should be contained the ActionHandlerSet. When using custom defined Actions, the ActionHandlerSet always have to be modified, as an exception is raised, when an Action is encountered, for that no handler is known.

        Parameters:
        actionHandlerSet - the new ActionHandlerSet
        Returns:
        the same ChannelBuilder instance the method was called one
      • build

        public Channel<T> build()
        Creates the configured Channel.
        Returns:
        the configured Channel