Skip to content

Commit

Permalink
fix: 缓存jar加载
Browse files Browse the repository at this point in the history
  • Loading branch information
Greatwallcorner committed Jul 16, 2024
1 parent 74a4baf commit cdbf4db
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import com.corner.catvodcore.util.Paths
import com.corner.catvodcore.util.Urls
import com.corner.catvodcore.util.Utils
import com.github.catvod.crawler.Spider
import org.slf4j.LoggerFactory
import java.io.File
import java.lang.reflect.Method
import java.net.URLClassLoader
import java.util.concurrent.ConcurrentHashMap

object JarLoader {
private val log = LoggerFactory.getLogger(this::class.java)
private val loaders: ConcurrentHashMap<String, URLClassLoader> by lazy { ConcurrentHashMap() }

//proxy method
Expand All @@ -35,7 +37,7 @@ object JarLoader {

// 可以避免重复下载
if(md5.isNotEmpty() && Utils.equals(parseJarUrl(jar), md5)){
load(key, Paths.jar(jar))
load(key, Paths.jar(parseJarUrl(jar)))
}else if (jar.startsWith("file")) {
load(key, Paths.local(jar))
} else if (jar.startsWith("http")) {
Expand All @@ -55,6 +57,7 @@ object JarLoader {
}

private fun load(key: String, jar: File) {
log.debug("load jar {}", jar)
loaders[key] = URLClassLoader(arrayOf(jar.toURI().toURL()),this.javaClass.classLoader)
putProxy(key)
invokeInit(key)
Expand Down Expand Up @@ -101,7 +104,9 @@ object JarLoader {
}

private fun download(jar: String): File {
return Paths.write(Paths.jar(jar), Http.Get(jar).execute().body.bytes())
val jarPath = Paths.jar(jar)
log.debug("download jar file {} to:{}",jar, jarPath)
return Paths.write(jarPath, Http.Get(jar).execute().body.bytes())
}

fun proxyInvoke(params: Map<String, String>): Array<Any>? {
Expand Down

0 comments on commit cdbf4db

Please sign in to comment.