Skip to content

Commit

Permalink
Merge pull request #15 from OSGP/FDP-1988-fix-threads-issue
Browse files Browse the repository at this point in the history
FDP-1988 ~ Fixes threads issue
  • Loading branch information
jasperkamerling authored Mar 6, 2024
2 parents a07a3e2 + 77ddf13 commit 266afbe
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.gxf.crestdevicesimulator.simulator

import com.fasterxml.jackson.databind.ObjectMapper
import org.eclipse.californium.core.CoapClient
import io.github.oshai.kotlinlogging.KotlinLogging
import org.eclipse.californium.core.coap.MediaTypeRegistry
import org.eclipse.californium.core.coap.Request
Expand Down Expand Up @@ -45,16 +46,18 @@ class Simulator(
}

private fun request(request: Request) {
var coapClient: CoapClient? = null
try {
val coapClient = coapClientService.createCoapClient()
coapClient = coapClientService.createCoapClient()
val response = coapClient.advanced(request)
responseHandler.handleResponse(response)
coapClientService.shutdownCoapClient(coapClient)
logger.info { "RESPONSE $response" }
} catch (e: ConnectorException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
} finally {
if (coapClient != null) coapClientService.shutdownCoapClient(coapClient)
}
}
}

0 comments on commit 266afbe

Please sign in to comment.