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

dev.bpmcrafters.processengineapi.adapter.commons.task.InMemSubscriptionRepository.kt Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
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()
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy