Renamed the ListenerToken into a AsyncListenerHandler.

This commit is contained in:
Kristian S. Stangeland 2012-09-29 20:32:18 +02:00
parent fad6a0a99c
commit 880520cd94
4 changed files with 19 additions and 14 deletions

View File

@ -43,8 +43,8 @@ public class AsyncFilterManager {
this.mainThread = Thread.currentThread(); this.mainThread = Thread.currentThread();
} }
public ListenerToken registerAsyncHandler(Plugin plugin, PacketListener listener) { public AsyncListenerHandler registerAsyncHandler(Plugin plugin, PacketListener listener) {
ListenerToken token = new ListenerToken(plugin, mainThread, this, listener); AsyncListenerHandler token = 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()))
@ -63,7 +63,7 @@ public class AsyncFilterManager {
* Unregisters and closes the given asynchronous handler. * Unregisters and closes the given asynchronous handler.
* @param listenerToken - asynchronous handler. * @param listenerToken - asynchronous handler.
*/ */
public void unregisterAsyncHandler(ListenerToken listenerToken) { public void unregisterAsyncHandler(AsyncListenerHandler listenerToken) {
if (listenerToken == null) if (listenerToken == null)
throw new IllegalArgumentException("listenerToken cannot be NULL"); throw new IllegalArgumentException("listenerToken cannot be NULL");
@ -71,7 +71,7 @@ public class AsyncFilterManager {
} }
// Called by ListenerToken // Called by ListenerToken
void unregisterAsyncHandlerInternal(ListenerToken listenerToken) { void unregisterAsyncHandlerInternal(AsyncListenerHandler listenerToken) {
PacketListener listener = listenerToken.getAsyncListener(); PacketListener listener = listenerToken.getAsyncListener();

View File

@ -8,7 +8,12 @@ import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.events.PacketListener; 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. * Signal an end to the packet processing.
@ -36,7 +41,7 @@ class ListenerToken {
// Minecraft main thread // Minecraft main thread
private Thread mainThread; 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) if (filterManager == null)
throw new IllegalArgumentException("filterManager cannot be NULL"); throw new IllegalArgumentException("filterManager cannot be NULL");
if (listener == null) if (listener == null)
@ -117,7 +122,7 @@ class ListenerToken {
// Now, get the next non-cancelled listener // Now, get the next non-cancelled listener
for (; marker.getListenerTraversal().hasNext(); ) { for (; marker.getListenerTraversal().hasNext(); ) {
ListenerToken token = marker.getListenerTraversal().next().getListener(); AsyncListenerHandler token = marker.getListenerTraversal().next().getListener();
if (!token.isCancelled()) { if (!token.isCancelled()) {
token.enqueuePacket(packet); token.enqueuePacket(packet);

View File

@ -40,7 +40,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
/** /**
* Current list of async packet listeners. * Current list of async packet listeners.
*/ */
private transient Iterator<PrioritizedListener<ListenerToken>> listenerTraversal; private transient Iterator<PrioritizedListener<AsyncListenerHandler>> listenerTraversal;
// Timeout handling // Timeout handling
private long initialTime; private long initialTime;
@ -207,7 +207,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
* Retrieve iterator for the next listener in line. * Retrieve iterator for the next listener in line.
* @return Next async packet listener iterator. * @return Next async packet listener iterator.
*/ */
public Iterator<PrioritizedListener<ListenerToken>> getListenerTraversal() { public Iterator<PrioritizedListener<AsyncListenerHandler>> getListenerTraversal() {
return listenerTraversal; return listenerTraversal;
} }
@ -215,7 +215,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
* Set the iterator for the next listener. * Set the iterator for the next listener.
* @param listenerTraversal - the new async packet listener iterator. * @param listenerTraversal - the new async packet listener iterator.
*/ */
void setListenerTraversal(Iterator<PrioritizedListener<ListenerToken>> listenerTraversal) { void setListenerTraversal(Iterator<PrioritizedListener<AsyncListenerHandler>> listenerTraversal) {
this.listenerTraversal = listenerTraversal; this.listenerTraversal = listenerTraversal;
} }

View File

@ -14,7 +14,7 @@ import com.comphenix.protocol.injector.PrioritizedListener;
* *
* @author Kristian * @author Kristian
*/ */
class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerToken> { class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncListenerHandler> {
/** /**
* Default maximum number of packets to process concurrently. * Default maximum number of packets to process concurrently.
@ -76,11 +76,11 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerT
// Any packet queued? // Any packet queued?
if (packet != null) { if (packet != null) {
Collection<PrioritizedListener<ListenerToken>> list = getListener(packet.getPacketID()); Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID());
AsyncMarker marker = packet.getAsyncMarker(); AsyncMarker marker = packet.getAsyncMarker();
if (list != null) { if (list != null) {
Iterator<PrioritizedListener<ListenerToken>> iterator = list.iterator(); Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator();
if (iterator.hasNext()) { if (iterator.hasNext()) {
marker.setListenerTraversal(iterator); marker.setListenerTraversal(iterator);
@ -117,7 +117,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<ListenerT
public void cleanupAll() { public void cleanupAll() {
// Cancel all the threads and every listener // Cancel all the threads and every listener
for (PrioritizedListener<ListenerToken> token : values()) { for (PrioritizedListener<AsyncListenerHandler> token : values()) {
if (token != null) { if (token != null) {
token.getListener().cancel(); token.getListener().cancel();
} }