Renamed the ListenerToken in the code as well.

This commit is contained in:
Kristian S. Stangeland 2012-09-29 20:34:29 +02:00
parent 880520cd94
commit 025e97ca95
3 changed files with 19 additions and 19 deletions

View File

@ -44,15 +44,15 @@ public class AsyncFilterManager {
}
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
if (hasValidWhitelist(listener.getSendingWhitelist()))
serverProcessingQueue.addListener(token, listener.getSendingWhitelist());
serverProcessingQueue.addListener(handler, listener.getSendingWhitelist());
if (hasValidWhitelist(listener.getReceivingWhitelist()))
clientProcessingQueue.addListener(token, listener.getReceivingWhitelist());
clientProcessingQueue.addListener(handler, listener.getReceivingWhitelist());
return token;
return handler;
}
private boolean hasValidWhitelist(ListeningWhitelist whitelist) {
@ -61,25 +61,25 @@ public class AsyncFilterManager {
/**
* Unregisters and closes the given asynchronous handler.
* @param listenerToken - asynchronous handler.
* @param handler - asynchronous handler.
*/
public void unregisterAsyncHandler(AsyncListenerHandler listenerToken) {
if (listenerToken == null)
public void unregisterAsyncHandler(AsyncListenerHandler handler) {
if (handler == null)
throw new IllegalArgumentException("listenerToken cannot be NULL");
listenerToken.cancel();
handler.cancel();
}
// Called by ListenerToken
void unregisterAsyncHandlerInternal(AsyncListenerHandler listenerToken) {
// Called by AsyncListenerHandler
void unregisterAsyncHandlerInternal(AsyncListenerHandler handler) {
PacketListener listener = listenerToken.getAsyncListener();
PacketListener listener = handler.getAsyncListener();
// Just remove it from the queue(s)
if (hasValidWhitelist(listener.getSendingWhitelist()))
serverProcessingQueue.removeListener(listenerToken, listener.getSendingWhitelist());
serverProcessingQueue.removeListener(handler, listener.getSendingWhitelist());
if (hasValidWhitelist(listener.getReceivingWhitelist()))
clientProcessingQueue.removeListener(listenerToken, listener.getReceivingWhitelist());
clientProcessingQueue.removeListener(handler, listener.getReceivingWhitelist());
}
/**

View File

@ -122,10 +122,10 @@ public class AsyncListenerHandler {
// Now, get the next non-cancelled listener
for (; marker.getListenerTraversal().hasNext(); ) {
AsyncListenerHandler token = marker.getListenerTraversal().next().getListener();
AsyncListenerHandler handler = marker.getListenerTraversal().next().getListener();
if (!token.isCancelled()) {
token.enqueuePacket(packet);
if (!handler.isCancelled()) {
handler.enqueuePacket(packet);
continue mainLoop;
}
}

View File

@ -117,9 +117,9 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
public void cleanupAll() {
// Cancel all the threads and every listener
for (PrioritizedListener<AsyncListenerHandler> token : values()) {
if (token != null) {
token.getListener().cancel();
for (PrioritizedListener<AsyncListenerHandler> handler : values()) {
if (handler != null) {
handler.getListener().cancel();
}
}