Открыть боковую панель
Aurora OS
Kotlin Multiplatform
Libraries
ktor
Коммиты
7ef65de0
Коммит
7ef65de0
создал
Дек 17, 2024
по автору
Bruce Hamilton
Зафиксировано автором
Bruce Hamilton
Дек 19, 2024
Просмотр файлов
KTOR-7963 Handle ClosedWatchServiceException
владелец
23eee5a9
Изменения
2
Скрыть пробелы
Построчно
Рядом
ktor-server/ktor-server-cio/jvm/test/io/ktor/tests/server/cio/CIOEngineTestJvm.kt
Просмотр файла @
7ef65de0
...
...
@@ -7,8 +7,10 @@ package io.ktor.tests.server.cio
import
io.ktor.server.cio.*
import
io.ktor.server.engine.*
import
io.ktor.server.testing.suites.*
import
kotlin.system.*
import
kotlin.test.*
import
kotlin.system.measureTimeMillis
import
kotlin.test.Ignore
import
kotlin.test.Test
import
kotlin.test.assertTrue
class
CIOCompressionTest
:
CompressionTestSuite
<
CIOApplicationEngine
,
CIOApplicationEngine
.
Configuration
>(
CIO
)
{
init
{
...
...
ktor-server/ktor-server-core/jvm/src/io/ktor/server/engine/EmbeddedServerJvm.kt
Просмотр файла @
7ef65de0
...
...
@@ -100,28 +100,10 @@ actual constructor(
return
@read
currentApplication
}
val
changes
=
packageWatchKeys
.
flatMap
{
it
.
pollEvents
()
}
if
(
changes
.
isEmpty
())
{
if
(
getFileChanges
().
isNullOrEmpty
())
{
return
@read
currentApplication
}
environment
.
log
.
info
(
"Changes in application detected."
)
var
count
=
changes
.
size
while
(
true
)
{
Thread
.
sleep
(
200
)
val
moreChanges
=
packageWatchKeys
.
flatMap
{
it
.
pollEvents
()
}
if
(
moreChanges
.
isEmpty
())
{
break
}
environment
.
log
.
debug
(
"Waiting for more changes."
)
count
+=
moreChanges
.
size
}
environment
.
log
.
debug
(
"Changes to $count files caused application restart."
)
changes
.
take
(
5
).
forEach
{
environment
.
log
.
debug
(
"... ${it.context()}"
)
}
applicationInstanceLock
.
write
{
destroyApplication
()
val
(
application
,
classLoader
)
=
createApplication
()
...
...
@@ -132,6 +114,39 @@ actual constructor(
return
@read
applicationInstance
?:
error
(
"EmbeddedServer was stopped"
)
}
private
fun
getFileChanges
():
List
<
WatchEvent
<
*
>>?
{
try
{
val
changes
=
packageWatchKeys
.
flatMap
{
it
.
pollEvents
()
}
if
(
changes
.
isEmpty
())
{
return
changes
}
environment
.
log
.
info
(
"Changes in application detected."
)
var
count
=
changes
.
size
while
(
true
)
{
Thread
.
sleep
(
200
)
val
moreChanges
=
packageWatchKeys
.
flatMap
{
it
.
pollEvents
()
}
if
(
moreChanges
.
isEmpty
())
{
break
}
environment
.
log
.
debug
(
"Waiting for more changes."
)
count
+=
moreChanges
.
size
}
environment
.
log
.
debug
(
"Changes to $count files caused application restart."
)
changes
.
take
(
5
).
forEach
{
environment
.
log
.
debug
(
"... {}"
,
it
.
context
())
}
return
changes
}
catch
(
e
:
InterruptedException
)
{
environment
.
log
.
debug
(
"Watch service was interrupted"
,
e
)
return
null
}
catch
(
e
:
ClosedWatchServiceException
)
{
environment
.
log
.
debug
(
"Watch service was closed"
,
e
)
return
null
}
}
private
fun
createApplication
():
Pair
<
Application
,
ClassLoader
>
{
val
classLoader
=
createClassLoader
()
val
currentThread
=
Thread
.
currentThread
()
...
...
@@ -383,10 +398,7 @@ actual constructor(
}
private
fun
cleanupWatcher
()
{
try
{
watcher
?.
close
()
}
catch
(
_
:
NoClassDefFoundError
)
{
}
runCatching
{
watcher
?.
close
()
}
}
}
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать