Skip to content

Commit

Permalink
load locations resource #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Jul 21, 2022
1 parent 7183ff7 commit 09da07c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.utbot.jcdb.api.JCDB
import org.utbot.jcdb.impl.LibrariesMixin
import org.utbot.jcdb.jcdb
import java.nio.file.Files
import java.util.*
import java.util.concurrent.TimeUnit

@State(Scope.Benchmark)
Expand All @@ -17,7 +18,7 @@ import java.util.concurrent.TimeUnit
class RestoreDBBenchmark : LibrariesMixin {

companion object {
private val jdbcLocation = Files.createTempDirectory("jdbc").toFile().absolutePath
private val jdbcLocation = Files.createTempDirectory("jdbc-${UUID.randomUUID()}").toFile().absolutePath
}

var db: JCDB? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap
import kotlin.concurrent.thread


class RemoteRdServer(private val port: Int, val db: JCDBImpl) : Hook {
class RemoteRdServer(private val port: Int, private val db: JCDBImpl) : Hook {

companion object : KLogging()

Expand Down Expand Up @@ -42,7 +42,8 @@ class RemoteRdServer(private val port: Int, val db: JCDBImpl) : Hook {
CloseClasspathResource(classpaths),
GetClassResource(classpaths),
GetSubClassesResource(classpaths),
StopServerResource(this)
StopServerResource(this),
LoadLocationsResource()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ class GetClasspathResource(private val classpaths: ConcurrentHashMap<String, Cla
}
}

class LoadLocationsResource() : CallResource<GetClasspathReq, Unit>(10, "load-locations") {

override val serializers = listOf(GetClasspathReq)

override suspend fun JCDB.handler(req: GetClasspathReq) {
load(req.locations.map { File(it) }.filter { it.exists() })
}
}

class CloseClasspathResource(private val classpaths: ConcurrentHashMap<String, ClasspathSet> = ConcurrentHashMap()) :
CallResource<String, Unit>(2, "close-classpath") {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.utbot.jcdb.api.ClasspathSet
import org.utbot.jcdb.api.JCDB
import org.utbot.jcdb.remote.rd.*
import java.io.File
import java.nio.file.Paths

class RemoteJCDB(port: Int) : JCDB {

Expand All @@ -34,6 +35,7 @@ class RemoteJCDB(port: Int) : JCDB {

private val getId = GetGlobalIdResource().clientCall(clientProtocol)
private val getName = GetGlobalNameResource().clientCall(clientProtocol)
private val loadLocations = LoadLocationsResource().clientCall(clientProtocol)

init {
scheduler.flush()
Expand All @@ -52,16 +54,20 @@ class RemoteJCDB(port: Int) : JCDB {
)
}

override suspend fun load(dirOrJar: File): JCDB {
TODO("Not yet implemented")
override suspend fun load(dirOrJar: File): JCDB = apply {
loadLocations.startSuspending(GetClasspathReq(listOf(dirOrJar.absolutePath)))
}

override suspend fun load(dirOrJars: List<File>): JCDB {
TODO("Not yet implemented")
override suspend fun load(dirOrJars: List<File>): JCDB = apply {
loadLocations.startSuspending(GetClasspathReq(dirOrJars.map { it.absolutePath }))
}

override suspend fun loadLocations(locations: List<ByteCodeLocation>): JCDB {
TODO("Not yet implemented")
override suspend fun loadLocations(locations: List<ByteCodeLocation>): JCDB = apply {
loadLocations.startSuspending(
GetClasspathReq(
locations.map { Paths.get(it.locationURL.toURI()).toFile().absolutePath }
)
)
}

override suspend fun refresh() {
Expand Down

0 comments on commit 09da07c

Please sign in to comment.