Make it even clearer that the listener loop method should be
called from a separate thread.
Dieser Commit ist enthalten in:
Ursprung
025e97ca95
Commit
4f4202185c
@ -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>
|
* <p>
|
||||||
* <b>WARNING:</b>
|
* <b>Warning</b>: Never call the run() method in the main thread.
|
||||||
* Never call this method from the main thread. Doing so will block Minecraft.
|
|
||||||
*/
|
*/
|
||||||
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!
|
// Danger, danger!
|
||||||
if (Thread.currentThread().getId() == mainThread.getId())
|
if (Thread.currentThread().getId() == mainThread.getId())
|
||||||
throw new IllegalStateException("Do not call this method from the main thread.");
|
throw new IllegalStateException("Do not call this method from the main thread.");
|
||||||
|
@ -27,7 +27,13 @@ class PacketSendingQueue {
|
|||||||
public synchronized void signalPacketUpdate(PacketEvent packetUpdated) {
|
public synchronized void signalPacketUpdate(PacketEvent packetUpdated) {
|
||||||
// Mark this packet as finished
|
// Mark this packet as finished
|
||||||
packetUpdated.getAsyncMarker().setProcessed(true);
|
packetUpdated.getAsyncMarker().setProcessed(true);
|
||||||
|
trySendPackets();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to send any remaining packets.
|
||||||
|
*/
|
||||||
|
public synchronized void trySendPackets() {
|
||||||
// Transmit as many packets as we can
|
// Transmit as many packets as we can
|
||||||
while (true) {
|
while (true) {
|
||||||
PacketEvent current = sendingQueue.peek();
|
PacketEvent current = sendingQueue.peek();
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren