Package yapion.packet
Class YAPIONPacketReceiver
- java.lang.Object
-
- yapion.packet.YAPIONPacketReceiver
-
public class YAPIONPacketReceiver extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description YAPIONPacketReceiver()
Creates an YAPIONPacketReceiver
-
Method Summary
Modifier and Type Method Description YAPIONPacketReceiver
add(java.lang.Class<? extends YAPIONPacket>[] packetTypes, YAPIONPacketHandler yapionPacketHandler)
Add an YAPIONPacketHandler for the specified packetTypes to handle.YAPIONPacketReceiver
add(java.lang.Class<? extends YAPIONPacket> packetType, YAPIONPacketHandler yapionPacketHandler)
Add an YAPIONPacketHandler for a specified packetType to handle.YAPIONPacketReceiver
add(YAPIONPacketHandler yapionPacketHandler, java.lang.Class<? extends YAPIONPacket> packetType)
A wrapper function toadd(Class, YAPIONPacketHandler)
YAPIONPacketReceiver
add(YAPIONPacketHandler yapionPacketHandler, java.lang.Class<? extends YAPIONPacket>... packetTypes)
A wrapper function toadd(Class[], YAPIONPacketHandler)
void
handle(YAPIONPacket yapionPacket)
Handles an YAPIONPacket by calling the specified yapionPacketHandler for the type of the packet.YAPIONPacketReceiver
setDeserializationExceptionHandler(YAPIONPacketHandler yapionPacketHandler)
Set the Deserialization ExceptionYAPIONPacketHandler
to do something when a deserialization exception occurred.YAPIONPacketReceiver
setDropHandler(YAPIONPacketHandler yapionPacketHandler)
Set the DropYAPIONPacketHandler
to do something when a data drop occurred.YAPIONPacketReceiver
setErrorHandler(YAPIONPacketHandler yapionPacketHandler)
Set the ErrorYAPIONPacketHandler
to do something when an error occurred.YAPIONPacketReceiver
setExceptionHandler(YAPIONPacketHandler yapionPacketHandler)
Set the ExceptionYAPIONPacketHandler
to do something when an exception gets thrown.YAPIONPacketReceiver
setHandleFailedHandler(YAPIONPacketHandler yapionPacketHandler)
Set the HandleFailedYAPIONPacketHandler
to do something when the internalYAPIONInputStream
.handle() failed.YAPIONPacketReceiver
setUnknownHandler(YAPIONPacketHandler yapionPacketHandler)
Set the UnknownYAPIONPacketHandler
to do something when an unknown packet was handled occurred.
-
-
-
Method Detail
-
add
public YAPIONPacketReceiver add(java.lang.Class<? extends YAPIONPacket> packetType, YAPIONPacketHandler yapionPacketHandler)
Add an YAPIONPacketHandler for a specified packetType to handle. If either the packetType or yapionPacketHandler isnull
this method throws an YAPIONPacketException.- Parameters:
packetType
- the packet to handleyapionPacketHandler
- the handler which handles the specified packet
-
add
public YAPIONPacketReceiver add(java.lang.Class<? extends YAPIONPacket>[] packetTypes, YAPIONPacketHandler yapionPacketHandler)
Add an YAPIONPacketHandler for the specified packetTypes to handle. If either the yapionPacketHandler or the packetTypes itself isnull
this method throws an YAPIONPacketException. If any value in the packetTypes array isnull
it will just be skipped over.- Parameters:
packetTypes
- the packets to handleyapionPacketHandler
- the handler which handles the specified packets
-
add
public YAPIONPacketReceiver add(YAPIONPacketHandler yapionPacketHandler, java.lang.Class<? extends YAPIONPacket> packetType)
A wrapper function toadd(Class, YAPIONPacketHandler)
-
add
public YAPIONPacketReceiver add(YAPIONPacketHandler yapionPacketHandler, java.lang.Class<? extends YAPIONPacket>... packetTypes)
A wrapper function toadd(Class[], YAPIONPacketHandler)
-
setExceptionHandler
public YAPIONPacketReceiver setExceptionHandler(YAPIONPacketHandler yapionPacketHandler)
Set the ExceptionYAPIONPacketHandler
to do something when an exception gets thrown.- Parameters:
yapionPacketHandler
- theYAPIONPacketHandler
to set
-
setUnknownHandler
public YAPIONPacketReceiver setUnknownHandler(YAPIONPacketHandler yapionPacketHandler)
Set the UnknownYAPIONPacketHandler
to do something when an unknown packet was handled occurred.- Parameters:
yapionPacketHandler
-
-
setDropHandler
public YAPIONPacketReceiver setDropHandler(YAPIONPacketHandler yapionPacketHandler)
Set the DropYAPIONPacketHandler
to do something when a data drop occurred.- Parameters:
yapionPacketHandler
-
-
setDeserializationExceptionHandler
public YAPIONPacketReceiver setDeserializationExceptionHandler(YAPIONPacketHandler yapionPacketHandler)
Set the Deserialization ExceptionYAPIONPacketHandler
to do something when a deserialization exception occurred.- Parameters:
yapionPacketHandler
-
-
setHandleFailedHandler
public YAPIONPacketReceiver setHandleFailedHandler(YAPIONPacketHandler yapionPacketHandler)
Set the HandleFailedYAPIONPacketHandler
to do something when the internalYAPIONInputStream
.handle() failed.- Parameters:
yapionPacketHandler
-
-
setErrorHandler
public YAPIONPacketReceiver setErrorHandler(YAPIONPacketHandler yapionPacketHandler)
Set the ErrorYAPIONPacketHandler
to do something when an error occurred.- Parameters:
yapionPacketHandler
- theYAPIONPacketHandler
to set
-
handle
public void handle(YAPIONPacket yapionPacket)
Handles an YAPIONPacket by calling the specified yapionPacketHandler for the type of the packet. If the packet type is not found the "@error" handler gets called. If any exception gets thrown the special "@exception" handler is called. If this also throws an exception this method will log the exception as a warning.- Parameters:
yapionPacket
- to handle
-
-