mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Renamed the ListenerToken into a AsyncListenerHandler.
This commit is contained in:
parent
fad6a0a99c
commit
880520cd94
@ -43,8 +43,8 @@ public class AsyncFilterManager {
|
||||
this.mainThread = Thread.currentThread();
|
||||
}
|
||||
|
||||
public ListenerToken registerAsyncHandler(Plugin plugin, PacketListener listener) {
|
||||
ListenerToken token = new ListenerToken(plugin, mainThread, this, listener);
|
||||
public AsyncListenerHandler registerAsyncHandler(Plugin plugin, PacketListener listener) {
|
||||
AsyncListenerHandler token = new AsyncListenerHandler(plugin, mainThread, this, listener);
|
||||
|
||||
// Add listener to either or both processing queue
|
||||
if (hasValidWhitelist(listener.getSendingWhitelist()))
|
||||
@ -63,7 +63,7 @@ public class AsyncFilterManager {
|
||||
* Unregisters and closes the given asynchronous handler.
|
||||
* @param listenerToken - asynchronous handler.
|
||||
*/
|
||||
public void unregisterAsyncHandler(ListenerToken listenerToken) {
|
||||
public void unregisterAsyncHandler(AsyncListenerHandler listenerToken) {
|
||||
if (listenerToken == null)
|
||||
throw new IllegalArgumentException("listenerToken cannot be NULL");
|
||||
|
||||
@ -71,7 +71,7 @@ public class AsyncFilterManager {
|
||||
}
|
||||
|
||||
// Called by ListenerToken
|
||||
void unregisterAsyncHandlerInternal(ListenerToken listenerToken) {
|
||||
void unregisterAsyncHandlerInternal(AsyncListenerHandler listenerToken) {
|
||||
|
||||
PacketListener listener = listenerToken.getAsyncListener();
|
||||
|
||||
|
@ -8,7 +8,12 @@ import org.bukkit.plugin.Plugin;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
|
||||
class ListenerToken {
|
||||
/**
|
||||
* Represents a handler for an asynchronous event.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class AsyncListenerHandler {
|
||||
|
||||
/**
|
||||
* Signal an end to the packet processing.
|
||||
@ -36,7 +41,7 @@ class ListenerToken {
|
||||
// Minecraft main thread
|
||||
private Thread mainThread;
|
||||
|
||||
public ListenerToken(Plugin plugin, Thread mainThread, AsyncFilterManager filterManager, PacketListener listener) {
|
||||
public AsyncListenerHandler(Plugin plugin, Thread mainThread, AsyncFilterManager filterManager, PacketListener listener) {
|
||||
if (filterManager == null)
|
||||
throw new IllegalArgumentException("filterManager cannot be NULL");
|
||||
if (listener == null)
|
||||
@ -117,7 +122,7 @@ class ListenerToken {
|
||||
|
||||
// Now, get the next non-cancelled listener
|
||||
for (; marker.getListenerTraversal().hasNext(); ) {
|
||||
ListenerToken token = marker.getListenerTraversal().next().getListener();
|
||||
AsyncListenerHandler token = marker.getListenerTraversal().next().getListener();
|
||||
|
||||
if (!token.isCancelled()) {
|
||||
token.enqueuePacket(packet);
|
@ -40,7 +40,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
/**
|
||||
* Current list of async packet listeners.
|
||||
*/
|
||||
private transient Iterator<PrioritizedListener<ListenerToken>> listenerTraversal;
|
||||
private transient Iterator<PrioritizedListener<AsyncListenerHandler>> listenerTraversal;
|
||||
|
||||
// Timeout handling
|
||||
private long initialTime;
|
||||
@ -207,7 +207,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* Retrieve iterator for the next listener in line.
|
||||
* @return Next async packet listener iterator.
|
||||
*/
|
||||
public Iterator<PrioritizedListener<ListenerToken>> getListenerTraversal() {
|
||||
public Iterator<PrioritizedListener<AsyncListenerHandler>> getListenerTraversal() {
|
||||
return listenerTraversal;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* Set the iterator for the next listener.
|
||||
* @param listenerTraversal - the new async packet listener iterator.
|
||||
*/
|
||||
void setListenerTraversal(Iterator<PrioritizedListener<ListenerToken>> listenerTraversal) {
|
||||
void setListenerTraversal(Iterator<PrioritizedListener<AsyncListenerHandler>> listenerTraversal) {
|
||||
this.listenerTraversal = listenerTraversal;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ import com.comphenix.protocol.injector.PrioritizedListener;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerToken> {
|
||||
class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncListenerHandler> {
|
||||
|
||||
/**
|
||||
* Default maximum number of packets to process concurrently.
|
||||
@ -76,11 +76,11 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerT
|
||||
|
||||
// Any packet queued?
|
||||
if (packet != null) {
|
||||
Collection<PrioritizedListener<ListenerToken>> list = getListener(packet.getPacketID());
|
||||
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID());
|
||||
AsyncMarker marker = packet.getAsyncMarker();
|
||||
|
||||
if (list != null) {
|
||||
Iterator<PrioritizedListener<ListenerToken>> iterator = list.iterator();
|
||||
Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator();
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
marker.setListenerTraversal(iterator);
|
||||
@ -117,7 +117,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerT
|
||||
|
||||
public void cleanupAll() {
|
||||
// Cancel all the threads and every listener
|
||||
for (PrioritizedListener<ListenerToken> token : values()) {
|
||||
for (PrioritizedListener<AsyncListenerHandler> token : values()) {
|
||||
if (token != null) {
|
||||
token.getListener().cancel();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user