|
@@ -30,6 +30,8 @@ import java.net.URI
|
|
|
import java.time.LocalDateTime
|
|
|
import java.time.format.DateTimeFormatter
|
|
|
import java.util.*
|
|
|
+import java.util.concurrent.ConcurrentHashMap
|
|
|
+import java.util.concurrent.ConcurrentMap
|
|
|
import kotlin.system.exitProcess
|
|
|
import kotlin.system.measureTimeMillis
|
|
|
|
|
@@ -74,7 +76,8 @@ fun main(args: Array<String>) {
|
|
|
class Client(
|
|
|
val number: String,
|
|
|
var connectAt: String,
|
|
|
- var lastRequest: String
|
|
|
+ var lastRequest: String,
|
|
|
+ val sessionId: String?
|
|
|
) : Serializable {
|
|
|
var reqSuccess = 0
|
|
|
var reqFailed = 0
|
|
@@ -83,7 +86,7 @@ class Client(
|
|
|
|
|
|
object ClientHolder {
|
|
|
private val mutexSucReq = Mutex()
|
|
|
- private val clientMap: MutableMap<String, Client> = mutableMapOf()
|
|
|
+ private val clientMap: ConcurrentMap<String, Client> by lazy { ConcurrentHashMap() }
|
|
|
private suspend fun massiveRun(action: suspend () -> Unit) {
|
|
|
measureTimeMillis {
|
|
|
coroutineScope { // sc
|
|
@@ -94,11 +97,17 @@ object ClientHolder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ fun removeBySessionId(sessionId: String?) {
|
|
|
+ clientMap.entries.filter { it.value.sessionId == sessionId }.forEach {
|
|
|
+ clientMap.remove(it.key)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
fun put(key: String, client: Client) {
|
|
|
- clientMap[key] = client
|
|
|
+ clientMap.getOrPut(key) { client }
|
|
|
}
|
|
|
|
|
|
- fun get() = clientMap.toMap()
|
|
|
+ fun get() = clientMap
|
|
|
|
|
|
fun addFailedRequest(clNum: String) {
|
|
|
runBlocking {
|
|
@@ -142,69 +151,25 @@ object ClientHolder {
|
|
|
class WebSocketEventListener {
|
|
|
@EventListener(ApplicationReadyEvent::class)
|
|
|
fun doSomethingAfterStartup() {
|
|
|
- Configurator.reconfigure(URI("http://127.0.0.1:9090/log-setting.xml"))
|
|
|
+ logBuilder()
|
|
|
}
|
|
|
|
|
|
- fun logBuilder(clNum: String) {
|
|
|
-// val builder = ConfigurationBuilderFactory.newConfigurationBuilder()
|
|
|
-// val consoleAppender = builder.newAppender("stdout", "Console")
|
|
|
-//
|
|
|
-// val appLog = builder.newAppender("appLog", "RollingFile")
|
|
|
-// appLog.addAttribute("fileName", "log/app/app.log")
|
|
|
-// appLog.addAttribute("filePattern", "log/app/\$\${date:yyyy - MM}/app-%d{yyyy-MM-dd}-%i.log.zip")
|
|
|
-//
|
|
|
-// val flow: FilterComponentBuilder = builder.newFilter(
|
|
|
-// "MarkerFilter",
|
|
|
-// Filter.Result.ACCEPT,
|
|
|
-// Filter.Result.DENY
|
|
|
-// )
|
|
|
-// flow.addAttribute("marker", "FLOW")
|
|
|
-// consoleAppender.add(flow)
|
|
|
-// val standard = builder.newLayout("PatternLayout")
|
|
|
-// standard.addAttribute("pattern", "%d %p [%c{1}] %m%n")
|
|
|
-// val policies = builder.newLayout("Policies")
|
|
|
-// val timeBasedTriggeringPolicy = builder.newLayout("TimeBasedTriggeringPolicy")
|
|
|
-// val sizeBasedTriggeringPolicy = builder.newLayout("SizeBasedTriggeringPolicy")
|
|
|
-//
|
|
|
-// sizeBasedTriggeringPolicy.addAttribute("size", "10 MB")
|
|
|
-// policies.addComponent(timeBasedTriggeringPolicy)
|
|
|
-// policies.addComponent(sizeBasedTriggeringPolicy)
|
|
|
-// consoleAppender.add(standard)
|
|
|
-// builder.add(consoleAppender)
|
|
|
-//
|
|
|
-// appLog.add(standard)
|
|
|
-// appLog.addComponent(policies)
|
|
|
-// builder.add(appLog)
|
|
|
-//
|
|
|
-// val rootLogger: RootLoggerComponentBuilder = builder.newRootLogger(Level.INFO)
|
|
|
-// rootLogger.add(builder.newAppenderRef("stdout"))
|
|
|
-// builder.add(rootLogger)
|
|
|
-//
|
|
|
-// val logger: LoggerComponentBuilder = builder.newLogger("co.id.datacomsolusindo.ipphonebridge", Level.DEBUG)
|
|
|
-// logger.add(builder.newAppenderRef("appLog"))
|
|
|
-// logger.addAttribute("additivity", false)
|
|
|
-// builder.add(logger)
|
|
|
-// rootLogger.add(builder.newAppenderRef("appLog"))
|
|
|
-//
|
|
|
-// ClientHolder.get().entries.forEach {
|
|
|
-// val clientLog = builder.newAppender("client-${it.key}", "RollingFile")
|
|
|
-// clientLog.addAttribute("fileName", "log/${it.key}/client-${it.key}.log")
|
|
|
-// clientLog.addAttribute(
|
|
|
-// "filePattern",
|
|
|
-// "log/${it.key}/\$\${date:yyyy - MM}/app-%d{yyyy-MM-dd}-%i.client-${it.key}.zip"
|
|
|
-// )
|
|
|
-// clientLog.add(standard)
|
|
|
-// clientLog.addComponent(policies)
|
|
|
-// builder.add(clientLog)
|
|
|
-//
|
|
|
-// val loggerClient: LoggerComponentBuilder = builder.newLogger("client-${it.key}", Level.DEBUG)
|
|
|
-// loggerClient.add(builder.newAppenderRef("client-${it.key}"))
|
|
|
-// loggerClient.addAttribute("additivity", false)
|
|
|
-// builder.add(loggerClient)
|
|
|
-// rootLogger.add(builder.newAppenderRef("client-${it.key}"))
|
|
|
-// }
|
|
|
+ fun logBuilder() {
|
|
|
+ val confFile = File("conf/general.ini")
|
|
|
+ var port = if (confFile.exists()) {
|
|
|
+ val ini = Wini(File("conf/general.ini"))
|
|
|
+ ini.get("server", "port")
|
|
|
+ } else {
|
|
|
+ System.getenv("PORT")
|
|
|
+ }
|
|
|
+ port = if (port == null) {
|
|
|
+// println("undefined port")
|
|
|
+ "9090"
|
|
|
+ } else {
|
|
|
+ port
|
|
|
+ }
|
|
|
|
|
|
- Configurator.reconfigure(URI("http://127.0.0.1:9090/log-setting.xml"))
|
|
|
+ Configurator.reconfigure(URI("http://127.0.0.1:$port/log-setting.xml"))
|
|
|
}
|
|
|
|
|
|
// @EventListener
|
|
@@ -227,6 +192,7 @@ class WebSocketEventListener {
|
|
|
@EventListener
|
|
|
fun onDisconnect(event: SessionDisconnectEvent) {
|
|
|
AppLog.write(this.javaClass).info("disconnect with session id ${event.sessionId}")
|
|
|
+ ClientHolder.removeBySessionId(event.sessionId)
|
|
|
}
|
|
|
|
|
|
@EventListener
|
|
@@ -245,12 +211,13 @@ class WebSocketEventListener {
|
|
|
clNum, Client(
|
|
|
clNum,
|
|
|
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")),
|
|
|
- LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"))
|
|
|
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")),
|
|
|
+ sessionId
|
|
|
)
|
|
|
)
|
|
|
|
|
|
LogManager.getLogger(this.javaClass).info("clientConnected $simDestination")
|
|
|
- logBuilder(clNum)
|
|
|
+ logBuilder()
|
|
|
LogManager.getLogger("client-$clNum").info("Client $clNum Connected")
|
|
|
}
|
|
|
}
|