mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 21:26:17 +01:00
Renamed the ListenerToken in the code as well.
This commit is contained in:
parent
880520cd94
commit
025e97ca95
@ -44,15 +44,15 @@ public class AsyncFilterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AsyncListenerHandler registerAsyncHandler(Plugin plugin, PacketListener listener) {
|
public AsyncListenerHandler registerAsyncHandler(Plugin plugin, PacketListener listener) {
|
||||||
AsyncListenerHandler token = new AsyncListenerHandler(plugin, mainThread, this, listener);
|
AsyncListenerHandler handler = new AsyncListenerHandler(plugin, mainThread, this, listener);
|
||||||
|
|
||||||
// Add listener to either or both processing queue
|
// Add listener to either or both processing queue
|
||||||
if (hasValidWhitelist(listener.getSendingWhitelist()))
|
if (hasValidWhitelist(listener.getSendingWhitelist()))
|
||||||
serverProcessingQueue.addListener(token, listener.getSendingWhitelist());
|
serverProcessingQueue.addListener(handler, listener.getSendingWhitelist());
|
||||||
if (hasValidWhitelist(listener.getReceivingWhitelist()))
|
if (hasValidWhitelist(listener.getReceivingWhitelist()))
|
||||||
clientProcessingQueue.addListener(token, listener.getReceivingWhitelist());
|
clientProcessingQueue.addListener(handler, listener.getReceivingWhitelist());
|
||||||
|
|
||||||
return token;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
|
private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
|
||||||
@ -61,25 +61,25 @@ public class AsyncFilterManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters and closes the given asynchronous handler.
|
* Unregisters and closes the given asynchronous handler.
|
||||||
* @param listenerToken - asynchronous handler.
|
* @param handler - asynchronous handler.
|
||||||
*/
|
*/
|
||||||
public void unregisterAsyncHandler(AsyncListenerHandler listenerToken) {
|
public void unregisterAsyncHandler(AsyncListenerHandler handler) {
|
||||||
if (listenerToken == null)
|
if (handler == null)
|
||||||
throw new IllegalArgumentException("listenerToken cannot be NULL");
|
throw new IllegalArgumentException("listenerToken cannot be NULL");
|
||||||
|
|
||||||
listenerToken.cancel();
|
handler.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called by ListenerToken
|
// Called by AsyncListenerHandler
|
||||||
void unregisterAsyncHandlerInternal(AsyncListenerHandler listenerToken) {
|
void unregisterAsyncHandlerInternal(AsyncListenerHandler handler) {
|
||||||
|
|
||||||
PacketListener listener = listenerToken.getAsyncListener();
|
PacketListener listener = handler.getAsyncListener();
|
||||||
|
|
||||||
// Just remove it from the queue(s)
|
// Just remove it from the queue(s)
|
||||||
if (hasValidWhitelist(listener.getSendingWhitelist()))
|
if (hasValidWhitelist(listener.getSendingWhitelist()))
|
||||||
serverProcessingQueue.removeListener(listenerToken, listener.getSendingWhitelist());
|
serverProcessingQueue.removeListener(handler, listener.getSendingWhitelist());
|
||||||
if (hasValidWhitelist(listener.getReceivingWhitelist()))
|
if (hasValidWhitelist(listener.getReceivingWhitelist()))
|
||||||
clientProcessingQueue.removeListener(listenerToken, listener.getReceivingWhitelist());
|
clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,10 +122,10 @@ public class AsyncListenerHandler {
|
|||||||
|
|
||||||
// Now, get the next non-cancelled listener
|
// Now, get the next non-cancelled listener
|
||||||
for (; marker.getListenerTraversal().hasNext(); ) {
|
for (; marker.getListenerTraversal().hasNext(); ) {
|
||||||
AsyncListenerHandler token = marker.getListenerTraversal().next().getListener();
|
AsyncListenerHandler handler = marker.getListenerTraversal().next().getListener();
|
||||||
|
|
||||||
if (!token.isCancelled()) {
|
if (!handler.isCancelled()) {
|
||||||
token.enqueuePacket(packet);
|
handler.enqueuePacket(packet);
|
||||||
continue mainLoop;
|
continue mainLoop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,9 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||||||
|
|
||||||
public void cleanupAll() {
|
public void cleanupAll() {
|
||||||
// Cancel all the threads and every listener
|
// Cancel all the threads and every listener
|
||||||
for (PrioritizedListener<AsyncListenerHandler> token : values()) {
|
for (PrioritizedListener<AsyncListenerHandler> handler : values()) {
|
||||||
if (token != null) {
|
if (handler != null) {
|
||||||
token.getListener().cancel();
|
handler.getListener().cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user