Код: Выделить всё
class SSEService : AutoCloseable {
private val emitters: MutableMap = ConcurrentHashMap()
private var running = true
@PreDestroy
override fun close() {
running = false
logger.info("Shutting down SSE service...")
emitters.values.flatMap { it }.forEach (SseEmitter::complete)
emitters.clear()
}
fun newEmitterFor(type: SSEEventType): SseEmitter {
val emitter = SseEmitter(Long.MAX_VALUE)
val list = CopyOnWriteArrayList()
emitters.getOrPut(type) { list }.add(emitter)
emitter.onCompletion {
// cleanup ...
}
emitter.onTimeout {
// cleanup ...
}
emitter.onError { e: Throwable ->
// cleanup ...
}
return emitter
}
fun emitServiceStatus(statusList: List) {
// ...
}
}
Код: Выделить всё
[ionShutdownHook] o.s.b.w.e.undertow.UndertowWebServer : Commencing graceful shutdown. Waiting for active requests to complete
------ after 30 seconds ------
[ionShutdownHook] o.s.c.support.DefaultLifecycleProcessor : Shutdown phase 2147482623 ends with 1 bean still running after timeout of 30000ms: [webServerGracefulShutdown]
[ionShutdownHook] o.s.b.w.e.undertow.UndertowWebServer : Graceful shutdown aborted with one or more requests still active
[ionShutdownHook] io.undertow : stopping server: Undertow - 2.3.19.Final
[ionShutdownHook] io.undertow.servlet : Destroying Spring FrameworkServlet 'dispatcherServlet'
[ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
[ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
[ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
------ this is my @PreDestroy call ------
[ionShutdownHook] org.hexworks.photon.service.SSEService : Shutting down SSE service...
[ionShutdownHook] .s.c.a.CommonAnnotationBeanPostProcessor : Destroy method on bean with name 'sseService' threw an exception: java.lang.NullPointerException: Cannot invoke "io.undertow.servlet.api.Deployment.getServletContext()" because the return value of "io.undertow.servlet.api.DeploymentManager.getDeployment()" is null
Process finished with exit code 130
Я проверил документацию Spring, и информации о том, как правильно использовать SSE, практически нет. Что я делаю неправильно? Как правильно завершить соединения SSE?
Подробнее здесь: https://stackoverflow.com/questions/797 ... l-shutdown
Мобильная версия