Class AsyncFilterManager

java.lang.Object
com.comphenix.protocol.async.AsyncFilterManager
All Implemented Interfaces:
AsynchronousManager

public class AsyncFilterManager extends Object implements AsynchronousManager
Represents a filter manager for asynchronous packets.

By using AsyncMarker.incrementProcessingDelay(), a packet can be delayed without having to block the processing thread.

  • Constructor Details

    • AsyncFilterManager

      public AsyncFilterManager(ErrorReporter reporter, ProtocolScheduler scheduler)
      Initialize a asynchronous filter manager.

      Internal method. Retrieve the global asynchronous manager from the protocol manager instead.

      Parameters:
      reporter - - desired error reporter.
      scheduler - - task scheduler.
  • Method Details

    • getManager

      public ProtocolManager getManager()
      Retrieve the protocol manager.
      Returns:
      The protocol manager.
    • setManager

      public void setManager(ProtocolManager manager)
      Set the associated protocol manager.
      Parameters:
      manager - - the new manager.
    • registerAsyncHandler

      public AsyncListenerHandler registerAsyncHandler(PacketListener listener)
      Description copied from interface: AsynchronousManager
      Registers an asynchronous packet handler.

      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.

      Specified by:
      registerAsyncHandler in interface AsynchronousManager
      Parameters:
      listener - - the packet listener that will receive these asynchronous events.
      Returns:
      An asynchronous handler.
    • registerTimeoutHandler

      public void registerTimeoutHandler(PacketListener listener)
      Description copied from interface: AsynchronousManager
      Register a synchronous listener that handles packets when they time out.
      Specified by:
      registerTimeoutHandler in interface AsynchronousManager
      Parameters:
      listener - - synchronous listener that will handle timed out packets.
    • getTimeoutHandlers

      public Set<PacketListener> getTimeoutHandlers()
      Description copied from interface: AsynchronousManager
      Get a immutable set of every registered timeout handler.
      Specified by:
      getTimeoutHandlers in interface AsynchronousManager
      Returns:
      Set of every registered timeout handler.
    • getAsyncHandlers

      public Set<PacketListener> getAsyncHandlers()
      Description copied from interface: AsynchronousManager
      Get an immutable set of every registered asynchronous packet listener.
      Specified by:
      getAsyncHandlers in interface AsynchronousManager
      Returns:
      Set of every asynchronous packet listener.
    • registerAsyncHandler

      public AsyncListenerHandler registerAsyncHandler(PacketListener listener, boolean autoInject)
      Registers an asynchronous packet handler.

      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.

      Parameters:
      listener - - the packet listener that will receive these asynchronous events.
      autoInject - - whether or not to automatically create the corresponding synchronous listener,
      Returns:
      An asynchronous handler.
    • unregisterTimeoutHandler

      public void unregisterTimeoutHandler(PacketListener listener)
      Description copied from interface: AsynchronousManager
      Unregisters a given timeout listener.
      Specified by:
      unregisterTimeoutHandler in interface AsynchronousManager
      Parameters:
      listener - - the timeout listener to unregister.
    • unregisterAsyncHandler

      public void unregisterAsyncHandler(PacketListener listener)
      Description copied from interface: AsynchronousManager
      Unregisters and closes the first asynchronous handler associated with the given listener.
      Specified by:
      unregisterAsyncHandler in interface AsynchronousManager
      Parameters:
      listener - - asynchronous listener
    • unregisterAsyncHandler

      public void unregisterAsyncHandler(AsyncListenerHandler handler)
      Description copied from interface: AsynchronousManager
      Unregisters and closes the given asynchronous handler.
      Specified by:
      unregisterAsyncHandler in interface AsynchronousManager
      Parameters:
      handler - - asynchronous handler.
    • unregisterAsyncHandlers

      public void unregisterAsyncHandlers(org.bukkit.plugin.Plugin plugin)
      Description copied from interface: AsynchronousManager
      Unregisters every asynchronous handler associated with this plugin.
      Specified by:
      unregisterAsyncHandlers in interface AsynchronousManager
      Parameters:
      plugin - - the original plugin.
    • enqueueSyncPacket

      public void enqueueSyncPacket(PacketEvent syncPacket, AsyncMarker asyncMarker)
      Enqueue a packet for asynchronous processing.
      Parameters:
      syncPacket - - synchronous packet event.
      asyncMarker - - the asynchronous marker to use.
    • getReceivingTypes

      public Set<PacketType> getReceivingTypes()
      Description copied from interface: AsynchronousManager
      Retrieves a immutable set containing the types of the received client packets that will be observed by the asynchronous listeners.
      Specified by:
      getReceivingTypes in interface AsynchronousManager
      Returns:
      Every filtered client packet.
    • getSendingTypes

      public Set<PacketType> getSendingTypes()
      Description copied from interface: AsynchronousManager
      Retrieves a immutable set containing the types of the sent server packets that will be observed by the asynchronous listeners.
      Specified by:
      getSendingTypes in interface AsynchronousManager
      Returns:
      Every filtered server packet.
    • getScheduler

      public ProtocolScheduler getScheduler()
      Retrieve the current task scheduler.
      Returns:
      Current task scheduler.
    • hasAsynchronousListeners

      public boolean hasAsynchronousListeners(PacketEvent packet)
      Description copied from interface: AsynchronousManager
      Determine if a given synchronous packet has asynchronous listeners.
      Specified by:
      hasAsynchronousListeners in interface AsynchronousManager
      Parameters:
      packet - - packet to test.
      Returns:
      TRUE if it does, FALSE otherwise.
    • createAsyncMarker

      public AsyncMarker createAsyncMarker()
      Construct a asynchronous marker with all the default values.
      Returns:
      Asynchronous marker.
    • createAsyncMarker

      public AsyncMarker createAsyncMarker(long timeoutDelta)
      Construct an async marker with the given sending priority delta and timeout delta.
      Parameters:
      timeoutDelta - - how long (in ms) until the packet expire.
      Returns:
      An async marker.
    • getPacketStream

      public PacketStream getPacketStream()
      Description copied from interface: AsynchronousManager
      Retrieve the default packet stream.
      Specified by:
      getPacketStream in interface AsynchronousManager
      Returns:
      Default packet stream.
    • getErrorReporter

      public ErrorReporter getErrorReporter()
      Description copied from interface: AsynchronousManager
      Retrieve the default error reporter.
      Specified by:
      getErrorReporter in interface AsynchronousManager
      Returns:
      Default reporter.
    • cleanupAll

      public void cleanupAll()
      Description copied from interface: AsynchronousManager
      Remove listeners, close threads and transmit every delayed packet.
      Specified by:
      cleanupAll in interface AsynchronousManager
    • signalPacketTransmission

      public void signalPacketTransmission(PacketEvent packet)
      Description copied from interface: AsynchronousManager
      Signal that a packet is ready to be transmitted.

      This should only be called if AsyncMarker.incrementProcessingDelay() has been called previously.

      Specified by:
      signalPacketTransmission in interface AsynchronousManager
      Parameters:
      packet - - packet to signal.
    • getSendingQueue

      public com.comphenix.protocol.async.PacketSendingQueue getSendingQueue(PacketEvent packet)
      Retrieve the sending queue this packet belongs to.
      Parameters:
      packet - - the packet.
      Returns:
      The server or client sending queue the packet belongs to.
    • getSendingQueue

      public com.comphenix.protocol.async.PacketSendingQueue getSendingQueue(PacketEvent packet, boolean createNew)
      Retrieve the sending queue this packet belongs to.
      Parameters:
      packet - - the packet.
      createNew - - if TRUE, create a new queue if it hasn't already been created.
      Returns:
      The server or client sending queue the packet belongs to.
    • getProcessingQueue

      public com.comphenix.protocol.async.PacketProcessingQueue getProcessingQueue(PacketEvent packet)
      Retrieve the processing queue this packet belongs to.
      Parameters:
      packet - - the packet.
      Returns:
      The server or client sending processing the packet belongs to.
    • signalFreeProcessingSlot

      public void signalFreeProcessingSlot(PacketEvent packet, boolean onMainThread)
      Signal that a packet has finished processing. Tries to process further packets if a processing slot is still free.
      Parameters:
      packet - - packet to signal.
      onMainThread - whether or not this method was run by the main thread.
    • sendProcessedPackets

      public void sendProcessedPackets(int tickCounter, boolean onMainThread)
      Send any due packets, or clean up packets that have expired.
      Parameters:
      tickCounter - Tick counter
      onMainThread - Whether or not to execute on the main thread
    • removePlayer

      public void removePlayer(org.bukkit.entity.Player player)
      Clean up after a given player has logged out.
      Parameters:
      player - - the player that has just logged out.