Interface ChannelHandler<C extends ListenerContext>
- Type Parameters:
C
- the listener context
- 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 ChannelHandler<C extends ListenerContext>
This is supposed to be implemented by API users to accomplish packet handling functionalities.
- See Also:
PacketReceiver
-
Method Details
-
receive
Receives a packet.This method is executed on netty's event loops. Modification to the game should be scheduled.
The
buf
will be released on exiting this method. To ensure access to the buf later, you shouldretain
thebuf
.An example usage can be like below, assuming
C
is a client context:(context, buf) -&rt; { String message = buf.readString(32767); context.getEngine().submit(() -&rt; { context.getEngine().send(() -&rt; context.getEngine().inGameHud.setOverlayMessage(message, true)); }); }
When this method throws an exception, it will be captured and logged. The exception will be fed to
rethrow(Throwable)
, which by default throws the exception to the event loop and handled byClientConnection.exceptionCaught(ChannelHandlerContext, Throwable)
, causing a disconnection.- Parameters:
context
- the context for the packetbuf
- the content of the packet
-
rethrow
Handles a exception thrown byreceive(ListenerContext, PacketByteBuf)
.By default, this implementation will simply throw the captured exception.
Throwables thrown by this method will be handled by
ClientConnection.exceptionCaught(ChannelHandlerContext, Throwable)
.- Type Parameters:
E
- the throwable type variable, which allows throwing any throwable as unchecked- Parameters:
ex
- the captured exception- Throws:
E
- any exception as a result of exception handling.
-