@@ -25,7 +25,6 @@ import kotlinx.coroutines.launch
25
25
import kotlinx.coroutines.runBlocking
26
26
import kotlinx.datetime.Clock
27
27
import org.apache.commons.collections4.map.LRUMap
28
- import org.modelix.model.InMemoryModels
29
28
import org.modelix.model.ModelMigrations
30
29
import org.modelix.model.VersionMerger
31
30
import org.modelix.model.api.IBranch
@@ -51,7 +50,7 @@ import org.slf4j.LoggerFactory
51
50
import java.lang.ref.SoftReference
52
51
import java.util.UUID
53
52
54
- class RepositoriesManager (val client : LocalModelClient ) {
53
+ class RepositoriesManager (val client : LocalModelClient ) : IRepositoriesManager {
55
54
56
55
init {
57
56
fun migrateLegacyRepositoriesList (infoBranch : IBranch ) {
@@ -82,13 +81,6 @@ class RepositoriesManager(val client: LocalModelClient) {
82
81
83
82
private val store: IStoreClient get() = client.store
84
83
private val objectStore: IDeserializingKeyValueStore get() = client.storeCache
85
- val inMemoryModels = InMemoryModels ()
86
-
87
- fun dispose () {
88
- // TODO find instance creations and add a dispose() call if needed. Whoever creates an instance is responsible
89
- // for its lifecycle.
90
- inMemoryModels.dispose()
91
- }
92
84
93
85
fun generateClientId (repositoryId : RepositoryId ): Long {
94
86
return client.store.generateId(" $KEY_PREFIX :${repositoryId.id} :clientId" )
@@ -103,7 +95,7 @@ class RepositoriesManager(val client: LocalModelClient) {
103
95
* If the server ID was created previously but is only stored under a legacy database key,
104
96
* it also gets stored under the current and all legacy database keys.
105
97
*/
106
- suspend fun maybeInitAndGetSeverId (): String {
98
+ override suspend fun maybeInitAndGetSeverId (): String {
107
99
return store.runTransactionSuspendable {
108
100
var serverId = store[SERVER_ID_KEY ]
109
101
if (serverId == null ) {
@@ -118,7 +110,7 @@ class RepositoriesManager(val client: LocalModelClient) {
118
110
}
119
111
}
120
112
121
- fun getRepositories (): Set <RepositoryId > {
113
+ override fun getRepositories (): Set <RepositoryId > {
122
114
val repositoriesList = store[REPOSITORIES_LIST_KEY ]
123
115
val emptyRepositoriesList = repositoriesList.isNullOrBlank()
124
116
return if (emptyRepositoriesList) {
@@ -130,7 +122,7 @@ class RepositoriesManager(val client: LocalModelClient) {
130
122
131
123
private fun repositoryExists (repositoryId : RepositoryId ) = getRepositories().contains(repositoryId)
132
124
133
- suspend fun createRepository (repositoryId : RepositoryId , userName : String? , useRoleIds : Boolean = true ): CLVersion {
125
+ override suspend fun createRepository (repositoryId : RepositoryId , userName : String? , useRoleIds : Boolean ): CLVersion {
134
126
var initialVersion: CLVersion ? = null
135
127
store.runTransactionSuspendable {
136
128
val masterBranch = repositoryId.getBranchReference()
@@ -155,7 +147,7 @@ class RepositoriesManager(val client: LocalModelClient) {
155
147
return store[branchListKey(repositoryId)]?.lines()?.toSet() ? : emptySet()
156
148
}
157
149
158
- fun getBranches (repositoryId : RepositoryId ): Set <BranchReference > {
150
+ override fun getBranches (repositoryId : RepositoryId ): Set <BranchReference > {
159
151
return getBranchNames(repositoryId)
160
152
.map { repositoryId.getBranchReference(it) }
161
153
.sortedBy { it.branchName }
@@ -188,7 +180,7 @@ class RepositoriesManager(val client: LocalModelClient) {
188
180
}
189
181
}
190
182
191
- suspend fun removeRepository (repository : RepositoryId ): Boolean {
183
+ override suspend fun removeRepository (repository : RepositoryId ): Boolean {
192
184
return store.runTransactionSuspendable {
193
185
if (! repositoryExists(repository)) {
194
186
return @runTransactionSuspendable false
@@ -206,7 +198,7 @@ class RepositoriesManager(val client: LocalModelClient) {
206
198
}
207
199
}
208
200
209
- suspend fun removeBranches (repository : RepositoryId , branchNames : Set <String >) {
201
+ override suspend fun removeBranches (repository : RepositoryId , branchNames : Set <String >) {
210
202
return store.runTransactionSuspendable {
211
203
removeBranchesBlocking(repository, branchNames)
212
204
}
@@ -216,7 +208,7 @@ class RepositoriesManager(val client: LocalModelClient) {
216
208
* Same as [removeBranches] but blocking.
217
209
* Caller is expected to execute it outside the request thread.
218
210
*/
219
- fun removeBranchesBlocking (repository : RepositoryId , branchNames : Set <String >) {
211
+ override fun removeBranchesBlocking (repository : RepositoryId , branchNames : Set <String >) {
220
212
if (branchNames.isEmpty()) return
221
213
store.runTransaction {
222
214
val key = branchListKey(repository)
@@ -229,7 +221,7 @@ class RepositoriesManager(val client: LocalModelClient) {
229
221
}
230
222
}
231
223
232
- suspend fun mergeChanges (branch : BranchReference , newVersionHash : String ): String {
224
+ override suspend fun mergeChanges (branch : BranchReference , newVersionHash : String ): String {
233
225
return store.runTransactionSuspendable {
234
226
mergeChangesBlocking(branch, newVersionHash)
235
227
}
@@ -239,7 +231,7 @@ class RepositoriesManager(val client: LocalModelClient) {
239
231
* Same as [mergeChanges] but blocking.
240
232
* Caller is expected to execute it outside the request thread.
241
233
*/
242
- fun mergeChangesBlocking (branch : BranchReference , newVersionHash : String ): String {
234
+ override fun mergeChangesBlocking (branch : BranchReference , newVersionHash : String ): String {
243
235
return store.runTransaction {
244
236
val headHash = getVersionHashBlocking(branch)
245
237
val mergedHash = if (headHash == null ) {
@@ -262,11 +254,11 @@ class RepositoriesManager(val client: LocalModelClient) {
262
254
}
263
255
}
264
256
265
- suspend fun getVersion (branch : BranchReference ): CLVersion ? {
257
+ override suspend fun getVersion (branch : BranchReference ): CLVersion ? {
266
258
return getVersionHash(branch)?.let { CLVersion .loadFromHash(it, client.storeCache) }
267
259
}
268
260
269
- suspend fun getVersionHash (branch : BranchReference ): String? {
261
+ override suspend fun getVersionHash (branch : BranchReference ): String? {
270
262
return store.runTransactionSuspendable {
271
263
getVersionHashBlocking(branch)
272
264
}
@@ -293,13 +285,13 @@ class RepositoriesManager(val client: LocalModelClient) {
293
285
store.put(legacyBranchKey(branch), hash, false )
294
286
}
295
287
296
- suspend fun pollVersionHash (branch : BranchReference , lastKnown : String? ): String {
288
+ override suspend fun pollVersionHash (branch : BranchReference , lastKnown : String? ): String {
297
289
return pollEntry(client.store, branchKey(branch), lastKnown)
298
290
? : throw IllegalStateException (" No version found for branch '${branch.branchName} ' in repository '${branch.repositoryId} '" )
299
291
}
300
292
301
293
private val versionDeltaCache = VersionDeltaCache (client.storeCache)
302
- suspend fun computeDelta (versionHash : String , baseVersionHash : String? ): ObjectData {
294
+ override suspend fun computeDelta (versionHash : String , baseVersionHash : String? ): ObjectData {
303
295
if (versionHash == baseVersionHash) return ObjectData .empty
304
296
if (baseVersionHash == null ) {
305
297
// no need to cache anything if there is no delta computation happening
0 commit comments