Make it even clearer that the listener loop method should be

called from a separate thread.
This commit is contained in:
Kristian S. Stangeland 2012-09-29 21:18:21 +02:00
parent 025e97ca95
commit 4f4202185c
2 changed files with 20 additions and 4 deletions

View File

@ -86,12 +86,22 @@ public class AsyncListenerHandler {
}
/**
* Entry point for the background thread that will be processing the packet asynchronously.
* Create a runnable that will initiate the listener loop.
* <p>
* <b>WARNING:</b>
* Never call this method from the main thread. Doing so will block Minecraft.
* <b>Warning</b>: Never call the run() method in the main thread.
*/
public void listenerLoop() {
public Runnable getListenerLoop() {
return new Runnable() {
@Override
public void run() {
listenerLoop();
}
};
}
// DO NOT call this method from the main thread
private void listenerLoop() {
// Danger, danger!
if (Thread.currentThread().getId() == mainThread.getId())
throw new IllegalStateException("Do not call this method from the main thread.");

View File

@ -27,7 +27,13 @@ class PacketSendingQueue {
public synchronized void signalPacketUpdate(PacketEvent packetUpdated) {
// Mark this packet as finished
packetUpdated.getAsyncMarker().setProcessed(true);
trySendPackets();
}
/**
* Attempt to send any remaining packets.
*/
public synchronized void trySendPackets() {
// Transmit as many packets as we can
while (true) {
PacketEvent current = sendingQueue.peek();