Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use constant session #8

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions src/main/kotlin/com/faforever/icebreaker/service/SessionService.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faforever.icebreaker.service

import com.faforever.icebreaker.config.FafProperties
import com.faforever.icebreaker.persistence.IceSessionEntity
import com.faforever.icebreaker.persistence.IceSessionRepository
import io.quarkus.scheduler.Scheduled
import jakarta.enterprise.inject.Instance
Expand All @@ -11,6 +10,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.UUID

private val LOG: Logger = LoggerFactory.getLogger(SessionService::class.java)

Expand All @@ -20,33 +20,34 @@ class SessionService(
private val fafProperties: FafProperties,
private val iceSessionRepository: IceSessionRepository,
) {
private val sessionId = UUID.randomUUID().toString()
private val activeSessionHandlers = sessionHandlers.filter { it.active }

fun getServers(): List<Server> = activeSessionHandlers.flatMap { it.getIceServers() }

@Transactional
fun getSession(gameId: Long): Session {
try {
iceSessionRepository.acquireGameLock(gameId)
// try {
// iceSessionRepository.acquireGameLock(gameId)

val session = iceSessionRepository.findByGameId(gameId)
?: IceSessionEntity(gameId = gameId, createdAt = Instant.now()).also {
LOG.debug("Creating session for gameId $gameId")
iceSessionRepository.persist(it)
}
// val session = iceSessionRepository.findByGameId(gameId)
// ?: IceSessionEntity(gameId = gameId, createdAt = Instant.now()).also {
// LOG.debug("Creating session for gameId $gameId")
// iceSessionRepository.persist(it)
// }

val servers = activeSessionHandlers.flatMap {
it.createSession(session.id)
it.getIceServersSession(session.id)
}

return Session(
id = session.id,
servers = servers,
)
} finally {
iceSessionRepository.releaseGameLock(gameId)
val servers = activeSessionHandlers.flatMap {
it.createSession(sessionId)
it.getIceServersSession(sessionId)
}

return Session(
id = sessionId,
servers = servers,
)
// } finally {
// iceSessionRepository.releaseGameLock(gameId)
// }
}

@Transactional
Expand Down
Loading