mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-10-27 13:59:58 +01:00
Give automatically created worker threads sensible names.
This commit is contained in:
parent
12eab67db7
commit
5e36547aa2
@ -9,9 +9,11 @@ import java.util.logging.Level;
|
|||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.events.PacketListener;
|
import com.comphenix.protocol.events.PacketListener;
|
||||||
|
import com.google.common.base.Joiner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a handler for an asynchronous event.
|
* Represents a handler for an asynchronous event.
|
||||||
@ -206,7 +208,47 @@ public class AsyncListenerHandler {
|
|||||||
if (cancelled)
|
if (cancelled)
|
||||||
throw new IllegalStateException("Cannot start a worker when the listener is closing.");
|
throw new IllegalStateException("Cannot start a worker when the listener is closing.");
|
||||||
|
|
||||||
filterManager.scheduleAsyncTask(listener.getPlugin(), getListenerLoop());
|
final AsyncRunnable listenerLoop = getListenerLoop();
|
||||||
|
|
||||||
|
filterManager.scheduleAsyncTask(listener.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String workerName = getFriendlyWorkerName(listenerLoop.getID());
|
||||||
|
|
||||||
|
// Add the friendly worker name
|
||||||
|
Thread.currentThread().setName(workerName);
|
||||||
|
listenerLoop.run();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a friendly thread name using the following convention:
|
||||||
|
* <p><code>
|
||||||
|
* Protocol Worker {id} - {plugin} - [recv: {packets}, send: {packets}]
|
||||||
|
* </code></p>
|
||||||
|
* @param id - the worker ID.
|
||||||
|
* @return A friendly thread name.
|
||||||
|
*/
|
||||||
|
public String getFriendlyWorkerName(int id) {
|
||||||
|
return String.format("Protocol Worker #%s - %s - [recv: %s, send: %s]",
|
||||||
|
id,
|
||||||
|
PacketAdapter.getPluginName(listener),
|
||||||
|
fromWhitelist(listener.getReceivingWhitelist()),
|
||||||
|
fromWhitelist(listener.getSendingWhitelist())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert the given whitelist to a comma-separated list of packet IDs.
|
||||||
|
* @param whitelist - the whitelist.
|
||||||
|
* @return A comma separated list of packet IDs in the whitelist, or the emtpy string.
|
||||||
|
*/
|
||||||
|
private String fromWhitelist(ListeningWhitelist whitelist) {
|
||||||
|
if (whitelist == null)
|
||||||
|
return "";
|
||||||
|
else
|
||||||
|
return Joiner.on(", ").join(whitelist.getWhitelist());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user