scray.querying.source.TimeoutMappingSource.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scray-querying Show documentation
Show all versions of scray-querying Show documentation
query engine core source code
package scray.querying.source
import com.typesafe.scalalogging.slf4j.LazyLogging
import scray.querying.description.Row
import scray.querying.queries.DomainQuery
import scray.querying.description.EmptyRow
import scray.querying.description.internal.SingleValueDomain
import scray.querying.description.internal.QueryTimeOutException
/**
* Check if query timed out. Triggered by received data.
*/
class TimeoutMappingSource [Q <: DomainQuery](source: LazySource[Q]) extends LazyQueryMappingSource[Q](source) with LazyLogging {
var startTime: Long = 0;
override def transformSpoolElement(element: Row, query: Q): Row = {
query.getQueryRange.filter(queryRange => queryRange.timeout match {
case None => false
case Some(time) => {(time * 1000 + startTime) < System.currentTimeMillis()}
}) match {
case None => element
case Some(x) => throw new QueryTimeOutException(query)
}
}
override def init(query: Q): Unit = {
startTime = System.currentTimeMillis();
}
def getColumns: Set[scray.querying.description.Column] = { source.getColumns }
def getDiscriminant: String = {"Timeout" + source.getDiscriminant}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy