diff --git a/README.md b/README.md index c92a5e23..bb762149 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ val job = ippPrinter.printJob( PrintQuality.High, Media.ISO_A4, mediaColWithSource("tray-1"), - notifyEvents = listOf("job-state-changed", "job-stopped", "job-completed") // CUPS + notifyEvents = listOf("job-state-changed", "job-progress") // CUPS ) job.subscription?.pollAndHandleNotifications { println(it) } diff --git a/src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt b/src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt index f2d66321..170c151f 100644 --- a/src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt +++ b/src/main/kotlin/de/gmuth/ipp/client/IppSubscription.kt @@ -139,13 +139,12 @@ class IppSubscription( @JvmOverloads fun pollAndHandleNotifications( - pollEvery: Duration = ofSeconds(5), // should be larger than 1s + pollEvery: Duration = ofSeconds(1), autoRenewSubscription: Boolean = false, handleNotification: (event: IppEventNotification) -> Unit = { logger.info { it.toString() } } ) { fun expiresAfterDelay() = expiresAt != null && now().plus(pollEvery).isAfter(expiresAt!!.minusSeconds(2)) try { - updateAttributes() pollHandlesNotifications = true while (pollHandlesNotifications) { if (expiryAvailable() && expired()) logger.warning { "Subscription #$id has expired" } @@ -154,7 +153,8 @@ class IppSubscription( Thread.sleep(pollEvery.toMillis()) } } catch (clientErrorNotFoundException: ClientErrorNotFoundException) { - logger.info { clientErrorNotFoundException.response.statusMessage.toString() } + // Subscription ends on job termination. CUPS than responds with "Subscription #... does not exist." + logger.fine { "${clientErrorNotFoundException.response.statusMessage}" } } }