All Downloads are FREE. Search and download functionalities are using the official Maven repository.

helper.Timer.kt Maven / Gradle / Ivy

Go to download

This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.

There is a newer version: 0.15.1
Show newest version
package helper

import org.slf4j.LoggerFactory
import java.util.*

private val logger = LoggerFactory.getLogger(EcuTimerTask::class.java)

class EcuTimerTask(private val action: TimerTask.() -> Unit) : TimerTask() {
    private var _canBeRemoved = false

    override fun run() {
        try {
            action()
        } catch (e: Exception) {
            logger.error("Error while executing timer: " + e.stackTraceToString())
        } finally {
            _canBeRemoved = true
        }
    }

    override fun cancel(): Boolean {
        try {
            return super.cancel()
        } finally {
            _canBeRemoved = true
        }
    }

    val canBeRemoved
        get() = _canBeRemoved
}

fun Timer.scheduleEcuTimerTask(delay: Long, action: TimerTask.() -> Unit): EcuTimerTask {
    val task = EcuTimerTask(action)
    schedule(task, delay)
    return task
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy