public class AsyncFilterManager extends java.lang.Object implements AsynchronousManager
By using AsyncMarker.incrementProcessingDelay()
, a packet can be delayed without having to block the
processing thread.
Constructor and Description |
---|
AsyncFilterManager(ErrorReporter reporter,
org.bukkit.scheduler.BukkitScheduler scheduler)
Initialize a asynchronous filter manager.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupAll()
Remove listeners, close threads and transmit every delayed packet.
|
AsyncMarker |
createAsyncMarker()
Construct a asynchronous marker with all the default values.
|
AsyncMarker |
createAsyncMarker(long sendingDelta,
long timeoutDelta)
Construct an async marker with the given sending priority delta and timeout delta.
|
void |
enqueueSyncPacket(PacketEvent syncPacket,
AsyncMarker asyncMarker)
Enqueue a packet for asynchronous processing.
|
java.util.Set<PacketListener> |
getAsyncHandlers()
Get an immutable set of every registered asynchronous packet listener.
|
ErrorReporter |
getErrorReporter()
Retrieve the default error reporter.
|
ProtocolManager |
getManager()
Retrieve the protocol manager.
|
PacketStream |
getPacketStream()
Retrieve the default packet stream.
|
com.comphenix.protocol.async.PacketProcessingQueue |
getProcessingQueue(PacketEvent packet)
Retrieve the processing queue this packet belongs to.
|
java.util.Set<java.lang.Integer> |
getReceivingFilters()
Retrieves a immutable set containing the ID of the recieved client packets that will be
|
java.util.Set<PacketType> |
getReceivingTypes()
Retrieves a immutable set containing the types of the received client packets that will be
observed by the asynchronous listeners.
|
org.bukkit.scheduler.BukkitScheduler |
getScheduler()
Retrieve the current task scheduler.
|
java.util.Set<java.lang.Integer> |
getSendingFilters()
Retrieves a immutable set containing the ID of the sent server packets that will be
observed by the asynchronous listeners.
|
com.comphenix.protocol.async.PacketSendingQueue |
getSendingQueue(PacketEvent packet)
Retrieve the sending queue this packet belongs to.
|
com.comphenix.protocol.async.PacketSendingQueue |
getSendingQueue(PacketEvent packet,
boolean createNew)
Retrieve the sending queue this packet belongs to.
|
java.util.Set<PacketType> |
getSendingTypes()
Retrieves a immutable set containing the types of the sent server packets that will be
observed by the asynchronous listeners.
|
java.util.Set<PacketListener> |
getTimeoutHandlers()
Get a immutable set of every registered timeout handler.
|
boolean |
hasAsynchronousListeners(PacketEvent packet)
Determine if a given synchronous packet has asynchronous listeners.
|
AsyncListenerHandler |
registerAsyncHandler(PacketListener listener)
Registers an asynchronous packet handler.
|
AsyncListenerHandler |
registerAsyncHandler(PacketListener listener,
boolean autoInject)
Registers an asynchronous packet handler.
|
void |
registerTimeoutHandler(PacketListener listener)
Register a synchronous listener that handles packets when they time out.
|
void |
removePlayer(org.bukkit.entity.Player player)
Clean up after a given player has logged out.
|
void |
sendProcessedPackets(int tickCounter,
boolean onMainThread)
Send any due packets, or clean up packets that have expired.
|
void |
setManager(ProtocolManager manager)
Set the associated protocol manager.
|
void |
signalFreeProcessingSlot(PacketEvent packet)
Signal that a packet has finished processing.
|
void |
signalPacketTransmission(PacketEvent packet)
Signal that a packet is ready to be transmitted.
|
void |
unregisterAsyncHandler(AsyncListenerHandler handler)
Unregisters and closes the given asynchronous handler.
|
void |
unregisterAsyncHandlers(org.bukkit.plugin.Plugin plugin)
Unregisters every asynchronous handler associated with this plugin.
|
void |
unregisterTimeoutHandler(PacketListener listener)
Unregisters a given timeout listener.
|
public AsyncFilterManager(ErrorReporter reporter, org.bukkit.scheduler.BukkitScheduler scheduler)
Internal method. Retrieve the global asynchronous manager from the protocol manager instead.
reporter
- - desired error reporter.scheduler
- - task scheduler.public ProtocolManager getManager()
public void setManager(ProtocolManager manager)
manager
- - the new manager.public AsyncListenerHandler registerAsyncHandler(PacketListener listener)
AsynchronousManager
Use AsyncMarker.incrementProcessingDelay()
to delay a packet until its ready to be transmitted.
To start listening asynchronously, pass the getListenerLoop() runnable to a different thread.
registerAsyncHandler
in interface AsynchronousManager
listener
- - the packet listener that will receive these asynchronous events.public void registerTimeoutHandler(PacketListener listener)
AsynchronousManager
registerTimeoutHandler
in interface AsynchronousManager
listener
- - synchronous listener that will handle timed out packets.public java.util.Set<PacketListener> getTimeoutHandlers()
AsynchronousManager
getTimeoutHandlers
in interface AsynchronousManager
public java.util.Set<PacketListener> getAsyncHandlers()
AsynchronousManager
getAsyncHandlers
in interface AsynchronousManager
public AsyncListenerHandler registerAsyncHandler(PacketListener listener, boolean autoInject)
Use AsyncMarker.incrementProcessingDelay()
to delay a packet until its ready to be transmitted.
To start listening asynchronously, pass the getListenerLoop() runnable to a different thread.
Asynchronous events will only be executed if a synchronous listener with the same packets is registered. If you already have a synchronous event, call this method with autoInject set to FALSE.
listener
- - the packet listener that will receive these asynchronous events.autoInject
- - whether or not to automatically create the corresponding synchronous listener,public void unregisterTimeoutHandler(PacketListener listener)
AsynchronousManager
unregisterTimeoutHandler
in interface AsynchronousManager
listener
- - the timeout listener to unregister.public void unregisterAsyncHandler(AsyncListenerHandler handler)
AsynchronousManager
unregisterAsyncHandler
in interface AsynchronousManager
handler
- - asynchronous handler.public void unregisterAsyncHandlers(org.bukkit.plugin.Plugin plugin)
AsynchronousManager
unregisterAsyncHandlers
in interface AsynchronousManager
plugin
- - the original plugin.public void enqueueSyncPacket(PacketEvent syncPacket, AsyncMarker asyncMarker)
syncPacket
- - synchronous packet event.asyncMarker
- - the asynchronous marker to use.public java.util.Set<java.lang.Integer> getSendingFilters()
AsynchronousManager
Deprecated: Use AsynchronousManager.getSendingTypes()
instead.
getSendingFilters
in interface AsynchronousManager
public java.util.Set<PacketType> getReceivingTypes()
AsynchronousManager
getReceivingTypes
in interface AsynchronousManager
public java.util.Set<java.lang.Integer> getReceivingFilters()
AsynchronousManager
Deprecated: Use AsynchronousManager.getReceivingTypes()
instead.
observed by the asynchronous listeners.
getReceivingFilters
in interface AsynchronousManager
public java.util.Set<PacketType> getSendingTypes()
AsynchronousManager
getSendingTypes
in interface AsynchronousManager
public org.bukkit.scheduler.BukkitScheduler getScheduler()
public boolean hasAsynchronousListeners(PacketEvent packet)
AsynchronousManager
hasAsynchronousListeners
in interface AsynchronousManager
packet
- - packet to test.public AsyncMarker createAsyncMarker()
public AsyncMarker createAsyncMarker(long sendingDelta, long timeoutDelta)
sendingDelta
- - how many packets we're willing to wait.timeoutDelta
- - how long (in ms) until the packet expire.public PacketStream getPacketStream()
AsynchronousManager
getPacketStream
in interface AsynchronousManager
public ErrorReporter getErrorReporter()
AsynchronousManager
getErrorReporter
in interface AsynchronousManager
public void cleanupAll()
AsynchronousManager
cleanupAll
in interface AsynchronousManager
public void signalPacketTransmission(PacketEvent packet)
AsynchronousManager
This should only be called if AsyncMarker.incrementProcessingDelay()
has been called previously.
signalPacketTransmission
in interface AsynchronousManager
packet
- - packet to signal.public com.comphenix.protocol.async.PacketSendingQueue getSendingQueue(PacketEvent packet)
packet
- - the packet.public com.comphenix.protocol.async.PacketSendingQueue getSendingQueue(PacketEvent packet, boolean createNew)
packet
- - the packet.createNew
- - if TRUE, create a new queue if it hasn't already been created.public com.comphenix.protocol.async.PacketProcessingQueue getProcessingQueue(PacketEvent packet)
packet
- - the packet.public void signalFreeProcessingSlot(PacketEvent packet)
packet
- - packet to signal.public void sendProcessedPackets(int tickCounter, boolean onMainThread)
public void removePlayer(org.bukkit.entity.Player player)
player
- - the player that has just logged out.