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

main.app.cash.backfila.client.jooq.JooqBackfillModule.kt Maven / Gradle / Ivy

Go to download

Backfila is a service that manages backfill state, calling into other services to do batched work.

There is a newer version: 2024.10.28.205607-fab304f
Show newest version
package app.cash.backfila.client.jooq

import app.cash.backfila.client.RealBackfillModule
import app.cash.backfila.client.jooq.internal.JooqBackend
import app.cash.backfila.client.spi.BackfillBackend
import com.google.inject.AbstractModule
import com.google.inject.Binder
import com.google.inject.TypeLiteral
import com.google.inject.multibindings.MapBinder
import com.google.inject.multibindings.Multibinder
import javax.inject.Qualifier
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName

/**
 * Installs the [BackfillBackend] for Hibernate backfills. See the java doc for [RealBackfillModule].
 */
class JooqBackfillModule> private constructor(
  private val backfillClass: KClass,
) : AbstractModule() {
  override fun configure() {
    install(JooqBackfillBackendModule)
    // Ensures that the backfill class is injectable. If you are failing this check you probably
    // want to add an @Inject annotation to your class or check that all of your dependencies are provided.
    binder().getProvider(backfillClass.java)
    mapBinder(binder()).addBinding(backfillClass.jvmName).toInstance(backfillClass)
  }

  companion object {
    inline fun > create(): JooqBackfillModule = create(T::class)

    @JvmStatic
    fun > create(backfillClass: KClass): JooqBackfillModule {
      return JooqBackfillModule(backfillClass)
    }

    @JvmStatic
    fun > create(backfillClass: Class): JooqBackfillModule {
      return JooqBackfillModule(backfillClass.kotlin)
    }
  }
}

/**
 * This is a kotlin object so these dependencies are only installed once.
 */
private object JooqBackfillBackendModule : AbstractModule() {
  override fun configure() {
    Multibinder.newSetBinder(binder(), BackfillBackend::class.java).addBinding()
      .to(JooqBackend::class.java)
  }
}

private fun mapBinder(binder: Binder) = MapBinder.newMapBinder(
  binder,
  object : TypeLiteral() {},
  object : TypeLiteral>>() {},
  ForJooqBackend::class.java,
)

/** Annotation for specifying dependencies specifically for this Backend. */
@Qualifier annotation class ForJooqBackend




© 2015 - 2024 Weber Informatics LLC | Privacy Policy