ILifecycle
This commit is contained in:
1 parent
2919e9731a
commit
0eb4fbcaa3
7 files changed
+22
-11
No files matched your search
@@ -3,6 +3,7 @@ package no.iktdev.eventi.events
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import no.iktdev.eventi.MyTime
|
import no.iktdev.eventi.MyTime
|
||||||
|
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleStore
|
import no.iktdev.eventi.lifecycle.LifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.ListenerFatalError
|
import no.iktdev.eventi.lifecycle.ListenerFatalError
|
||||||
import no.iktdev.eventi.lifecycle.ListenerResult
|
import no.iktdev.eventi.lifecycle.ListenerResult
|
||||||
@@ -14,7 +15,7 @@ import no.iktdev.eventi.registry.EventListenerRegistry
|
|||||||
import no.iktdev.eventi.stores.EventStore
|
import no.iktdev.eventi.stores.EventStore
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
open class EventDispatcher(val eventStore: EventStore, private val lifecycleStore: LifecycleStore) {
|
open class EventDispatcher(val eventStore: EventStore, private val lifecycleStore: ILifecycleStore) {
|
||||||
|
|
||||||
private val log = KotlinLogging.logger {}
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import no.iktdev.eventi.MyTime
|
|||||||
import no.iktdev.eventi.PollerTraceStore
|
import no.iktdev.eventi.PollerTraceStore
|
||||||
import no.iktdev.eventi.lifecycle.CurrentState
|
import no.iktdev.eventi.lifecycle.CurrentState
|
||||||
import no.iktdev.eventi.lifecycle.EventState
|
import no.iktdev.eventi.lifecycle.EventState
|
||||||
|
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleStore
|
import no.iktdev.eventi.lifecycle.LifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.PollerBackoff
|
import no.iktdev.eventi.lifecycle.PollerBackoff
|
||||||
import no.iktdev.eventi.lifecycle.PollerCycleStart
|
import no.iktdev.eventi.lifecycle.PollerCycleStart
|
||||||
@@ -27,7 +28,7 @@ abstract class EventPollerImplementation(
|
|||||||
private val eventStore: EventStore,
|
private val eventStore: EventStore,
|
||||||
private val dispatchQueue: SequenceDispatchQueue,
|
private val dispatchQueue: SequenceDispatchQueue,
|
||||||
private val dispatcher: EventDispatcher,
|
private val dispatcher: EventDispatcher,
|
||||||
private val lifecycleStore: LifecycleStore
|
private val lifecycleStore: ILifecycleStore
|
||||||
) {
|
) {
|
||||||
private val log = KotlinLogging.logger {}
|
private val log = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import no.iktdev.eventi.lifecycle.DispatchExceptionEntry
|
|||||||
import no.iktdev.eventi.lifecycle.DispatchQueueAcquired
|
import no.iktdev.eventi.lifecycle.DispatchQueueAcquired
|
||||||
import no.iktdev.eventi.lifecycle.DispatchQueueReleased
|
import no.iktdev.eventi.lifecycle.DispatchQueueReleased
|
||||||
import no.iktdev.eventi.lifecycle.DispatchQueueSkipped
|
import no.iktdev.eventi.lifecycle.DispatchQueueSkipped
|
||||||
|
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleStore
|
import no.iktdev.eventi.lifecycle.LifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.RefDispatchCompleted
|
import no.iktdev.eventi.lifecycle.RefDispatchCompleted
|
||||||
import no.iktdev.eventi.lifecycle.RefDispatchStarted
|
import no.iktdev.eventi.lifecycle.RefDispatchStarted
|
||||||
@@ -22,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap
|
|||||||
open class SequenceDispatchQueue(
|
open class SequenceDispatchQueue(
|
||||||
private val maxConcurrency: Int = 8,
|
private val maxConcurrency: Int = 8,
|
||||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()),
|
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default + SupervisorJob()),
|
||||||
private val lifecycleStore: LifecycleStore
|
private val lifecycleStore: ILifecycleStore
|
||||||
) {
|
) {
|
||||||
private val semaphore = Semaphore(maxConcurrency)
|
private val semaphore = Semaphore(maxConcurrency)
|
||||||
private val active = ConcurrentHashMap.newKeySet<UUID>()
|
private val active = ConcurrentHashMap.newKeySet<UUID>()
|
||||||
|
|||||||
@@ -3,12 +3,19 @@ package no.iktdev.eventi.lifecycle
|
|||||||
import java.util.ArrayDeque
|
import java.util.ArrayDeque
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class LifecycleStore(private val capacity: Int = 50_000) {
|
interface ILifecycleStore {
|
||||||
|
fun add(entry: LifecycleEntry)
|
||||||
|
fun getAll(): List<LifecycleEntry>
|
||||||
|
fun getForRef(ref: UUID): List<LifecycleEntry>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class LifecycleStore(private val capacity: Int = 50_000): ILifecycleStore {
|
||||||
|
|
||||||
private val buffer = ArrayDeque<LifecycleEntry>(capacity)
|
private val buffer = ArrayDeque<LifecycleEntry>(capacity)
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun add(entry: LifecycleEntry) {
|
override fun add(entry: LifecycleEntry) {
|
||||||
if (buffer.size >= capacity) {
|
if (buffer.size >= capacity) {
|
||||||
buffer.removeFirst()
|
buffer.removeFirst()
|
||||||
}
|
}
|
||||||
@@ -16,11 +23,11 @@ class LifecycleStore(private val capacity: Int = 50_000) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getAll(): List<LifecycleEntry> =
|
override fun getAll(): List<LifecycleEntry> =
|
||||||
buffer.toList()
|
buffer.toList()
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getForRef(ref: UUID): List<LifecycleEntry> =
|
override fun getForRef(ref: UUID): List<LifecycleEntry> =
|
||||||
buffer.filter {
|
buffer.filter {
|
||||||
when (it) {
|
when (it) {
|
||||||
is RefFiltered -> it.ref == ref
|
is RefFiltered -> it.ref == ref
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.UUID
|
|||||||
|
|
||||||
class LifecycleTaskReporter(
|
class LifecycleTaskReporter(
|
||||||
private val delegate: TaskReporter,
|
private val delegate: TaskReporter,
|
||||||
private val lifecycleStore: LifecycleStore
|
private val lifecycleStore: ILifecycleStore
|
||||||
) : TaskReporter {
|
) : TaskReporter {
|
||||||
override fun markClaimed(taskId: UUID, workerId: String): Result {
|
override fun markClaimed(taskId: UUID, workerId: String): Result {
|
||||||
lifecycleStore.add(
|
lifecycleStore.add(
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ enum class TimelineCategory {
|
|||||||
ERROR
|
ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
fun LifecycleStore.timeline(): List<TimelineEntry> =
|
fun ILifecycleStore.timeline(): List<TimelineEntry> =
|
||||||
getAll().map { it.toTimeline() }.sortedBy { it.timestamp }
|
getAll().map { it.toTimeline() }.sortedBy { it.timestamp }
|
||||||
|
|
||||||
fun LifecycleStore.timelineForRef(ref: UUID): List<TimelineEntry> =
|
fun ILifecycleStore.timelineForRef(ref: UUID): List<TimelineEntry> =
|
||||||
getForRef(ref).map { it.toTimeline() }.sortedBy { it.timestamp }
|
getForRef(ref).map { it.toTimeline() }.sortedBy { it.timestamp }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.time.delay
|
import kotlinx.coroutines.time.delay
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import no.iktdev.eventi.MyTime
|
import no.iktdev.eventi.MyTime
|
||||||
|
import no.iktdev.eventi.lifecycle.ILifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleStore
|
import no.iktdev.eventi.lifecycle.LifecycleStore
|
||||||
import no.iktdev.eventi.lifecycle.LifecycleTaskReporter
|
import no.iktdev.eventi.lifecycle.LifecycleTaskReporter
|
||||||
import no.iktdev.eventi.lifecycle.TaskListenerFatalError
|
import no.iktdev.eventi.lifecycle.TaskListenerFatalError
|
||||||
@@ -23,7 +24,7 @@ import java.time.Duration
|
|||||||
|
|
||||||
abstract class TaskPollerImplementation(
|
abstract class TaskPollerImplementation(
|
||||||
private val taskStore: TaskStore,
|
private val taskStore: TaskStore,
|
||||||
private val lifecycleStore: LifecycleStore,
|
private val lifecycleStore: ILifecycleStore,
|
||||||
private val reporterFactory: (Task) -> TaskReporter,
|
private val reporterFactory: (Task) -> TaskReporter,
|
||||||
) {
|
) {
|
||||||
private val log = KotlinLogging.logger {}
|
private val log = KotlinLogging.logger {}
|
||||||
|
|||||||
Reference in new issue
Block a user