dev.bpmcrafters.processengineapi.adapter.commons.task.InMemSubscriptionRepository.kt Maven / Gradle / Ivy
package dev.bpmcrafters.processengineapi.adapter.commons.task
import dev.bpmcrafters.processengineapi.task.TaskType
import java.util.concurrent.ConcurrentHashMap
/**
* Trivial in-memory implementation of the repository.
*/
class InMemSubscriptionRepository : SubscriptionRepository {
private val subscriptions: MutableList = mutableListOf()
private val activeSubscribedHandler: ConcurrentHashMap = ConcurrentHashMap()
override fun getTaskSubscriptions(): List = subscriptions.toList()
override fun createTaskSubscription(subscription: TaskSubscriptionHandle) {
subscriptions.add(subscription)
}
override fun deleteTaskSubscription(subscription: TaskSubscriptionHandle) {
subscriptions.remove(subscription)
}
override fun getActiveSubscriptionForTask(taskId: String): TaskSubscriptionHandle? {
return activeSubscribedHandler[taskId]
}
override fun activateSubscriptionForTask(taskId: String, subscription: TaskSubscriptionHandle) {
this.activeSubscribedHandler[taskId] = subscription
}
override fun deactivateSubscriptionForTask(taskId: String): TaskSubscriptionHandle? {
return this.activeSubscribedHandler.remove(taskId)
}
override fun getDeliveredTaskIds(taskType: TaskType) : List {
return this.activeSubscribedHandler.filter {
it.value.taskType == taskType
}.keys.toList()
}
fun deleteAllTaskSubscriptions() {
subscriptions.clear()
activeSubscribedHandler.clear()
}
}