Class AsyncMarker

java.lang.Object
com.comphenix.protocol.async.AsyncMarker
All Implemented Interfaces:
Serializable, Comparable<AsyncMarker>

public class AsyncMarker extends Object implements Serializable, Comparable<AsyncMarker>
Contains information about the packet that is being processed by asynchronous listeners.

Asynchronous listeners can use this to set packet timeout or transmission order.

See Also:
  • Field Details

    • DEFAULT_TIMEOUT_DELTA

      public static final int DEFAULT_TIMEOUT_DELTA
      Default number of milliseconds until a packet will rejected.
      See Also:
    • DEFAULT_SENDING_DELTA

      public static final int DEFAULT_SENDING_DELTA
      Default number of packets to skip.
      See Also:
  • Method Details

    • getInitialTime

      public long getInitialTime()
      Retrieve the time the packet was initially queued for asynchronous processing.
      Returns:
      The initial time in number of milliseconds since 01.01.1970 00:00.
    • getTimeout

      public long getTimeout()
      Retrieve the time the packet will be forcefully rejected.
      Returns:
      The time to reject the packet, in milliseconds since 01.01.1970 00:00.
    • setTimeout

      public void setTimeout(long timeout)
      Set the time the packet will be forcefully rejected.
      Parameters:
      timeout - - time to reject the packet, in milliseconds since 01.01.1970 00:00.
    • getOriginalSendingIndex

      public long getOriginalSendingIndex()
      Retrieve the order the packet was originally transmitted.
      Returns:
      The original packet index.
    • getNewSendingIndex

      public long getNewSendingIndex()
      Retrieve the desired sending order after processing has completed.

      Higher sending order means lower priority.

      Returns:
      Desired sending order.
    • setNewSendingIndex

      public void setNewSendingIndex(long newSendingIndex)
      Sets the desired sending order after processing has completed.

      Higher sending order means lower priority.

      Parameters:
      newSendingIndex - - new packet send index.
    • getPacketStream

      public PacketStream getPacketStream()
      Retrieve the packet stream responsible for transmitting this packet.
      Returns:
      The packet stream.
    • setPacketStream

      public void setPacketStream(PacketStream packetStream)
      Sets the output packet stream responsible for transmitting this packet.
      Parameters:
      packetStream - - new output packet stream.
    • isProcessed

      public boolean isProcessed()
      Retrieve whether or not this packet has been processed by the async listeners.
      Returns:
      TRUE if it has been processed, FALSE otherwise.
    • incrementProcessingDelay

      public int incrementProcessingDelay()
      Increment the number of times the current packet must be signalled as done before its transmitted.

      This is useful if an asynchronous listener is waiting for further information before the packet can be sent to the user. A packet listener MUST eventually call AsyncFilterManager.signalPacketTransmission(PacketEvent), even if the packet is cancelled, after this method is called.

      It is recommended that processing outside a packet listener is wrapped in a synchronized block using the getProcessingLock() method.

      Returns:
      The new processing delay.
    • getProcessingDelay

      public int getProcessingDelay()
      Retrieve the number of times a packet must be signalled to be done before it's sent.
      Returns:
      Number of processing delays.
    • isQueued

      public boolean isQueued()
      Whether or not this packet is or has been queued for processing.
      Returns:
      TRUE if it has, FALSE otherwise.
    • getQueuedSendingIndex

      public long getQueuedSendingIndex()
      Retrieve the sending index when the packet was queued.
      Returns:
      Queued sending index.
    • getProcessingLock

      public Object getProcessingLock()
      Processing lock used to synchronize access to the parent PacketEvent and PacketContainer.

      This lock is automatically acquired for every asynchronous packet listener. It should only be used to synchronize access to a PacketEvent if it's processing has been delayed.

      Returns:
      A processing lock.
    • setProcessingLock

      public void setProcessingLock(Object processingLock)
    • isTransmitted

      public boolean isTransmitted()
      Retrieve whether or not this packet has already been sent.
      Returns:
      TRUE if it has been sent before, FALSE otherwise.
    • hasExpired

      public boolean hasExpired()
      Determine if this packet has expired.
      Returns:
      TRUE if it has, FALSE otherwise.
    • hasExpired

      public boolean hasExpired(long currentTime)
      Determine if this packet has expired given this time.
      Parameters:
      currentTime - - the current time in milliseconds since 01.01.1970 00:00.
      Returns:
      TRUE if it has, FALSE otherwise.
    • isAsyncCancelled

      public boolean isAsyncCancelled()
      Determine if the asynchronous handling should be cancelled.
      Returns:
      TRUE if it should, FALSE otherwise.
    • setAsyncCancelled

      public void setAsyncCancelled(boolean asyncCancelled)
      Set whether or not the asynchronous handling should be cancelled.

      This is only relevant during the synchronous processing. Asynchronous listeners should use the normal cancel-field to cancel a PacketEvent.

      Parameters:
      asyncCancelled - - TRUE to cancel it, FALSE otherwise.
    • getListenerHandler

      public AsyncListenerHandler getListenerHandler()
      Retrieve the current asynchronous listener handler.
      Returns:
      Asychronous listener handler, or NULL if this packet is not asynchronous.
    • getWorkerID

      public int getWorkerID()
      Retrieve the current worker ID.
      Returns:
      Current worker ID.
    • isMinecraftAsync

      public boolean isMinecraftAsync(PacketEvent event) throws FieldAccessException
      Determine if Minecraft allows asynchronous processing of this packet.
      Parameters:
      event - - packet event
      Returns:
      TRUE if it does, FALSE otherwise.
      Throws:
      FieldAccessException - If determining fails for some reasaon
    • compareTo

      public int compareTo(AsyncMarker o)
      Specified by:
      compareTo in interface Comparable<AsyncMarker>
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object