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

br.com.guiabolso.events.context.EventThreadContextManager.kt Maven / Gradle / Ivy

There is a newer version: 8.0.4
Show newest version
package br.com.guiabolso.events.context

import br.com.guiabolso.tracing.context.ThreadContextManager
import java.io.Closeable

object EventThreadContextManager : ThreadContextManager {

    override val type = EventContext::class.java

    private val holder = ThreadLocal()

    val current: EventContext
        get() = holder.get() ?: EventContext()

    override fun extract(): EventContext {
        return current
    }

    override fun withContext(context: EventContext): Closeable {
        holder.set(context)
        return Closeable { holder.remove() }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy