From: David ‘Bombe’ Roden Date: Sun, 20 Nov 2016 00:14:04 +0000 (+0100) Subject: Add some logging to element loader X-Git-Tag: 0.9.7^2~415 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7a70c5564da777276295d6ec29ab76446425bb36;p=Sone.git Add some logging to element loader --- diff --git a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt index ac3ab6a..3f33efe 100644 --- a/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt +++ b/src/main/kotlin/net/pterodactylus/sone/core/DefaultElementLoader.kt @@ -20,27 +20,32 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke private val imageCache = CacheBuilder.newBuilder().build() private val callback = object : FreenetInterface.BackgroundFetchCallback { override fun cancelForMimeType(uri: FreenetURI, mimeType: String): Boolean { + println("Got MIME Type “$mimeType” for $uri.") return !mimeType.startsWith("image/") } override fun loaded(uri: FreenetURI, mimeType: String, data: ByteArray) { + println("Got ${data.size} Bytes with MIME Type $mimeType for $uri.") if (!mimeType.startsWith("image/")) { return } ByteArrayInputStream(data).use { ImageIO.read(it) }?.let { + println("Successfully parsed images from $uri.") imageCache.get(uri.toString()) { LinkedElement(uri.toString()) } } removeLoadingLink(uri) } override fun failed(uri: FreenetURI) { + println("Failed to load $uri.") failureCache.put(uri.toString(), true) removeLoadingLink(uri) } private fun removeLoadingLink(uri: FreenetURI) { + println("Not loading anymore: $uri.") synchronized(loadingLinks) { loadingLinks.invalidate(uri.toString()) } @@ -48,18 +53,23 @@ class DefaultElementLoader(private val freenetInterface: FreenetInterface, ticke } override fun loadElement(link: String): LinkedElement { + println("Checking for $link...") synchronized(loadingLinks) { imageCache.getIfPresent(link)?.run { + println("In the Image Cache: $link") return this } failureCache.getIfPresent(link)?.run { + println("In the Failure Cache: $link") return LinkedElement(link, failed = true) } if (loadingLinks.getIfPresent(link) == null) { + println("Not loading: $link") loadingLinks.put(link, true) freenetInterface.startFetch(FreenetURI(link), callback) } } + println("Returning loading element: $link") return LinkedElement(link, loading = true) }