...
This commit is contained in:
parent
62e408230e
commit
d552584446
@ -1,7 +1,7 @@
|
|||||||
object Defines {
|
object Defines {
|
||||||
val DETAILLOG = false
|
val DETAILLOG = false
|
||||||
val LLM_PORT = 8080
|
var LLM_PORT = 8080
|
||||||
val EMBEDDING_PORT = 8081
|
var EMBEDDING_PORT = 8081
|
||||||
val AUTOSELL = false
|
val AUTOSELL = false
|
||||||
val BLACKLISTEDSTOCKCODES = listOf<String>()
|
val BLACKLISTEDSTOCKCODES = listOf<String>()
|
||||||
}
|
}
|
||||||
@ -54,6 +54,7 @@ import service.TradingDecisionCallback
|
|||||||
import ui.DashboardScreen
|
import ui.DashboardScreen
|
||||||
import ui.SettingsScreen
|
import ui.SettingsScreen
|
||||||
import ui.TradingDecisionLog
|
import ui.TradingDecisionLog
|
||||||
|
import util.PortFinder
|
||||||
|
|
||||||
// 화면 상태 정의
|
// 화면 상태 정의
|
||||||
enum class AppScreen { Settings, Dashboard, TradingDecision }
|
enum class AppScreen { Settings, Dashboard, TradingDecision }
|
||||||
@ -94,13 +95,21 @@ fun initLogger(isDebug: Boolean) {
|
|||||||
println("🤫 운영 모드: 에러 로그만 출력합니다.")
|
println("🤫 운영 모드: 에러 로그만 출력합니다.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private var isAppStarted = false
|
||||||
fun main() = application {
|
fun main() = application {
|
||||||
initLogger(DETAILLOG)
|
if (!isAppStarted) {
|
||||||
|
initLogger(DETAILLOG)
|
||||||
|
val (port1, port2) = PortFinder.findAvailablePortPair(18080)
|
||||||
|
|
||||||
|
println("🚀 AI 서버용 포트 할당 완료: 메인($port1), 서브($port2)")
|
||||||
|
LLM_PORT = port1
|
||||||
|
EMBEDDING_PORT = port2
|
||||||
|
|
||||||
|
isAppStarted = true
|
||||||
|
}
|
||||||
|
|
||||||
val trayState = rememberTrayState()
|
val trayState = rememberTrayState()
|
||||||
var isWindowOpen by remember { mutableStateOf(false) } // 창의 표시 상태 관리
|
var isWindowOpen by remember { mutableStateOf(false) } // 창의 표시 상태 관리
|
||||||
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
SystemSleepPreventer.start()
|
SystemSleepPreventer.start()
|
||||||
AutoTradingManager.startBackgroundScheduler()
|
AutoTradingManager.startBackgroundScheduler()
|
||||||
|
|||||||
51
src/main/kotlin/util/PortFinder.kt
Normal file
51
src/main/kotlin/util/PortFinder.kt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package util
|
||||||
|
import java.net.ServerSocket
|
||||||
|
|
||||||
|
object PortFinder {
|
||||||
|
/**
|
||||||
|
* 사용 가능한 두 개의 포트를 찾아 Pair(첫번째, 두번째)로 반환합니다.
|
||||||
|
* @param startPort 검색을 시작할 포트 번호
|
||||||
|
* @param mustBeConsecutive true일 경우 두 포트가 연속번호(ex: 18080, 18081)여야 함
|
||||||
|
*/
|
||||||
|
fun findAvailablePortPair(startPort: Int, mustBeConsecutive: Boolean = true): Pair<Int, Int> {
|
||||||
|
var currentPort = startPort
|
||||||
|
|
||||||
|
while (currentPort < 65534) {
|
||||||
|
if (isPortAvailable(currentPort)) {
|
||||||
|
if (mustBeConsecutive) {
|
||||||
|
// 연속된 포트가 필요한 경우 (n, n+1)
|
||||||
|
if (isPortAvailable(currentPort + 1)) {
|
||||||
|
return Pair(currentPort, currentPort + 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 연속될 필요 없는 경우, 그다음 사용 가능한 포트를 찾음
|
||||||
|
val secondPort = findAvailablePort(currentPort + 1)
|
||||||
|
return Pair(currentPort, secondPort)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentPort++
|
||||||
|
}
|
||||||
|
throw RuntimeException("⚠️ 사용 가능한 포트 쌍을 찾을 수 없습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 단일 포트 가용성 체크 (기존 로직 유지)
|
||||||
|
*/
|
||||||
|
fun findAvailablePort(startPort: Int): Int {
|
||||||
|
for (port in startPort..65535) {
|
||||||
|
if (isPortAvailable(port)) return port
|
||||||
|
}
|
||||||
|
throw RuntimeException("⚠️ 사용 가능한 포트가 없습니다.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isPortAvailable(port: Int): Boolean {
|
||||||
|
return try {
|
||||||
|
ServerSocket(port).use { socket ->
|
||||||
|
socket.reuseAddress = true
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user