Interface ChannelExceptionHandler<C extends EngineConnection>

  • Type Parameters:
    C - The connection type
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ChannelExceptionHandler<C extends EngineConnection>
    Represents a handler for exceptions of Channels. This handler can be implemented by plugin developers.
    • Method Detail

      • handle

        void handle​(C connection,
                    Channel channel,
                    ChannelException exception,
                    @Nullable java.util.concurrent.CompletableFuture<?> future)
        Handles a ChannelException that occurred for a specific EngineConnection. This includes exceptions caused by encoding or decoding payloads, handling packets, when a packet is send to an unsupported connection, etc.

        The CompletableFuture is the one that was returned by one of the send operations, this one must be completed when an exception occurs. The future is always null when a request packet is being handled on the other side.

        Parameters:
        connection - The connection that the exception occurred for
        channel - The channel the exception occurred on
        exception - The exception the occurred
        future - The future of the send operation or receive operation
      • suppressIfFutureIsPresent

        default ChannelExceptionHandler<C> suppressIfFutureIsPresent​(java.lang.Class<? extends ChannelException> exceptionType)
        Returns a new ChannelExceptionHandler that suppresses ChannelException of the given type to be handled through this exception handler if a CompletableFuture is applicable.

        The returned ChannelExceptionHandler is useful if you're planning to handle certain exception types of the returned CompletableFutures.

        Parameters:
        exceptionType - The exception type to suppress
        Returns:
        The new channel exception handler
      • suppress

        default ChannelExceptionHandler<C> suppress​(java.lang.Class<? extends ChannelException> exceptionType)
        Returns a new ChannelExceptionHandler that suppresses a certain type of ChannelException to be handled through this exception handler. The CompletableFutures will still receive the exception.

        This is useful to suppress certain exceptions from being logged. For example ChannelNotSupportedException can be suppressed if you don't want to log the exception every time you send a payload to a connection that doesn't support the channel. Then you can handle this through the CompletableFutures.

        Parameters:
        exceptionType - The exception type to suppress
        Returns:
        The new channel exception handler