ai.platon.pulsar.common.collect.DelayCacheCollector.kt Maven / Gradle / Ivy
package ai.platon.pulsar.common.collect
import ai.platon.pulsar.common.Priority13
import ai.platon.pulsar.common.collect.collector.AbstractPriorityDataCollector
import ai.platon.pulsar.common.urls.UrlAware
import java.util.*
open class DelayCacheCollector(
val queue: Queue,
priority: Int = Priority13.HIGHER.value
) : AbstractPriorityDataCollector(priority) {
override var name = "DelayCacheC"
override val size: Int
get() = queue.size
constructor(queue: Queue, priority: Priority13) : this(queue, priority.value)
@Synchronized
override fun hasMore() = queue.isNotEmpty()
@Synchronized
override fun collectTo(sink: MutableList): Int {
beforeCollect()
val count = queue.poll()?.takeIf { sink.add(it.url) }?.let { 1 } ?: 0
return afterCollect(count)
}
@Synchronized
override fun dump(): List {
return queue.map { it.url.toString() + " delay: " + it.delay }
}
override fun clear() = queue.clear()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy