We don't expect consumers to create asynchronous markers, so

don't allow them to set it in the packet event.
This commit is contained in:
Kristian S. Stangeland 2012-09-29 21:42:16 +02:00
parent a6db5419c0
commit 65b5a0e8ec
5 changed files with 16 additions and 21 deletions

View File

@ -24,6 +24,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.comphenix.protocol.async.AsyncFilterManager;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketListener; import com.comphenix.protocol.events.PacketListener;
import com.comphenix.protocol.injector.PacketConstructor; import com.comphenix.protocol.injector.PacketConstructor;
@ -122,4 +123,10 @@ public interface ProtocolManager extends PacketStream {
* @return TRUE if it has, FALSE otherwise. * @return TRUE if it has, FALSE otherwise.
*/ */
public boolean isClosed(); public boolean isClosed();
/**
* Retrieve the current asyncronous packet manager.
* @return Asyncronous packet manager.
*/
public AsyncFilterManager getAsyncFilterManager();
} }

View File

@ -79,6 +79,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID()); Collection<PrioritizedListener<AsyncListenerHandler>> list = getListener(packet.getPacketID());
AsyncMarker marker = packet.getAsyncMarker(); AsyncMarker marker = packet.getAsyncMarker();
// Yes, removing the marker will cause the chain to stop
if (list != null) { if (list != null) {
Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator(); Iterator<PrioritizedListener<AsyncListenerHandler>> iterator = list.iterator();
@ -89,7 +90,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
} }
} }
// The packet has no listeners. Just send it. // The packet has no further listeners. Just send it.
sendingQueue.signalPacketUpdate(packet); sendingQueue.signalPacketUpdate(packet);
signalProcessingDone(); signalProcessingDone();

View File

@ -42,7 +42,7 @@ class PacketSendingQueue {
AsyncMarker marker = current.getAsyncMarker(); AsyncMarker marker = current.getAsyncMarker();
if (marker.isProcessed() || marker.hasExpired()) { if (marker.isProcessed() || marker.hasExpired()) {
if (marker.isProcessed()) if (marker.isProcessed() && !current.isCancelled())
sendPacket(current); sendPacket(current);
sendingQueue.poll(); sendingQueue.poll();

View File

@ -60,6 +60,7 @@ public class PacketEvent extends EventObject implements Cancellable {
super(origial.source); super(origial.source);
this.packet = origial.packet; this.packet = origial.packet;
this.player = origial.player; this.player = origial.player;
this.cancel = origial.cancel;
this.serverPacket = origial.serverPacket; this.serverPacket = origial.serverPacket;
this.asyncMarker = asyncMarker; this.asyncMarker = asyncMarker;
this.asynchronous = true; this.asynchronous = true;
@ -156,7 +157,7 @@ public class PacketEvent extends EventObject implements Cancellable {
/** /**
* Retrieve the asynchronous marker. * Retrieve the asynchronous marker.
* <p> * <p>
* If the packet is synchronous, this marker will be used to schedule an asynchronous event. In this * If the packet is synchronous, this marker will be used to schedule an asynchronous event. In the following
* asynchronous event, the marker is used to correctly pass the packet around to the different threads. * asynchronous event, the marker is used to correctly pass the packet around to the different threads.
* <p> * <p>
* Note that if there are no asynchronous events that can receive this packet, the marker is NULL. * Note that if there are no asynchronous events that can receive this packet, the marker is NULL.
@ -166,19 +167,6 @@ public class PacketEvent extends EventObject implements Cancellable {
return asyncMarker; return asyncMarker;
} }
/**
* Set the asynchronous marker.
* <p>
* If the marker is non-null at the end of an synchronous event processing, the packet will be scheduled
* to be processed asynchronously with the given settings.
* <p>
* Note that if there are no asynchronous events that can receive this packet, the marker should be NULL.
* @param asyncMarker - the new asynchronous marker, or NULL.
*/
public void setAsyncMarker(AsyncMarker asyncMarker) {
this.asyncMarker = asyncMarker;
}
/** /**
* Determine if the packet event has been executed asynchronously or not. * Determine if the packet event has been executed asynchronously or not.
* @return TRUE if this packet event is asynchronous, FALSE otherwise. * @return TRUE if this packet event is asynchronous, FALSE otherwise.

View File

@ -137,10 +137,7 @@ public final class PacketFilterManager implements ProtocolManager {
} }
} }
/** @Override
* Retrieve the current async packet filter manager.
* @return Async filter manager.
*/
public AsyncFilterManager getAsyncFilterManager() { public AsyncFilterManager getAsyncFilterManager() {
return asyncFilterManager; return asyncFilterManager;
} }
@ -313,9 +310,11 @@ public final class PacketFilterManager implements ProtocolManager {
// Process synchronous events // Process synchronous events
packetListeners.invokePacketRecieving(logger, event); packetListeners.invokePacketRecieving(logger, event);
// To cancel the asynchronous processing, use the async marker // To cancel asynchronous processing, use the async marker
if (!event.isCancelled() && !hasAsyncCancelled(event.getAsyncMarker())) { if (!event.isCancelled() && !hasAsyncCancelled(event.getAsyncMarker())) {
asyncFilterManager.enqueueSyncPacket(event, event.getAsyncMarker()); asyncFilterManager.enqueueSyncPacket(event, event.getAsyncMarker());
// The above makes a copy of the event, so it's safe to cancel it
event.setCancelled(true); event.setCancelled(true);
} }
} }