
org.bdd.reporting.events.EventBusImpl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bdd-reporting-service Show documentation
Show all versions of bdd-reporting-service Show documentation
BDD Enterprise Reporting Server. This server provides the ability to upload reports from tools like Cucumber,
SpecFlow, Pickles and the information is then aggregated into a central view across all projects.
The newest version!
package org.bdd.reporting.events
import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Service
/**
*/
@Service("DbEventBus")
@Suppress("UNCHECKED_CAST")
class EventBusImpl(val objectMapper : ObjectMapper) : EventBus {
private val registrations : MutableMap Unit>> = mutableMapOf()
override fun send(name: String, event: T) {
// val localEvent = DbEvent(name, UUID.randomUUID().toString(), Date(), objectMapper.writeValueAsString(event))
sendEvents(name, event)
}
override fun send(name: String, id : String, event: T) {
sendEvents(name, event)
}
override fun register(name: String, consumer : (T) -> Unit) {
var list = registrations[name]
if (null == list) {
list = mutableListOf()
registrations[name] = list
}
list.add(consumer as (Any) -> Unit)
}
private fun sendEvents(topic : String, event : T) {
registrations[topic]?.forEach {
val handler = it as ((T) -> Unit)
handler(event)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy