Skip to content

Commit

Permalink
add access to JcDatabase#features
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Nov 29, 2023
1 parent b01fdc7 commit 1c6a543
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
4 changes: 3 additions & 1 deletion jacodb-api/src/main/kotlin/org/jacodb/api/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ interface JcDatabase : Closeable {
suspend fun awaitBackgroundJobs()
fun asyncAwaitBackgroundJobs() = GlobalScope.future { awaitBackgroundJobs() }

fun isInstalled(feature: JcFeature<*, *>): Boolean
fun isInstalled(feature: JcFeature<*, *>): Boolean = features.contains(feature)

val features: List<JcFeature<*, *>>
}


Expand Down
20 changes: 5 additions & 15 deletions jacodb-core/src/main/kotlin/org/jacodb/impl/FeaturesRegistry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@

package org.jacodb.impl

import org.jacodb.api.ByteCodeIndexer
import org.jacodb.api.ClassSource
import org.jacodb.api.JcDatabase
import org.jacodb.api.JcFeature
import org.jacodb.api.JcSignal
import org.jacodb.api.RegisteredLocation
import kotlinx.collections.immutable.toPersistentList
import org.jacodb.api.*
import org.jacodb.impl.fs.fullAsmNode
import java.io.Closeable

class FeaturesRegistry(private val features: List<JcFeature<*, *>>) : Closeable {
class FeaturesRegistry(features: List<JcFeature<*, *>>) : Closeable {

val features = features.toPersistentList()

private lateinit var jcdb: JcDatabase

fun bind(jcdb: JcDatabase) {
this.jcdb = jcdb
}

fun has(feature: JcFeature<*, *>): Boolean {
return features.contains(feature)
}

fun index(location: RegisteredLocation, classes: List<ClassSource>) {
features.forEach { feature ->
feature.index(location, classes)
Expand All @@ -58,10 +52,6 @@ class FeaturesRegistry(private val features: List<JcFeature<*, *>>) : Closeable
features.forEach { it.onSignal(signal.asJcSignal(jcdb)) }
}

fun forEach(action: (JcDatabase, JcFeature<*, *>) -> Unit) {
features.forEach { action(jcdb, it) }
}

override fun close() {
}

Expand Down
5 changes: 2 additions & 3 deletions jacodb-core/src/main/kotlin/org/jacodb/impl/JcDatabaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ class JcDatabaseImpl(
backgroundJobs.values.joinAll()
}

override fun isInstalled(feature: JcFeature<*, *>): Boolean {
return featureRegistry.has(feature)
}
override val features: List<JcFeature<*, *>>
get() = featureRegistry.features

suspend fun afterStart() {
hooks.forEach { it.afterStart() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ public void jcdbOperations() throws ExecutionException, InterruptedException, IO
System.out.println("asyncRebuildFeatures finished");
instance.asyncAwaitBackgroundJobs().get();
System.out.println("asyncAwaitBackgroundJobs finished");
instance.getFeatures();
}
}

0 comments on commit 1c6a543

Please sign in to comment.