Skip to content

Commit

Permalink
fix(graphql): EmbeddedServer now encapsulates ApplicationEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloFilaseta authored and DanySK committed Oct 20, 2024
1 parent 598385f commit 57f9738
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

package it.unibo.alchemist.boundary.monitors

import io.ktor.server.engine.ApplicationEngine
import io.ktor.server.engine.EmbeddedServer
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import io.ktor.server.netty.NettyApplicationEngine
import it.unibo.alchemist.boundary.OutputMonitor
import it.unibo.alchemist.boundary.graphql.monitor.EnvironmentSubscriptionMonitor
import it.unibo.alchemist.boundary.graphql.server.modules.graphQLModule
Expand All @@ -36,14 +37,14 @@ private val logger = LoggerFactory.getLogger(GraphQLMonitor::class.java)
*/
class GraphQLMonitor<T, P : Position<out P>> @JvmOverloads constructor(
val environment: Environment<T, P>,
val host: String = DefaultGraphQLSettings.DEFAULT_HOST,
val port: Int = DefaultGraphQLSettings.DEFAULT_PORT,
val teardownOnSimulationTermination: Boolean = true,
private val host: String = DefaultGraphQLSettings.DEFAULT_HOST,
private val port: Int = DefaultGraphQLSettings.DEFAULT_PORT,
private val teardownOnSimulationTermination: Boolean = true,
private val serverDispatcher: CoroutineDispatcher = Dispatchers.Default,
) : OutputMonitor<Any, Nothing> {

private val subscriptionMonitor = EnvironmentSubscriptionMonitor<Any, Nothing>()
private lateinit var server: ApplicationEngine
private lateinit var server: EmbeddedServer<NettyApplicationEngine, NettyApplicationEngine.Configuration>

override fun initialized(environment: Environment<Any, Nothing>) {
environment.simulation.addOutputMonitor(subscriptionMonitor)
Expand All @@ -61,7 +62,7 @@ class GraphQLMonitor<T, P : Position<out P>> @JvmOverloads constructor(
"alchemist-graphql-server@$host:$port",
).start()
runBlocking {
logger.info("Starting GraphQL server at $host:${server.resolvedConnectors().first().port}")
logger.info("Starting GraphQL server at $host:${server.engine.resolvedConnectors().first().port}")
}
mutex.acquireUninterruptibly()
}
Expand All @@ -72,14 +73,13 @@ class GraphQLMonitor<T, P : Position<out P>> @JvmOverloads constructor(
}
}

private fun makeServer(): ApplicationEngine =
embeddedServer(
Netty,
port = port,
host = host,
module = {
graphQLModule(this@GraphQLMonitor.environment)
graphQLRoutingModule()
},
)
private fun makeServer() = embeddedServer(
Netty,
port = port,
host = host,
module = {
graphQLModule(this@GraphQLMonitor.environment)
graphQLRoutingModule()
},
)
}

0 comments on commit 57f9738

Please sign in to comment.