mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-28 03:57:33 +01:00
Add the other cases where we need to know if we're on the main thread
or not.
This commit is contained in:
parent
8a26d047b2
commit
63197bbbd5
@ -143,7 +143,9 @@ public class AsyncFilterManager implements AsynchronousManager {
|
|||||||
|
|
||||||
// Start the process
|
// Start the process
|
||||||
getSendingQueue(syncPacket).enqueue(newEvent);
|
getSendingQueue(syncPacket).enqueue(newEvent);
|
||||||
getProcessingQueue(syncPacket).enqueue(newEvent);
|
|
||||||
|
// We know this is occuring on the main thread, to pass TRUE
|
||||||
|
getProcessingQueue(syncPacket).enqueue(newEvent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,14 +53,15 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||||||
/**
|
/**
|
||||||
* Enqueue a packet for processing by the asynchronous listeners.
|
* Enqueue a packet for processing by the asynchronous listeners.
|
||||||
* @param packet - packet to process.
|
* @param packet - packet to process.
|
||||||
|
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||||
* @return TRUE if we sucessfully queued the packet, FALSE if the queue ran out if space.
|
* @return TRUE if we sucessfully queued the packet, FALSE if the queue ran out if space.
|
||||||
*/
|
*/
|
||||||
public boolean enqueue(PacketEvent packet) {
|
public boolean enqueue(PacketEvent packet, boolean onMainThread) {
|
||||||
try {
|
try {
|
||||||
processingQueue.add(packet);
|
processingQueue.add(packet);
|
||||||
|
|
||||||
// Begin processing packets
|
// Begin processing packets
|
||||||
signalBeginProcessing();
|
signalBeginProcessing(onMainThread);
|
||||||
return true;
|
return true;
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
return false;
|
return false;
|
||||||
@ -69,8 +70,9 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the current method and each thread to signal that a packet might be ready for processing.
|
* Called by the current method and each thread to signal that a packet might be ready for processing.
|
||||||
|
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||||
*/
|
*/
|
||||||
public void signalBeginProcessing() {
|
public void signalBeginProcessing(boolean onMainThread) {
|
||||||
while (concurrentProcessing.tryAcquire()) {
|
while (concurrentProcessing.tryAcquire()) {
|
||||||
PacketEvent packet = processingQueue.poll();
|
PacketEvent packet = processingQueue.poll();
|
||||||
|
|
||||||
@ -91,7 +93,7 @@ class PacketProcessingQueue extends AbstractConcurrentListenerMultimap<AsyncList
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The packet has no further listeners. Just send it.
|
// The packet has no further listeners. Just send it.
|
||||||
sendingQueue.signalPacketUpdate(packet);
|
sendingQueue.signalPacketUpdate(packet, onMainThread);
|
||||||
signalProcessingDone();
|
signalProcessingDone();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,6 +23,10 @@ class PacketSendingQueue {
|
|||||||
// Whether or not packet transmission can only occur on the main thread
|
// Whether or not packet transmission can only occur on the main thread
|
||||||
private final boolean synchronizeMain;
|
private final boolean synchronizeMain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a packet sending queue.
|
||||||
|
* @param synchronizeMain - whether or not to synchronize with the main thread.
|
||||||
|
*/
|
||||||
public PacketSendingQueue(boolean synchronizeMain) {
|
public PacketSendingQueue(boolean synchronizeMain) {
|
||||||
this.synchronizeMain = synchronizeMain;
|
this.synchronizeMain = synchronizeMain;
|
||||||
this.sendingQueue = new PriorityBlockingQueue<PacketEvent>(INITIAL_CAPACITY, new Comparator<PacketEvent>() {
|
this.sendingQueue = new PriorityBlockingQueue<PacketEvent>(INITIAL_CAPACITY, new Comparator<PacketEvent>() {
|
||||||
@ -46,6 +50,8 @@ class PacketSendingQueue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when one of the packets have finished processing.
|
* Invoked when one of the packets have finished processing.
|
||||||
|
* @param packetUpdated - the packet that has now been updated.
|
||||||
|
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||||
*/
|
*/
|
||||||
public synchronized void signalPacketUpdate(PacketEvent packetUpdated, boolean onMainThread) {
|
public synchronized void signalPacketUpdate(PacketEvent packetUpdated, boolean onMainThread) {
|
||||||
// Mark this packet as finished
|
// Mark this packet as finished
|
||||||
@ -53,6 +59,11 @@ class PacketSendingQueue {
|
|||||||
trySendPackets(onMainThread);
|
trySendPackets(onMainThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Invoked when a list of packet IDs are no longer associated with any listeners.
|
||||||
|
* @param packetsRemoved - packets that no longer have any listeners.
|
||||||
|
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||||
|
*/
|
||||||
public synchronized void signalPacketUpdate(List<Integer> packetsRemoved, boolean onMainThread) {
|
public synchronized void signalPacketUpdate(List<Integer> packetsRemoved, boolean onMainThread) {
|
||||||
|
|
||||||
Set<Integer> lookup = new HashSet<Integer>(packetsRemoved);
|
Set<Integer> lookup = new HashSet<Integer>(packetsRemoved);
|
||||||
@ -70,6 +81,7 @@ class PacketSendingQueue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to send any remaining packets.
|
* Attempt to send any remaining packets.
|
||||||
|
* @param onMainThread - whether or not this is occuring on the main thread.
|
||||||
*/
|
*/
|
||||||
public void trySendPackets(boolean onMainThread) {
|
public void trySendPackets(boolean onMainThread) {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user