From 65b3e1315a7932b9396f6495f19a1fce0b627687 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 16 May 2021 13:47:56 +0100 Subject: [PATCH] Add Store and Js5MasterIndex providers Signed-off-by: Graham --- .../main/kotlin/org/openrs2/cache/CacheModule.kt | 9 +++++++++ .../org/openrs2/cache/Js5MasterIndexProvider.kt | 12 ++++++++++++ .../main/kotlin/org/openrs2/cache/StoreProvider.kt | 14 ++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndexProvider.kt create mode 100644 cache/src/main/kotlin/org/openrs2/cache/StoreProvider.kt diff --git a/cache/src/main/kotlin/org/openrs2/cache/CacheModule.kt b/cache/src/main/kotlin/org/openrs2/cache/CacheModule.kt index 16691153..abf492cc 100644 --- a/cache/src/main/kotlin/org/openrs2/cache/CacheModule.kt +++ b/cache/src/main/kotlin/org/openrs2/cache/CacheModule.kt @@ -1,6 +1,7 @@ package org.openrs2.cache import com.google.inject.AbstractModule +import com.google.inject.Scopes import org.openrs2.buffer.BufferModule import org.openrs2.crypto.CryptoModule @@ -8,5 +9,13 @@ public object CacheModule : AbstractModule() { override fun configure() { install(BufferModule) install(CryptoModule) + + bind(Store::class.java) + .toProvider(StoreProvider::class.java) + .`in`(Scopes.SINGLETON) + + bind(Js5MasterIndex::class.java) + .toProvider(Js5MasterIndexProvider::class.java) + .`in`(Scopes.SINGLETON) } } diff --git a/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndexProvider.kt b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndexProvider.kt new file mode 100644 index 00000000..10844646 --- /dev/null +++ b/cache/src/main/kotlin/org/openrs2/cache/Js5MasterIndexProvider.kt @@ -0,0 +1,12 @@ +package org.openrs2.cache + +import javax.inject.Inject +import javax.inject.Provider + +public class Js5MasterIndexProvider @Inject constructor( + private val store: Store +) : Provider { + override fun get(): Js5MasterIndex { + return Js5MasterIndex.create(store) + } +} diff --git a/cache/src/main/kotlin/org/openrs2/cache/StoreProvider.kt b/cache/src/main/kotlin/org/openrs2/cache/StoreProvider.kt new file mode 100644 index 00000000..1643eb3d --- /dev/null +++ b/cache/src/main/kotlin/org/openrs2/cache/StoreProvider.kt @@ -0,0 +1,14 @@ +package org.openrs2.cache + +import io.netty.buffer.ByteBufAllocator +import java.nio.file.Path +import javax.inject.Inject +import javax.inject.Provider + +public class StoreProvider @Inject constructor( + private val alloc: ByteBufAllocator +) : Provider { + override fun get(): Store { + return Store.open(Path.of("nonfree/share/cache"), alloc) + } +}