From bde79b5734c9161614c56eb00fe54dc28b153979 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Tue, 26 Nov 2024 18:24:53 -0500 Subject: [PATCH] Stop listening on printers properly --- src/qz/printer/status/StatusMonitor.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qz/printer/status/StatusMonitor.java b/src/qz/printer/status/StatusMonitor.java index a9dace95..069a66c4 100644 --- a/src/qz/printer/status/StatusMonitor.java +++ b/src/qz/printer/status/StatusMonitor.java @@ -134,19 +134,19 @@ public synchronized static void sendStatuses(SocketConnection connection) { ArrayList statuses = isWindows() ? WmiPrinterStatusThread.getAllStatuses(): CupsUtils.getAllStatuses(); // First check if we're listening on all printers for this connection - List allPrinters = clientPrinterConnections.get(ALL_PRINTERS); - if (allPrinters != null) { - sendForAllPrinters = allPrinters.contains(connection); + List connections = clientPrinterConnections.get(ALL_PRINTERS); + if (connections != null) { + sendForAllPrinters = connections.contains(connection); } for (Status status : statuses) { if (sendForAllPrinters) { - statusSessions.get(connection).statusChanged(status, () -> allPrinters.remove(connection)); + statusSessions.get(connection).statusChanged(status, () -> stopListening(connection)); } else { // Only send the status of the printers requested - List thisPrinter = clientPrinterConnections.get(status.getPrinter()); - if ((thisPrinter != null) && thisPrinter.contains(connection)) { - statusSessions.get(connection).statusChanged(status, () -> thisPrinter.remove(connection)); + connections = clientPrinterConnections.get(status.getPrinter()); + if ((connections != null) && connections.contains(connection)) { + statusSessions.get(connection).statusChanged(status, () -> stopListening(connection)); } } } @@ -210,7 +210,7 @@ private synchronized static boolean dispatchStatusEvent() { // Notify each client subscription for(SocketConnection connection : listeningConnections) { - statusSessions.get(connection).statusChanged(status, () -> statusSessions.remove(connection)); + statusSessions.get(connection).statusChanged(status, () -> stopListening(connection)); } return true;