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 ofChannels. This handler can be implemented by plugin developers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceChannelExceptionHandler.Factory
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidhandle(C connection, Channel channel, ChannelException exception, @Nullable java.util.concurrent.CompletableFuture<?> future)Handles aChannelExceptionthat occurred for a specificEngineConnection.static ChannelExceptionHandler<EngineConnection>logEverything()Gets theChannelExceptionHandlerthat will always log when aChannelExceptionoccurs.default ChannelExceptionHandler<C>suppress(java.lang.Class<? extends ChannelException> exceptionType)Returns a newChannelExceptionHandlerthat suppresses a certain type ofChannelExceptionto be handled through this exception handler.default ChannelExceptionHandler<C>suppressAllIfFutureIsPresent()Returns a newChannelExceptionHandlerthat suppresses everyChannelExceptionto be handled through this exception handler if aCompletableFutureis applicable.default ChannelExceptionHandler<C>suppressIfFutureIsPresent(java.lang.Class<? extends ChannelException> exceptionType)Returns a newChannelExceptionHandlerthat suppressesChannelExceptionof the given type to be handled through this exception handler if aCompletableFutureis applicable.
-
-
-
Method Detail
-
logEverything
static ChannelExceptionHandler<EngineConnection> logEverything()
Gets theChannelExceptionHandlerthat will always log when aChannelExceptionoccurs.CompletableFutures will also receive theChannelExceptions like expected.This
ChannelExceptionHandleris useful if you don't need special handling for exceptions. This handler can be customized through the suppress methods.- Returns:
- The channel exception handler
-
handle
void handle(C connection, Channel channel, ChannelException exception, @Nullable java.util.concurrent.CompletableFuture<?> future)
Handles aChannelExceptionthat occurred for a specificEngineConnection. This includes exceptions caused by encoding or decoding payloads, handling packets, when a packet is send to an unsupported connection, etc.The
CompletableFutureis 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 forchannel- The channel the exception occurred onexception- The exception the occurredfuture- The future of the send operation or receive operation
-
suppressAllIfFutureIsPresent
default ChannelExceptionHandler<C> suppressAllIfFutureIsPresent()
Returns a newChannelExceptionHandlerthat suppresses everyChannelExceptionto be handled through this exception handler if aCompletableFutureis applicable.This
ChannelExceptionHandleris useful if you're planning to handle every exception of the returnedCompletableFutures.- Returns:
- The new channel exception handler
-
suppressIfFutureIsPresent
default ChannelExceptionHandler<C> suppressIfFutureIsPresent(java.lang.Class<? extends ChannelException> exceptionType)
Returns a newChannelExceptionHandlerthat suppressesChannelExceptionof the given type to be handled through this exception handler if aCompletableFutureis applicable.The returned
ChannelExceptionHandleris useful if you're planning to handle certain exception types of the returnedCompletableFutures.- 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 newChannelExceptionHandlerthat suppresses a certain type ofChannelExceptionto be handled through this exception handler. TheCompletableFutures will still receive the exception.This is useful to suppress certain exceptions from being logged. For example
ChannelNotSupportedExceptioncan 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 theCompletableFutures.- Parameters:
exceptionType- The exception type to suppress- Returns:
- The new channel exception handler
-
-