Don't bother adding checks to the listener queue if no listeners are registered

This commit is contained in:
Luck 2017-02-15 19:39:24 +00:00
parent 05f906a759
commit 8d86eed0a7
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -39,6 +39,7 @@ public class DebugHandler implements Runnable {
private final Map<UUID, DebugListener> listeners; private final Map<UUID, DebugListener> listeners;
private final Queue<CheckData> queue; private final Queue<CheckData> queue;
private boolean listening = false;
@Setter @Setter
private boolean shutdown = false; private boolean shutdown = false;
@ -52,16 +53,25 @@ public class DebugHandler implements Runnable {
} }
public void offer(String checked, String node, Tristate value) { public void offer(String checked, String node, Tristate value) {
if (!listening) {
return;
}
queue.offer(new CheckData(checked, node, value)); queue.offer(new CheckData(checked, node, value));
} }
public void register(Sender sender, String filter, boolean notify) { public void register(Sender sender, String filter, boolean notify) {
listening = true;
listeners.put(sender.getUuid(), new DebugListener(pluginVersion, sender, filter, notify)); listeners.put(sender.getUuid(), new DebugListener(pluginVersion, sender, filter, notify));
} }
public DebugListener unregister(UUID uuid) { public DebugListener unregister(UUID uuid) {
flush(); flush();
return listeners.remove(uuid); DebugListener ret = listeners.remove(uuid);
if (listeners.isEmpty()) {
listening = false;
}
return ret;
} }
@Override @Override