Selaa lähdekoodia

fix minor thing

herlanS_ 3 vuotta sitten
vanhempi
commit
b776d20641

+ 22 - 0
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/BridgeFIlter.kt

@@ -3,6 +3,7 @@ package co.id.datacomsolusindo.ipphonebridge
 import com.fasterxml.jackson.databind.ObjectMapper
 import com.fasterxml.jackson.databind.ObjectWriter
 import org.apache.logging.log4j.LogManager
+import org.ini4j.Wini
 import org.springframework.core.Ordered
 import org.springframework.core.annotation.Order
 import org.springframework.core.io.ResourceLoader
@@ -233,6 +234,27 @@ object Singletons {
     val responseQue: ConcurrentMap<String, Resp> by lazy { ConcurrentHashMap() }
     val requestInstance: ConcurrentMap<String, RequestQue> by lazy { ConcurrentHashMap() }
     val buildSocketChunkData: ConcurrentMap<String, ChunkCollector> by lazy { ConcurrentHashMap() }
+
+    private val properties by lazy { Properties() }
+    fun properties(): Properties {
+
+        if (properties.isEmpty) {
+            val iniFIle = File("conf/general.ini")
+            properties["server.port"] = when {
+                System.getenv("PORT") != null -> {
+                    System.getenv("PORT")
+                }
+                iniFIle.exists() -> {
+                    val ini = Wini(iniFIle)
+                    ini.get("server", "port") ?: "9090"
+                }
+                else -> {
+                    "9090"
+                }
+            }
+        }
+        return properties
+    }
 }
 
 

+ 18 - 27
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/ChunkCollector.kt

@@ -10,35 +10,26 @@ import kotlin.concurrent.fixedRateTimer
 class ChunkCollector(private val id: String) {
     private val mapSocketChunk: ConcurrentMap<Int, SocketChunkData> by lazy { ConcurrentHashMap() }
 
-    init {
-        val tStart = LocalDateTime.now()
-        fixedRateTimer("timer-$id", false, 20, 50) {
-            val listSocketChunk = mapSocketChunk.entries.sortedBy { it.key }.map { it.value }
-            if (listSocketChunk.size > 1 && listSocketChunk[0].totalPart == listSocketChunk.size) {
-                val sortedChunk = listSocketChunk.sortedBy { it.part }
-                val bodyList = sortedChunk.mapNotNull { it.body }
-                var bd = ByteArray(0)
-                bodyList.forEach { bd += it }
-                Singletons.responseQue.getOrPut(id) {
-                    Resp(
-                        bd,
-                        sortedChunk.last().status,
-                        listSocketChunk.firstOrNull { it.header != null }?.header?.entries?.associate {
-                            Pair(it.key, it.value.toTypedArray())
-                        }
-                    )
-                }
-
-                this.cancel()
-            }
-            if (Duration.between(tStart, LocalDateTime.now()).toMillis() > 10 * 60 * 1000) {
-                this.cancel()
-            }
-        }
-    }
-
+    @Synchronized
     fun add(dt: SocketChunkData) {
         mapSocketChunk.getOrPut(dt.part) { dt }
+        val listSocketChunk = mapSocketChunk.entries.sortedBy { it.key }.map { it.value }
+        if (listSocketChunk.isNotEmpty() && listSocketChunk[0].totalPart == listSocketChunk.size) {
+            println("----> $id")
+            val sortedChunk = listSocketChunk.sortedBy { it.part }
+            val bodyList = sortedChunk.mapNotNull { it.body }
+            var bd = ByteArray(0)
+            bodyList.forEach { bd += it }
+            Singletons.responseQue.getOrPut(id) {
+                Resp(
+                    bd,
+                    sortedChunk.last().status,
+                    listSocketChunk.firstOrNull { it.header != null }?.header?.entries?.associate {
+                        Pair(it.key, it.value.toTypedArray())
+                    }
+                )
+            }
+        }
     }
 }
 

+ 1 - 19
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/IpPhoneBridgeApplication.kt

@@ -17,27 +17,9 @@ class IpPhoneBridgeApplication
 
 fun main(args: Array<String>) {
     TimeZone.setDefault(TimeZone.getTimeZone("Asia/Jakarta"))
-    val properties = Properties()
-    val iniFIle = File("conf/general.ini")
-
-    properties["server.port"] = when {
-        System.getenv("PORT") != null -> {
-            System.getenv("PORT")
-        }
-        iniFIle.exists() -> {
-            val ini = Wini(iniFIle)
-            ini.get("server", "port") ?: "9090"
-        }
-        else -> {
-            "9090"
-        }
-    }
-
-
-
     val sApp = SpringApplication(IpPhoneBridgeApplication::class.java)
 
-    sApp.setDefaultProperties(properties)
+    sApp.setDefaultProperties(Singletons.properties())
     sApp.run(*args)
     //Configurator.reconfigure(URI("http://127.0.0.1:9090/log-setting.xml"))
     LogManager.getLogger("co.id.datacomsolusindo.ipphonebridge.IpPhoneBridgeApplication").info("Bridge Start")

+ 1 - 10
src/main/kotlin/co/id/datacomsolusindo/ipphonebridge/WebSocketEventListener.kt

@@ -29,16 +29,7 @@ class WebSocketEventListener {
     }
 
     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 = port ?: "9090"
-
-        Configurator.reconfigure(URI("http://127.0.0.1:$port/log-setting.xml"))
+        Configurator.reconfigure(URI("http://127.0.0.1:${Singletons.properties()["server.port"]}/log-setting.xml"))
     }
 
     @EventListener